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 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <string.h> |
| 16 | #include <netdb.h> |
| 17 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 18 | #include <pwd.h> |
| 19 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 20 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 26 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 27 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 29 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 30 | #include <common/memory.h> |
| 31 | #include <common/standard.h> |
| 32 | #include <common/time.h> |
| 33 | #include <common/uri_auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | |
| 35 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 36 | #include <types/compression.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 37 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 38 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 39 | #include <types/peers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 41 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 42 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 44 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 46 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 47 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 49 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 50 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 51 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 52 | #include <proto/lb_fwlc.h> |
| 53 | #include <proto/lb_fwrr.h> |
| 54 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 55 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 56 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 57 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 58 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 59 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 60 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 61 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 62 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 63 | #include <proto/sample.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 64 | #include <proto/server.h> |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 65 | #include <proto/session.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 66 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 67 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 68 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 69 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 70 | #ifdef USE_OPENSSL |
| 71 | #include <types/ssl_sock.h> |
| 72 | #include <proto/ssl_sock.h> |
| 73 | #include <proto/shctx.h> |
| 74 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 76 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 77 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 78 | * |
| 79 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 80 | */ |
| 81 | const char sslv3_client_hello_pkt[] = { |
| 82 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 83 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 84 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 85 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 86 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 87 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 88 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 89 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 90 | "\x00" /* Session ID length : empty (no session ID) */ |
| 91 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 92 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 93 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 94 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 95 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 96 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 97 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 98 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 99 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 100 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 101 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 102 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 103 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 104 | }; |
| 105 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 106 | /* various keyword modifiers */ |
| 107 | enum kw_mod { |
| 108 | KWM_STD = 0, /* normal */ |
| 109 | KWM_NO, /* "no" prefixed before the keyword */ |
| 110 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 111 | }; |
| 112 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 113 | /* permit to store configuration section */ |
| 114 | struct cfg_section { |
| 115 | struct list list; |
| 116 | char *section_name; |
| 117 | int (*section_parser)(const char *, int, char **, int); |
| 118 | }; |
| 119 | |
| 120 | /* Used to chain configuration sections definitions. This list |
| 121 | * stores struct cfg_section |
| 122 | */ |
| 123 | struct list sections = LIST_HEAD_INIT(sections); |
| 124 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 125 | /* 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] | 126 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 127 | const char *name; |
| 128 | unsigned int val; |
| 129 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 130 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 131 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | /* proxy->options */ |
| 135 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 136 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 137 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 138 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 139 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 140 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 141 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 142 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 143 | { "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] | 144 | { "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] | 145 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 146 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 147 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 148 | { "redispatch", PR_O_REDISP, PR_CAP_BE, 0, 0 }, |
| 149 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 150 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 151 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 152 | #else |
| 153 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 154 | #endif |
| 155 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 156 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 157 | }; |
| 158 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 159 | /* proxy->options2 */ |
| 160 | static const struct cfg_opt cfg_opts2[] = |
| 161 | { |
| 162 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 163 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 164 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 165 | { "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] | 166 | #else |
| 167 | { "splice-request", 0, 0, 0, 0 }, |
| 168 | { "splice-response", 0, 0, 0, 0 }, |
| 169 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 170 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 171 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 172 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 173 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 174 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 175 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 176 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 177 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 178 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 179 | { "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] | 180 | { "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] | 181 | { "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] | 182 | { "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] | 183 | { "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] | 184 | { NULL, 0, 0, 0 } |
| 185 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 186 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 187 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 188 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 189 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 190 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 191 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 192 | /* List head of all known configuration keywords */ |
| 193 | static struct cfg_kw_list cfg_keywords = { |
| 194 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 195 | }; |
| 196 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 197 | /* |
| 198 | * converts <str> to a list of listeners which are dynamically allocated. |
| 199 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 200 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 201 | * - <port> is a numerical port from 1 to 65535 ; |
| 202 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 203 | * 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] | 204 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 205 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 206 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 207 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 208 | 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] | 209 | { |
| 210 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 211 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 212 | int port, end; |
| 213 | |
| 214 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 215 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 216 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 217 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 218 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 219 | |
| 220 | str = next; |
| 221 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 222 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 223 | *next++ = 0; |
| 224 | } |
| 225 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 226 | ss2 = str2sa_range(str, &port, &end, err, |
| 227 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix); |
| 228 | if (!ss2) |
| 229 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 230 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 231 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 232 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 233 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 234 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 235 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 236 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 237 | if (!port || !end) { |
| 238 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 239 | goto fail; |
| 240 | } |
| 241 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 242 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 243 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 244 | goto fail; |
| 245 | } |
| 246 | |
| 247 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 248 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 249 | goto fail; |
| 250 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 251 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 252 | else if (ss2->ss_family == AF_UNSPEC) { |
| 253 | socklen_t addr_len; |
| 254 | |
| 255 | /* We want to attach to an already bound fd whose number |
| 256 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 257 | * Note that by definition there is a single listener. |
| 258 | * We still have to determine the address family to |
| 259 | * register the correct protocol. |
| 260 | */ |
| 261 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 262 | addr_len = sizeof(*ss2); |
| 263 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 264 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 265 | goto fail; |
| 266 | } |
| 267 | |
| 268 | port = end = get_host_port(ss2); |
| 269 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 270 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 271 | /* OK the address looks correct */ |
| 272 | ss = *ss2; |
| 273 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 274 | for (; port <= end; port++) { |
| 275 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 276 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 277 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 278 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 279 | l->frontend = curproxy; |
| 280 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 281 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 282 | l->fd = fd; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 283 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 284 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 285 | l->state = LI_INIT; |
| 286 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 287 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 288 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 289 | tcpv4_add_listener(l); |
| 290 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 291 | else if (ss.ss_family == AF_INET6) { |
| 292 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 293 | tcpv6_add_listener(l); |
| 294 | } |
| 295 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 296 | uxst_add_listener(l); |
| 297 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 298 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 299 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 300 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 301 | } /* end for(port) */ |
| 302 | } /* end while(next) */ |
| 303 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 304 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 305 | fail: |
| 306 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 307 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 310 | /* Report a warning if a rule is placed after a 'block' rule. |
| 311 | * Return 1 if the warning has been emitted, otherwise 0. |
| 312 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 313 | 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] | 314 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 315 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 316 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 317 | file, line, arg); |
| 318 | return 1; |
| 319 | } |
| 320 | return 0; |
| 321 | } |
| 322 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 323 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 324 | * Return 1 if the warning has been emitted, otherwise 0. |
| 325 | */ |
| 326 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 327 | { |
| 328 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 329 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 330 | file, line, arg); |
| 331 | return 1; |
| 332 | } |
| 333 | return 0; |
| 334 | } |
| 335 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 336 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 337 | * Return 1 if the warning has been emitted, otherwise 0. |
| 338 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 339 | 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] | 340 | { |
| 341 | if (proxy->req_exp) { |
| 342 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 343 | file, line, arg); |
| 344 | return 1; |
| 345 | } |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | /* Report a warning if a rule is placed after a reqadd rule. |
| 350 | * Return 1 if the warning has been emitted, otherwise 0. |
| 351 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 352 | 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] | 353 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 354 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 355 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 356 | file, line, arg); |
| 357 | return 1; |
| 358 | } |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /* Report a warning if a rule is placed after a redirect rule. |
| 363 | * Return 1 if the warning has been emitted, otherwise 0. |
| 364 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 365 | 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] | 366 | { |
| 367 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 368 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 369 | file, line, arg); |
| 370 | return 1; |
| 371 | } |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 376 | * Return 1 if the warning has been emitted, otherwise 0. |
| 377 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 378 | 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] | 379 | { |
| 380 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 381 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 382 | file, line, arg); |
| 383 | return 1; |
| 384 | } |
| 385 | return 0; |
| 386 | } |
| 387 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 388 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 389 | * Return 1 if the warning has been emitted, otherwise 0. |
| 390 | */ |
| 391 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 392 | { |
| 393 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 394 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 395 | file, line, arg); |
| 396 | return 1; |
| 397 | } |
| 398 | return 0; |
| 399 | } |
| 400 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 401 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 402 | 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] | 403 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 404 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 405 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 406 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 407 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 408 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 409 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* report a warning if an http-request rule is dangerously placed */ |
| 413 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 414 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 415 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 416 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 417 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 418 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 419 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 423 | 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] | 424 | { |
| 425 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 426 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 427 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 428 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 432 | 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] | 433 | { |
| 434 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 435 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 436 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 437 | } |
| 438 | |
| 439 | /* report a warning if a redirect rule is dangerously placed */ |
| 440 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 441 | { |
| 442 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 443 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 446 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 447 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 448 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 449 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 450 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 451 | 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] | 452 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 453 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 454 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 455 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 456 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 457 | return 0; |
| 458 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 459 | acl = acl_cond_conflicts(cond, where); |
| 460 | if (acl) { |
| 461 | if (acl->name && *acl->name) |
| 462 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 463 | file, line, acl->name, sample_ckp_names(where)); |
| 464 | else |
| 465 | 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] | 466 | 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] | 467 | return ERR_WARN; |
| 468 | } |
| 469 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 470 | return 0; |
| 471 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 472 | if (acl->name && *acl->name) |
| 473 | 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] | 474 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 475 | else |
| 476 | 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] | 477 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 478 | return ERR_WARN; |
| 479 | } |
| 480 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 481 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 482 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 483 | * any combination of : |
| 484 | * - ERR_ABORT: must abort ASAP |
| 485 | * - ERR_FATAL: we can continue parsing but not start the service |
| 486 | * - ERR_WARN: a warning has been emitted |
| 487 | * - ERR_ALERT: an alert has been emitted |
| 488 | * Only the two first ones can stop processing, the two others are just |
| 489 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 490 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 491 | 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] | 492 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 493 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 494 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 495 | |
| 496 | if (!strcmp(args[0], "global")) { /* new section */ |
| 497 | /* no option, nothing special to do */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 498 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 499 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 500 | else if (!strcmp(args[0], "ca-base")) { |
| 501 | #ifdef USE_OPENSSL |
| 502 | if (global.ca_base != NULL) { |
| 503 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 504 | err_code |= ERR_ALERT; |
| 505 | goto out; |
| 506 | } |
| 507 | if (*(args[1]) == 0) { |
| 508 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 510 | goto out; |
| 511 | } |
| 512 | global.ca_base = strdup(args[1]); |
| 513 | #else |
| 514 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 516 | goto out; |
| 517 | #endif |
| 518 | } |
| 519 | else if (!strcmp(args[0], "crt-base")) { |
| 520 | #ifdef USE_OPENSSL |
| 521 | if (global.crt_base != NULL) { |
| 522 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 523 | err_code |= ERR_ALERT; |
| 524 | goto out; |
| 525 | } |
| 526 | if (*(args[1]) == 0) { |
| 527 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 529 | goto out; |
| 530 | } |
| 531 | global.crt_base = strdup(args[1]); |
| 532 | #else |
| 533 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 535 | goto out; |
| 536 | #endif |
| 537 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 538 | else if (!strcmp(args[0], "daemon")) { |
| 539 | global.mode |= MODE_DAEMON; |
| 540 | } |
| 541 | else if (!strcmp(args[0], "debug")) { |
| 542 | global.mode |= MODE_DEBUG; |
| 543 | } |
| 544 | else if (!strcmp(args[0], "noepoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 545 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 546 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 547 | else if (!strcmp(args[0], "nokqueue")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 548 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 549 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 550 | else if (!strcmp(args[0], "nopoll")) { |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 551 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 552 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 553 | else if (!strcmp(args[0], "nosplice")) { |
| 554 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 555 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 556 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
| 557 | global.tune.options &= ~GTUNE_USE_GAI; |
| 558 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 559 | else if (!strcmp(args[0], "quiet")) { |
| 560 | global.mode |= MODE_QUIET; |
| 561 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 562 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
| 563 | if (global.tune.maxpollevents != 0) { |
| 564 | 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] | 565 | err_code |= ERR_ALERT; |
| 566 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 567 | } |
| 568 | if (*(args[1]) == 0) { |
| 569 | 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] | 570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 571 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 572 | } |
| 573 | global.tune.maxpollevents = atol(args[1]); |
| 574 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 575 | else if (!strcmp(args[0], "tune.maxaccept")) { |
| 576 | if (global.tune.maxaccept != 0) { |
| 577 | 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] | 578 | err_code |= ERR_ALERT; |
| 579 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 580 | } |
| 581 | if (*(args[1]) == 0) { |
| 582 | 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] | 583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 584 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 585 | } |
| 586 | global.tune.maxaccept = atol(args[1]); |
| 587 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 588 | else if (!strcmp(args[0], "tune.chksize")) { |
| 589 | if (*(args[1]) == 0) { |
| 590 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 592 | goto out; |
| 593 | } |
| 594 | global.tune.chksize = atol(args[1]); |
| 595 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 596 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 597 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
| 598 | global.tune.sslprivatecache = 1; |
| 599 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 600 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 601 | if (*(args[1]) == 0) { |
| 602 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 604 | goto out; |
| 605 | } |
| 606 | global.tune.sslcachesize = atol(args[1]); |
| 607 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 608 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 609 | unsigned int ssllifetime; |
| 610 | const char *res; |
| 611 | |
| 612 | if (*(args[1]) == 0) { |
| 613 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 615 | goto out; |
| 616 | } |
| 617 | |
| 618 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 619 | if (res) { |
| 620 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 621 | file, linenum, *res, args[0]); |
| 622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 623 | goto out; |
| 624 | } |
| 625 | |
| 626 | global.tune.ssllifetime = ssllifetime; |
| 627 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 628 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
| 629 | if (*(args[1]) == 0) { |
| 630 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 632 | goto out; |
| 633 | } |
| 634 | global.tune.ssl_max_record = atol(args[1]); |
| 635 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 636 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 637 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 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.bufsize = atol(args[1]); |
| 644 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 645 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 646 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 647 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 648 | } |
| 649 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 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.maxrewrite = atol(args[1]); |
| 656 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 657 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 658 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 659 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 660 | unsigned int idle; |
| 661 | const char *res; |
| 662 | |
| 663 | if (*(args[1]) == 0) { |
| 664 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 665 | err_code |= ERR_ALERT | ERR_FATAL; |
| 666 | goto out; |
| 667 | } |
| 668 | |
| 669 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 670 | if (res) { |
| 671 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 672 | file, linenum, *res, args[0]); |
| 673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 674 | goto out; |
| 675 | } |
| 676 | |
| 677 | if (idle > 65535) { |
| 678 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 680 | goto out; |
| 681 | } |
| 682 | global.tune.idle_timer = idle; |
| 683 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 684 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 685 | if (global.tune.client_rcvbuf != 0) { |
| 686 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 687 | err_code |= ERR_ALERT; |
| 688 | goto out; |
| 689 | } |
| 690 | if (*(args[1]) == 0) { |
| 691 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 693 | goto out; |
| 694 | } |
| 695 | global.tune.client_rcvbuf = atol(args[1]); |
| 696 | } |
| 697 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 698 | if (global.tune.server_rcvbuf != 0) { |
| 699 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 700 | err_code |= ERR_ALERT; |
| 701 | goto out; |
| 702 | } |
| 703 | if (*(args[1]) == 0) { |
| 704 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 706 | goto out; |
| 707 | } |
| 708 | global.tune.server_rcvbuf = atol(args[1]); |
| 709 | } |
| 710 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 711 | if (global.tune.client_sndbuf != 0) { |
| 712 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 713 | err_code |= ERR_ALERT; |
| 714 | goto out; |
| 715 | } |
| 716 | if (*(args[1]) == 0) { |
| 717 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 719 | goto out; |
| 720 | } |
| 721 | global.tune.client_sndbuf = atol(args[1]); |
| 722 | } |
| 723 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 724 | if (global.tune.server_sndbuf != 0) { |
| 725 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 726 | err_code |= ERR_ALERT; |
| 727 | goto out; |
| 728 | } |
| 729 | if (*(args[1]) == 0) { |
| 730 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 732 | goto out; |
| 733 | } |
| 734 | global.tune.server_sndbuf = atol(args[1]); |
| 735 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 736 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 737 | if (*(args[1]) == 0) { |
| 738 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 740 | goto out; |
| 741 | } |
| 742 | global.tune.pipesize = atol(args[1]); |
| 743 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 744 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 745 | if (*(args[1]) == 0) { |
| 746 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 748 | goto out; |
| 749 | } |
| 750 | global.tune.cookie_len = atol(args[1]) + 1; |
| 751 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 752 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 753 | if (*(args[1]) == 0) { |
| 754 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 756 | goto out; |
| 757 | } |
| 758 | global.tune.max_http_hdr = atol(args[1]); |
| 759 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 760 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 761 | #ifdef USE_ZLIB |
| 762 | if (*args[1]) { |
| 763 | global.tune.zlibmemlevel = atoi(args[1]); |
| 764 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 765 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 766 | file, linenum, args[0]); |
| 767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 768 | goto out; |
| 769 | } |
| 770 | } else { |
| 771 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 772 | file, linenum, args[0]); |
| 773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 774 | goto out; |
| 775 | } |
| 776 | #else |
| 777 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 779 | goto out; |
| 780 | #endif |
| 781 | } |
| 782 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 783 | #ifdef USE_ZLIB |
| 784 | if (*args[1]) { |
| 785 | global.tune.zlibwindowsize = atoi(args[1]); |
| 786 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 787 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 788 | file, linenum, args[0]); |
| 789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 790 | goto out; |
| 791 | } |
| 792 | } else { |
| 793 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 794 | file, linenum, args[0]); |
| 795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 796 | goto out; |
| 797 | } |
| 798 | #else |
| 799 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 801 | goto out; |
| 802 | #endif |
| 803 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 804 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 805 | if (*args[1]) { |
| 806 | global.tune.comp_maxlevel = atoi(args[1]); |
| 807 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 808 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 809 | file, linenum, args[0]); |
| 810 | err_code |= ERR_ALERT | ERR_FATAL; |
| 811 | goto out; |
| 812 | } |
| 813 | } else { |
| 814 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 815 | file, linenum, args[0]); |
| 816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 817 | goto out; |
| 818 | } |
| 819 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 820 | else if (!strcmp(args[0], "uid")) { |
| 821 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 822 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 823 | err_code |= ERR_ALERT; |
| 824 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 825 | } |
| 826 | if (*(args[1]) == 0) { |
| 827 | 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] | 828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 829 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 830 | } |
| 831 | global.uid = atol(args[1]); |
| 832 | } |
| 833 | else if (!strcmp(args[0], "gid")) { |
| 834 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 835 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 836 | err_code |= ERR_ALERT; |
| 837 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 838 | } |
| 839 | if (*(args[1]) == 0) { |
| 840 | 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] | 841 | err_code |= ERR_ALERT | ERR_FATAL; |
| 842 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 843 | } |
| 844 | global.gid = atol(args[1]); |
| 845 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 846 | /* user/group name handling */ |
| 847 | else if (!strcmp(args[0], "user")) { |
| 848 | struct passwd *ha_user; |
| 849 | if (global.uid != 0) { |
| 850 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 851 | err_code |= ERR_ALERT; |
| 852 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 853 | } |
| 854 | errno = 0; |
| 855 | ha_user = getpwnam(args[1]); |
| 856 | if (ha_user != NULL) { |
| 857 | global.uid = (int)ha_user->pw_uid; |
| 858 | } |
| 859 | else { |
| 860 | 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] | 861 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | else if (!strcmp(args[0], "group")) { |
| 865 | struct group *ha_group; |
| 866 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 867 | 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] | 868 | err_code |= ERR_ALERT; |
| 869 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 870 | } |
| 871 | errno = 0; |
| 872 | ha_group = getgrnam(args[1]); |
| 873 | if (ha_group != NULL) { |
| 874 | global.gid = (int)ha_group->gr_gid; |
| 875 | } |
| 876 | else { |
| 877 | 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] | 878 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 882 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 883 | if (*(args[1]) == 0) { |
| 884 | 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] | 885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 886 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 887 | } |
| 888 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 889 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 890 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 891 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 893 | goto out; |
| 894 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 895 | } |
| 896 | else if (!strcmp(args[0], "maxconn")) { |
| 897 | if (global.maxconn != 0) { |
| 898 | 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] | 899 | err_code |= ERR_ALERT; |
| 900 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 901 | } |
| 902 | if (*(args[1]) == 0) { |
| 903 | 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] | 904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 905 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 906 | } |
| 907 | global.maxconn = atol(args[1]); |
| 908 | #ifdef SYSTEM_MAXCONN |
| 909 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 910 | 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); |
| 911 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 912 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 913 | } |
| 914 | #endif /* SYSTEM_MAXCONN */ |
| 915 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 916 | else if (!strcmp(args[0], "maxsslconn")) { |
| 917 | #ifdef USE_OPENSSL |
| 918 | if (*(args[1]) == 0) { |
| 919 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 921 | goto out; |
| 922 | } |
| 923 | global.maxsslconn = atol(args[1]); |
| 924 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 925 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 927 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 928 | #endif |
| 929 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 930 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 931 | #ifdef USE_OPENSSL |
| 932 | if (*(args[1]) == 0) { |
| 933 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 935 | goto out; |
| 936 | } |
| 937 | free(global.listen_default_ciphers); |
| 938 | global.listen_default_ciphers = strdup(args[1]); |
| 939 | #else |
| 940 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 942 | goto out; |
| 943 | #endif |
| 944 | } |
| 945 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 946 | #ifdef USE_OPENSSL |
| 947 | if (*(args[1]) == 0) { |
| 948 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 950 | goto out; |
| 951 | } |
| 952 | free(global.connect_default_ciphers); |
| 953 | global.connect_default_ciphers = strdup(args[1]); |
| 954 | #else |
| 955 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 957 | goto out; |
| 958 | #endif |
| 959 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 960 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 961 | if (*(args[1]) == 0) { |
| 962 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 964 | goto out; |
| 965 | } |
| 966 | if (strcmp(args[1],"none") == 0) |
| 967 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 968 | else if (strcmp(args[1],"required") == 0) |
| 969 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 970 | else { |
| 971 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 973 | goto out; |
| 974 | } |
| 975 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 976 | else if (!strcmp(args[0], "maxconnrate")) { |
| 977 | if (global.cps_lim != 0) { |
| 978 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 979 | err_code |= ERR_ALERT; |
| 980 | goto out; |
| 981 | } |
| 982 | if (*(args[1]) == 0) { |
| 983 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 985 | goto out; |
| 986 | } |
| 987 | global.cps_lim = atol(args[1]); |
| 988 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 989 | else if (!strcmp(args[0], "maxsessrate")) { |
| 990 | if (global.sps_lim != 0) { |
| 991 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 992 | err_code |= ERR_ALERT; |
| 993 | goto out; |
| 994 | } |
| 995 | if (*(args[1]) == 0) { |
| 996 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 998 | goto out; |
| 999 | } |
| 1000 | global.sps_lim = atol(args[1]); |
| 1001 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1002 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1003 | if (global.ssl_lim != 0) { |
| 1004 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1005 | err_code |= ERR_ALERT; |
| 1006 | goto out; |
| 1007 | } |
| 1008 | if (*(args[1]) == 0) { |
| 1009 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1011 | goto out; |
| 1012 | } |
| 1013 | global.ssl_lim = atol(args[1]); |
| 1014 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1015 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1016 | if (*(args[1]) == 0) { |
| 1017 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1019 | goto out; |
| 1020 | } |
| 1021 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1022 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1023 | else if (!strcmp(args[0], "maxpipes")) { |
| 1024 | if (global.maxpipes != 0) { |
| 1025 | 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] | 1026 | err_code |= ERR_ALERT; |
| 1027 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1028 | } |
| 1029 | if (*(args[1]) == 0) { |
| 1030 | 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] | 1031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1032 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1033 | } |
| 1034 | global.maxpipes = atol(args[1]); |
| 1035 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1036 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1037 | if (*(args[1]) == 0) { |
| 1038 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1040 | goto out; |
| 1041 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1042 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1043 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1044 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1045 | if (*(args[1]) == 0) { |
| 1046 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
| 1049 | } |
| 1050 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1051 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1052 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1054 | goto out; |
| 1055 | } |
| 1056 | } |
| 1057 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1058 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1059 | if (global.rlimit_nofile != 0) { |
| 1060 | 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] | 1061 | err_code |= ERR_ALERT; |
| 1062 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1063 | } |
| 1064 | if (*(args[1]) == 0) { |
| 1065 | 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] | 1066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1067 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1068 | } |
| 1069 | global.rlimit_nofile = atol(args[1]); |
| 1070 | } |
| 1071 | else if (!strcmp(args[0], "chroot")) { |
| 1072 | if (global.chroot != NULL) { |
| 1073 | 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] | 1074 | err_code |= ERR_ALERT; |
| 1075 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1076 | } |
| 1077 | if (*(args[1]) == 0) { |
| 1078 | 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] | 1079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1080 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1081 | } |
| 1082 | global.chroot = strdup(args[1]); |
| 1083 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1084 | else if (!strcmp(args[0], "description")) { |
| 1085 | int i, len=0; |
| 1086 | char *d; |
| 1087 | |
| 1088 | if (!*args[1]) { |
| 1089 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1090 | file, linenum, args[0]); |
| 1091 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1092 | goto out; |
| 1093 | } |
| 1094 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1095 | for (i = 1; *args[i]; i++) |
| 1096 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1097 | |
| 1098 | if (global.desc) |
| 1099 | free(global.desc); |
| 1100 | |
| 1101 | global.desc = d = (char *)calloc(1, len); |
| 1102 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1103 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1104 | for (i = 2; *args[i]; i++) |
| 1105 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1106 | } |
| 1107 | else if (!strcmp(args[0], "node")) { |
| 1108 | int i; |
| 1109 | char c; |
| 1110 | |
| 1111 | for (i=0; args[1][i]; i++) { |
| 1112 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1113 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1114 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1115 | break; |
| 1116 | } |
| 1117 | |
| 1118 | if (!i || args[1][i]) { |
| 1119 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1120 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1121 | file, linenum, args[0]); |
| 1122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1123 | goto out; |
| 1124 | } |
| 1125 | |
| 1126 | if (global.node) |
| 1127 | free(global.node); |
| 1128 | |
| 1129 | global.node = strdup(args[1]); |
| 1130 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1131 | else if (!strcmp(args[0], "pidfile")) { |
| 1132 | if (global.pidfile != NULL) { |
| 1133 | 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] | 1134 | err_code |= ERR_ALERT; |
| 1135 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1136 | } |
| 1137 | if (*(args[1]) == 0) { |
| 1138 | 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] | 1139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1140 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1141 | } |
| 1142 | global.pidfile = strdup(args[1]); |
| 1143 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1144 | else if (!strcmp(args[0], "unix-bind")) { |
| 1145 | int cur_arg = 1; |
| 1146 | while (*(args[cur_arg])) { |
| 1147 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1148 | if (global.unix_bind.prefix != NULL) { |
| 1149 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1150 | err_code |= ERR_ALERT; |
| 1151 | cur_arg += 2; |
| 1152 | continue; |
| 1153 | } |
| 1154 | |
| 1155 | if (*(args[cur_arg+1]) == 0) { |
| 1156 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1158 | goto out; |
| 1159 | } |
| 1160 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1161 | cur_arg += 2; |
| 1162 | continue; |
| 1163 | } |
| 1164 | |
| 1165 | if (!strcmp(args[cur_arg], "mode")) { |
| 1166 | |
| 1167 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1168 | cur_arg += 2; |
| 1169 | continue; |
| 1170 | } |
| 1171 | |
| 1172 | if (!strcmp(args[cur_arg], "uid")) { |
| 1173 | |
| 1174 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1175 | cur_arg += 2; |
| 1176 | continue; |
| 1177 | } |
| 1178 | |
| 1179 | if (!strcmp(args[cur_arg], "gid")) { |
| 1180 | |
| 1181 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1182 | cur_arg += 2; |
| 1183 | continue; |
| 1184 | } |
| 1185 | |
| 1186 | if (!strcmp(args[cur_arg], "user")) { |
| 1187 | struct passwd *user; |
| 1188 | |
| 1189 | user = getpwnam(args[cur_arg + 1]); |
| 1190 | if (!user) { |
| 1191 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1192 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1194 | goto out; |
| 1195 | } |
| 1196 | |
| 1197 | global.unix_bind.ux.uid = user->pw_uid; |
| 1198 | cur_arg += 2; |
| 1199 | continue; |
| 1200 | } |
| 1201 | |
| 1202 | if (!strcmp(args[cur_arg], "group")) { |
| 1203 | struct group *group; |
| 1204 | |
| 1205 | group = getgrnam(args[cur_arg + 1]); |
| 1206 | if (!group) { |
| 1207 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1208 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1209 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1210 | goto out; |
| 1211 | } |
| 1212 | |
| 1213 | global.unix_bind.ux.gid = group->gr_gid; |
| 1214 | cur_arg += 2; |
| 1215 | continue; |
| 1216 | } |
| 1217 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1218 | 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] | 1219 | file, linenum, args[0]); |
| 1220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1221 | goto out; |
| 1222 | } |
| 1223 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1224 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1225 | /* delete previous herited or defined syslog servers */ |
| 1226 | struct logsrv *back; |
| 1227 | struct logsrv *tmp; |
| 1228 | |
| 1229 | if (*(args[1]) != 0) { |
| 1230 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1232 | goto out; |
| 1233 | } |
| 1234 | |
| 1235 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1236 | LIST_DEL(&tmp->list); |
| 1237 | free(tmp); |
| 1238 | } |
| 1239 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1240 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1241 | struct sockaddr_storage *sk; |
| 1242 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1243 | struct logsrv *logsrv; |
| 1244 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1245 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1246 | 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] | 1247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1249 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1250 | |
| 1251 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1252 | |
| 1253 | logsrv->facility = get_log_facility(args[2]); |
| 1254 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1255 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1256 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1257 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1258 | } |
| 1259 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1260 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1261 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1262 | logsrv->level = get_log_level(args[3]); |
| 1263 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1264 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1265 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1266 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1270 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1271 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1272 | logsrv->minlvl = get_log_level(args[4]); |
| 1273 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1274 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1275 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1276 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1280 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1281 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1282 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1283 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1284 | free(logsrv); |
| 1285 | goto out; |
| 1286 | } |
| 1287 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1288 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1289 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1290 | if (port1 != port2) { |
| 1291 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1292 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1293 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1294 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1295 | goto out; |
| 1296 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1297 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1298 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1299 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1300 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1301 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1302 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1303 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1304 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1305 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1306 | char *name; |
| 1307 | int len; |
| 1308 | |
| 1309 | if (global.log_send_hostname != NULL) { |
| 1310 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1311 | err_code |= ERR_ALERT; |
| 1312 | goto out; |
| 1313 | } |
| 1314 | |
| 1315 | if (*(args[1])) |
| 1316 | name = args[1]; |
| 1317 | else |
| 1318 | name = hostname; |
| 1319 | |
| 1320 | len = strlen(name); |
| 1321 | |
| 1322 | /* We'll add a space after the name to respect the log format */ |
| 1323 | free(global.log_send_hostname); |
| 1324 | global.log_send_hostname = malloc(len + 2); |
| 1325 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1326 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1327 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1328 | if (*(args[1]) == 0) { |
| 1329 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1331 | goto out; |
| 1332 | } |
| 1333 | free(global.log_tag); |
| 1334 | global.log_tag = strdup(args[1]); |
| 1335 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1336 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1337 | if (global.spread_checks != 0) { |
| 1338 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1339 | err_code |= ERR_ALERT; |
| 1340 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1341 | } |
| 1342 | if (*(args[1]) == 0) { |
| 1343 | 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] | 1344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1345 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1346 | } |
| 1347 | global.spread_checks = atol(args[1]); |
| 1348 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1349 | 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] | 1350 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1351 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1352 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1353 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1354 | const char *err; |
| 1355 | unsigned int val; |
| 1356 | |
| 1357 | |
| 1358 | if (*(args[1]) == 0) { |
| 1359 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1361 | goto out; |
| 1362 | } |
| 1363 | |
| 1364 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1365 | if (err) { |
| 1366 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1368 | } |
| 1369 | global.max_spread_checks = val; |
| 1370 | if (global.max_spread_checks < 0) { |
| 1371 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1373 | } |
| 1374 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1375 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1376 | #ifdef USE_CPU_AFFINITY |
| 1377 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1378 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1379 | unsigned long cpus = 0; |
| 1380 | |
| 1381 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1382 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1383 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1384 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1385 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1386 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1387 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1388 | proc = atol(args[1]); |
| 1389 | if (proc >= 1 && proc <= LONGBITS) |
| 1390 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1394 | 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", |
| 1395 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1397 | goto out; |
| 1398 | } |
| 1399 | |
| 1400 | cur_arg = 2; |
| 1401 | while (*args[cur_arg]) { |
| 1402 | unsigned int low, high; |
| 1403 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1404 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1405 | char *dash = strchr(args[cur_arg], '-'); |
| 1406 | |
| 1407 | low = high = str2uic(args[cur_arg]); |
| 1408 | if (dash) |
| 1409 | high = str2uic(dash + 1); |
| 1410 | |
| 1411 | if (high < low) { |
| 1412 | unsigned int swap = low; |
| 1413 | low = high; |
| 1414 | high = swap; |
| 1415 | } |
| 1416 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1417 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1418 | 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] | 1419 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1421 | goto out; |
| 1422 | } |
| 1423 | |
| 1424 | while (low <= high) |
| 1425 | cpus |= 1UL << low++; |
| 1426 | } |
| 1427 | else { |
| 1428 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1429 | file, linenum, args[0], args[cur_arg]); |
| 1430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1431 | goto out; |
| 1432 | } |
| 1433 | cur_arg++; |
| 1434 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1435 | for (i = 0; i < LONGBITS; i++) |
| 1436 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1437 | global.cpu_map[i] = cpus; |
| 1438 | #else |
| 1439 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1441 | goto out; |
| 1442 | #endif |
| 1443 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1444 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1445 | struct cfg_kw_list *kwl; |
| 1446 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1447 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1448 | |
| 1449 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1450 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1451 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1452 | continue; |
| 1453 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1454 | 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] | 1455 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1456 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1457 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1458 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1459 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1460 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1461 | err_code |= ERR_WARN; |
| 1462 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1463 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1464 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1465 | } |
| 1466 | } |
| 1467 | } |
| 1468 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1469 | 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] | 1470 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1471 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1472 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1473 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1474 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1475 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1476 | } |
| 1477 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1478 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1479 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1480 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1481 | defproxy.mode = PR_MODE_TCP; |
| 1482 | defproxy.state = PR_STNEW; |
| 1483 | defproxy.maxconn = cfg_maxpconn; |
| 1484 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1485 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1486 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1487 | defproxy.defsrv.check.fastinter = 0; |
| 1488 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1489 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1490 | defproxy.defsrv.agent.fastinter = 0; |
| 1491 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1492 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1493 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1494 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1495 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1496 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1497 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1498 | defproxy.defsrv.maxqueue = 0; |
| 1499 | defproxy.defsrv.minconn = 0; |
| 1500 | defproxy.defsrv.maxconn = 0; |
| 1501 | defproxy.defsrv.slowstart = 0; |
| 1502 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1503 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1504 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1507 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1508 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1509 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1510 | * ERR_FATAL in case of error. |
| 1511 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1512 | static int create_cond_regex_rule(const char *file, int line, |
| 1513 | struct proxy *px, int dir, int action, int flags, |
| 1514 | const char *cmd, const char *reg, const char *repl, |
| 1515 | const char **cond_start) |
| 1516 | { |
| 1517 | regex_t *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1518 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1519 | const char *err; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1520 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1521 | struct acl_cond *cond = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1522 | |
| 1523 | if (px == &defproxy) { |
| 1524 | 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] | 1525 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1526 | goto err; |
| 1527 | } |
| 1528 | |
| 1529 | if (*reg == 0) { |
| 1530 | 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] | 1531 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1532 | goto err; |
| 1533 | } |
| 1534 | |
| 1535 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1536 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1537 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1538 | if (cond_start && |
| 1539 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1540 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1541 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1542 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1543 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1544 | goto err; |
| 1545 | } |
| 1546 | } |
| 1547 | else if (cond_start && **cond_start) { |
| 1548 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1549 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1550 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1551 | goto err; |
| 1552 | } |
| 1553 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1554 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1555 | (dir == SMP_OPT_DIR_REQ) ? |
| 1556 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1557 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1558 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1559 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1560 | preg = calloc(1, sizeof(regex_t)); |
| 1561 | if (!preg) { |
| 1562 | 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] | 1563 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1564 | goto err; |
| 1565 | } |
| 1566 | |
| 1567 | if (regcomp(preg, reg, REG_EXTENDED | flags) != 0) { |
| 1568 | Alert("parsing [%s:%d] : '%s' : bad regular expression '%s'.\n", file, line, cmd, reg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1569 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1570 | goto err; |
| 1571 | } |
| 1572 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1573 | 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] | 1574 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1575 | if (repl && err) { |
| 1576 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1577 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1578 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1579 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1580 | } |
| 1581 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1582 | 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] | 1583 | ret_code |= ERR_WARN; |
| 1584 | |
| 1585 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1586 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1587 | err_free: |
| 1588 | regfree(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1589 | err: |
| 1590 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1591 | free(errmsg); |
| 1592 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1593 | } |
| 1594 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1595 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1596 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1597 | * Returns the error code, 0 if OK, or any combination of : |
| 1598 | * - ERR_ABORT: must abort ASAP |
| 1599 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1600 | * - ERR_WARN: a warning has been emitted |
| 1601 | * - ERR_ALERT: an alert has been emitted |
| 1602 | * Only the two first ones can stop processing, the two others are just |
| 1603 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1604 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1605 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1606 | { |
| 1607 | static struct peers *curpeers = NULL; |
| 1608 | struct peer *newpeer = NULL; |
| 1609 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1610 | struct bind_conf *bind_conf; |
| 1611 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1612 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1613 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1614 | |
| 1615 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1616 | if (!*args[1]) { |
| 1617 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1618 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1619 | goto out; |
| 1620 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1621 | |
| 1622 | err = invalid_char(args[1]); |
| 1623 | if (err) { |
| 1624 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1625 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1626 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1627 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1631 | /* |
| 1632 | * If there are two proxies with the same name only following |
| 1633 | * combinations are allowed: |
| 1634 | */ |
| 1635 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1636 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1637 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1638 | err_code |= ERR_WARN; |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1643 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1644 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1645 | goto out; |
| 1646 | } |
| 1647 | |
| 1648 | curpeers->next = peers; |
| 1649 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1650 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1651 | curpeers->conf.line = linenum; |
| 1652 | curpeers->last_change = now.tv_sec; |
| 1653 | curpeers->id = strdup(args[1]); |
| 1654 | } |
| 1655 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1656 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1657 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1658 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1659 | |
| 1660 | if (!*args[2]) { |
| 1661 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1662 | file, linenum, args[0]); |
| 1663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1664 | goto out; |
| 1665 | } |
| 1666 | |
| 1667 | err = invalid_char(args[1]); |
| 1668 | if (err) { |
| 1669 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1670 | file, linenum, *err, args[1]); |
| 1671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1672 | goto out; |
| 1673 | } |
| 1674 | |
| 1675 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1676 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1677 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1678 | goto out; |
| 1679 | } |
| 1680 | |
| 1681 | /* the peers are linked backwards first */ |
| 1682 | curpeers->count++; |
| 1683 | newpeer->next = curpeers->remote; |
| 1684 | curpeers->remote = newpeer; |
| 1685 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1686 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1687 | newpeer->conf.line = linenum; |
| 1688 | |
| 1689 | newpeer->last_change = now.tv_sec; |
| 1690 | newpeer->id = strdup(args[1]); |
| 1691 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1692 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1693 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1694 | 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] | 1695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1696 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1697 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1698 | |
| 1699 | proto = protocol_by_family(sk->ss_family); |
| 1700 | if (!proto || !proto->connect) { |
| 1701 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1702 | file, linenum, args[0], args[1]); |
| 1703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1704 | goto out; |
| 1705 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1706 | |
| 1707 | if (port1 != port2) { |
| 1708 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1709 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1711 | goto out; |
| 1712 | } |
| 1713 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1714 | if (!port1) { |
| 1715 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1716 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1718 | goto out; |
| 1719 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1720 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1721 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1722 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1723 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1724 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1725 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1726 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1727 | /* Current is local peer, it define a frontend */ |
| 1728 | newpeer->local = 1; |
| 1729 | |
| 1730 | if (!curpeers->peers_fe) { |
| 1731 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1732 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1733 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1734 | goto out; |
| 1735 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1736 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1737 | init_new_proxy(curpeers->peers_fe); |
| 1738 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1739 | |
| 1740 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1741 | curpeers->peers_fe->id = strdup(args[1]); |
| 1742 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1743 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1744 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1745 | curpeers->peers_fe->timeout.connect = 5000; |
| 1746 | curpeers->peers_fe->accept = peer_accept; |
| 1747 | 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] | 1748 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1749 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1750 | |
| 1751 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1752 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1753 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1754 | if (errmsg && *errmsg) { |
| 1755 | indent_msg(&errmsg, 2); |
| 1756 | 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] | 1757 | } |
| 1758 | else |
| 1759 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1760 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1761 | err_code |= ERR_FATAL; |
| 1762 | goto out; |
| 1763 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1764 | |
| 1765 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1766 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1767 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1768 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1769 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1770 | l->accept = session_accept; |
| 1771 | l->handler = process_session; |
| 1772 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1773 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1774 | global.maxsock += l->maxconn; |
| 1775 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1776 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1777 | else { |
| 1778 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1779 | file, linenum, args[0], args[1], |
| 1780 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1781 | err_code |= ERR_FATAL; |
| 1782 | goto out; |
| 1783 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1784 | } |
| 1785 | } /* neither "peer" nor "peers" */ |
| 1786 | else if (*args[0] != 0) { |
| 1787 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1789 | goto out; |
| 1790 | } |
| 1791 | |
| 1792 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1793 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1794 | return err_code; |
| 1795 | } |
| 1796 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1797 | 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] | 1798 | { |
| 1799 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1800 | const char *err; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1801 | int rc; |
| 1802 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1803 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1804 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1805 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1806 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1807 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1808 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1809 | if (!strcmp(args[0], "listen")) |
| 1810 | rc = PR_CAP_LISTEN; |
| 1811 | else if (!strcmp(args[0], "frontend")) |
| 1812 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1813 | else if (!strcmp(args[0], "backend")) |
| 1814 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1815 | else if (!strcmp(args[0], "ruleset")) |
| 1816 | rc = PR_CAP_RS; |
| 1817 | else |
| 1818 | rc = PR_CAP_NONE; |
| 1819 | |
| 1820 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1821 | struct ebpt_node *node; |
| 1822 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1823 | if (!*args[1]) { |
| 1824 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1825 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1826 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1827 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1828 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1829 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1830 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1831 | err = invalid_char(args[1]); |
| 1832 | if (err) { |
| 1833 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1834 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1835 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1836 | } |
| 1837 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1838 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1839 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1840 | |
| 1841 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1842 | break; |
| 1843 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1844 | /* |
| 1845 | * If there are two proxies with the same name only following |
| 1846 | * combinations are allowed: |
| 1847 | * |
| 1848 | * listen backend frontend ruleset |
| 1849 | * listen - - - - |
| 1850 | * backend - - OK - |
| 1851 | * frontend - OK - - |
| 1852 | * ruleset - - - - |
| 1853 | */ |
| 1854 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1855 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1856 | (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] | 1857 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1858 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1859 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1860 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1861 | } |
| 1862 | } |
| 1863 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1864 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1865 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1866 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1867 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1868 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1869 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1870 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1871 | curproxy->next = proxy; |
| 1872 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1873 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1874 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1875 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1876 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1877 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 1878 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1879 | |
| 1880 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1881 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1882 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1883 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1884 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1885 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1886 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1887 | if (errmsg && *errmsg) { |
| 1888 | indent_msg(&errmsg, 2); |
| 1889 | 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] | 1890 | } |
| 1891 | else |
| 1892 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1893 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1894 | err_code |= ERR_FATAL; |
| 1895 | goto out; |
| 1896 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1897 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1898 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1899 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1900 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1904 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1905 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1906 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1907 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1908 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1909 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1910 | curproxy->no_options = defproxy.no_options; |
| 1911 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1912 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1913 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1914 | curproxy->except_net = defproxy.except_net; |
| 1915 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1916 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1917 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1918 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1919 | if (defproxy.fwdfor_hdr_len) { |
| 1920 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1921 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1922 | } |
| 1923 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1924 | if (defproxy.orgto_hdr_len) { |
| 1925 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1926 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1927 | } |
| 1928 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1929 | if (defproxy.server_id_hdr_len) { |
| 1930 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1931 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1932 | } |
| 1933 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1934 | if (curproxy->cap & PR_CAP_FE) { |
| 1935 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1936 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1937 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1938 | |
| 1939 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1940 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1941 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1942 | |
| 1943 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1944 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1945 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1946 | if (curproxy->cap & PR_CAP_BE) { |
| 1947 | curproxy->fullconn = defproxy.fullconn; |
| 1948 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 1949 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1950 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1951 | if (defproxy.check_req) { |
| 1952 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1953 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1954 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1955 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1956 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1957 | if (defproxy.expect_str) { |
| 1958 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1959 | if (defproxy.expect_regex) { |
| 1960 | /* note: this regex is known to be valid */ |
| 1961 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 1962 | regcomp(curproxy->expect_regex, defproxy.expect_str, REG_EXTENDED); |
| 1963 | } |
| 1964 | } |
| 1965 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1966 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1967 | if (defproxy.cookie_name) |
| 1968 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1969 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1970 | if (defproxy.cookie_domain) |
| 1971 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1972 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1973 | if (defproxy.cookie_maxidle) |
| 1974 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1975 | |
| 1976 | if (defproxy.cookie_maxlife) |
| 1977 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 1978 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1979 | if (defproxy.rdp_cookie_name) |
| 1980 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 1981 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 1982 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1983 | if (defproxy.url_param_name) |
| 1984 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 1985 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1986 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1987 | if (defproxy.hh_name) |
| 1988 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 1989 | curproxy->hh_len = defproxy.hh_len; |
| 1990 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 1991 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 1992 | if (defproxy.conn_src.iface_name) |
| 1993 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 1994 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 1995 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 1996 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 1997 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 1998 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1999 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2000 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2001 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2002 | if (defproxy.capture_name) |
| 2003 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2004 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2005 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2006 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2007 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2008 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2009 | curproxy->timeout.client = defproxy.timeout.client; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2010 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2011 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2012 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2013 | curproxy->mon_net = defproxy.mon_net; |
| 2014 | curproxy->mon_mask = defproxy.mon_mask; |
| 2015 | if (defproxy.monitor_uri) |
| 2016 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2017 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2018 | if (defproxy.defbe.name) |
| 2019 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2020 | |
| 2021 | /* 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] | 2022 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2023 | if (curproxy->conf.logformat_string && |
| 2024 | curproxy->conf.logformat_string != default_http_log_format && |
| 2025 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2026 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2027 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2028 | |
| 2029 | if (defproxy.conf.lfs_file) { |
| 2030 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2031 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2032 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2036 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2037 | curproxy->timeout.server = defproxy.timeout.server; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2038 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2039 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2040 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2041 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2042 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2043 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2044 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2045 | } |
| 2046 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2047 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2048 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2049 | |
| 2050 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2051 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2052 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2053 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2054 | LIST_INIT(&node->list); |
| 2055 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2056 | } |
| 2057 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2058 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2059 | if (curproxy->conf.uniqueid_format_string) |
| 2060 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2061 | |
| 2062 | if (defproxy.conf.uif_file) { |
| 2063 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2064 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2065 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2066 | |
| 2067 | /* copy default header unique id */ |
| 2068 | if (defproxy.header_unique_id) |
| 2069 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2070 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2071 | /* default compression options */ |
| 2072 | if (defproxy.comp != NULL) { |
| 2073 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2074 | curproxy->comp->algos = defproxy.comp->algos; |
| 2075 | curproxy->comp->types = defproxy.comp->types; |
| 2076 | } |
| 2077 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2078 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2079 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2080 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2081 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2082 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2083 | } |
| 2084 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2085 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2086 | /* FIXME-20070101: we should do this too at the end of the |
| 2087 | * config parsing to free all default values. |
| 2088 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2089 | free(defproxy.check_req); |
| 2090 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2091 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2092 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2093 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2094 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2095 | free(defproxy.capture_name); |
| 2096 | free(defproxy.monitor_uri); |
| 2097 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2098 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2099 | free(defproxy.fwdfor_hdr_name); |
| 2100 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2101 | free(defproxy.orgto_hdr_name); |
| 2102 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2103 | free(defproxy.server_id_hdr_name); |
| 2104 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2105 | free(defproxy.expect_str); |
| 2106 | if (defproxy.expect_regex) regfree(defproxy.expect_regex); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2107 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2108 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2109 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2110 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2111 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2112 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2113 | free(defproxy.conf.uniqueid_format_string); |
| 2114 | free(defproxy.conf.lfs_file); |
| 2115 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2116 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2117 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2118 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2119 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2120 | /* we cannot free uri_auth because it might already be used */ |
| 2121 | init_default_instance(); |
| 2122 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2123 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2124 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2125 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2126 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2127 | } |
| 2128 | else if (curproxy == NULL) { |
| 2129 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2131 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2132 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2133 | |
| 2134 | /* update the current file and line being parsed */ |
| 2135 | curproxy->conf.args.file = curproxy->conf.file; |
| 2136 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2137 | |
| 2138 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2139 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2140 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2141 | if (err_code & ERR_FATAL) |
| 2142 | goto out; |
| 2143 | } |
| 2144 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2145 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2146 | int cur_arg; |
| 2147 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2148 | if (curproxy == &defproxy) { |
| 2149 | 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] | 2150 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2151 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2152 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2153 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2154 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2155 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2156 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2157 | 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] | 2158 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2160 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2161 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2162 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2163 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2164 | |
| 2165 | /* use default settings for unix sockets */ |
| 2166 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2167 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2168 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2169 | |
| 2170 | /* NOTE: the following line might create several listeners if there |
| 2171 | * are comma-separated IPs or port ranges. So all further processing |
| 2172 | * will have to be applied to all listeners created after last_listen. |
| 2173 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2174 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2175 | if (errmsg && *errmsg) { |
| 2176 | indent_msg(&errmsg, 2); |
| 2177 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2178 | } |
| 2179 | else |
| 2180 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2181 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2183 | goto out; |
| 2184 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2185 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2186 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2187 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2188 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2189 | } |
| 2190 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2191 | cur_arg = 2; |
| 2192 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2193 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2194 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2195 | char *err; |
| 2196 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2197 | kw = bind_find_kw(args[cur_arg]); |
| 2198 | if (kw) { |
| 2199 | char *err = NULL; |
| 2200 | int code; |
| 2201 | |
| 2202 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2203 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2204 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2205 | cur_arg += 1 + kw->skip ; |
| 2206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2207 | goto out; |
| 2208 | } |
| 2209 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2210 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2211 | err_code |= code; |
| 2212 | |
| 2213 | if (code) { |
| 2214 | if (err && *err) { |
| 2215 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2216 | 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] | 2217 | } |
| 2218 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2219 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2220 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2221 | if (code & ERR_FATAL) { |
| 2222 | free(err); |
| 2223 | cur_arg += 1 + kw->skip; |
| 2224 | goto out; |
| 2225 | } |
| 2226 | } |
| 2227 | free(err); |
| 2228 | cur_arg += 1 + kw->skip; |
| 2229 | continue; |
| 2230 | } |
| 2231 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2232 | err = NULL; |
| 2233 | if (!bind_dumped) { |
| 2234 | bind_dump_kws(&err); |
| 2235 | indent_msg(&err, 4); |
| 2236 | bind_dumped = 1; |
| 2237 | } |
| 2238 | |
| 2239 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2240 | file, linenum, args[0], args[1], args[cur_arg], |
| 2241 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2242 | free(err); |
| 2243 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2245 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2246 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2247 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2248 | } |
| 2249 | 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] | 2250 | 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] | 2251 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2252 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2254 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2255 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2256 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2257 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2258 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2259 | /* flush useless bits */ |
| 2260 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2261 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2262 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2263 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2264 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2265 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2266 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2267 | if (!*args[1]) { |
| 2268 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2269 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2271 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2272 | } |
| 2273 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2274 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2275 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2276 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2277 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2278 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2279 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2280 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2281 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2282 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2283 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2284 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2285 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2286 | else { |
| 2287 | 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] | 2288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2289 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2290 | } |
| 2291 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2292 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2293 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2294 | |
| 2295 | if (curproxy == &defproxy) { |
| 2296 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2297 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2299 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | if (!*args[1]) { |
| 2303 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2304 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2310 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2311 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2312 | if (curproxy->uuid <= 0) { |
| 2313 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2314 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2316 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2317 | } |
| 2318 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2319 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2320 | if (node) { |
| 2321 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2322 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2323 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2324 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2326 | goto out; |
| 2327 | } |
| 2328 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2329 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2330 | else if (!strcmp(args[0], "description")) { |
| 2331 | int i, len=0; |
| 2332 | char *d; |
| 2333 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2334 | if (curproxy == &defproxy) { |
| 2335 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2336 | file, linenum, args[0]); |
| 2337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2338 | goto out; |
| 2339 | } |
| 2340 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2341 | if (!*args[1]) { |
| 2342 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2343 | file, linenum, args[0]); |
| 2344 | return -1; |
| 2345 | } |
| 2346 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2347 | for (i = 1; *args[i]; i++) |
| 2348 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2349 | |
| 2350 | d = (char *)calloc(1, len); |
| 2351 | curproxy->desc = d; |
| 2352 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2353 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2354 | for (i = 2; *args[i]; i++) |
| 2355 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2356 | |
| 2357 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2358 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2359 | curproxy->state = PR_STSTOPPED; |
| 2360 | } |
| 2361 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2362 | curproxy->state = PR_STNEW; |
| 2363 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2364 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2365 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2366 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2367 | |
| 2368 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2369 | unsigned int low, high; |
| 2370 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2371 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2372 | set = 0; |
| 2373 | break; |
| 2374 | } |
| 2375 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2376 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2377 | } |
| 2378 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2379 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2380 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2381 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2382 | char *dash = strchr(args[cur_arg], '-'); |
| 2383 | |
| 2384 | low = high = str2uic(args[cur_arg]); |
| 2385 | if (dash) |
| 2386 | high = str2uic(dash + 1); |
| 2387 | |
| 2388 | if (high < low) { |
| 2389 | unsigned int swap = low; |
| 2390 | low = high; |
| 2391 | high = swap; |
| 2392 | } |
| 2393 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2394 | if (low < 1 || high > LONGBITS) { |
| 2395 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2396 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2398 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2399 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2400 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2401 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2402 | } |
| 2403 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2404 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2405 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2407 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2408 | } |
| 2409 | cur_arg++; |
| 2410 | } |
| 2411 | curproxy->bind_proc = set; |
| 2412 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2413 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2414 | if (curproxy == &defproxy) { |
| 2415 | 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] | 2416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2417 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2418 | } |
| 2419 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2420 | err = invalid_char(args[1]); |
| 2421 | if (err) { |
| 2422 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2423 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2424 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2425 | } |
| 2426 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2427 | 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] | 2428 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2429 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2432 | } |
| 2433 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2434 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2435 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2436 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2437 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2438 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2439 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2440 | if (*(args[1]) == 0) { |
| 2441 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2442 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2444 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2445 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2446 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2447 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2448 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2449 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2450 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2451 | curproxy->cookie_name = strdup(args[1]); |
| 2452 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2453 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2454 | cur_arg = 2; |
| 2455 | while (*(args[cur_arg])) { |
| 2456 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2457 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2458 | } |
| 2459 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2460 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2461 | } |
| 2462 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2463 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2464 | } |
| 2465 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2466 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2467 | } |
| 2468 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2469 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2470 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2471 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2472 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2473 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2474 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2475 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2476 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2477 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2478 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2479 | } |
| 2480 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2481 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2482 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2483 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2484 | if (!*args[cur_arg + 1]) { |
| 2485 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2486 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2487 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2488 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2491 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2492 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2493 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2494 | " dots nor does not start with a dot." |
| 2495 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2496 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2497 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2501 | if (err) { |
| 2502 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2503 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2505 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2506 | } |
| 2507 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2508 | if (!curproxy->cookie_domain) { |
| 2509 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2510 | } else { |
| 2511 | /* one domain was already specified, add another one by |
| 2512 | * building the string which will be returned along with |
| 2513 | * the cookie. |
| 2514 | */ |
| 2515 | char *new_ptr; |
| 2516 | int new_len = strlen(curproxy->cookie_domain) + |
| 2517 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2518 | new_ptr = malloc(new_len); |
| 2519 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2520 | free(curproxy->cookie_domain); |
| 2521 | curproxy->cookie_domain = new_ptr; |
| 2522 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2523 | cur_arg++; |
| 2524 | } |
| 2525 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2526 | unsigned int maxidle; |
| 2527 | const char *res; |
| 2528 | |
| 2529 | if (!*args[cur_arg + 1]) { |
| 2530 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2531 | file, linenum, args[cur_arg]); |
| 2532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2533 | goto out; |
| 2534 | } |
| 2535 | |
| 2536 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2537 | if (res) { |
| 2538 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2539 | file, linenum, *res, args[cur_arg]); |
| 2540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2541 | goto out; |
| 2542 | } |
| 2543 | curproxy->cookie_maxidle = maxidle; |
| 2544 | cur_arg++; |
| 2545 | } |
| 2546 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2547 | unsigned int maxlife; |
| 2548 | const char *res; |
| 2549 | |
| 2550 | if (!*args[cur_arg + 1]) { |
| 2551 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2552 | file, linenum, args[cur_arg]); |
| 2553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2554 | goto out; |
| 2555 | } |
| 2556 | |
| 2557 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2558 | if (res) { |
| 2559 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2560 | file, linenum, *res, args[cur_arg]); |
| 2561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2562 | goto out; |
| 2563 | } |
| 2564 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2565 | cur_arg++; |
| 2566 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2567 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2568 | 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] | 2569 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2571 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2572 | } |
| 2573 | cur_arg++; |
| 2574 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2575 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2576 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2577 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2578 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2579 | } |
| 2580 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2581 | 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] | 2582 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2583 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2584 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2585 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2586 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2587 | 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] | 2588 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2589 | file, linenum); |
| 2590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2591 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2592 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2593 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2594 | if (*(args[1]) == 0) { |
| 2595 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2596 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2598 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2602 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2603 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2604 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2605 | const char *beg, *end; |
| 2606 | |
| 2607 | beg = args[1] + 11; |
| 2608 | end = strchr(beg, ')'); |
| 2609 | |
| 2610 | if (!end || end == beg) { |
| 2611 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2612 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2614 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | free(curproxy->rdp_cookie_name); |
| 2618 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2619 | curproxy->rdp_cookie_len = end-beg; |
| 2620 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2621 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2622 | free(curproxy->rdp_cookie_name); |
| 2623 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2624 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2625 | } |
| 2626 | else { /* syntax */ |
| 2627 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2628 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2630 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | else { |
| 2634 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2635 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2637 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2638 | } |
| 2639 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2640 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2641 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2642 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2643 | if (curproxy == &defproxy) { |
| 2644 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2646 | goto out; |
| 2647 | } |
| 2648 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2649 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2650 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2651 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2652 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2653 | 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] | 2654 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2656 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2657 | } |
| 2658 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2659 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2660 | curproxy->appsession_name = strdup(args[1]); |
| 2661 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2662 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2663 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2664 | if (err) { |
| 2665 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2666 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2668 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2669 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2670 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2671 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2672 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2673 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2674 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2675 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2676 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2677 | |
| 2678 | cur_arg = 6; |
| 2679 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2680 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2681 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2682 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2683 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2684 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2685 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2686 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2687 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2688 | if (!*args[cur_arg + 1]) { |
| 2689 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2690 | file, linenum, args[0], args[cur_arg]); |
| 2691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2692 | goto out; |
| 2693 | } |
| 2694 | |
| 2695 | cur_arg++; |
| 2696 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2697 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2698 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2699 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2700 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2701 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2702 | } else { |
| 2703 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2705 | goto out; |
| 2706 | } |
| 2707 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2708 | cur_arg++; |
| 2709 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2710 | } /* Url App Session */ |
| 2711 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2712 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2713 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2714 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2715 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2716 | if (curproxy == &defproxy) { |
| 2717 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2719 | goto out; |
| 2720 | } |
| 2721 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2722 | if (*(args[4]) == 0) { |
| 2723 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2724 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2726 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2727 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2728 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2729 | curproxy->capture_name = strdup(args[2]); |
| 2730 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2731 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2732 | curproxy->to_log |= LW_COOKIE; |
| 2733 | } |
| 2734 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2735 | struct cap_hdr *hdr; |
| 2736 | |
| 2737 | if (curproxy == &defproxy) { |
| 2738 | 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] | 2739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2740 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2744 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2745 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2747 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2751 | hdr->next = curproxy->req_cap; |
| 2752 | hdr->name = strdup(args[3]); |
| 2753 | hdr->namelen = strlen(args[3]); |
| 2754 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2755 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2756 | hdr->index = curproxy->nb_req_cap++; |
| 2757 | curproxy->req_cap = hdr; |
| 2758 | curproxy->to_log |= LW_REQHDR; |
| 2759 | } |
| 2760 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2761 | struct cap_hdr *hdr; |
| 2762 | |
| 2763 | if (curproxy == &defproxy) { |
| 2764 | 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] | 2765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2766 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2770 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2771 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2773 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2774 | } |
| 2775 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2776 | hdr->next = curproxy->rsp_cap; |
| 2777 | hdr->name = strdup(args[3]); |
| 2778 | hdr->namelen = strlen(args[3]); |
| 2779 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2780 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2781 | hdr->index = curproxy->nb_rsp_cap++; |
| 2782 | curproxy->rsp_cap = hdr; |
| 2783 | curproxy->to_log |= LW_RSPHDR; |
| 2784 | } |
| 2785 | else { |
| 2786 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2787 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2789 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2790 | } |
| 2791 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2792 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2793 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2794 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2795 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2796 | if (*(args[1]) == 0) { |
| 2797 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2798 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2800 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2801 | } |
| 2802 | curproxy->conn_retries = atol(args[1]); |
| 2803 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2804 | 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] | 2805 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2806 | |
| 2807 | if (curproxy == &defproxy) { |
| 2808 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2810 | goto out; |
| 2811 | } |
| 2812 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2813 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2814 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2815 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2816 | 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] | 2817 | 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] | 2818 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2819 | 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] | 2820 | file, linenum, args[0]); |
| 2821 | err_code |= ERR_WARN; |
| 2822 | } |
| 2823 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2824 | 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] | 2825 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2826 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2827 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2828 | goto out; |
| 2829 | } |
| 2830 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 2831 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2832 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2833 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2834 | file, linenum); |
| 2835 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2836 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2837 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2838 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2839 | struct http_res_rule *rule; |
| 2840 | |
| 2841 | if (curproxy == &defproxy) { |
| 2842 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2844 | goto out; |
| 2845 | } |
| 2846 | |
| 2847 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2848 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2849 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2850 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2851 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2852 | file, linenum, args[0]); |
| 2853 | err_code |= ERR_WARN; |
| 2854 | } |
| 2855 | |
| 2856 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 2857 | |
| 2858 | if (!rule) { |
| 2859 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2860 | goto out; |
| 2861 | } |
| 2862 | |
| 2863 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2864 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 2865 | file, linenum); |
| 2866 | |
| 2867 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 2868 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2869 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2870 | /* set the header name and length into the proxy structure */ |
| 2871 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2872 | err_code |= ERR_WARN; |
| 2873 | |
| 2874 | if (!*args[1]) { |
| 2875 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2876 | file, linenum, args[0]); |
| 2877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2878 | goto out; |
| 2879 | } |
| 2880 | |
| 2881 | /* set the desired header name */ |
| 2882 | free(curproxy->server_id_hdr_name); |
| 2883 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2884 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2885 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2886 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2887 | struct http_req_rule *rule; |
| 2888 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2889 | if (curproxy == &defproxy) { |
| 2890 | 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] | 2891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2892 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2893 | } |
| 2894 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2895 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 2896 | * be processed before all http-request rules, we put them into their own list |
| 2897 | * and will insert them at the end. |
| 2898 | */ |
| 2899 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 2900 | if (!rule) { |
| 2901 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2902 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2903 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2904 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 2905 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2906 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2907 | file, linenum); |
| 2908 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 2909 | |
| 2910 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 2911 | 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]); |
| 2912 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2913 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2914 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2915 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2916 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2917 | if (curproxy == &defproxy) { |
| 2918 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2919 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2920 | goto out; |
| 2921 | } |
| 2922 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 2923 | 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] | 2924 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 2925 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2927 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2928 | } |
| 2929 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2930 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 2931 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2932 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2933 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2934 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2935 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 2936 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2937 | struct switching_rule *rule; |
| 2938 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2939 | if (curproxy == &defproxy) { |
| 2940 | 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] | 2941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2942 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2943 | } |
| 2944 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2945 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2946 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2947 | |
| 2948 | if (*(args[1]) == 0) { |
| 2949 | 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] | 2950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2951 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2952 | } |
| 2953 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 2954 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 2955 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2956 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2957 | file, linenum, errmsg); |
| 2958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2959 | goto out; |
| 2960 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 2961 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 2962 | 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] | 2963 | } |
| 2964 | |
| 2965 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 2966 | rule->cond = cond; |
| 2967 | rule->be.name = strdup(args[1]); |
| 2968 | LIST_INIT(&rule->list); |
| 2969 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 2970 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2971 | else if (strcmp(args[0], "use-server") == 0) { |
| 2972 | struct server_rule *rule; |
| 2973 | |
| 2974 | if (curproxy == &defproxy) { |
| 2975 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2977 | goto out; |
| 2978 | } |
| 2979 | |
| 2980 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2981 | err_code |= ERR_WARN; |
| 2982 | |
| 2983 | if (*(args[1]) == 0) { |
| 2984 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 2985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2986 | goto out; |
| 2987 | } |
| 2988 | |
| 2989 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2990 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2991 | file, linenum, args[0]); |
| 2992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2993 | goto out; |
| 2994 | } |
| 2995 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2996 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2997 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 2998 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 2999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3000 | goto out; |
| 3001 | } |
| 3002 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3003 | 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] | 3004 | |
| 3005 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3006 | rule->cond = cond; |
| 3007 | rule->srv.name = strdup(args[1]); |
| 3008 | LIST_INIT(&rule->list); |
| 3009 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3010 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3011 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3012 | else if ((!strcmp(args[0], "force-persist")) || |
| 3013 | (!strcmp(args[0], "ignore-persist"))) { |
| 3014 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3015 | |
| 3016 | if (curproxy == &defproxy) { |
| 3017 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3019 | goto out; |
| 3020 | } |
| 3021 | |
| 3022 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3023 | err_code |= ERR_WARN; |
| 3024 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3025 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3026 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3027 | file, linenum, args[0]); |
| 3028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3029 | goto out; |
| 3030 | } |
| 3031 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3032 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3033 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3034 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3036 | goto out; |
| 3037 | } |
| 3038 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3039 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3040 | * where force-persist is applied. |
| 3041 | */ |
| 3042 | 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] | 3043 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3044 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3045 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3046 | if (!strcmp(args[0], "force-persist")) { |
| 3047 | rule->type = PERSIST_TYPE_FORCE; |
| 3048 | } else { |
| 3049 | rule->type = PERSIST_TYPE_IGNORE; |
| 3050 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3051 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3052 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3053 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3054 | else if (!strcmp(args[0], "stick-table")) { |
| 3055 | int myidx = 1; |
| 3056 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3057 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3058 | curproxy->table.type = (unsigned int)-1; |
| 3059 | while (*args[myidx]) { |
| 3060 | const char *err; |
| 3061 | |
| 3062 | if (strcmp(args[myidx], "size") == 0) { |
| 3063 | myidx++; |
| 3064 | if (!*(args[myidx])) { |
| 3065 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3066 | file, linenum, args[myidx-1]); |
| 3067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3068 | goto out; |
| 3069 | } |
| 3070 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3071 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3072 | file, linenum, *err, args[myidx-1]); |
| 3073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3074 | goto out; |
| 3075 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3076 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3077 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3078 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3079 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3080 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3081 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3082 | file, linenum, args[myidx-1]); |
| 3083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3084 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3085 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3086 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3087 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3088 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3089 | myidx++; |
| 3090 | if (!*(args[myidx])) { |
| 3091 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3092 | file, linenum, args[myidx-1]); |
| 3093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3094 | goto out; |
| 3095 | } |
| 3096 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3097 | if (err) { |
| 3098 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3099 | file, linenum, *err, args[myidx-1]); |
| 3100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3101 | goto out; |
| 3102 | } |
| 3103 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3104 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3105 | } |
| 3106 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3107 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3108 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3109 | } |
| 3110 | else if (strcmp(args[myidx], "type") == 0) { |
| 3111 | myidx++; |
| 3112 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3113 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3114 | file, linenum, args[myidx]); |
| 3115 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3116 | goto out; |
| 3117 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3118 | /* myidx already points to next arg */ |
| 3119 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3120 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3121 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3122 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3123 | |
| 3124 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3125 | nw = args[myidx]; |
| 3126 | while (*nw) { |
| 3127 | /* the "store" keyword supports a comma-separated list */ |
| 3128 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3129 | sa = NULL; /* store arg */ |
| 3130 | while (*nw && *nw != ',') { |
| 3131 | if (*nw == '(') { |
| 3132 | *nw = 0; |
| 3133 | sa = ++nw; |
| 3134 | while (*nw != ')') { |
| 3135 | if (!*nw) { |
| 3136 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3137 | file, linenum, args[0], cw); |
| 3138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3139 | goto out; |
| 3140 | } |
| 3141 | nw++; |
| 3142 | } |
| 3143 | *nw = '\0'; |
| 3144 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3145 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3146 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3147 | if (*nw) |
| 3148 | *nw++ = '\0'; |
| 3149 | type = stktable_get_data_type(cw); |
| 3150 | if (type < 0) { |
| 3151 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3152 | file, linenum, args[0], cw); |
| 3153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3154 | goto out; |
| 3155 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3156 | |
| 3157 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3158 | switch (err) { |
| 3159 | case PE_NONE: break; |
| 3160 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3161 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3162 | file, linenum, args[0], cw); |
| 3163 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3164 | break; |
| 3165 | |
| 3166 | case PE_ARG_MISSING: |
| 3167 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3168 | file, linenum, args[0], cw); |
| 3169 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3170 | goto out; |
| 3171 | |
| 3172 | case PE_ARG_NOT_USED: |
| 3173 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3174 | file, linenum, args[0], cw); |
| 3175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3176 | goto out; |
| 3177 | |
| 3178 | default: |
| 3179 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3180 | file, linenum, args[0], cw); |
| 3181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3182 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3183 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3184 | } |
| 3185 | myidx++; |
| 3186 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3187 | else { |
| 3188 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3189 | file, linenum, args[myidx]); |
| 3190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3191 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3192 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | if (!curproxy->table.size) { |
| 3196 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3197 | file, linenum); |
| 3198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3199 | goto out; |
| 3200 | } |
| 3201 | |
| 3202 | if (curproxy->table.type == (unsigned int)-1) { |
| 3203 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3204 | file, linenum); |
| 3205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3206 | goto out; |
| 3207 | } |
| 3208 | } |
| 3209 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3210 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3211 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3212 | int myidx = 0; |
| 3213 | const char *name = NULL; |
| 3214 | int flags; |
| 3215 | |
| 3216 | if (curproxy == &defproxy) { |
| 3217 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3219 | goto out; |
| 3220 | } |
| 3221 | |
| 3222 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3223 | err_code |= ERR_WARN; |
| 3224 | goto out; |
| 3225 | } |
| 3226 | |
| 3227 | myidx++; |
| 3228 | if ((strcmp(args[myidx], "store") == 0) || |
| 3229 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3230 | myidx++; |
| 3231 | flags = STK_IS_STORE; |
| 3232 | } |
| 3233 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3234 | myidx++; |
| 3235 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3236 | } |
| 3237 | else if (strcmp(args[myidx], "match") == 0) { |
| 3238 | myidx++; |
| 3239 | flags = STK_IS_MATCH; |
| 3240 | } |
| 3241 | else if (strcmp(args[myidx], "on") == 0) { |
| 3242 | myidx++; |
| 3243 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3244 | } |
| 3245 | else { |
| 3246 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3248 | goto out; |
| 3249 | } |
| 3250 | |
| 3251 | if (*(args[myidx]) == 0) { |
| 3252 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3254 | goto out; |
| 3255 | } |
| 3256 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3257 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3258 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3259 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3260 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3262 | goto out; |
| 3263 | } |
| 3264 | |
| 3265 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3266 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3267 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3268 | 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] | 3269 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3270 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3271 | goto out; |
| 3272 | } |
| 3273 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3274 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3275 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3276 | 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] | 3277 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3278 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3279 | goto out; |
| 3280 | } |
| 3281 | } |
| 3282 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3283 | /* 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] | 3284 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3285 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3286 | if (strcmp(args[myidx], "table") == 0) { |
| 3287 | myidx++; |
| 3288 | name = args[myidx++]; |
| 3289 | } |
| 3290 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3291 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3292 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3293 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3294 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3295 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3296 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3297 | goto out; |
| 3298 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3299 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3300 | else if (*(args[myidx])) { |
| 3301 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3302 | file, linenum, args[0], args[myidx]); |
| 3303 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3304 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3305 | goto out; |
| 3306 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3307 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3308 | 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] | 3309 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3310 | 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] | 3311 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3312 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3313 | rule->cond = cond; |
| 3314 | rule->expr = expr; |
| 3315 | rule->flags = flags; |
| 3316 | rule->table.name = name ? strdup(name) : NULL; |
| 3317 | LIST_INIT(&rule->list); |
| 3318 | if (flags & STK_ON_RSP) |
| 3319 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3320 | else |
| 3321 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3322 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3323 | else if (!strcmp(args[0], "stats")) { |
| 3324 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3325 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3326 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3327 | if (!*args[1]) { |
| 3328 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3329 | } else if (!strcmp(args[1], "admin")) { |
| 3330 | struct stats_admin_rule *rule; |
| 3331 | |
| 3332 | if (curproxy == &defproxy) { |
| 3333 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3335 | goto out; |
| 3336 | } |
| 3337 | |
| 3338 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3339 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3340 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3341 | goto out; |
| 3342 | } |
| 3343 | |
| 3344 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3345 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3346 | file, linenum, args[0], args[1]); |
| 3347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3348 | goto out; |
| 3349 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3350 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3351 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3352 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3354 | goto out; |
| 3355 | } |
| 3356 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3357 | err_code |= warnif_cond_conflicts(cond, |
| 3358 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3359 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3360 | |
| 3361 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3362 | rule->cond = cond; |
| 3363 | LIST_INIT(&rule->list); |
| 3364 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3365 | } else if (!strcmp(args[1], "uri")) { |
| 3366 | if (*(args[2]) == 0) { |
| 3367 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3370 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3371 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3372 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3373 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3374 | } |
| 3375 | } else if (!strcmp(args[1], "realm")) { |
| 3376 | if (*(args[2]) == 0) { |
| 3377 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3379 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3380 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3381 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3382 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3383 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3384 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3385 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3386 | unsigned interval; |
| 3387 | |
| 3388 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3389 | if (err) { |
| 3390 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3391 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3393 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3394 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3395 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3396 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3397 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3398 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3399 | } 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] | 3400 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3401 | |
| 3402 | if (curproxy == &defproxy) { |
| 3403 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3405 | goto out; |
| 3406 | } |
| 3407 | |
| 3408 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3409 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3410 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3411 | goto out; |
| 3412 | } |
| 3413 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3414 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3415 | !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] | 3416 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3417 | file, linenum, args[0]); |
| 3418 | err_code |= ERR_WARN; |
| 3419 | } |
| 3420 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3421 | 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] | 3422 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3423 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3424 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3425 | goto out; |
| 3426 | } |
| 3427 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3428 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3429 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3430 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3431 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3432 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3433 | } else if (!strcmp(args[1], "auth")) { |
| 3434 | if (*(args[2]) == 0) { |
| 3435 | 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] | 3436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3437 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3438 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3439 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3440 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3441 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3442 | } |
| 3443 | } else if (!strcmp(args[1], "scope")) { |
| 3444 | if (*(args[2]) == 0) { |
| 3445 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3447 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3448 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3449 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3450 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3451 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3452 | } |
| 3453 | } else if (!strcmp(args[1], "enable")) { |
| 3454 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3455 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3456 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3457 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3458 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3459 | } else if (!strcmp(args[1], "hide-version")) { |
| 3460 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3461 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3462 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3463 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3464 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3465 | } else if (!strcmp(args[1], "show-legends")) { |
| 3466 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3467 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3468 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3469 | goto out; |
| 3470 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3471 | } else if (!strcmp(args[1], "show-node")) { |
| 3472 | |
| 3473 | if (*args[2]) { |
| 3474 | int i; |
| 3475 | char c; |
| 3476 | |
| 3477 | for (i=0; args[2][i]; i++) { |
| 3478 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3479 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3480 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3481 | break; |
| 3482 | } |
| 3483 | |
| 3484 | if (!i || args[2][i]) { |
| 3485 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3486 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3487 | file, linenum, args[0], args[1]); |
| 3488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3489 | goto out; |
| 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3494 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3495 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3496 | goto out; |
| 3497 | } |
| 3498 | } else if (!strcmp(args[1], "show-desc")) { |
| 3499 | char *desc = NULL; |
| 3500 | |
| 3501 | if (*args[2]) { |
| 3502 | int i, len=0; |
| 3503 | char *d; |
| 3504 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3505 | for (i = 2; *args[i]; i++) |
| 3506 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3507 | |
| 3508 | desc = d = (char *)calloc(1, len); |
| 3509 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3510 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3511 | for (i = 3; *args[i]; i++) |
| 3512 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | if (!*args[2] && !global.desc) |
| 3516 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3517 | file, linenum, args[1]); |
| 3518 | else { |
| 3519 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3520 | free(desc); |
| 3521 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3522 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3523 | goto out; |
| 3524 | } |
| 3525 | free(desc); |
| 3526 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3527 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3528 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3529 | 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] | 3530 | 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] | 3531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3532 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3536 | int optnum; |
| 3537 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3538 | if (*(args[1]) == '\0') { |
| 3539 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3540 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3542 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3543 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3544 | |
| 3545 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3546 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3547 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3548 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3549 | file, linenum, cfg_opts[optnum].name); |
| 3550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3551 | goto out; |
| 3552 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3553 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3554 | err_code |= ERR_WARN; |
| 3555 | goto out; |
| 3556 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3557 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3558 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3559 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3560 | |
| 3561 | switch (kwm) { |
| 3562 | case KWM_STD: |
| 3563 | curproxy->options |= cfg_opts[optnum].val; |
| 3564 | break; |
| 3565 | case KWM_NO: |
| 3566 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3567 | break; |
| 3568 | case KWM_DEF: /* already cleared */ |
| 3569 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3570 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3571 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3572 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3573 | } |
| 3574 | } |
| 3575 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3576 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3577 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3578 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3579 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3580 | file, linenum, cfg_opts2[optnum].name); |
| 3581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3582 | goto out; |
| 3583 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3584 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3585 | err_code |= ERR_WARN; |
| 3586 | goto out; |
| 3587 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3588 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3589 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3590 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3591 | |
| 3592 | switch (kwm) { |
| 3593 | case KWM_STD: |
| 3594 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3595 | break; |
| 3596 | case KWM_NO: |
| 3597 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3598 | break; |
| 3599 | case KWM_DEF: /* already cleared */ |
| 3600 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3601 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3602 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3603 | } |
| 3604 | } |
| 3605 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3606 | /* HTTP options override each other. They can be cancelled using |
| 3607 | * "no option xxx" which only switches to default mode if the mode |
| 3608 | * was this one (useful for cancelling options set in defaults |
| 3609 | * sections). |
| 3610 | */ |
| 3611 | if (strcmp(args[1], "httpclose") == 0) { |
| 3612 | if (kwm == KWM_STD) { |
| 3613 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3614 | curproxy->options |= PR_O_HTTP_PCL; |
| 3615 | goto out; |
| 3616 | } |
| 3617 | else if (kwm == KWM_NO) { |
| 3618 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3619 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3620 | goto out; |
| 3621 | } |
| 3622 | } |
| 3623 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3624 | if (kwm == KWM_STD) { |
| 3625 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3626 | curproxy->options |= PR_O_HTTP_FCL; |
| 3627 | goto out; |
| 3628 | } |
| 3629 | else if (kwm == KWM_NO) { |
| 3630 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3631 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3632 | goto out; |
| 3633 | } |
| 3634 | } |
| 3635 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3636 | if (kwm == KWM_STD) { |
| 3637 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3638 | curproxy->options |= PR_O_HTTP_SCL; |
| 3639 | goto out; |
| 3640 | } |
| 3641 | else if (kwm == KWM_NO) { |
| 3642 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3643 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3644 | goto out; |
| 3645 | } |
| 3646 | } |
| 3647 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3648 | if (kwm == KWM_STD) { |
| 3649 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3650 | curproxy->options |= PR_O_HTTP_KAL; |
| 3651 | goto out; |
| 3652 | } |
| 3653 | else if (kwm == KWM_NO) { |
| 3654 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3655 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3656 | goto out; |
| 3657 | } |
| 3658 | } |
| 3659 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3660 | if (kwm == KWM_STD) { |
| 3661 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3662 | curproxy->options |= PR_O_HTTP_TUN; |
| 3663 | goto out; |
| 3664 | } |
| 3665 | else if (kwm == KWM_NO) { |
| 3666 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3667 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3668 | goto out; |
| 3669 | } |
| 3670 | } |
| 3671 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3672 | if (kwm != KWM_STD) { |
| 3673 | 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] | 3674 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3676 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3677 | } |
| 3678 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3679 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3680 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3681 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3682 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3683 | if (*(args[2]) != '\0') { |
| 3684 | if (!strcmp(args[2], "clf")) { |
| 3685 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3686 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3687 | } else { |
| 3688 | 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] | 3689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3690 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3691 | } |
| 3692 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3693 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3694 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3695 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3696 | free(curproxy->conf.logformat_string); |
| 3697 | curproxy->conf.logformat_string = logformat; |
| 3698 | |
| 3699 | free(curproxy->conf.lfs_file); |
| 3700 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3701 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3702 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3703 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3704 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3705 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3706 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3707 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3708 | free(curproxy->conf.logformat_string); |
| 3709 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3710 | |
| 3711 | free(curproxy->conf.lfs_file); |
| 3712 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3713 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3714 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3715 | else if (!strcmp(args[1], "tcpka")) { |
| 3716 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3717 | 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] | 3718 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3719 | |
| 3720 | if (curproxy->cap & PR_CAP_FE) |
| 3721 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3722 | if (curproxy->cap & PR_CAP_BE) |
| 3723 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3724 | } |
| 3725 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3726 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3727 | err_code |= ERR_WARN; |
| 3728 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3729 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3730 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3731 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3732 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3733 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3734 | if (!*args[2]) { /* no argument */ |
| 3735 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3736 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3737 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3738 | 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] | 3739 | curproxy->check_req = (char *)malloc(reqlen); |
| 3740 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3741 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3742 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3743 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3744 | if (*args[4]) |
| 3745 | reqlen += strlen(args[4]); |
| 3746 | else |
| 3747 | reqlen += strlen("HTTP/1.0"); |
| 3748 | |
| 3749 | curproxy->check_req = (char *)malloc(reqlen); |
| 3750 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3751 | "%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] | 3752 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3753 | } |
| 3754 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3755 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3756 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3757 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3758 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3759 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3760 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3761 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3762 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3763 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3764 | else if (!strcmp(args[1], "smtpchk")) { |
| 3765 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3766 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3767 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3768 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3769 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3770 | |
| 3771 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3772 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3773 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3774 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3775 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3776 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3777 | curproxy->check_req = (char *)malloc(reqlen); |
| 3778 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3779 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3780 | } else { |
| 3781 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3782 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3783 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3784 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3785 | } |
| 3786 | } |
| 3787 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3788 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3789 | /* use PostgreSQL request to check servers' health */ |
| 3790 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3791 | err_code |= ERR_WARN; |
| 3792 | |
| 3793 | free(curproxy->check_req); |
| 3794 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3795 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3796 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3797 | |
| 3798 | if (*(args[2])) { |
| 3799 | int cur_arg = 2; |
| 3800 | |
| 3801 | while (*(args[cur_arg])) { |
| 3802 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3803 | char * packet; |
| 3804 | uint32_t packet_len; |
| 3805 | uint32_t pv; |
| 3806 | |
| 3807 | /* suboption header - needs additional argument for it */ |
| 3808 | if (*(args[cur_arg+1]) == 0) { |
| 3809 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3810 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3812 | goto out; |
| 3813 | } |
| 3814 | |
| 3815 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3816 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3817 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3818 | |
| 3819 | packet = (char*) calloc(1, packet_len); |
| 3820 | |
| 3821 | memcpy(packet + 4, &pv, 4); |
| 3822 | |
| 3823 | /* copy "user" */ |
| 3824 | memcpy(packet + 8, "user", 4); |
| 3825 | |
| 3826 | /* copy username */ |
| 3827 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3828 | |
| 3829 | free(curproxy->check_req); |
| 3830 | curproxy->check_req = packet; |
| 3831 | curproxy->check_len = packet_len; |
| 3832 | |
| 3833 | packet_len = htonl(packet_len); |
| 3834 | memcpy(packet, &packet_len, 4); |
| 3835 | cur_arg += 2; |
| 3836 | } else { |
| 3837 | /* unknown suboption - catchall */ |
| 3838 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3839 | file, linenum, args[0], args[1]); |
| 3840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3841 | goto out; |
| 3842 | } |
| 3843 | } /* end while loop */ |
| 3844 | } |
| 3845 | } |
| 3846 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3847 | else if (!strcmp(args[1], "redis-check")) { |
| 3848 | /* use REDIS PING request to check servers' health */ |
| 3849 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3850 | err_code |= ERR_WARN; |
| 3851 | |
| 3852 | free(curproxy->check_req); |
| 3853 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3854 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3855 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3856 | |
| 3857 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3858 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3859 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3860 | } |
| 3861 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3862 | else if (!strcmp(args[1], "mysql-check")) { |
| 3863 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3864 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3865 | err_code |= ERR_WARN; |
| 3866 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3867 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3868 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3869 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3870 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3871 | |
| 3872 | /* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
| 3873 | * const char mysql40_client_auth_pkt[] = { |
| 3874 | * "\x0e\x00\x00" // packet length |
| 3875 | * "\x01" // packet number |
| 3876 | * "\x00\x00" // client capabilities |
| 3877 | * "\x00\x00\x01" // max packet |
| 3878 | * "haproxy\x00" // username (null terminated string) |
| 3879 | * "\x00" // filler (always 0x00) |
| 3880 | * "\x01\x00\x00" // packet length |
| 3881 | * "\x00" // packet number |
| 3882 | * "\x01" // COM_QUIT command |
| 3883 | * }; |
| 3884 | */ |
| 3885 | |
| 3886 | if (*(args[2])) { |
| 3887 | int cur_arg = 2; |
| 3888 | |
| 3889 | while (*(args[cur_arg])) { |
| 3890 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3891 | char *mysqluser; |
| 3892 | int packetlen, reqlen, userlen; |
| 3893 | |
| 3894 | /* suboption header - needs additional argument for it */ |
| 3895 | if (*(args[cur_arg+1]) == 0) { |
| 3896 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3897 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3899 | goto out; |
| 3900 | } |
| 3901 | mysqluser = args[cur_arg + 1]; |
| 3902 | userlen = strlen(mysqluser); |
| 3903 | packetlen = userlen + 7; |
| 3904 | reqlen = packetlen + 9; |
| 3905 | |
| 3906 | free(curproxy->check_req); |
| 3907 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 3908 | curproxy->check_len = reqlen; |
| 3909 | |
| 3910 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 3911 | ((unsigned char) packetlen & 0xff), |
| 3912 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 3913 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 3914 | |
| 3915 | curproxy->check_req[3] = 1; |
Hervé COMMOWICK | 212f778 | 2011-06-10 14:05:59 +0200 | [diff] [blame] | 3916 | curproxy->check_req[5] = 128; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3917 | curproxy->check_req[8] = 1; |
| 3918 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 3919 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 3920 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 3921 | cur_arg += 2; |
| 3922 | } else { |
| 3923 | /* unknown suboption - catchall */ |
| 3924 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3925 | file, linenum, args[0], args[1]); |
| 3926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3927 | goto out; |
| 3928 | } |
| 3929 | } /* end while loop */ |
| 3930 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3931 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3932 | else if (!strcmp(args[1], "ldap-check")) { |
| 3933 | /* use LDAP request to check servers' health */ |
| 3934 | free(curproxy->check_req); |
| 3935 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3936 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 3937 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 3938 | |
| 3939 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3940 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 3941 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 3942 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 3943 | else if (!strcmp(args[1], "tcp-check")) { |
| 3944 | /* use raw TCPCHK send/expect to check servers' health */ |
| 3945 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3946 | err_code |= ERR_WARN; |
| 3947 | |
| 3948 | free(curproxy->check_req); |
| 3949 | curproxy->check_req = NULL; |
| 3950 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3951 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 3952 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3953 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3954 | int cur_arg; |
| 3955 | |
| 3956 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 3957 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3958 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3959 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3960 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3961 | |
| 3962 | free(curproxy->fwdfor_hdr_name); |
| 3963 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 3964 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 3965 | |
| 3966 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 3967 | cur_arg = 2; |
| 3968 | while (*(args[cur_arg])) { |
| 3969 | if (!strcmp(args[cur_arg], "except")) { |
| 3970 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 3971 | 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] | 3972 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 3973 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3975 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3976 | } |
| 3977 | /* flush useless bits */ |
| 3978 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3979 | cur_arg += 2; |
| 3980 | } else if (!strcmp(args[cur_arg], "header")) { |
| 3981 | /* suboption header - needs additional argument for it */ |
| 3982 | if (*(args[cur_arg+1]) == 0) { |
| 3983 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 3984 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3986 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3987 | } |
| 3988 | free(curproxy->fwdfor_hdr_name); |
| 3989 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 3990 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 3991 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3992 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 3993 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 3994 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 3995 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 3996 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 3997 | 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] | 3998 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4000 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4001 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4002 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4003 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4004 | else if (!strcmp(args[1], "originalto")) { |
| 4005 | int cur_arg; |
| 4006 | |
| 4007 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4008 | * set default options (ie: bitfield, header name, etc) |
| 4009 | */ |
| 4010 | |
| 4011 | curproxy->options |= PR_O_ORGTO; |
| 4012 | |
| 4013 | free(curproxy->orgto_hdr_name); |
| 4014 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4015 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4016 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4017 | /* 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] | 4018 | cur_arg = 2; |
| 4019 | while (*(args[cur_arg])) { |
| 4020 | if (!strcmp(args[cur_arg], "except")) { |
| 4021 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4022 | 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] | 4023 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4024 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4026 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4027 | } |
| 4028 | /* flush useless bits */ |
| 4029 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4030 | cur_arg += 2; |
| 4031 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4032 | /* suboption header - needs additional argument for it */ |
| 4033 | if (*(args[cur_arg+1]) == 0) { |
| 4034 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4035 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4037 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4038 | } |
| 4039 | free(curproxy->orgto_hdr_name); |
| 4040 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4041 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4042 | cur_arg += 2; |
| 4043 | } else { |
| 4044 | /* unknown suboption - catchall */ |
| 4045 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4046 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4048 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4049 | } |
| 4050 | } /* end while loop */ |
| 4051 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4052 | else { |
| 4053 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4055 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4056 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4057 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4058 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4059 | else if (!strcmp(args[0], "default_backend")) { |
| 4060 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4061 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4062 | |
| 4063 | if (*(args[1]) == 0) { |
| 4064 | 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] | 4065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4066 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4067 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4068 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4069 | curproxy->defbe.name = strdup(args[1]); |
| 4070 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4071 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4072 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4073 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4074 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4075 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4076 | 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] | 4077 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4078 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4079 | /* enable reconnections to dispatch */ |
| 4080 | curproxy->options |= PR_O_REDISP; |
| 4081 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4082 | else if (!strcmp(args[0], "http-check")) { |
| 4083 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4084 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4085 | |
| 4086 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4087 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4088 | curproxy->options |= PR_O_DISABLE404; |
| 4089 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4090 | else if (strcmp(args[1], "send-state") == 0) { |
| 4091 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4092 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4093 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4094 | else if (strcmp(args[1], "expect") == 0) { |
| 4095 | const char *ptr_arg; |
| 4096 | int cur_arg; |
| 4097 | |
| 4098 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4099 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4101 | goto out; |
| 4102 | } |
| 4103 | |
| 4104 | cur_arg = 2; |
| 4105 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4106 | while (*(ptr_arg = args[cur_arg])) { |
| 4107 | while (*ptr_arg == '!') { |
| 4108 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4109 | ptr_arg++; |
| 4110 | } |
| 4111 | if (*ptr_arg) |
| 4112 | break; |
| 4113 | cur_arg++; |
| 4114 | } |
| 4115 | /* now ptr_arg points to the beginning of a word past any possible |
| 4116 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4117 | */ |
| 4118 | if (strcmp(ptr_arg, "status") == 0) { |
| 4119 | if (!*(args[cur_arg + 1])) { |
| 4120 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4121 | file, linenum, args[0], args[1], ptr_arg); |
| 4122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4123 | goto out; |
| 4124 | } |
| 4125 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4126 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4127 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4128 | } |
| 4129 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4130 | if (!*(args[cur_arg + 1])) { |
| 4131 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4132 | file, linenum, args[0], args[1], ptr_arg); |
| 4133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4134 | goto out; |
| 4135 | } |
| 4136 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4137 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4138 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4139 | } |
| 4140 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4141 | if (!*(args[cur_arg + 1])) { |
| 4142 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4143 | file, linenum, args[0], args[1], ptr_arg); |
| 4144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4145 | goto out; |
| 4146 | } |
| 4147 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4148 | free(curproxy->expect_str); |
| 4149 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 4150 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4151 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 4152 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 4153 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 4154 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 4155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4156 | goto out; |
| 4157 | } |
| 4158 | } |
| 4159 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4160 | if (!*(args[cur_arg + 1])) { |
| 4161 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4162 | file, linenum, args[0], args[1], ptr_arg); |
| 4163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4164 | goto out; |
| 4165 | } |
| 4166 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4167 | free(curproxy->expect_str); |
| 4168 | if (curproxy->expect_regex) regfree(curproxy->expect_regex); |
| 4169 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4170 | curproxy->expect_regex = calloc(1, sizeof(regex_t)); |
| 4171 | if (regcomp(curproxy->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 4172 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 4173 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 4174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4175 | goto out; |
| 4176 | } |
| 4177 | } |
| 4178 | else { |
| 4179 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4180 | file, linenum, args[0], args[1], ptr_arg); |
| 4181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4182 | goto out; |
| 4183 | } |
| 4184 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4185 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4186 | 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] | 4187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4188 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4189 | } |
| 4190 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4191 | else if (!strcmp(args[0], "tcp-check")) { |
| 4192 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4193 | err_code |= ERR_WARN; |
| 4194 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4195 | if (strcmp(args[1], "connect") == 0) { |
| 4196 | const char *ptr_arg; |
| 4197 | int cur_arg; |
| 4198 | struct tcpcheck_rule *tcpcheck; |
| 4199 | struct list *l; |
| 4200 | |
| 4201 | /* check if first rule is also a 'connect' action */ |
| 4202 | l = (struct list *)&curproxy->tcpcheck_rules; |
| 4203 | if (l->p != l->n) { |
| 4204 | tcpcheck = (struct tcpcheck_rule *)l->n; |
| 4205 | if (tcpcheck && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4206 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4207 | file, linenum); |
| 4208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4209 | goto out; |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | cur_arg = 2; |
| 4214 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4215 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4216 | |
| 4217 | /* parsing each parameters to fill up the rule */ |
| 4218 | while (*(ptr_arg = args[cur_arg])) { |
| 4219 | /* tcp port */ |
| 4220 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4221 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4222 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4223 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4224 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4226 | goto out; |
| 4227 | } |
| 4228 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4229 | cur_arg += 2; |
| 4230 | } |
| 4231 | /* send proxy protocol */ |
| 4232 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4233 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4234 | cur_arg++; |
| 4235 | } |
| 4236 | #ifdef USE_OPENSSL |
| 4237 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4238 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4239 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4240 | cur_arg++; |
| 4241 | } |
| 4242 | #endif /* USE_OPENSSL */ |
| 4243 | else { |
| 4244 | #ifdef USE_OPENSSL |
| 4245 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4246 | #else /* USE_OPENSSL */ |
| 4247 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4248 | #endif /* USE_OPENSSL */ |
| 4249 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4251 | goto out; |
| 4252 | } |
| 4253 | |
| 4254 | } |
| 4255 | |
| 4256 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4257 | } |
| 4258 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4259 | if (! *(args[2]) ) { |
| 4260 | /* SEND string expected */ |
| 4261 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4262 | file, linenum, args[0], args[1], args[2]); |
| 4263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4264 | goto out; |
| 4265 | } else { |
| 4266 | struct tcpcheck_rule *tcpcheck; |
| 4267 | |
| 4268 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4269 | |
| 4270 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4271 | tcpcheck->string_len = strlen(args[2]); |
| 4272 | tcpcheck->string = strdup(args[2]); |
| 4273 | tcpcheck->expect_regex = NULL; |
| 4274 | |
| 4275 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4276 | } |
| 4277 | } |
| 4278 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4279 | if (! *(args[2]) ) { |
| 4280 | /* SEND binary string expected */ |
| 4281 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4282 | file, linenum, args[0], args[1], args[2]); |
| 4283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4284 | goto out; |
| 4285 | } else { |
| 4286 | struct tcpcheck_rule *tcpcheck; |
| 4287 | char *err = NULL; |
| 4288 | |
| 4289 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4290 | |
| 4291 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4292 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4293 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4294 | file, linenum, args[0], args[1], args[2], err); |
| 4295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4296 | goto out; |
| 4297 | } |
| 4298 | tcpcheck->expect_regex = NULL; |
| 4299 | |
| 4300 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4301 | } |
| 4302 | } |
| 4303 | else if (strcmp(args[1], "expect") == 0) { |
| 4304 | const char *ptr_arg; |
| 4305 | int cur_arg; |
| 4306 | int inverse = 0; |
| 4307 | |
| 4308 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4309 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4311 | goto out; |
| 4312 | } |
| 4313 | |
| 4314 | cur_arg = 2; |
| 4315 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4316 | while (*(ptr_arg = args[cur_arg])) { |
| 4317 | while (*ptr_arg == '!') { |
| 4318 | inverse = !inverse; |
| 4319 | ptr_arg++; |
| 4320 | } |
| 4321 | if (*ptr_arg) |
| 4322 | break; |
| 4323 | cur_arg++; |
| 4324 | } |
| 4325 | /* now ptr_arg points to the beginning of a word past any possible |
| 4326 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4327 | */ |
| 4328 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4329 | if (!*(args[cur_arg + 1])) { |
| 4330 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary 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 | struct tcpcheck_rule *tcpcheck; |
| 4336 | char *err = NULL; |
| 4337 | |
| 4338 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4339 | |
| 4340 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4341 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4342 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4343 | file, linenum, args[0], args[1], args[2], err); |
| 4344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4345 | goto out; |
| 4346 | } |
| 4347 | tcpcheck->expect_regex = NULL; |
| 4348 | tcpcheck->inverse = inverse; |
| 4349 | |
| 4350 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4351 | } |
| 4352 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4353 | if (!*(args[cur_arg + 1])) { |
| 4354 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4355 | file, linenum, args[0], args[1], ptr_arg); |
| 4356 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4357 | goto out; |
| 4358 | } |
| 4359 | struct tcpcheck_rule *tcpcheck; |
| 4360 | |
| 4361 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4362 | |
| 4363 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4364 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4365 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4366 | tcpcheck->expect_regex = NULL; |
| 4367 | tcpcheck->inverse = inverse; |
| 4368 | |
| 4369 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4370 | } |
| 4371 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4372 | if (!*(args[cur_arg + 1])) { |
| 4373 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4374 | file, linenum, args[0], args[1], ptr_arg); |
| 4375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4376 | goto out; |
| 4377 | } |
| 4378 | struct tcpcheck_rule *tcpcheck; |
| 4379 | |
| 4380 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4381 | |
| 4382 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4383 | tcpcheck->string_len = 0; |
| 4384 | tcpcheck->string = NULL; |
| 4385 | tcpcheck->expect_regex = calloc(1, sizeof(regex_t)); |
| 4386 | if (regcomp(tcpcheck->expect_regex, args[cur_arg + 1], REG_EXTENDED) != 0) { |
| 4387 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s'.\n", |
| 4388 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1]); |
| 4389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4390 | goto out; |
| 4391 | } |
| 4392 | tcpcheck->inverse = inverse; |
| 4393 | |
| 4394 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4395 | } |
| 4396 | else { |
| 4397 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4398 | file, linenum, args[0], args[1], ptr_arg); |
| 4399 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4400 | goto out; |
| 4401 | } |
| 4402 | } |
| 4403 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4404 | 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] | 4405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4406 | goto out; |
| 4407 | } |
| 4408 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4409 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4410 | if (curproxy == &defproxy) { |
| 4411 | 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] | 4412 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4413 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4414 | } |
| 4415 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4416 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4417 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4418 | |
| 4419 | if (strcmp(args[1], "fail") == 0) { |
| 4420 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4421 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4422 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4423 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4425 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4426 | } |
| 4427 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4428 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4429 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4430 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4431 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4432 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4433 | } |
| 4434 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4435 | } |
| 4436 | else { |
| 4437 | 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] | 4438 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4439 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4440 | } |
| 4441 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4442 | #ifdef TPROXY |
| 4443 | else if (!strcmp(args[0], "transparent")) { |
| 4444 | /* enable transparent proxy connections */ |
| 4445 | curproxy->options |= PR_O_TRANSP; |
| 4446 | } |
| 4447 | #endif |
| 4448 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4449 | 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] | 4450 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4451 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4452 | if (*(args[1]) == 0) { |
| 4453 | 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] | 4454 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4455 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4456 | } |
| 4457 | curproxy->maxconn = atol(args[1]); |
| 4458 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4459 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4460 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4461 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4462 | |
| 4463 | if (*(args[1]) == 0) { |
| 4464 | 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] | 4465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4466 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4467 | } |
| 4468 | curproxy->backlog = atol(args[1]); |
| 4469 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4470 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4471 | 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] | 4472 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4473 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4474 | if (*(args[1]) == 0) { |
| 4475 | 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] | 4476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4477 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4478 | } |
| 4479 | curproxy->fullconn = atol(args[1]); |
| 4480 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4481 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4482 | if (*(args[1]) == 0) { |
| 4483 | 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] | 4484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4485 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4486 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4487 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4488 | if (err) { |
| 4489 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4490 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4492 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4493 | } |
| 4494 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4495 | } |
| 4496 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4497 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4498 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4499 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4500 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4501 | if (curproxy == &defproxy) { |
| 4502 | 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] | 4503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4504 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4505 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4506 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4507 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4508 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4509 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4510 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4511 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4512 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4513 | goto out; |
| 4514 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4515 | |
| 4516 | proto = protocol_by_family(sk->ss_family); |
| 4517 | if (!proto || !proto->connect) { |
| 4518 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4519 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4521 | goto out; |
| 4522 | } |
| 4523 | |
| 4524 | if (port1 != port2) { |
| 4525 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4526 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4528 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4529 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4530 | |
| 4531 | if (!port1) { |
| 4532 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4533 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4535 | goto out; |
| 4536 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4537 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4538 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4539 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4540 | } |
| 4541 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4542 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4543 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4544 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4545 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4546 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4547 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4548 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4549 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4550 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4551 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4552 | /** |
| 4553 | * The syntax for hash-type config element is |
| 4554 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4555 | * |
| 4556 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4557 | */ |
| 4558 | 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] | 4559 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4560 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4561 | err_code |= ERR_WARN; |
| 4562 | |
| 4563 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4564 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4565 | } |
| 4566 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4567 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4568 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4569 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4570 | 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]); |
| 4571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4572 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4573 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4574 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4575 | 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] | 4576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4577 | goto out; |
| 4578 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4579 | |
| 4580 | /* set the hash function to use */ |
| 4581 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4582 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4583 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4584 | |
| 4585 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4586 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4587 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4588 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4589 | /* set the hash function */ |
| 4590 | if (!strcmp(args[2], "sdbm")) { |
| 4591 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4592 | } |
| 4593 | else if (!strcmp(args[2], "djb2")) { |
| 4594 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4595 | } else if (!strcmp(args[2], "wt6")) { |
| 4596 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4597 | } |
| 4598 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4599 | 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] | 4600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4601 | goto out; |
| 4602 | } |
| 4603 | |
| 4604 | /* set the hash modifier */ |
| 4605 | if (!strcmp(args[3], "avalanche")) { |
| 4606 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4607 | } |
| 4608 | else if (*args[3]) { |
| 4609 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4611 | goto out; |
| 4612 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4613 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4614 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4615 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4616 | if (!*(args[1])) { |
| 4617 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4619 | goto out; |
| 4620 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4621 | if (*(args[2])) { |
| 4622 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4624 | goto out; |
| 4625 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4626 | free(curproxy->conf.uniqueid_format_string); |
| 4627 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4628 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4629 | free(curproxy->conf.uif_file); |
| 4630 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4631 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4632 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4633 | |
| 4634 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4635 | if (!*(args[1])) { |
| 4636 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4638 | goto out; |
| 4639 | } |
| 4640 | free(curproxy->header_unique_id); |
| 4641 | curproxy->header_unique_id = strdup(args[1]); |
| 4642 | } |
| 4643 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4644 | else if (strcmp(args[0], "log-format") == 0) { |
| 4645 | if (!*(args[1])) { |
| 4646 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4648 | goto out; |
| 4649 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4650 | if (*(args[2])) { |
| 4651 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4653 | goto out; |
| 4654 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4655 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4656 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4657 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4658 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4659 | free(curproxy->conf.logformat_string); |
| 4660 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4661 | |
| 4662 | free(curproxy->conf.lfs_file); |
| 4663 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4664 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4665 | |
| 4666 | /* get a chance to improve log-format error reporting by |
| 4667 | * reporting the correct line-number when possible. |
| 4668 | */ |
| 4669 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4670 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4671 | file, linenum, curproxy->id); |
| 4672 | err_code |= ERR_WARN; |
| 4673 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4674 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4675 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4676 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4677 | /* delete previous herited or defined syslog servers */ |
| 4678 | struct logsrv *back; |
| 4679 | |
| 4680 | if (*(args[1]) != 0) { |
| 4681 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4683 | goto out; |
| 4684 | } |
| 4685 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4686 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4687 | LIST_DEL(&tmplogsrv->list); |
| 4688 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4689 | } |
| 4690 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4691 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4692 | struct logsrv *logsrv; |
| 4693 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4694 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4695 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4696 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4697 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4698 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4699 | LIST_INIT(&node->list); |
| 4700 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4701 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4702 | } |
| 4703 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4704 | struct sockaddr_storage *sk; |
| 4705 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4706 | |
| 4707 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4708 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4709 | logsrv->facility = get_log_facility(args[2]); |
| 4710 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4711 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4713 | goto out; |
| 4714 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4715 | } |
| 4716 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4717 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4718 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4719 | logsrv->level = get_log_level(args[3]); |
| 4720 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4721 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4723 | goto out; |
| 4724 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4725 | } |
| 4726 | } |
| 4727 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4728 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4729 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4730 | logsrv->minlvl = get_log_level(args[4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4731 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4732 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4734 | goto out; |
| 4735 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4736 | } |
| 4737 | } |
| 4738 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4739 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4740 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4741 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4742 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4743 | goto out; |
| 4744 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4745 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4746 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4747 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4748 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4749 | if (port1 != port2) { |
| 4750 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4751 | file, linenum, args[0], args[1]); |
| 4752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4753 | goto out; |
| 4754 | } |
| 4755 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4756 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4757 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4758 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4759 | |
| 4760 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4761 | } |
| 4762 | else { |
| 4763 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4764 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4766 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | 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] | 4770 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4771 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4772 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4773 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4774 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4775 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4776 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4777 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4778 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4779 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4780 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4782 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4783 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4784 | |
| 4785 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4786 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4787 | free(curproxy->conn_src.iface_name); |
| 4788 | curproxy->conn_src.iface_name = NULL; |
| 4789 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4790 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4791 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4792 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4793 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4794 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4795 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4796 | goto out; |
| 4797 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4798 | |
| 4799 | proto = protocol_by_family(sk->ss_family); |
| 4800 | if (!proto || !proto->connect) { |
| 4801 | 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] | 4802 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4804 | goto out; |
| 4805 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4806 | |
| 4807 | if (port1 != port2) { |
| 4808 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4809 | file, linenum, args[0], args[1]); |
| 4810 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4811 | goto out; |
| 4812 | } |
| 4813 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4814 | curproxy->conn_src.source_addr = *sk; |
| 4815 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4816 | |
| 4817 | cur_arg = 2; |
| 4818 | while (*(args[cur_arg])) { |
| 4819 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 4820 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 4821 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 4822 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4823 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4824 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4826 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4827 | } |
| 4828 | #endif |
| 4829 | if (!*args[cur_arg + 1]) { |
| 4830 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4831 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4833 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4837 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4838 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4839 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4840 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4841 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4842 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4843 | char *name, *end; |
| 4844 | |
| 4845 | name = args[cur_arg+1] + 7; |
| 4846 | while (isspace(*name)) |
| 4847 | name++; |
| 4848 | |
| 4849 | end = name; |
| 4850 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4851 | end++; |
| 4852 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4853 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4854 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 4855 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 4856 | curproxy->conn_src.bind_hdr_len = end - name; |
| 4857 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 4858 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 4859 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4860 | |
| 4861 | /* now look for an occurrence number */ |
| 4862 | while (isspace(*end)) |
| 4863 | end++; |
| 4864 | if (*end == ',') { |
| 4865 | end++; |
| 4866 | name = end; |
| 4867 | if (*end == '-') |
| 4868 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 4869 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4870 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4871 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4872 | } |
| 4873 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4874 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4875 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 4876 | " occurrences values smaller than %d.\n", |
| 4877 | file, linenum, MAX_HDR_HISTORY); |
| 4878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4879 | goto out; |
| 4880 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4881 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4882 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4883 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4884 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4885 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4886 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4887 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4888 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4889 | goto out; |
| 4890 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4891 | |
| 4892 | proto = protocol_by_family(sk->ss_family); |
| 4893 | if (!proto || !proto->connect) { |
| 4894 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4895 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4897 | goto out; |
| 4898 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4899 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4900 | if (port1 != port2) { |
| 4901 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4902 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4904 | goto out; |
| 4905 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4906 | curproxy->conn_src.tproxy_addr = *sk; |
| 4907 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4908 | } |
| 4909 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 4910 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4911 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4912 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4913 | #else /* no TPROXY support */ |
| 4914 | 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] | 4915 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4916 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4917 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4918 | #endif |
| 4919 | cur_arg += 2; |
| 4920 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 4921 | } |
| 4922 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4923 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 4924 | #ifdef SO_BINDTODEVICE |
| 4925 | if (!*args[cur_arg + 1]) { |
| 4926 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 4927 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4929 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4930 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4931 | free(curproxy->conn_src.iface_name); |
| 4932 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 4933 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4934 | global.last_checks |= LSTCHK_NETADM; |
| 4935 | #else |
| 4936 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 4937 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4939 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 4940 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4941 | cur_arg += 2; |
| 4942 | continue; |
| 4943 | } |
| 4944 | 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] | 4945 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4947 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4948 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4949 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4950 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 4951 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 4952 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4953 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4954 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 4955 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4956 | 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] | 4957 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4958 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 4959 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4961 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4962 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4963 | |
| 4964 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4965 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4966 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4967 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4968 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4969 | } |
| 4970 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4971 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4972 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4973 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4974 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4975 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4976 | } |
| 4977 | 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] | 4978 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4979 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4980 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4981 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4982 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4983 | } |
| 4984 | 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] | 4985 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4986 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4987 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4988 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4989 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4990 | } |
| 4991 | 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] | 4992 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 4993 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 4994 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 4995 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4997 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 4998 | 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] | 4999 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5000 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5001 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5002 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5003 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5004 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5005 | 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] | 5006 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5007 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5008 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5009 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5010 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5011 | |
| 5012 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5013 | 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] | 5014 | } |
| 5015 | 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] | 5016 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5017 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5018 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5019 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5020 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5021 | |
| 5022 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5023 | 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] | 5024 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5025 | 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] | 5026 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5027 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5028 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5030 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5031 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5032 | |
| 5033 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5034 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5035 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5036 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5037 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5038 | } |
| 5039 | 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] | 5040 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5041 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5042 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5043 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5044 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5045 | } |
| 5046 | 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] | 5047 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5048 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5049 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5050 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5051 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5052 | } |
| 5053 | 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] | 5054 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5055 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5056 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5057 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5058 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5059 | } |
| 5060 | 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] | 5061 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5062 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5063 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5064 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5065 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5066 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5067 | 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] | 5068 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5069 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5070 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5071 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5072 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5073 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5074 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5075 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5076 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5077 | if (curproxy == &defproxy) { |
| 5078 | 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] | 5079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5080 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5081 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5082 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5083 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5084 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5085 | if (*(args[1]) == 0) { |
| 5086 | 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] | 5087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5088 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5089 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5090 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5091 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5092 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5093 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5094 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5096 | goto out; |
| 5097 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5098 | err_code |= warnif_cond_conflicts(cond, |
| 5099 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5100 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5101 | } |
| 5102 | else if (*args[2]) { |
| 5103 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5104 | file, linenum, args[0], args[2]); |
| 5105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5106 | goto out; |
| 5107 | } |
| 5108 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5109 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5110 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5111 | wl->s = strdup(args[1]); |
| 5112 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5113 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5114 | } |
| 5115 | 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] | 5116 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5117 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5118 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5119 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5120 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5121 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5122 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5123 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5124 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5125 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5126 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5127 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5128 | } |
| 5129 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5130 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5131 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5132 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5133 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5134 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5135 | } |
| 5136 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5137 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5138 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5139 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5140 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5141 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5142 | } |
| 5143 | 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] | 5144 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5145 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5146 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5148 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5149 | } |
| 5150 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5151 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5152 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5153 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5154 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5155 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5156 | } |
| 5157 | 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] | 5158 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5159 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5160 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5161 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5162 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5163 | } |
| 5164 | 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] | 5165 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5166 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5167 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5168 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5169 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5170 | } |
| 5171 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5172 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5173 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5174 | if (curproxy == &defproxy) { |
| 5175 | 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] | 5176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5177 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5178 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5179 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5180 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5181 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5182 | if (*(args[1]) == 0) { |
| 5183 | 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] | 5184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5185 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5186 | } |
| 5187 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5188 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5189 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5190 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5191 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5193 | goto out; |
| 5194 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5195 | err_code |= warnif_cond_conflicts(cond, |
| 5196 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5197 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5198 | } |
| 5199 | else if (*args[2]) { |
| 5200 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5201 | file, linenum, args[0], args[2]); |
| 5202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5203 | goto out; |
| 5204 | } |
| 5205 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5206 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5207 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5208 | wl->s = strdup(args[1]); |
| 5209 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5210 | } |
| 5211 | else if (!strcmp(args[0], "errorloc") || |
| 5212 | !strcmp(args[0], "errorloc302") || |
| 5213 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5214 | int errnum, errlen; |
| 5215 | char *err; |
| 5216 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5217 | 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] | 5218 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5219 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5220 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5221 | 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] | 5222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5223 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | errnum = atol(args[1]); |
| 5227 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5228 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5229 | err = malloc(errlen); |
| 5230 | 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] | 5231 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5232 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5233 | err = malloc(errlen); |
| 5234 | 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] | 5235 | } |
| 5236 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5237 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5238 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5239 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5240 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5241 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5242 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5243 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5244 | |
| 5245 | if (rc >= HTTP_ERR_SIZE) { |
| 5246 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5247 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5248 | free(err); |
| 5249 | } |
| 5250 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5251 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5252 | int errnum, errlen, fd; |
| 5253 | char *err; |
| 5254 | struct stat stat; |
| 5255 | |
| 5256 | 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] | 5257 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5258 | |
| 5259 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5260 | 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] | 5261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5262 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | fd = open(args[2], O_RDONLY); |
| 5266 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5267 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5268 | file, linenum, args[2], args[1]); |
| 5269 | if (fd >= 0) |
| 5270 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5272 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5273 | } |
| 5274 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5275 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5276 | errlen = stat.st_size; |
| 5277 | } else { |
| 5278 | 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] | 5279 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5280 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5281 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5282 | } |
| 5283 | |
| 5284 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5285 | errnum = read(fd, err, errlen); |
| 5286 | if (errnum != errlen) { |
| 5287 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5288 | file, linenum, args[2], args[1]); |
| 5289 | close(fd); |
| 5290 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5292 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5293 | } |
| 5294 | close(fd); |
| 5295 | |
| 5296 | errnum = atol(args[1]); |
| 5297 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5298 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5299 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5300 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5301 | break; |
| 5302 | } |
| 5303 | } |
| 5304 | |
| 5305 | if (rc >= HTTP_ERR_SIZE) { |
| 5306 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5307 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5308 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5309 | free(err); |
| 5310 | } |
| 5311 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5312 | else if (!strcmp(args[0], "compression")) { |
| 5313 | struct comp *comp; |
| 5314 | if (curproxy->comp == NULL) { |
| 5315 | comp = calloc(1, sizeof(struct comp)); |
| 5316 | curproxy->comp = comp; |
| 5317 | } else { |
| 5318 | comp = curproxy->comp; |
| 5319 | } |
| 5320 | |
| 5321 | if (!strcmp(args[1], "algo")) { |
| 5322 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5323 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5324 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5325 | cur_arg = 2; |
| 5326 | if (!*args[cur_arg]) { |
| 5327 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5328 | file, linenum, args[0]); |
| 5329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5330 | goto out; |
| 5331 | } |
| 5332 | while (*(args[cur_arg])) { |
| 5333 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5334 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5335 | file, linenum, args[0], args[cur_arg]); |
| 5336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5337 | goto out; |
| 5338 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5339 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5340 | curproxy->comp->algos->end(&ctx); |
| 5341 | } else { |
| 5342 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5343 | file, linenum, args[0], args[cur_arg]); |
| 5344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5345 | goto out; |
| 5346 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5347 | cur_arg ++; |
| 5348 | continue; |
| 5349 | } |
| 5350 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5351 | else if (!strcmp(args[1], "offload")) { |
| 5352 | comp->offload = 1; |
| 5353 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5354 | else if (!strcmp(args[1], "type")) { |
| 5355 | int cur_arg; |
| 5356 | cur_arg = 2; |
| 5357 | if (!*args[cur_arg]) { |
| 5358 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5359 | file, linenum, args[0]); |
| 5360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5361 | goto out; |
| 5362 | } |
| 5363 | while (*(args[cur_arg])) { |
| 5364 | comp_append_type(comp, args[cur_arg]); |
| 5365 | cur_arg ++; |
| 5366 | continue; |
| 5367 | } |
| 5368 | } |
| 5369 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5370 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5371 | file, linenum, args[0]); |
| 5372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5373 | goto out; |
| 5374 | } |
| 5375 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5376 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5377 | struct cfg_kw_list *kwl; |
| 5378 | int index; |
| 5379 | |
| 5380 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5381 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5382 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5383 | continue; |
| 5384 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5385 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5386 | 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] | 5387 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5388 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5390 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5391 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5392 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5393 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5394 | err_code |= ERR_WARN; |
| 5395 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5396 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5397 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5398 | } |
| 5399 | } |
| 5400 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5401 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5402 | 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] | 5403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5405 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5406 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5407 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5408 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5409 | } |
| 5410 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5411 | int |
| 5412 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5413 | { |
| 5414 | |
| 5415 | int err_code = 0; |
| 5416 | const char *err; |
| 5417 | |
| 5418 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5419 | struct userlist *newul; |
| 5420 | |
| 5421 | if (!*args[1]) { |
| 5422 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5423 | file, linenum, args[0]); |
| 5424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5425 | goto out; |
| 5426 | } |
| 5427 | |
| 5428 | err = invalid_char(args[1]); |
| 5429 | if (err) { |
| 5430 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5431 | file, linenum, *err, args[0], args[1]); |
| 5432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5433 | goto out; |
| 5434 | } |
| 5435 | |
| 5436 | for (newul = userlist; newul; newul = newul->next) |
| 5437 | if (!strcmp(newul->name, args[1])) { |
| 5438 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5439 | file, linenum, args[1]); |
| 5440 | err_code |= ERR_WARN; |
| 5441 | goto out; |
| 5442 | } |
| 5443 | |
| 5444 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5445 | if (!newul) { |
| 5446 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5447 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5448 | goto out; |
| 5449 | } |
| 5450 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5451 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5452 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5453 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5454 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5455 | goto out; |
| 5456 | } |
| 5457 | |
| 5458 | newul->next = userlist; |
| 5459 | userlist = newul; |
| 5460 | |
| 5461 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5462 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5463 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5464 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5465 | |
| 5466 | if (!*args[1]) { |
| 5467 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5468 | file, linenum, args[0]); |
| 5469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5470 | goto out; |
| 5471 | } |
| 5472 | |
| 5473 | err = invalid_char(args[1]); |
| 5474 | if (err) { |
| 5475 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5476 | file, linenum, *err, args[0], args[1]); |
| 5477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5478 | goto out; |
| 5479 | } |
| 5480 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5481 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5482 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5483 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5484 | file, linenum, args[1], userlist->name); |
| 5485 | err_code |= ERR_ALERT; |
| 5486 | goto out; |
| 5487 | } |
| 5488 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5489 | ag = calloc(1, sizeof(*ag)); |
| 5490 | if (!ag) { |
| 5491 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5492 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5493 | goto out; |
| 5494 | } |
| 5495 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5496 | ag->name = strdup(args[1]); |
| 5497 | if (!ag) { |
| 5498 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5499 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5500 | goto out; |
| 5501 | } |
| 5502 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5503 | cur_arg = 2; |
| 5504 | |
| 5505 | while (*args[cur_arg]) { |
| 5506 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5507 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5508 | cur_arg += 2; |
| 5509 | continue; |
| 5510 | } else { |
| 5511 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5512 | file, linenum, args[0]); |
| 5513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5514 | goto out; |
| 5515 | } |
| 5516 | } |
| 5517 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5518 | ag->next = userlist->groups; |
| 5519 | userlist->groups = ag; |
| 5520 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5521 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5522 | struct auth_users *newuser; |
| 5523 | int cur_arg; |
| 5524 | |
| 5525 | if (!*args[1]) { |
| 5526 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5527 | file, linenum, args[0]); |
| 5528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5529 | goto out; |
| 5530 | } |
| 5531 | |
| 5532 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5533 | if (!strcmp(newuser->user, args[1])) { |
| 5534 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5535 | file, linenum, args[1], userlist->name); |
| 5536 | err_code |= ERR_ALERT; |
| 5537 | goto out; |
| 5538 | } |
| 5539 | |
| 5540 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5541 | if (!newuser) { |
| 5542 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5543 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5544 | goto out; |
| 5545 | } |
| 5546 | |
| 5547 | newuser->user = strdup(args[1]); |
| 5548 | |
| 5549 | newuser->next = userlist->users; |
| 5550 | userlist->users = newuser; |
| 5551 | |
| 5552 | cur_arg = 2; |
| 5553 | |
| 5554 | while (*args[cur_arg]) { |
| 5555 | if (!strcmp(args[cur_arg], "password")) { |
| 5556 | #ifndef CONFIG_HAP_CRYPT |
| 5557 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5558 | file, linenum); |
| 5559 | err_code |= ERR_ALERT; |
| 5560 | #endif |
| 5561 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5562 | cur_arg += 2; |
| 5563 | continue; |
| 5564 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5565 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5566 | newuser->flags |= AU_O_INSECURE; |
| 5567 | cur_arg += 2; |
| 5568 | continue; |
| 5569 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5570 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5571 | cur_arg += 2; |
| 5572 | continue; |
| 5573 | } else { |
| 5574 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5575 | file, linenum, args[0]); |
| 5576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5577 | goto out; |
| 5578 | } |
| 5579 | } |
| 5580 | } else { |
| 5581 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5583 | } |
| 5584 | |
| 5585 | out: |
| 5586 | return err_code; |
| 5587 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5588 | |
| 5589 | /* |
| 5590 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5591 | * Returns the error code, 0 if OK, or any combination of : |
| 5592 | * - ERR_ABORT: must abort ASAP |
| 5593 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5594 | * - ERR_WARN: a warning has been emitted |
| 5595 | * - ERR_ALERT: an alert has been emitted |
| 5596 | * Only the two first ones can stop processing, the two others are just |
| 5597 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5598 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5599 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5600 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5601 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5602 | FILE *f; |
| 5603 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5604 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5605 | struct cfg_section *cs = NULL; |
| 5606 | struct cfg_section *ics; |
| 5607 | |
| 5608 | /* Register internal sections */ |
| 5609 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5610 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5611 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5612 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5613 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5614 | !cfg_register_section("global", cfg_parse_global) || |
| 5615 | !cfg_register_section("userlist", cfg_parse_users) || |
| 5616 | !cfg_register_section("peers", cfg_parse_peers)) |
| 5617 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5618 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5619 | if ((f=fopen(file,"r")) == NULL) |
| 5620 | return -1; |
| 5621 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5622 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5623 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5624 | char *end; |
| 5625 | char *args[MAX_LINE_ARGS + 1]; |
| 5626 | char *line = thisline; |
| 5627 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5628 | linenum++; |
| 5629 | |
| 5630 | end = line + strlen(line); |
| 5631 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5632 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5633 | /* Check if we reached the limit and the last char is not \n. |
| 5634 | * Watch out for the last line without the terminating '\n'! |
| 5635 | */ |
| 5636 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5637 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5638 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5639 | } |
| 5640 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5641 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5642 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5643 | line++; |
| 5644 | |
| 5645 | arg = 0; |
| 5646 | args[arg] = line; |
| 5647 | |
| 5648 | while (*line && arg < MAX_LINE_ARGS) { |
| 5649 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5650 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5651 | */ |
| 5652 | if (*line == '\\') { |
| 5653 | int skip = 0; |
| 5654 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5655 | *line = line[1]; |
| 5656 | skip = 1; |
| 5657 | } |
| 5658 | else if (line[1] == 'r') { |
| 5659 | *line = '\r'; |
| 5660 | skip = 1; |
| 5661 | } |
| 5662 | else if (line[1] == 'n') { |
| 5663 | *line = '\n'; |
| 5664 | skip = 1; |
| 5665 | } |
| 5666 | else if (line[1] == 't') { |
| 5667 | *line = '\t'; |
| 5668 | skip = 1; |
| 5669 | } |
| 5670 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5671 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5672 | unsigned char hex1, hex2; |
| 5673 | hex1 = toupper(line[2]) - '0'; |
| 5674 | hex2 = toupper(line[3]) - '0'; |
| 5675 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5676 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5677 | *line = (hex1<<4) + hex2; |
| 5678 | skip = 3; |
| 5679 | } |
| 5680 | else { |
| 5681 | 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] | 5682 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5683 | } |
| 5684 | } |
| 5685 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5686 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5687 | end -= skip; |
| 5688 | } |
| 5689 | line++; |
| 5690 | } |
| 5691 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5692 | /* end of string, end of loop */ |
| 5693 | *line = 0; |
| 5694 | break; |
| 5695 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5696 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5697 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5698 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5699 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5700 | line++; |
| 5701 | args[++arg] = line; |
| 5702 | } |
| 5703 | else { |
| 5704 | line++; |
| 5705 | } |
| 5706 | } |
| 5707 | |
| 5708 | /* empty line */ |
| 5709 | if (!**args) |
| 5710 | continue; |
| 5711 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5712 | if (*line) { |
| 5713 | /* we had to stop due to too many args. |
| 5714 | * Let's terminate the string, print the offending part then cut the |
| 5715 | * last arg. |
| 5716 | */ |
| 5717 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5718 | line++; |
| 5719 | *line = '\0'; |
| 5720 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5721 | 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] | 5722 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5724 | args[arg] = line; |
| 5725 | } |
| 5726 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5727 | /* zero out remaining args and ensure that at least one entry |
| 5728 | * is zeroed out. |
| 5729 | */ |
| 5730 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5731 | args[arg] = line; |
| 5732 | } |
| 5733 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5734 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5735 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5736 | char *tmp; |
| 5737 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5738 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5739 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5740 | for (arg=0; *args[arg+1]; arg++) |
| 5741 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5742 | *tmp = '\0'; // fix the next arg to \0 |
| 5743 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5744 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5745 | else if (!strcmp(args[0], "default")) { |
| 5746 | kwm = KWM_DEF; |
| 5747 | for (arg=0; *args[arg+1]; arg++) |
| 5748 | args[arg] = args[arg+1]; // shift args after inversion |
| 5749 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5750 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5751 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5752 | strcmp(args[0], "log") != 0) { |
| 5753 | 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] | 5754 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5755 | } |
| 5756 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5757 | /* detect section start */ |
| 5758 | list_for_each_entry(ics, §ions, list) { |
| 5759 | if (strcmp(args[0], ics->section_name) == 0) { |
| 5760 | cursection = ics->section_name; |
| 5761 | cs = ics; |
| 5762 | break; |
| 5763 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5764 | } |
| 5765 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5766 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5767 | if (cs) |
| 5768 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 5769 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5770 | 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] | 5771 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5772 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5773 | |
| 5774 | if (err_code & ERR_ABORT) |
| 5775 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5776 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5777 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5778 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5779 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5780 | } |
| 5781 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5782 | /* |
| 5783 | * Returns the error code, 0 if OK, or any combination of : |
| 5784 | * - ERR_ABORT: must abort ASAP |
| 5785 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5786 | * - ERR_WARN: a warning has been emitted |
| 5787 | * - ERR_ALERT: an alert has been emitted |
| 5788 | * Only the two first ones can stop processing, the two others are just |
| 5789 | * indicators. |
| 5790 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5791 | int check_config_validity() |
| 5792 | { |
| 5793 | int cfgerr = 0; |
| 5794 | struct proxy *curproxy = NULL; |
| 5795 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5796 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5797 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5798 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5799 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5800 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5801 | /* |
| 5802 | * Now, check for the integrity of all that we have collected. |
| 5803 | */ |
| 5804 | |
| 5805 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5806 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5807 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 5808 | if (!global.tune.max_http_hdr) |
| 5809 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 5810 | |
| 5811 | if (!global.tune.cookie_len) |
| 5812 | global.tune.cookie_len = CAPTURE_LEN; |
| 5813 | |
| 5814 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 5815 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5816 | /* Post initialisation of the users and groups lists. */ |
| 5817 | err_code = userlist_postinit(); |
| 5818 | if (err_code != ERR_NONE) |
| 5819 | goto out; |
| 5820 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5821 | /* first, we will invert the proxy list order */ |
| 5822 | curproxy = NULL; |
| 5823 | while (proxy) { |
| 5824 | struct proxy *next; |
| 5825 | |
| 5826 | next = proxy->next; |
| 5827 | proxy->next = curproxy; |
| 5828 | curproxy = proxy; |
| 5829 | if (!next) |
| 5830 | break; |
| 5831 | proxy = next; |
| 5832 | } |
| 5833 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5834 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5835 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5836 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5837 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5838 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5839 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5840 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5841 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5842 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5843 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5844 | /* proxy ID not set, use automatic numbering with first |
| 5845 | * spare entry starting with next_pxid. |
| 5846 | */ |
| 5847 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5848 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5849 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5850 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5851 | next_pxid++; |
| 5852 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5853 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5854 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5855 | /* ensure we don't keep listeners uselessly bound */ |
| 5856 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5857 | curproxy = curproxy->next; |
| 5858 | continue; |
| 5859 | } |
| 5860 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 5861 | /* Check multi-process mode compatibility for the current proxy */ |
| 5862 | |
| 5863 | if (curproxy->bind_proc) { |
| 5864 | /* an explicit bind-process was specified, let's check how many |
| 5865 | * processes remain. |
| 5866 | */ |
| 5867 | nbproc = popcount(curproxy->bind_proc); |
| 5868 | |
| 5869 | curproxy->bind_proc &= nbits(global.nbproc); |
| 5870 | if (!curproxy->bind_proc && nbproc == 1) { |
| 5871 | 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); |
| 5872 | curproxy->bind_proc = 1; |
| 5873 | } |
| 5874 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 5875 | 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); |
| 5876 | curproxy->bind_proc = 0; |
| 5877 | } |
| 5878 | } |
| 5879 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 5880 | /* check and reduce the bind-proc of each listener */ |
| 5881 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 5882 | unsigned long mask; |
| 5883 | |
| 5884 | if (!bind_conf->bind_proc) |
| 5885 | continue; |
| 5886 | |
| 5887 | mask = nbits(global.nbproc); |
| 5888 | if (curproxy->bind_proc) |
| 5889 | mask &= curproxy->bind_proc; |
| 5890 | /* mask cannot be null here thanks to the previous checks */ |
| 5891 | |
| 5892 | nbproc = popcount(bind_conf->bind_proc); |
| 5893 | bind_conf->bind_proc &= mask; |
| 5894 | |
| 5895 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 5896 | 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", |
| 5897 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 5898 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 5899 | } |
| 5900 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 5901 | 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", |
| 5902 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 5903 | bind_conf->bind_proc = 0; |
| 5904 | } |
| 5905 | } |
| 5906 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 5907 | /* here, if bind_proc is null, it means no limit, otherwise it's explicit. |
| 5908 | * We now check how many processes the proxy will effectively run on. |
| 5909 | */ |
| 5910 | |
| 5911 | nbproc = global.nbproc; |
| 5912 | if (curproxy->bind_proc) |
| 5913 | nbproc = popcount(curproxy->bind_proc & nbits(global.nbproc)); |
| 5914 | |
| 5915 | if (global.nbproc > 1 && curproxy->table.peers.name) { |
| 5916 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 5917 | curproxy->id); |
| 5918 | cfgerr++; |
| 5919 | } |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5920 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5921 | switch (curproxy->mode) { |
| 5922 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5923 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5924 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5925 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 5926 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5927 | cfgerr++; |
| 5928 | } |
| 5929 | |
| 5930 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5931 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 5932 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5933 | break; |
| 5934 | |
| 5935 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5936 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5937 | break; |
| 5938 | |
| 5939 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 5940 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 5941 | break; |
| 5942 | } |
| 5943 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5944 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 5945 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5946 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5947 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 5948 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5949 | cfgerr++; |
| 5950 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5951 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5952 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5953 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 5954 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5955 | cfgerr++; |
| 5956 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5957 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5958 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5959 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 5960 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5961 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 5962 | } |
| 5963 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5964 | 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] | 5965 | /* If no LB algo is set in a backend, and we're not in |
| 5966 | * transparent mode, dispatch mode nor proxy mode, we |
| 5967 | * want to use balance roundrobin by default. |
| 5968 | */ |
| 5969 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 5970 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5971 | } |
| 5972 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 5973 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5974 | if (curproxy->options & PR_O_DISPATCH) |
| 5975 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 5976 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 5977 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 5978 | else if (curproxy->options & PR_O_TRANSP) |
| 5979 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 5980 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5981 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 5982 | if (curproxy->options & PR_O_DISABLE404) { |
| 5983 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5984 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 5985 | err_code |= ERR_WARN; |
| 5986 | curproxy->options &= ~PR_O_DISABLE404; |
| 5987 | } |
| 5988 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 5989 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 5990 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 5991 | err_code |= ERR_WARN; |
| 5992 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 5993 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5994 | } |
| 5995 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5996 | /* if a default backend was specified, let's find it */ |
| 5997 | if (curproxy->defbe.name) { |
| 5998 | struct proxy *target; |
| 5999 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6000 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6001 | if (!target) { |
| 6002 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6003 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6004 | cfgerr++; |
| 6005 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6006 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6007 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6008 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6009 | } else { |
| 6010 | free(curproxy->defbe.name); |
| 6011 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6012 | /* we force the backend to be present on at least all of |
| 6013 | * the frontend's processes. |
| 6014 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6015 | if (target->bind_proc) |
| 6016 | target->bind_proc = curproxy->bind_proc ? |
| 6017 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6018 | |
| 6019 | /* Emit a warning if this proxy also has some servers */ |
| 6020 | if (curproxy->srv) { |
| 6021 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6022 | curproxy->id); |
| 6023 | err_code |= ERR_WARN; |
| 6024 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6025 | } |
| 6026 | } |
| 6027 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6028 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6029 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6030 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6031 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6032 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6033 | struct proxy *target; |
| 6034 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6035 | if (exp->action != ACT_SETBE) |
| 6036 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6037 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6038 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6039 | if (!target) { |
| 6040 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6041 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6042 | cfgerr++; |
| 6043 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6044 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6045 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6046 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6047 | } else { |
| 6048 | free((void *)exp->replace); |
| 6049 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6050 | /* we force the backend to be present on at least all of |
| 6051 | * the frontend's processes. |
| 6052 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6053 | if (target->bind_proc) |
| 6054 | target->bind_proc = curproxy->bind_proc ? |
| 6055 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6056 | } |
| 6057 | } |
| 6058 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6059 | |
| 6060 | /* find the target proxy for 'use_backend' rules */ |
| 6061 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6062 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6063 | struct logformat_node *node; |
| 6064 | char *pxname; |
| 6065 | |
| 6066 | /* Try to parse the string as a log format expression. If the result |
| 6067 | * of the parsing is only one entry containing a simple string, then |
| 6068 | * it's a standard string corresponding to a static rule, thus the |
| 6069 | * parsing is cancelled and be.name is restored to be resolved. |
| 6070 | */ |
| 6071 | pxname = rule->be.name; |
| 6072 | LIST_INIT(&rule->be.expr); |
| 6073 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6074 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6075 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6076 | |
| 6077 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6078 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6079 | rule->dynamic = 1; |
| 6080 | free(pxname); |
| 6081 | continue; |
| 6082 | } |
| 6083 | /* simple string: free the expression and fall back to static rule */ |
| 6084 | free(node->arg); |
| 6085 | free(node); |
| 6086 | } |
| 6087 | |
| 6088 | rule->dynamic = 0; |
| 6089 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6090 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6091 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6092 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6093 | if (!target) { |
| 6094 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6095 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6096 | cfgerr++; |
| 6097 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6098 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6099 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6100 | cfgerr++; |
| 6101 | } else { |
| 6102 | free((void *)rule->be.name); |
| 6103 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6104 | /* we force the backend to be present on at least all of |
| 6105 | * the frontend's processes. |
| 6106 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6107 | if (target->bind_proc) |
| 6108 | target->bind_proc = curproxy->bind_proc ? |
| 6109 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6110 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6111 | } |
| 6112 | |
| 6113 | /* find the target proxy for 'use_backend' rules */ |
| 6114 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6115 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6116 | |
| 6117 | if (!target) { |
| 6118 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6119 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6120 | cfgerr++; |
| 6121 | continue; |
| 6122 | } |
| 6123 | free((void *)srule->srv.name); |
| 6124 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6125 | } |
| 6126 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6127 | /* find the target table for 'stick' rules */ |
| 6128 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6129 | struct proxy *target; |
| 6130 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6131 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6132 | if (mrule->flags & STK_IS_STORE) |
| 6133 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6134 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6135 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6136 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6137 | else |
| 6138 | target = curproxy; |
| 6139 | |
| 6140 | if (!target) { |
| 6141 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6142 | curproxy->id, mrule->table.name); |
| 6143 | cfgerr++; |
| 6144 | } |
| 6145 | else if (target->table.size == 0) { |
| 6146 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6147 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6148 | cfgerr++; |
| 6149 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6150 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6151 | 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] | 6152 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6153 | cfgerr++; |
| 6154 | } |
| 6155 | else { |
| 6156 | free((void *)mrule->table.name); |
| 6157 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6158 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6159 | } |
| 6160 | } |
| 6161 | |
| 6162 | /* find the target table for 'store response' rules */ |
| 6163 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6164 | struct proxy *target; |
| 6165 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6166 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6167 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6168 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6169 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6170 | else |
| 6171 | target = curproxy; |
| 6172 | |
| 6173 | if (!target) { |
| 6174 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6175 | curproxy->id, mrule->table.name); |
| 6176 | cfgerr++; |
| 6177 | } |
| 6178 | else if (target->table.size == 0) { |
| 6179 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6180 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6181 | cfgerr++; |
| 6182 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6183 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6184 | 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] | 6185 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6186 | cfgerr++; |
| 6187 | } |
| 6188 | else { |
| 6189 | free((void *)mrule->table.name); |
| 6190 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6191 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6192 | } |
| 6193 | } |
| 6194 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6195 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6196 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6197 | struct proxy *target; |
| 6198 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6199 | 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] | 6200 | continue; |
| 6201 | |
| 6202 | if (trule->act_prm.trk_ctr.table.n) |
| 6203 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6204 | else |
| 6205 | target = curproxy; |
| 6206 | |
| 6207 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6208 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6209 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6210 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6211 | cfgerr++; |
| 6212 | } |
| 6213 | else if (target->table.size == 0) { |
| 6214 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6215 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6216 | cfgerr++; |
| 6217 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6218 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6219 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6220 | 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] | 6221 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6222 | cfgerr++; |
| 6223 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6224 | else { |
| 6225 | free(trule->act_prm.trk_ctr.table.n); |
| 6226 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6227 | /* 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] | 6228 | * to pass a list of counters to track and allocate them right here using |
| 6229 | * stktable_alloc_data_type(). |
| 6230 | */ |
| 6231 | } |
| 6232 | } |
| 6233 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6234 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6235 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6236 | struct proxy *target; |
| 6237 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6238 | 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] | 6239 | continue; |
| 6240 | |
| 6241 | if (trule->act_prm.trk_ctr.table.n) |
| 6242 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6243 | else |
| 6244 | target = curproxy; |
| 6245 | |
| 6246 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6247 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6248 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6249 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6250 | cfgerr++; |
| 6251 | } |
| 6252 | else if (target->table.size == 0) { |
| 6253 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6254 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6255 | cfgerr++; |
| 6256 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6257 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6258 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6259 | 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] | 6260 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6261 | cfgerr++; |
| 6262 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6263 | else { |
| 6264 | free(trule->act_prm.trk_ctr.table.n); |
| 6265 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6266 | /* 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] | 6267 | * to pass a list of counters to track and allocate them right here using |
| 6268 | * stktable_alloc_data_type(). |
| 6269 | */ |
| 6270 | } |
| 6271 | } |
| 6272 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6273 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6274 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6275 | /* insert block_rules into http_req_rules at the beginning */ |
| 6276 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6277 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6278 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6279 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6280 | LIST_INIT(&curproxy->block_rules); |
| 6281 | } |
| 6282 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6283 | if (curproxy->table.peers.name) { |
| 6284 | struct peers *curpeers = peers; |
| 6285 | |
| 6286 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6287 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6288 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6289 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6290 | break; |
| 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | if (!curpeers) { |
| 6295 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6296 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6297 | free((void *)curproxy->table.peers.name); |
| 6298 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6299 | cfgerr++; |
| 6300 | } |
| 6301 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6302 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6303 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6304 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6305 | cfgerr++; |
| 6306 | } |
| 6307 | } |
| 6308 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6309 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6310 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6311 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6312 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6313 | "proxy", curproxy->id); |
| 6314 | cfgerr++; |
| 6315 | goto out_uri_auth_compat; |
| 6316 | } |
| 6317 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6318 | 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] | 6319 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6320 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6321 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6322 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6323 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6324 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6325 | |
| 6326 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6327 | uri_auth_compat_req[i++] = "realm"; |
| 6328 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6329 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6330 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6331 | uri_auth_compat_req[i++] = "unless"; |
| 6332 | uri_auth_compat_req[i++] = "{"; |
| 6333 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6334 | uri_auth_compat_req[i++] = "}"; |
| 6335 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6336 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6337 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6338 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6339 | cfgerr++; |
| 6340 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6341 | } |
| 6342 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6343 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6344 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6345 | if (curproxy->uri_auth->auth_realm) { |
| 6346 | free(curproxy->uri_auth->auth_realm); |
| 6347 | curproxy->uri_auth->auth_realm = NULL; |
| 6348 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6349 | |
| 6350 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6351 | } |
| 6352 | out_uri_auth_compat: |
| 6353 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6354 | /* compile the log format */ |
| 6355 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6356 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6357 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6358 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6359 | free(curproxy->conf.logformat_string); |
| 6360 | curproxy->conf.logformat_string = NULL; |
| 6361 | free(curproxy->conf.lfs_file); |
| 6362 | curproxy->conf.lfs_file = NULL; |
| 6363 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6364 | } |
| 6365 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6366 | if (curproxy->conf.logformat_string) { |
| 6367 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6368 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6369 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6370 | 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] | 6371 | 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] | 6372 | curproxy->conf.args.file = NULL; |
| 6373 | curproxy->conf.args.line = 0; |
| 6374 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6375 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6376 | if (curproxy->conf.uniqueid_format_string) { |
| 6377 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6378 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6379 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6380 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 6381 | (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6382 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6383 | curproxy->conf.args.file = NULL; |
| 6384 | curproxy->conf.args.line = 0; |
| 6385 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6386 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6387 | /* only now we can check if some args remain unresolved. |
| 6388 | * This must be done after the users and groups resolution. |
| 6389 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6390 | cfgerr += smp_resolve_args(curproxy); |
| 6391 | if (!cfgerr) |
| 6392 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6393 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6394 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6395 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6396 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6397 | (!curproxy->timeout.connect || |
| 6398 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6399 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6400 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6401 | " | 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] | 6402 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6403 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6404 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6405 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6406 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6407 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6408 | * We must still support older configurations, so let's find out whether those |
| 6409 | * parameters have been set or must be copied from contimeouts. |
| 6410 | */ |
| 6411 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6412 | if (!curproxy->timeout.tarpit || |
| 6413 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6414 | /* tarpit timeout not set. We search in the following order: |
| 6415 | * default.tarpit, curr.connect, default.connect. |
| 6416 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6417 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6418 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6419 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6420 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6421 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6422 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6423 | } |
| 6424 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6425 | (!curproxy->timeout.queue || |
| 6426 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6427 | /* queue timeout not set. We search in the following order: |
| 6428 | * default.queue, curr.connect, default.connect. |
| 6429 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6430 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6431 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6432 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6433 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6434 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6435 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6436 | } |
| 6437 | } |
| 6438 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6439 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6440 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6441 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6442 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6443 | } |
| 6444 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6445 | /* ensure that cookie capture length is not too large */ |
| 6446 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6447 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6448 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6449 | err_code |= ERR_WARN; |
| 6450 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6451 | } |
| 6452 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6453 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6454 | if (curproxy->nb_req_cap) { |
| 6455 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6456 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6457 | curproxy->nb_req_cap * sizeof(char *), |
| 6458 | MEM_F_SHARED); |
| 6459 | } else { |
| 6460 | Warning("config : 'capture request header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6461 | proxy_type_str(curproxy), curproxy->id); |
| 6462 | err_code |= ERR_WARN; |
| 6463 | curproxy->to_log &= ~LW_REQHDR; |
| 6464 | curproxy->nb_req_cap = 0; |
| 6465 | } |
| 6466 | } |
| 6467 | |
| 6468 | if (curproxy->nb_rsp_cap) { |
| 6469 | if (curproxy->mode == PR_MODE_HTTP) { |
| 6470 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6471 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6472 | MEM_F_SHARED); |
| 6473 | } else { |
| 6474 | Warning("config : 'capture response header' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6475 | proxy_type_str(curproxy), curproxy->id); |
| 6476 | err_code |= ERR_WARN; |
| 6477 | curproxy->to_log &= ~LW_REQHDR; |
| 6478 | curproxy->nb_rsp_cap = 0; |
| 6479 | } |
| 6480 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6481 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6482 | /* first, we will invert the servers list order */ |
| 6483 | newsrv = NULL; |
| 6484 | while (curproxy->srv) { |
| 6485 | struct server *next; |
| 6486 | |
| 6487 | next = curproxy->srv->next; |
| 6488 | curproxy->srv->next = newsrv; |
| 6489 | newsrv = curproxy->srv; |
| 6490 | if (!next) |
| 6491 | break; |
| 6492 | curproxy->srv = next; |
| 6493 | } |
| 6494 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6495 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6496 | * We only emit a warning for the first conflict affecting each server, |
| 6497 | * in order to avoid combinatory explosion if all servers have the same |
| 6498 | * name. We do that only for servers which do not have an explicit ID, |
| 6499 | * because these IDs were made also for distinguishing them and we don't |
| 6500 | * want to annoy people who correctly manage them. |
| 6501 | */ |
| 6502 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6503 | struct server *other_srv; |
| 6504 | |
| 6505 | if (newsrv->puid) |
| 6506 | continue; |
| 6507 | |
| 6508 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6509 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6510 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6511 | newsrv->conf.file, newsrv->conf.line, |
| 6512 | proxy_type_str(curproxy), curproxy->id, |
| 6513 | newsrv->id, other_srv->conf.line); |
| 6514 | break; |
| 6515 | } |
| 6516 | } |
| 6517 | } |
| 6518 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6519 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6520 | next_id = 1; |
| 6521 | newsrv = curproxy->srv; |
| 6522 | while (newsrv != NULL) { |
| 6523 | if (!newsrv->puid) { |
| 6524 | /* server ID not set, use automatic numbering with first |
| 6525 | * spare entry starting with next_svid. |
| 6526 | */ |
| 6527 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6528 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6529 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6530 | } |
| 6531 | next_id++; |
| 6532 | newsrv = newsrv->next; |
| 6533 | } |
| 6534 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6535 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6536 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6537 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6538 | /* |
| 6539 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6540 | * tasks to fill the emptied slots when a connection leaves. |
| 6541 | * Also, resolve deferred tracking dependency if needed. |
| 6542 | */ |
| 6543 | newsrv = curproxy->srv; |
| 6544 | while (newsrv != NULL) { |
| 6545 | if (newsrv->minconn > newsrv->maxconn) { |
| 6546 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6547 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6548 | * this will avoid further useless expensive computations. |
| 6549 | */ |
| 6550 | newsrv->maxconn = newsrv->minconn; |
| 6551 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6552 | /* minconn was not specified, so we set it to maxconn */ |
| 6553 | newsrv->minconn = newsrv->maxconn; |
| 6554 | } |
| 6555 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6556 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6557 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6558 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6559 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6560 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6561 | /* set the check type on the server */ |
| 6562 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6563 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6564 | if (newsrv->trackit) { |
| 6565 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6566 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6567 | char *pname, *sname; |
| 6568 | |
| 6569 | pname = newsrv->trackit; |
| 6570 | sname = strrchr(pname, '/'); |
| 6571 | |
| 6572 | if (sname) |
| 6573 | *sname++ = '\0'; |
| 6574 | else { |
| 6575 | sname = pname; |
| 6576 | pname = NULL; |
| 6577 | } |
| 6578 | |
| 6579 | if (pname) { |
| 6580 | px = findproxy(pname, PR_CAP_BE); |
| 6581 | if (!px) { |
| 6582 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6583 | proxy_type_str(curproxy), curproxy->id, |
| 6584 | newsrv->id, pname); |
| 6585 | cfgerr++; |
| 6586 | goto next_srv; |
| 6587 | } |
| 6588 | } else |
| 6589 | px = curproxy; |
| 6590 | |
| 6591 | srv = findserver(px, sname); |
| 6592 | if (!srv) { |
| 6593 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6594 | proxy_type_str(curproxy), curproxy->id, |
| 6595 | newsrv->id, sname); |
| 6596 | cfgerr++; |
| 6597 | goto next_srv; |
| 6598 | } |
| 6599 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6600 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 6601 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 6602 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6603 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6604 | "tracking as it does not have any check nor agent enabled.\n", |
| 6605 | proxy_type_str(curproxy), curproxy->id, |
| 6606 | newsrv->id, px->id, srv->id); |
| 6607 | cfgerr++; |
| 6608 | goto next_srv; |
| 6609 | } |
| 6610 | |
| 6611 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 6612 | |
| 6613 | if (loop) { |
| 6614 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 6615 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 6616 | proxy_type_str(curproxy), curproxy->id, |
| 6617 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6618 | cfgerr++; |
| 6619 | goto next_srv; |
| 6620 | } |
| 6621 | |
| 6622 | if (curproxy != px && |
| 6623 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6624 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6625 | "tracking: disable-on-404 option inconsistency.\n", |
| 6626 | proxy_type_str(curproxy), curproxy->id, |
| 6627 | newsrv->id, px->id, srv->id); |
| 6628 | cfgerr++; |
| 6629 | goto next_srv; |
| 6630 | } |
| 6631 | |
| 6632 | /* 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] | 6633 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 6634 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 6635 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 6636 | newsrv->check.health = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 6637 | newsrv->agent.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6638 | } |
| 6639 | |
| 6640 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 6641 | newsrv->tracknext = srv->trackers; |
| 6642 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6643 | |
| 6644 | free(newsrv->trackit); |
| 6645 | newsrv->trackit = NULL; |
| 6646 | } |
| 6647 | next_srv: |
| 6648 | newsrv = newsrv->next; |
| 6649 | } |
| 6650 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6651 | /* We have to initialize the server lookup mechanism depending |
| 6652 | * on what LB algorithm was choosen. |
| 6653 | */ |
| 6654 | |
| 6655 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6656 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6657 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6658 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6659 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6660 | init_server_map(curproxy); |
| 6661 | } else { |
| 6662 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6663 | fwrr_init_server_groups(curproxy); |
| 6664 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6665 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6666 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6667 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6668 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6669 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6670 | fwlc_init_server_tree(curproxy); |
| 6671 | } else { |
| 6672 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6673 | fas_init_server_tree(curproxy); |
| 6674 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6675 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6676 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6677 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6678 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6679 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6680 | chash_init_server_tree(curproxy); |
| 6681 | } else { |
| 6682 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6683 | init_server_map(curproxy); |
| 6684 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6685 | break; |
| 6686 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6687 | |
| 6688 | if (curproxy->options & PR_O_LOGASAP) |
| 6689 | curproxy->to_log &= ~LW_BYTES; |
| 6690 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6691 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 6692 | (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] | 6693 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6694 | proxy_type_str(curproxy), curproxy->id); |
| 6695 | err_code |= ERR_WARN; |
| 6696 | } |
| 6697 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6698 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6699 | int optnum; |
| 6700 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6701 | if (curproxy->uri_auth) { |
| 6702 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6703 | proxy_type_str(curproxy), curproxy->id); |
| 6704 | err_code |= ERR_WARN; |
| 6705 | curproxy->uri_auth = NULL; |
| 6706 | } |
| 6707 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6708 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6709 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6710 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6711 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6712 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6713 | } |
| 6714 | |
| 6715 | if (curproxy->options & PR_O_ORGTO) { |
| 6716 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6717 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6718 | err_code |= ERR_WARN; |
| 6719 | curproxy->options &= ~PR_O_ORGTO; |
| 6720 | } |
| 6721 | |
| 6722 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6723 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6724 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6725 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6726 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6727 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6728 | err_code |= ERR_WARN; |
| 6729 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6730 | } |
| 6731 | } |
| 6732 | |
| 6733 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6734 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6735 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6736 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6737 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6738 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6739 | err_code |= ERR_WARN; |
| 6740 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6741 | } |
| 6742 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6743 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6744 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6745 | if (curproxy->conn_src.bind_hdr_occ) { |
| 6746 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6747 | 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] | 6748 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6749 | err_code |= ERR_WARN; |
| 6750 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6751 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6752 | } |
| 6753 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6754 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6755 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6756 | */ |
| 6757 | newsrv = curproxy->srv; |
| 6758 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6759 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6760 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6761 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6762 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6763 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6764 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6765 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6766 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6767 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6768 | err_code |= ERR_WARN; |
| 6769 | } |
| 6770 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 6771 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 6772 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 6773 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6774 | err_code |= ERR_WARN; |
| 6775 | } |
| 6776 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6777 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6778 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 6779 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6780 | 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] | 6781 | 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] | 6782 | err_code |= ERR_WARN; |
| 6783 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6784 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6785 | newsrv = newsrv->next; |
| 6786 | } |
| 6787 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6788 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6789 | if (!curproxy->accept) |
| 6790 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6791 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6792 | if (curproxy->tcp_req.inspect_delay || |
| 6793 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6794 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6795 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6796 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6797 | 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] | 6798 | 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] | 6799 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6800 | |
| 6801 | /* both TCP and HTTP must check switching rules */ |
| 6802 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6803 | } |
| 6804 | |
| 6805 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6806 | if (curproxy->tcp_req.inspect_delay || |
| 6807 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6808 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6809 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6810 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6811 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6812 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6813 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6814 | 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] | 6815 | 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] | 6816 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6817 | |
| 6818 | /* If the backend does requires RDP cookie persistence, we have to |
| 6819 | * enable the corresponding analyser. |
| 6820 | */ |
| 6821 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6822 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6823 | } |
| 6824 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6825 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6826 | /* Configure SSL for each bind line. |
| 6827 | * Note: if configuration fails at some point, the ->ctx member |
| 6828 | * remains NULL so that listeners can later detach. |
| 6829 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6830 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 6831 | int alloc_ctx; |
| 6832 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6833 | if (!bind_conf->is_ssl) { |
| 6834 | if (bind_conf->default_ctx) { |
| 6835 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 6836 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6837 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6838 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6839 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6840 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6841 | 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] | 6842 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6843 | cfgerr++; |
| 6844 | continue; |
| 6845 | } |
| 6846 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 6847 | 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] | 6848 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 6849 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 6850 | 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"); |
| 6851 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 6852 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 6853 | cfgerr++; |
| 6854 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6855 | } |
| 6856 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 6857 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6858 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6859 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6860 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6861 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6862 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6863 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 6864 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6865 | if (!listener->luid) { |
| 6866 | /* listener ID not set, use automatic numbering with first |
| 6867 | * spare entry starting with next_luid. |
| 6868 | */ |
| 6869 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 6870 | listener->conf.id.key = listener->luid = next_id; |
| 6871 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6872 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 6873 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 6874 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6875 | /* enable separate counters */ |
| 6876 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 6877 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6878 | if (!listener->name) |
| 6879 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 6880 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 6881 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6882 | if (curproxy->options & PR_O_TCP_NOLING) |
| 6883 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 6884 | if (!listener->maxconn) |
| 6885 | listener->maxconn = curproxy->maxconn; |
| 6886 | if (!listener->backlog) |
| 6887 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6888 | if (!listener->maxaccept) |
| 6889 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 6890 | |
| 6891 | /* we want to have an optimal behaviour on single process mode to |
| 6892 | * maximize the work at once, but in multi-process we want to keep |
| 6893 | * some fairness between processes, so we target half of the max |
| 6894 | * number of events to be balanced over all the processes the proxy |
| 6895 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 6896 | * used to disable the limit. |
| 6897 | */ |
| 6898 | if (listener->maxaccept > 0) { |
| 6899 | if (nbproc > 1) |
| 6900 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 6901 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 6902 | } |
| 6903 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6904 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6905 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6906 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6907 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 6908 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 6909 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 6910 | listener->options |= LI_O_TCP_RULES; |
| 6911 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 6912 | if (curproxy->mon_mask.s_addr) |
| 6913 | listener->options |= LI_O_CHK_MONNET; |
| 6914 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6915 | /* smart accept mode is automatic in HTTP mode */ |
| 6916 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6917 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 6918 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 6919 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 6920 | } |
| 6921 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6922 | /* Release unused SSL configs */ |
| 6923 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6924 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6925 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6926 | #ifdef USE_OPENSSL |
| 6927 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6928 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6929 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 6930 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 6931 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6932 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 6933 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6934 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6935 | if (nbproc > 1) { |
| 6936 | if (curproxy->uri_auth) { |
| 6937 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 6938 | curproxy->id); |
| 6939 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 6940 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 6941 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6942 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6943 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6944 | if (curproxy->appsession_name) { |
| 6945 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 6946 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6947 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6948 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 6949 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 6950 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6951 | } |
| 6952 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 6953 | |
| 6954 | /* create the task associated with the proxy */ |
| 6955 | curproxy->task = task_new(); |
| 6956 | if (curproxy->task) { |
| 6957 | curproxy->task->context = curproxy; |
| 6958 | curproxy->task->process = manage_proxy; |
| 6959 | /* no need to queue, it will be done automatically if some |
| 6960 | * listener gets limited. |
| 6961 | */ |
| 6962 | curproxy->task->expire = TICK_ETERNITY; |
| 6963 | } else { |
| 6964 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 6965 | curproxy->id); |
| 6966 | cfgerr++; |
| 6967 | } |
| 6968 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6969 | curproxy = curproxy->next; |
| 6970 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 6971 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6972 | /* Check multi-process mode compatibility */ |
Willy Tarreau | 4e5ed29 | 2014-05-13 13:37:54 +0200 | [diff] [blame] | 6973 | if (global.nbproc > 1 && global.stats_fe) { |
Willy Tarreau | 67c2abc | 2014-05-09 18:48:46 +0200 | [diff] [blame] | 6974 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 6975 | unsigned long mask; |
| 6976 | |
| 6977 | mask = nbits(global.nbproc); |
| 6978 | if (global.stats_fe->bind_proc) |
| 6979 | mask &= global.stats_fe->bind_proc; |
| 6980 | |
| 6981 | if (bind_conf->bind_proc) |
| 6982 | mask &= bind_conf->bind_proc; |
| 6983 | |
| 6984 | /* stop here if more than one process is used */ |
| 6985 | if (popcount(mask) > 1) |
| 6986 | break; |
| 6987 | } |
| 6988 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 6989 | Warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding globally using 'stats bind-process' or per socket using the 'process' attribute.\n"); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 6990 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 6991 | } |
| 6992 | |
| 6993 | /* automatically compute fullconn if not set. We must not do it in the |
| 6994 | * loop above because cross-references are not yet fully resolved. |
| 6995 | */ |
| 6996 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 6997 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 6998 | * the possible incoming frontend's maxconns. |
| 6999 | */ |
| 7000 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7001 | struct proxy *fe; |
| 7002 | int total = 0; |
| 7003 | |
| 7004 | /* sum up the number of maxconns of frontends which |
| 7005 | * reference this backend at least once or which are |
| 7006 | * the same one ('listen'). |
| 7007 | */ |
| 7008 | for (fe = proxy; fe; fe = fe->next) { |
| 7009 | struct switching_rule *rule; |
| 7010 | struct hdr_exp *exp; |
| 7011 | int found = 0; |
| 7012 | |
| 7013 | if (!(fe->cap & PR_CAP_FE)) |
| 7014 | continue; |
| 7015 | |
| 7016 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7017 | found = 1; |
| 7018 | |
| 7019 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7020 | found = 1; |
| 7021 | |
| 7022 | /* check if a "use_backend" rule matches */ |
| 7023 | if (!found) { |
| 7024 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7025 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7026 | found = 1; |
| 7027 | break; |
| 7028 | } |
| 7029 | } |
| 7030 | } |
| 7031 | |
| 7032 | /* check if a "reqsetbe" rule matches */ |
| 7033 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7034 | if (exp->action == ACT_SETBE && |
| 7035 | (struct proxy *)exp->replace == curproxy) { |
| 7036 | found = 1; |
| 7037 | break; |
| 7038 | } |
| 7039 | } |
| 7040 | |
| 7041 | /* now we've checked all possible ways to reference a backend |
| 7042 | * from a frontend. |
| 7043 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7044 | if (!found) |
| 7045 | continue; |
| 7046 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7047 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7048 | /* we have the sum of the maxconns in <total>. We only |
| 7049 | * keep 10% of that sum to set the default fullconn, with |
| 7050 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7051 | */ |
| 7052 | curproxy->fullconn = (total + 9) / 10; |
| 7053 | if (!curproxy->fullconn) |
| 7054 | curproxy->fullconn = 1; |
| 7055 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7056 | } |
| 7057 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7058 | /* initialize stick-tables on backend capable proxies. This must not |
| 7059 | * be done earlier because the data size may be discovered while parsing |
| 7060 | * other proxies. |
| 7061 | */ |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7062 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 5830213 | 2014-02-24 20:59:47 +0100 | [diff] [blame] | 7063 | if (curproxy->state == PR_STSTOPPED) |
| 7064 | continue; |
| 7065 | |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7066 | if (!stktable_init(&curproxy->table)) { |
| 7067 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7068 | cfgerr++; |
| 7069 | } |
| 7070 | } |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7071 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7072 | /* |
| 7073 | * Recount currently required checks. |
| 7074 | */ |
| 7075 | |
| 7076 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7077 | int optnum; |
| 7078 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7079 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7080 | if (curproxy->options & cfg_opts[optnum].val) |
| 7081 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7082 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7083 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7084 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7085 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7086 | } |
| 7087 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7088 | if (peers) { |
| 7089 | struct peers *curpeers = peers, **last; |
| 7090 | struct peer *p, *pb; |
| 7091 | |
| 7092 | /* Remove all peers sections which don't have a valid listener. |
| 7093 | * This can happen when a peers section is never referenced and |
| 7094 | * does not contain a local peer. |
| 7095 | */ |
| 7096 | last = &peers; |
| 7097 | while (*last) { |
| 7098 | curpeers = *last; |
| 7099 | if (curpeers->peers_fe) { |
| 7100 | last = &curpeers->next; |
| 7101 | continue; |
| 7102 | } |
| 7103 | |
| 7104 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7105 | curpeers->id, localpeer); |
| 7106 | |
| 7107 | p = curpeers->remote; |
| 7108 | while (p) { |
| 7109 | pb = p->next; |
| 7110 | free(p->id); |
| 7111 | free(p); |
| 7112 | p = pb; |
| 7113 | } |
| 7114 | |
| 7115 | /* Destroy and unlink this curpeers section. |
| 7116 | * Note: curpeers is backed up into *last. |
| 7117 | */ |
| 7118 | free(curpeers->id); |
| 7119 | curpeers = curpeers->next; |
| 7120 | free(*last); |
| 7121 | *last = curpeers; |
| 7122 | } |
| 7123 | } |
| 7124 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7125 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7126 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7127 | MEM_F_SHARED); |
| 7128 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7129 | if (cfgerr > 0) |
| 7130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7131 | out: |
| 7132 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7133 | } |
| 7134 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7135 | /* |
| 7136 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7137 | * parsing sessions. |
| 7138 | */ |
| 7139 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7140 | { |
| 7141 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7142 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7143 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7144 | /* |
| 7145 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7146 | */ |
| 7147 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7148 | { |
| 7149 | LIST_DEL(&kwl->list); |
| 7150 | LIST_INIT(&kwl->list); |
| 7151 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7152 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7153 | /* this function register new section in the haproxy configuration file. |
| 7154 | * <section_name> is the name of this new section and <section_parser> |
| 7155 | * is the called parser. If two section declaration have the same name, |
| 7156 | * only the first declared is used. |
| 7157 | */ |
| 7158 | int cfg_register_section(char *section_name, |
| 7159 | int (*section_parser)(const char *, int, char **, int)) |
| 7160 | { |
| 7161 | struct cfg_section *cs; |
| 7162 | |
| 7163 | cs = calloc(1, sizeof(*cs)); |
| 7164 | if (!cs) { |
| 7165 | Alert("register section '%s': out of memory.\n", section_name); |
| 7166 | return 0; |
| 7167 | } |
| 7168 | |
| 7169 | cs->section_name = section_name; |
| 7170 | cs->section_parser = section_parser; |
| 7171 | |
| 7172 | LIST_ADDQ(§ions, &cs->list); |
| 7173 | |
| 7174 | return 1; |
| 7175 | } |
| 7176 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7177 | /* |
| 7178 | * Local variables: |
| 7179 | * c-indent-level: 8 |
| 7180 | * c-basic-offset: 8 |
| 7181 | * End: |
| 7182 | */ |