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 | } |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 636 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
| 637 | if (*(args[1]) == 0) { |
| 638 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 640 | goto out; |
| 641 | } |
| 642 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 643 | if (global.tune.ssl_default_dh_param < 1024) { |
| 644 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 646 | goto out; |
| 647 | } |
| 648 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 649 | #endif |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 650 | else if (!strcmp(args[0], "tune.bufsize")) { |
| 651 | if (*(args[1]) == 0) { |
| 652 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 654 | goto out; |
| 655 | } |
| 656 | global.tune.bufsize = atol(args[1]); |
| 657 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 658 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 659 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 660 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 661 | } |
| 662 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
| 663 | if (*(args[1]) == 0) { |
| 664 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 665 | err_code |= ERR_ALERT | ERR_FATAL; |
| 666 | goto out; |
| 667 | } |
| 668 | global.tune.maxrewrite = atol(args[1]); |
| 669 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 670 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 671 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 672 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 673 | unsigned int idle; |
| 674 | const char *res; |
| 675 | |
| 676 | if (*(args[1]) == 0) { |
| 677 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 679 | goto out; |
| 680 | } |
| 681 | |
| 682 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 683 | if (res) { |
| 684 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 685 | file, linenum, *res, args[0]); |
| 686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 687 | goto out; |
| 688 | } |
| 689 | |
| 690 | if (idle > 65535) { |
| 691 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 693 | goto out; |
| 694 | } |
| 695 | global.tune.idle_timer = idle; |
| 696 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 697 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
| 698 | if (global.tune.client_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.client_rcvbuf = atol(args[1]); |
| 709 | } |
| 710 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
| 711 | if (global.tune.server_rcvbuf != 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.server_rcvbuf = atol(args[1]); |
| 722 | } |
| 723 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
| 724 | if (global.tune.client_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.client_sndbuf = atol(args[1]); |
| 735 | } |
| 736 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
| 737 | if (global.tune.server_sndbuf != 0) { |
| 738 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 739 | err_code |= ERR_ALERT; |
| 740 | goto out; |
| 741 | } |
| 742 | if (*(args[1]) == 0) { |
| 743 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 745 | goto out; |
| 746 | } |
| 747 | global.tune.server_sndbuf = atol(args[1]); |
| 748 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 749 | else if (!strcmp(args[0], "tune.pipesize")) { |
| 750 | if (*(args[1]) == 0) { |
| 751 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 753 | goto out; |
| 754 | } |
| 755 | global.tune.pipesize = atol(args[1]); |
| 756 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 757 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
| 758 | if (*(args[1]) == 0) { |
| 759 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 761 | goto out; |
| 762 | } |
| 763 | global.tune.cookie_len = atol(args[1]) + 1; |
| 764 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 765 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
| 766 | if (*(args[1]) == 0) { |
| 767 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 769 | goto out; |
| 770 | } |
| 771 | global.tune.max_http_hdr = atol(args[1]); |
| 772 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 773 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 774 | #ifdef USE_ZLIB |
| 775 | if (*args[1]) { |
| 776 | global.tune.zlibmemlevel = atoi(args[1]); |
| 777 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 778 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 779 | file, linenum, args[0]); |
| 780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 781 | goto out; |
| 782 | } |
| 783 | } else { |
| 784 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 785 | file, linenum, args[0]); |
| 786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 787 | goto out; |
| 788 | } |
| 789 | #else |
| 790 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 792 | goto out; |
| 793 | #endif |
| 794 | } |
| 795 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 796 | #ifdef USE_ZLIB |
| 797 | if (*args[1]) { |
| 798 | global.tune.zlibwindowsize = atoi(args[1]); |
| 799 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 800 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 801 | file, linenum, args[0]); |
| 802 | err_code |= ERR_ALERT | ERR_FATAL; |
| 803 | goto out; |
| 804 | } |
| 805 | } else { |
| 806 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 807 | file, linenum, args[0]); |
| 808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 809 | goto out; |
| 810 | } |
| 811 | #else |
| 812 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 814 | goto out; |
| 815 | #endif |
| 816 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 817 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
| 818 | if (*args[1]) { |
| 819 | global.tune.comp_maxlevel = atoi(args[1]); |
| 820 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 821 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 822 | file, linenum, args[0]); |
| 823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 824 | goto out; |
| 825 | } |
| 826 | } else { |
| 827 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 828 | file, linenum, args[0]); |
| 829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 830 | goto out; |
| 831 | } |
| 832 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 833 | else if (!strcmp(args[0], "uid")) { |
| 834 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 835 | Alert("parsing [%s:%d] : user/uid 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.uid = atol(args[1]); |
| 845 | } |
| 846 | else if (!strcmp(args[0], "gid")) { |
| 847 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 848 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 849 | err_code |= ERR_ALERT; |
| 850 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 851 | } |
| 852 | if (*(args[1]) == 0) { |
| 853 | 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] | 854 | err_code |= ERR_ALERT | ERR_FATAL; |
| 855 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 856 | } |
| 857 | global.gid = atol(args[1]); |
| 858 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 859 | else if (!strcmp(args[0], "external-check")) { |
| 860 | global.external_check = 1; |
| 861 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 862 | /* user/group name handling */ |
| 863 | else if (!strcmp(args[0], "user")) { |
| 864 | struct passwd *ha_user; |
| 865 | if (global.uid != 0) { |
| 866 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 867 | err_code |= ERR_ALERT; |
| 868 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 869 | } |
| 870 | errno = 0; |
| 871 | ha_user = getpwnam(args[1]); |
| 872 | if (ha_user != NULL) { |
| 873 | global.uid = (int)ha_user->pw_uid; |
| 874 | } |
| 875 | else { |
| 876 | 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] | 877 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | else if (!strcmp(args[0], "group")) { |
| 881 | struct group *ha_group; |
| 882 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 883 | 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] | 884 | err_code |= ERR_ALERT; |
| 885 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 886 | } |
| 887 | errno = 0; |
| 888 | ha_group = getgrnam(args[1]); |
| 889 | if (ha_group != NULL) { |
| 890 | global.gid = (int)ha_group->gr_gid; |
| 891 | } |
| 892 | else { |
| 893 | 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] | 894 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 898 | else if (!strcmp(args[0], "nbproc")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 899 | if (*(args[1]) == 0) { |
| 900 | 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] | 901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 902 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 903 | } |
| 904 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 905 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 906 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 907 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 909 | goto out; |
| 910 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 911 | } |
| 912 | else if (!strcmp(args[0], "maxconn")) { |
| 913 | if (global.maxconn != 0) { |
| 914 | 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] | 915 | err_code |= ERR_ALERT; |
| 916 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 917 | } |
| 918 | if (*(args[1]) == 0) { |
| 919 | 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] | 920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 921 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 922 | } |
| 923 | global.maxconn = atol(args[1]); |
| 924 | #ifdef SYSTEM_MAXCONN |
| 925 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 926 | 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); |
| 927 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 928 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 929 | } |
| 930 | #endif /* SYSTEM_MAXCONN */ |
| 931 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 932 | else if (!strcmp(args[0], "maxsslconn")) { |
| 933 | #ifdef USE_OPENSSL |
| 934 | if (*(args[1]) == 0) { |
| 935 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 937 | goto out; |
| 938 | } |
| 939 | global.maxsslconn = atol(args[1]); |
| 940 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 941 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 942 | err_code |= ERR_ALERT | ERR_FATAL; |
| 943 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 944 | #endif |
| 945 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 946 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 947 | #ifdef USE_OPENSSL |
| 948 | if (*(args[1]) == 0) { |
| 949 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto out; |
| 952 | } |
| 953 | free(global.listen_default_ciphers); |
| 954 | global.listen_default_ciphers = strdup(args[1]); |
| 955 | #else |
| 956 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 958 | goto out; |
| 959 | #endif |
| 960 | } |
| 961 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 962 | #ifdef USE_OPENSSL |
| 963 | if (*(args[1]) == 0) { |
| 964 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 966 | goto out; |
| 967 | } |
| 968 | free(global.connect_default_ciphers); |
| 969 | global.connect_default_ciphers = strdup(args[1]); |
| 970 | #else |
| 971 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 973 | goto out; |
| 974 | #endif |
| 975 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 976 | else if (!strcmp(args[0], "ssl-server-verify")) { |
| 977 | if (*(args[1]) == 0) { |
| 978 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 980 | goto out; |
| 981 | } |
| 982 | if (strcmp(args[1],"none") == 0) |
| 983 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 984 | else if (strcmp(args[1],"required") == 0) |
| 985 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 986 | else { |
| 987 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 989 | goto out; |
| 990 | } |
| 991 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 992 | else if (!strcmp(args[0], "maxconnrate")) { |
| 993 | if (global.cps_lim != 0) { |
| 994 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 995 | err_code |= ERR_ALERT; |
| 996 | goto out; |
| 997 | } |
| 998 | if (*(args[1]) == 0) { |
| 999 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1001 | goto out; |
| 1002 | } |
| 1003 | global.cps_lim = atol(args[1]); |
| 1004 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1005 | else if (!strcmp(args[0], "maxsessrate")) { |
| 1006 | if (global.sps_lim != 0) { |
| 1007 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1008 | err_code |= ERR_ALERT; |
| 1009 | goto out; |
| 1010 | } |
| 1011 | if (*(args[1]) == 0) { |
| 1012 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1014 | goto out; |
| 1015 | } |
| 1016 | global.sps_lim = atol(args[1]); |
| 1017 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1018 | else if (!strcmp(args[0], "maxsslrate")) { |
| 1019 | if (global.ssl_lim != 0) { |
| 1020 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1021 | err_code |= ERR_ALERT; |
| 1022 | goto out; |
| 1023 | } |
| 1024 | if (*(args[1]) == 0) { |
| 1025 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1027 | goto out; |
| 1028 | } |
| 1029 | global.ssl_lim = atol(args[1]); |
| 1030 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1031 | else if (!strcmp(args[0], "maxcomprate")) { |
| 1032 | if (*(args[1]) == 0) { |
| 1033 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1035 | goto out; |
| 1036 | } |
| 1037 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1038 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1039 | else if (!strcmp(args[0], "maxpipes")) { |
| 1040 | if (global.maxpipes != 0) { |
| 1041 | 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] | 1042 | err_code |= ERR_ALERT; |
| 1043 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1044 | } |
| 1045 | if (*(args[1]) == 0) { |
| 1046 | 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] | 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1049 | } |
| 1050 | global.maxpipes = atol(args[1]); |
| 1051 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1052 | else if (!strcmp(args[0], "maxzlibmem")) { |
| 1053 | if (*(args[1]) == 0) { |
| 1054 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1056 | goto out; |
| 1057 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1058 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1059 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1060 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
| 1061 | if (*(args[1]) == 0) { |
| 1062 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1064 | goto out; |
| 1065 | } |
| 1066 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1067 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1068 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1070 | goto out; |
| 1071 | } |
| 1072 | } |
| 1073 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1074 | else if (!strcmp(args[0], "ulimit-n")) { |
| 1075 | if (global.rlimit_nofile != 0) { |
| 1076 | 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] | 1077 | err_code |= ERR_ALERT; |
| 1078 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1079 | } |
| 1080 | if (*(args[1]) == 0) { |
| 1081 | 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] | 1082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1083 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1084 | } |
| 1085 | global.rlimit_nofile = atol(args[1]); |
| 1086 | } |
| 1087 | else if (!strcmp(args[0], "chroot")) { |
| 1088 | if (global.chroot != NULL) { |
| 1089 | 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] | 1090 | err_code |= ERR_ALERT; |
| 1091 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1092 | } |
| 1093 | if (*(args[1]) == 0) { |
| 1094 | 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] | 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1096 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1097 | } |
| 1098 | global.chroot = strdup(args[1]); |
| 1099 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1100 | else if (!strcmp(args[0], "description")) { |
| 1101 | int i, len=0; |
| 1102 | char *d; |
| 1103 | |
| 1104 | if (!*args[1]) { |
| 1105 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1106 | file, linenum, args[0]); |
| 1107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1108 | goto out; |
| 1109 | } |
| 1110 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1111 | for (i = 1; *args[i]; i++) |
| 1112 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1113 | |
| 1114 | if (global.desc) |
| 1115 | free(global.desc); |
| 1116 | |
| 1117 | global.desc = d = (char *)calloc(1, len); |
| 1118 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1119 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1120 | for (i = 2; *args[i]; i++) |
| 1121 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1122 | } |
| 1123 | else if (!strcmp(args[0], "node")) { |
| 1124 | int i; |
| 1125 | char c; |
| 1126 | |
| 1127 | for (i=0; args[1][i]; i++) { |
| 1128 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1129 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1130 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1131 | break; |
| 1132 | } |
| 1133 | |
| 1134 | if (!i || args[1][i]) { |
| 1135 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1136 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1137 | file, linenum, args[0]); |
| 1138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1139 | goto out; |
| 1140 | } |
| 1141 | |
| 1142 | if (global.node) |
| 1143 | free(global.node); |
| 1144 | |
| 1145 | global.node = strdup(args[1]); |
| 1146 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1147 | else if (!strcmp(args[0], "pidfile")) { |
| 1148 | if (global.pidfile != NULL) { |
| 1149 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1150 | err_code |= ERR_ALERT; |
| 1151 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1152 | } |
| 1153 | if (*(args[1]) == 0) { |
| 1154 | Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1156 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1157 | } |
| 1158 | global.pidfile = strdup(args[1]); |
| 1159 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1160 | else if (!strcmp(args[0], "unix-bind")) { |
| 1161 | int cur_arg = 1; |
| 1162 | while (*(args[cur_arg])) { |
| 1163 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1164 | if (global.unix_bind.prefix != NULL) { |
| 1165 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1166 | err_code |= ERR_ALERT; |
| 1167 | cur_arg += 2; |
| 1168 | continue; |
| 1169 | } |
| 1170 | |
| 1171 | if (*(args[cur_arg+1]) == 0) { |
| 1172 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1174 | goto out; |
| 1175 | } |
| 1176 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1177 | cur_arg += 2; |
| 1178 | continue; |
| 1179 | } |
| 1180 | |
| 1181 | if (!strcmp(args[cur_arg], "mode")) { |
| 1182 | |
| 1183 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1184 | cur_arg += 2; |
| 1185 | continue; |
| 1186 | } |
| 1187 | |
| 1188 | if (!strcmp(args[cur_arg], "uid")) { |
| 1189 | |
| 1190 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1191 | cur_arg += 2; |
| 1192 | continue; |
| 1193 | } |
| 1194 | |
| 1195 | if (!strcmp(args[cur_arg], "gid")) { |
| 1196 | |
| 1197 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1198 | cur_arg += 2; |
| 1199 | continue; |
| 1200 | } |
| 1201 | |
| 1202 | if (!strcmp(args[cur_arg], "user")) { |
| 1203 | struct passwd *user; |
| 1204 | |
| 1205 | user = getpwnam(args[cur_arg + 1]); |
| 1206 | if (!user) { |
| 1207 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\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.uid = user->pw_uid; |
| 1214 | cur_arg += 2; |
| 1215 | continue; |
| 1216 | } |
| 1217 | |
| 1218 | if (!strcmp(args[cur_arg], "group")) { |
| 1219 | struct group *group; |
| 1220 | |
| 1221 | group = getgrnam(args[cur_arg + 1]); |
| 1222 | if (!group) { |
| 1223 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1224 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1226 | goto out; |
| 1227 | } |
| 1228 | |
| 1229 | global.unix_bind.ux.gid = group->gr_gid; |
| 1230 | cur_arg += 2; |
| 1231 | continue; |
| 1232 | } |
| 1233 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1234 | 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] | 1235 | file, linenum, args[0]); |
| 1236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1237 | goto out; |
| 1238 | } |
| 1239 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1240 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1241 | /* delete previous herited or defined syslog servers */ |
| 1242 | struct logsrv *back; |
| 1243 | struct logsrv *tmp; |
| 1244 | |
| 1245 | if (*(args[1]) != 0) { |
| 1246 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1248 | goto out; |
| 1249 | } |
| 1250 | |
| 1251 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1252 | LIST_DEL(&tmp->list); |
| 1253 | free(tmp); |
| 1254 | } |
| 1255 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1256 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1257 | struct sockaddr_storage *sk; |
| 1258 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1259 | struct logsrv *logsrv; |
| 1260 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1261 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1262 | 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] | 1263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1264 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1265 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1266 | |
| 1267 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1268 | |
| 1269 | logsrv->facility = get_log_facility(args[2]); |
| 1270 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1271 | 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] | 1272 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1273 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1274 | } |
| 1275 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1276 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1277 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1278 | logsrv->level = get_log_level(args[3]); |
| 1279 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1280 | 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] | 1281 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1282 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1286 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1287 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1288 | logsrv->minlvl = get_log_level(args[4]); |
| 1289 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1290 | 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] | 1291 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1292 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1296 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1297 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1298 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1299 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1300 | free(logsrv); |
| 1301 | goto out; |
| 1302 | } |
| 1303 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1304 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1305 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1306 | if (port1 != port2) { |
| 1307 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1308 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1309 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1310 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1311 | goto out; |
| 1312 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1313 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1314 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1315 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1316 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1317 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1318 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1319 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1320 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1321 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1322 | char *name; |
| 1323 | int len; |
| 1324 | |
| 1325 | if (global.log_send_hostname != NULL) { |
| 1326 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1327 | err_code |= ERR_ALERT; |
| 1328 | goto out; |
| 1329 | } |
| 1330 | |
| 1331 | if (*(args[1])) |
| 1332 | name = args[1]; |
| 1333 | else |
| 1334 | name = hostname; |
| 1335 | |
| 1336 | len = strlen(name); |
| 1337 | |
| 1338 | /* We'll add a space after the name to respect the log format */ |
| 1339 | free(global.log_send_hostname); |
| 1340 | global.log_send_hostname = malloc(len + 2); |
| 1341 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1342 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1343 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 1344 | if (*(args[1]) == 0) { |
| 1345 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1347 | goto out; |
| 1348 | } |
| 1349 | free(global.log_tag); |
| 1350 | global.log_tag = strdup(args[1]); |
| 1351 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1352 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 1353 | if (global.spread_checks != 0) { |
| 1354 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1355 | err_code |= ERR_ALERT; |
| 1356 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1357 | } |
| 1358 | if (*(args[1]) == 0) { |
| 1359 | 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] | 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1361 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1362 | } |
| 1363 | global.spread_checks = atol(args[1]); |
| 1364 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1365 | 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] | 1366 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1367 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1368 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1369 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1370 | const char *err; |
| 1371 | unsigned int val; |
| 1372 | |
| 1373 | |
| 1374 | if (*(args[1]) == 0) { |
| 1375 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1377 | goto out; |
| 1378 | } |
| 1379 | |
| 1380 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1381 | if (err) { |
| 1382 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1384 | } |
| 1385 | global.max_spread_checks = val; |
| 1386 | if (global.max_spread_checks < 0) { |
| 1387 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1389 | } |
| 1390 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1391 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1392 | #ifdef USE_CPU_AFFINITY |
| 1393 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1394 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1395 | unsigned long cpus = 0; |
| 1396 | |
| 1397 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1398 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1399 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1400 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1401 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1402 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1403 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1404 | proc = atol(args[1]); |
| 1405 | if (proc >= 1 && proc <= LONGBITS) |
| 1406 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1410 | 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", |
| 1411 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1412 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1413 | goto out; |
| 1414 | } |
| 1415 | |
| 1416 | cur_arg = 2; |
| 1417 | while (*args[cur_arg]) { |
| 1418 | unsigned int low, high; |
| 1419 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1420 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1421 | char *dash = strchr(args[cur_arg], '-'); |
| 1422 | |
| 1423 | low = high = str2uic(args[cur_arg]); |
| 1424 | if (dash) |
| 1425 | high = str2uic(dash + 1); |
| 1426 | |
| 1427 | if (high < low) { |
| 1428 | unsigned int swap = low; |
| 1429 | low = high; |
| 1430 | high = swap; |
| 1431 | } |
| 1432 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1433 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1434 | 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] | 1435 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1437 | goto out; |
| 1438 | } |
| 1439 | |
| 1440 | while (low <= high) |
| 1441 | cpus |= 1UL << low++; |
| 1442 | } |
| 1443 | else { |
| 1444 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1445 | file, linenum, args[0], args[cur_arg]); |
| 1446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1447 | goto out; |
| 1448 | } |
| 1449 | cur_arg++; |
| 1450 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1451 | for (i = 0; i < LONGBITS; i++) |
| 1452 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1453 | global.cpu_map[i] = cpus; |
| 1454 | #else |
| 1455 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1457 | goto out; |
| 1458 | #endif |
| 1459 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1460 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1461 | struct cfg_kw_list *kwl; |
| 1462 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1463 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1464 | |
| 1465 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1466 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1467 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1468 | continue; |
| 1469 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1470 | 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] | 1471 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1472 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1473 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1474 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1475 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1476 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1477 | err_code |= ERR_WARN; |
| 1478 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1479 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1480 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1485 | 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] | 1486 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1487 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1488 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1489 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1490 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1491 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1492 | } |
| 1493 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1494 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1495 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1496 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1497 | defproxy.mode = PR_MODE_TCP; |
| 1498 | defproxy.state = PR_STNEW; |
| 1499 | defproxy.maxconn = cfg_maxpconn; |
| 1500 | defproxy.conn_retries = CONN_RETRIES; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1501 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1502 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1503 | defproxy.defsrv.check.fastinter = 0; |
| 1504 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1505 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1506 | defproxy.defsrv.agent.fastinter = 0; |
| 1507 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1508 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1509 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1510 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1511 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1512 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1513 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1514 | defproxy.defsrv.maxqueue = 0; |
| 1515 | defproxy.defsrv.minconn = 0; |
| 1516 | defproxy.defsrv.maxconn = 0; |
| 1517 | defproxy.defsrv.slowstart = 0; |
| 1518 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1519 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1520 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1521 | } |
| 1522 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1523 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1524 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1525 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1526 | * ERR_FATAL in case of error. |
| 1527 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1528 | static int create_cond_regex_rule(const char *file, int line, |
| 1529 | struct proxy *px, int dir, int action, int flags, |
| 1530 | const char *cmd, const char *reg, const char *repl, |
| 1531 | const char **cond_start) |
| 1532 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1533 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1534 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1535 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1536 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1537 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1538 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1539 | int cs; |
| 1540 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1541 | |
| 1542 | if (px == &defproxy) { |
| 1543 | 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] | 1544 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1545 | goto err; |
| 1546 | } |
| 1547 | |
| 1548 | if (*reg == 0) { |
| 1549 | 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] | 1550 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1551 | goto err; |
| 1552 | } |
| 1553 | |
| 1554 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1555 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1556 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1557 | if (cond_start && |
| 1558 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1559 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1560 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1561 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1562 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1563 | goto err; |
| 1564 | } |
| 1565 | } |
| 1566 | else if (cond_start && **cond_start) { |
| 1567 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1568 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1569 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1570 | goto err; |
| 1571 | } |
| 1572 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1573 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1574 | (dir == SMP_OPT_DIR_REQ) ? |
| 1575 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1576 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1577 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1578 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1579 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1580 | if (!preg) { |
| 1581 | 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] | 1582 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1583 | goto err; |
| 1584 | } |
| 1585 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1586 | cs = !(flags & REG_ICASE); |
| 1587 | cap = !(flags & REG_NOSUB); |
| 1588 | error = NULL; |
| 1589 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1590 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1591 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1592 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1593 | goto err; |
| 1594 | } |
| 1595 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1596 | 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] | 1597 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1598 | if (repl && err) { |
| 1599 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1600 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1601 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1602 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1605 | 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] | 1606 | ret_code |= ERR_WARN; |
| 1607 | |
| 1608 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1609 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1610 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1611 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1612 | err: |
| 1613 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1614 | free(errmsg); |
| 1615 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1618 | /* |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1619 | * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1620 | * Returns the error code, 0 if OK, or any combination of : |
| 1621 | * - ERR_ABORT: must abort ASAP |
| 1622 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1623 | * - ERR_WARN: a warning has been emitted |
| 1624 | * - ERR_ALERT: an alert has been emitted |
| 1625 | * Only the two first ones can stop processing, the two others are just |
| 1626 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1627 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1628 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1629 | { |
| 1630 | static struct peers *curpeers = NULL; |
| 1631 | struct peer *newpeer = NULL; |
| 1632 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1633 | struct bind_conf *bind_conf; |
| 1634 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1635 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1636 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1637 | |
| 1638 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1639 | if (!*args[1]) { |
| 1640 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1641 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1642 | goto out; |
| 1643 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1644 | |
| 1645 | err = invalid_char(args[1]); |
| 1646 | if (err) { |
| 1647 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1648 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1649 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1650 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1654 | /* |
| 1655 | * If there are two proxies with the same name only following |
| 1656 | * combinations are allowed: |
| 1657 | */ |
| 1658 | if (strcmp(curpeers->id, args[1]) == 0) { |
| 1659 | Warning("Parsing [%s:%d]: peers '%s' has same name as another peers (declared at %s:%d).\n", |
| 1660 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
| 1661 | err_code |= ERR_WARN; |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1666 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1667 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1668 | goto out; |
| 1669 | } |
| 1670 | |
| 1671 | curpeers->next = peers; |
| 1672 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1673 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1674 | curpeers->conf.line = linenum; |
| 1675 | curpeers->last_change = now.tv_sec; |
| 1676 | curpeers->id = strdup(args[1]); |
| 1677 | } |
| 1678 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1679 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1680 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1681 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1682 | |
| 1683 | if (!*args[2]) { |
| 1684 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1685 | file, linenum, args[0]); |
| 1686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1687 | goto out; |
| 1688 | } |
| 1689 | |
| 1690 | err = invalid_char(args[1]); |
| 1691 | if (err) { |
| 1692 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1693 | file, linenum, *err, args[1]); |
| 1694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1695 | goto out; |
| 1696 | } |
| 1697 | |
| 1698 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 1699 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1700 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1701 | goto out; |
| 1702 | } |
| 1703 | |
| 1704 | /* the peers are linked backwards first */ |
| 1705 | curpeers->count++; |
| 1706 | newpeer->next = curpeers->remote; |
| 1707 | curpeers->remote = newpeer; |
| 1708 | newpeer->peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1709 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1710 | newpeer->conf.line = linenum; |
| 1711 | |
| 1712 | newpeer->last_change = now.tv_sec; |
| 1713 | newpeer->id = strdup(args[1]); |
| 1714 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1715 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1716 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1717 | 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] | 1718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1719 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1720 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1721 | |
| 1722 | proto = protocol_by_family(sk->ss_family); |
| 1723 | if (!proto || !proto->connect) { |
| 1724 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1725 | file, linenum, args[0], args[1]); |
| 1726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1727 | goto out; |
| 1728 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1729 | |
| 1730 | if (port1 != port2) { |
| 1731 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1732 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1734 | goto out; |
| 1735 | } |
| 1736 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1737 | if (!port1) { |
| 1738 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1739 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1741 | goto out; |
| 1742 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1743 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1744 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1745 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1746 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 1747 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1748 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1749 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 1750 | /* Current is local peer, it define a frontend */ |
| 1751 | newpeer->local = 1; |
| 1752 | |
| 1753 | if (!curpeers->peers_fe) { |
| 1754 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 1755 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1756 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1757 | goto out; |
| 1758 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1759 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1760 | init_new_proxy(curpeers->peers_fe); |
| 1761 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1762 | |
| 1763 | curpeers->peers_fe->last_change = now.tv_sec; |
| 1764 | curpeers->peers_fe->id = strdup(args[1]); |
| 1765 | curpeers->peers_fe->cap = PR_CAP_FE; |
Willy Tarreau | 3ae65a1 | 2011-09-07 17:40:39 +0200 | [diff] [blame] | 1766 | curpeers->peers_fe->maxconn = 0; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1767 | curpeers->peers_fe->conn_retries = CONN_RETRIES; |
| 1768 | curpeers->peers_fe->timeout.connect = 5000; |
| 1769 | curpeers->peers_fe->accept = peer_accept; |
| 1770 | 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] | 1771 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 1772 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1773 | |
| 1774 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 1775 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1776 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 1777 | if (errmsg && *errmsg) { |
| 1778 | indent_msg(&errmsg, 2); |
| 1779 | 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] | 1780 | } |
| 1781 | else |
| 1782 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 1783 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1784 | err_code |= ERR_FATAL; |
| 1785 | goto out; |
| 1786 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1787 | |
| 1788 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 1789 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1790 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 1791 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
| 1792 | l->timeout = &((struct proxy *)curpeers->peers_fe)->timeout.client; |
| 1793 | l->accept = session_accept; |
| 1794 | l->handler = process_session; |
| 1795 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
| 1796 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 1797 | global.maxsock += l->maxconn; |
| 1798 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1799 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 1800 | else { |
| 1801 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 1802 | file, linenum, args[0], args[1], |
| 1803 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 1804 | err_code |= ERR_FATAL; |
| 1805 | goto out; |
| 1806 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1807 | } |
| 1808 | } /* neither "peer" nor "peers" */ |
| 1809 | else if (*args[0] != 0) { |
| 1810 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 1811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1812 | goto out; |
| 1813 | } |
| 1814 | |
| 1815 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1816 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1817 | return err_code; |
| 1818 | } |
| 1819 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 1820 | 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] | 1821 | { |
| 1822 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 1823 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1824 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 1825 | int rc; |
| 1826 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1827 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 1828 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1829 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 1830 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1831 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1832 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1833 | if (!strcmp(args[0], "listen")) |
| 1834 | rc = PR_CAP_LISTEN; |
| 1835 | else if (!strcmp(args[0], "frontend")) |
| 1836 | rc = PR_CAP_FE | PR_CAP_RS; |
| 1837 | else if (!strcmp(args[0], "backend")) |
| 1838 | rc = PR_CAP_BE | PR_CAP_RS; |
| 1839 | else if (!strcmp(args[0], "ruleset")) |
| 1840 | rc = PR_CAP_RS; |
| 1841 | else |
| 1842 | rc = PR_CAP_NONE; |
| 1843 | |
| 1844 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1845 | struct ebpt_node *node; |
| 1846 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1847 | if (!*args[1]) { |
| 1848 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 1849 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 1850 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1851 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1852 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1853 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1854 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1855 | err = invalid_char(args[1]); |
| 1856 | if (err) { |
| 1857 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1858 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1859 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1860 | } |
| 1861 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1862 | for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) { |
| 1863 | curproxy = container_of(node, struct proxy, conf.by_name); |
| 1864 | |
| 1865 | if (strcmp(curproxy->id, args[1]) != 0) |
| 1866 | break; |
| 1867 | |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1868 | /* |
| 1869 | * If there are two proxies with the same name only following |
| 1870 | * combinations are allowed: |
| 1871 | * |
| 1872 | * listen backend frontend ruleset |
| 1873 | * listen - - - - |
| 1874 | * backend - - OK - |
| 1875 | * frontend - OK - - |
| 1876 | * ruleset - - - - |
| 1877 | */ |
| 1878 | |
Willy Tarreau | 7cbc915 | 2014-03-15 08:17:08 +0100 | [diff] [blame] | 1879 | if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) && |
| 1880 | (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] | 1881 | Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n", |
| 1882 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 1883 | curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1884 | err_code |= ERR_WARN; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1888 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 1889 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1890 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1891 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1892 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 1893 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1894 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1895 | curproxy->next = proxy; |
| 1896 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1897 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 1898 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1899 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1900 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1901 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 1902 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1903 | |
| 1904 | /* parse the listener address if any */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1905 | if ((curproxy->cap & PR_CAP_FE) && *args[2]) { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1906 | struct listener *l; |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1907 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1908 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[2]); |
| 1909 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1910 | if (!str2listener(args[2], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 1911 | if (errmsg && *errmsg) { |
| 1912 | indent_msg(&errmsg, 2); |
| 1913 | 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] | 1914 | } |
| 1915 | else |
| 1916 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address '%s'.\n", |
| 1917 | file, linenum, args[0], args[1], args[2]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1918 | err_code |= ERR_FATAL; |
| 1919 | goto out; |
| 1920 | } |
Willy Tarreau | 81a8117 | 2012-09-18 20:52:35 +0200 | [diff] [blame] | 1921 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1922 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 1923 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 1924 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1928 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 1929 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1930 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1931 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1932 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 1933 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 1934 | curproxy->no_options = defproxy.no_options; |
| 1935 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 1936 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1937 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 1938 | curproxy->except_net = defproxy.except_net; |
| 1939 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 1940 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 1941 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1942 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 1943 | if (defproxy.fwdfor_hdr_len) { |
| 1944 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 1945 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 1946 | } |
| 1947 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 1948 | if (defproxy.orgto_hdr_len) { |
| 1949 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 1950 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 1951 | } |
| 1952 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 1953 | if (defproxy.server_id_hdr_len) { |
| 1954 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 1955 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 1956 | } |
| 1957 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1958 | if (curproxy->cap & PR_CAP_FE) { |
| 1959 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 1960 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 1961 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1962 | |
| 1963 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1964 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 1965 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1966 | |
| 1967 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 1968 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1969 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1970 | if (curproxy->cap & PR_CAP_BE) { |
| 1971 | curproxy->fullconn = defproxy.fullconn; |
| 1972 | curproxy->conn_retries = defproxy.conn_retries; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 1973 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1974 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 1975 | if (defproxy.check_req) { |
| 1976 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 1977 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 1978 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1979 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1980 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1981 | if (defproxy.expect_str) { |
| 1982 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 1983 | if (defproxy.expect_regex) { |
| 1984 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1985 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 1986 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1990 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 1991 | if (defproxy.cookie_name) |
| 1992 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 1993 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 1994 | if (defproxy.cookie_domain) |
| 1995 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1996 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 1997 | if (defproxy.cookie_maxidle) |
| 1998 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 1999 | |
| 2000 | if (defproxy.cookie_maxlife) |
| 2001 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2002 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2003 | if (defproxy.rdp_cookie_name) |
| 2004 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2005 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2006 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2007 | if (defproxy.url_param_name) |
| 2008 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2009 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2010 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2011 | if (defproxy.hh_name) |
| 2012 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2013 | curproxy->hh_len = defproxy.hh_len; |
| 2014 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2015 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2016 | if (defproxy.conn_src.iface_name) |
| 2017 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2018 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2019 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2020 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2021 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2022 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2023 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2024 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2025 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2026 | if (defproxy.capture_name) |
| 2027 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2028 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2029 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2030 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2031 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2032 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2033 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2034 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2035 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2036 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2037 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2038 | curproxy->mon_net = defproxy.mon_net; |
| 2039 | curproxy->mon_mask = defproxy.mon_mask; |
| 2040 | if (defproxy.monitor_uri) |
| 2041 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2042 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2043 | if (defproxy.defbe.name) |
| 2044 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2045 | |
| 2046 | /* 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] | 2047 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2048 | if (curproxy->conf.logformat_string && |
| 2049 | curproxy->conf.logformat_string != default_http_log_format && |
| 2050 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2051 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2052 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2053 | |
| 2054 | if (defproxy.conf.lfs_file) { |
| 2055 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2056 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2057 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2061 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2062 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2063 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2064 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2065 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2066 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2067 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2068 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2069 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2070 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2071 | } |
| 2072 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2073 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2074 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2075 | |
| 2076 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2077 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2078 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2079 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2080 | LIST_INIT(&node->list); |
| 2081 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2082 | } |
| 2083 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2084 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2085 | if (curproxy->conf.uniqueid_format_string) |
| 2086 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2087 | |
| 2088 | if (defproxy.conf.uif_file) { |
| 2089 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2090 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2091 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2092 | |
| 2093 | /* copy default header unique id */ |
| 2094 | if (defproxy.header_unique_id) |
| 2095 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2096 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2097 | /* default compression options */ |
| 2098 | if (defproxy.comp != NULL) { |
| 2099 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2100 | curproxy->comp->algos = defproxy.comp->algos; |
| 2101 | curproxy->comp->types = defproxy.comp->types; |
| 2102 | } |
| 2103 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2104 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2105 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2106 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2107 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2108 | if (defproxy.check_path) |
| 2109 | curproxy->check_path = strdup(defproxy.check_path); |
| 2110 | if (defproxy.check_command) |
| 2111 | curproxy->check_command = strdup(defproxy.check_command); |
| 2112 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2113 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2114 | } |
| 2115 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2116 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2117 | /* FIXME-20070101: we should do this too at the end of the |
| 2118 | * config parsing to free all default values. |
| 2119 | */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2120 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2121 | free(defproxy.check_command); |
| 2122 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2123 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2124 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2125 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2126 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2127 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2128 | free(defproxy.capture_name); |
| 2129 | free(defproxy.monitor_uri); |
| 2130 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2131 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2132 | free(defproxy.fwdfor_hdr_name); |
| 2133 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2134 | free(defproxy.orgto_hdr_name); |
| 2135 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2136 | free(defproxy.server_id_hdr_name); |
| 2137 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2138 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2139 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2140 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2141 | free(defproxy.expect_regex); |
| 2142 | defproxy.expect_regex = NULL; |
| 2143 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2144 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2145 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2146 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2147 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2148 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2149 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2150 | free(defproxy.conf.uniqueid_format_string); |
| 2151 | free(defproxy.conf.lfs_file); |
| 2152 | free(defproxy.conf.uif_file); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2153 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2154 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2155 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2156 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2157 | /* we cannot free uri_auth because it might already be used */ |
| 2158 | init_default_instance(); |
| 2159 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2160 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2161 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2162 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2163 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2164 | } |
| 2165 | else if (curproxy == NULL) { |
| 2166 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2167 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2168 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2169 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2170 | |
| 2171 | /* update the current file and line being parsed */ |
| 2172 | curproxy->conf.args.file = curproxy->conf.file; |
| 2173 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2174 | |
| 2175 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2176 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2177 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2178 | if (err_code & ERR_FATAL) |
| 2179 | goto out; |
| 2180 | } |
| 2181 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2182 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2183 | int cur_arg; |
| 2184 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2185 | if (curproxy == &defproxy) { |
| 2186 | 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] | 2187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2188 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2189 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2190 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2191 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2192 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2193 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2194 | 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] | 2195 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2197 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2198 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2199 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2200 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2201 | |
| 2202 | /* use default settings for unix sockets */ |
| 2203 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2204 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2205 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2206 | |
| 2207 | /* NOTE: the following line might create several listeners if there |
| 2208 | * are comma-separated IPs or port ranges. So all further processing |
| 2209 | * will have to be applied to all listeners created after last_listen. |
| 2210 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2211 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2212 | if (errmsg && *errmsg) { |
| 2213 | indent_msg(&errmsg, 2); |
| 2214 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2215 | } |
| 2216 | else |
| 2217 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2218 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2220 | goto out; |
| 2221 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2222 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2223 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2224 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2225 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2226 | } |
| 2227 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2228 | cur_arg = 2; |
| 2229 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2230 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2231 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2232 | char *err; |
| 2233 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2234 | kw = bind_find_kw(args[cur_arg]); |
| 2235 | if (kw) { |
| 2236 | char *err = NULL; |
| 2237 | int code; |
| 2238 | |
| 2239 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2240 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2241 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2242 | cur_arg += 1 + kw->skip ; |
| 2243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2244 | goto out; |
| 2245 | } |
| 2246 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2247 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2248 | err_code |= code; |
| 2249 | |
| 2250 | if (code) { |
| 2251 | if (err && *err) { |
| 2252 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2253 | 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] | 2254 | } |
| 2255 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2256 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2257 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2258 | if (code & ERR_FATAL) { |
| 2259 | free(err); |
| 2260 | cur_arg += 1 + kw->skip; |
| 2261 | goto out; |
| 2262 | } |
| 2263 | } |
| 2264 | free(err); |
| 2265 | cur_arg += 1 + kw->skip; |
| 2266 | continue; |
| 2267 | } |
| 2268 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2269 | err = NULL; |
| 2270 | if (!bind_dumped) { |
| 2271 | bind_dump_kws(&err); |
| 2272 | indent_msg(&err, 4); |
| 2273 | bind_dumped = 1; |
| 2274 | } |
| 2275 | |
| 2276 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2277 | file, linenum, args[0], args[1], args[cur_arg], |
| 2278 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2279 | free(err); |
| 2280 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2282 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2283 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2284 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2285 | } |
| 2286 | 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] | 2287 | 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] | 2288 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2289 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2291 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2292 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2293 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2294 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2295 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2296 | /* flush useless bits */ |
| 2297 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2298 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2299 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2300 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2301 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2302 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2303 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2304 | if (!*args[1]) { |
| 2305 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2306 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2308 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2309 | } |
| 2310 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2311 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2312 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2313 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2314 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2315 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2316 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2317 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2318 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2319 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
| 2320 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2321 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2322 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2323 | else { |
| 2324 | 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] | 2325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2326 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2327 | } |
| 2328 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2329 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2330 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2331 | |
| 2332 | if (curproxy == &defproxy) { |
| 2333 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2334 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2336 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | if (!*args[1]) { |
| 2340 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2341 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2343 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2347 | curproxy->conf.id.key = curproxy->uuid; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2348 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2349 | if (curproxy->uuid <= 0) { |
| 2350 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2351 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2353 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2354 | } |
| 2355 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2356 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 2357 | if (node) { |
| 2358 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 2359 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 2360 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 2361 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 2362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2363 | goto out; |
| 2364 | } |
| 2365 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2366 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2367 | else if (!strcmp(args[0], "description")) { |
| 2368 | int i, len=0; |
| 2369 | char *d; |
| 2370 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2371 | if (curproxy == &defproxy) { |
| 2372 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2373 | file, linenum, args[0]); |
| 2374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2375 | goto out; |
| 2376 | } |
| 2377 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2378 | if (!*args[1]) { |
| 2379 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 2380 | file, linenum, args[0]); |
| 2381 | return -1; |
| 2382 | } |
| 2383 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2384 | for (i = 1; *args[i]; i++) |
| 2385 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2386 | |
| 2387 | d = (char *)calloc(1, len); |
| 2388 | curproxy->desc = d; |
| 2389 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 2390 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 2391 | for (i = 2; *args[i]; i++) |
| 2392 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2393 | |
| 2394 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2395 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
| 2396 | curproxy->state = PR_STSTOPPED; |
| 2397 | } |
| 2398 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
| 2399 | curproxy->state = PR_STNEW; |
| 2400 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2401 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 2402 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2403 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2404 | |
| 2405 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2406 | unsigned int low, high; |
| 2407 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2408 | if (strcmp(args[cur_arg], "all") == 0) { |
| 2409 | set = 0; |
| 2410 | break; |
| 2411 | } |
| 2412 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2413 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2414 | } |
| 2415 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2416 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2417 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 2418 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2419 | char *dash = strchr(args[cur_arg], '-'); |
| 2420 | |
| 2421 | low = high = str2uic(args[cur_arg]); |
| 2422 | if (dash) |
| 2423 | high = str2uic(dash + 1); |
| 2424 | |
| 2425 | if (high < low) { |
| 2426 | unsigned int swap = low; |
| 2427 | low = high; |
| 2428 | high = swap; |
| 2429 | } |
| 2430 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2431 | if (low < 1 || high > LONGBITS) { |
| 2432 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 2433 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2435 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2436 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2437 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2438 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2439 | } |
| 2440 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 2441 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 2442 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 2443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2444 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2445 | } |
| 2446 | cur_arg++; |
| 2447 | } |
| 2448 | curproxy->bind_proc = set; |
| 2449 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2450 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2451 | if (curproxy == &defproxy) { |
| 2452 | 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] | 2453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2454 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2455 | } |
| 2456 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2457 | err = invalid_char(args[1]); |
| 2458 | if (err) { |
| 2459 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 2460 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2461 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2462 | } |
| 2463 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 2464 | 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] | 2465 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 2466 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2468 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 2469 | } |
| 2470 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2471 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 2472 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2473 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2474 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2475 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2476 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2477 | if (*(args[1]) == 0) { |
| 2478 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 2479 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2481 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2482 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2483 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2484 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2485 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2486 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2487 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2488 | curproxy->cookie_name = strdup(args[1]); |
| 2489 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 2490 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2491 | cur_arg = 2; |
| 2492 | while (*(args[cur_arg])) { |
| 2493 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2494 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2495 | } |
| 2496 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2497 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2498 | } |
| 2499 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2500 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2501 | } |
| 2502 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2503 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2504 | } |
| 2505 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2506 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2507 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2508 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2509 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2510 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2511 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2512 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2513 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 2514 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 2515 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 2516 | } |
| 2517 | else if (!strcmp(args[cur_arg], "secure")) { |
| 2518 | curproxy->ck_opts |= PR_CK_SECURE; |
| 2519 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2520 | else if (!strcmp(args[cur_arg], "domain")) { |
| 2521 | if (!*args[cur_arg + 1]) { |
| 2522 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 2523 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2525 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2526 | } |
| 2527 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2528 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2529 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2530 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 2531 | " dots nor does not start with a dot." |
| 2532 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2533 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 2534 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | err = invalid_domainchar(args[cur_arg + 1]); |
| 2538 | if (err) { |
| 2539 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 2540 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2542 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2543 | } |
| 2544 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 2545 | if (!curproxy->cookie_domain) { |
| 2546 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 2547 | } else { |
| 2548 | /* one domain was already specified, add another one by |
| 2549 | * building the string which will be returned along with |
| 2550 | * the cookie. |
| 2551 | */ |
| 2552 | char *new_ptr; |
| 2553 | int new_len = strlen(curproxy->cookie_domain) + |
| 2554 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 2555 | new_ptr = malloc(new_len); |
| 2556 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 2557 | free(curproxy->cookie_domain); |
| 2558 | curproxy->cookie_domain = new_ptr; |
| 2559 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2560 | cur_arg++; |
| 2561 | } |
| 2562 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 2563 | unsigned int maxidle; |
| 2564 | const char *res; |
| 2565 | |
| 2566 | if (!*args[cur_arg + 1]) { |
| 2567 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 2568 | file, linenum, args[cur_arg]); |
| 2569 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2570 | goto out; |
| 2571 | } |
| 2572 | |
| 2573 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 2574 | if (res) { |
| 2575 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2576 | file, linenum, *res, args[cur_arg]); |
| 2577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2578 | goto out; |
| 2579 | } |
| 2580 | curproxy->cookie_maxidle = maxidle; |
| 2581 | cur_arg++; |
| 2582 | } |
| 2583 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 2584 | unsigned int maxlife; |
| 2585 | const char *res; |
| 2586 | |
| 2587 | if (!*args[cur_arg + 1]) { |
| 2588 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 2589 | file, linenum, args[cur_arg]); |
| 2590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2591 | goto out; |
| 2592 | } |
| 2593 | |
| 2594 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 2595 | if (res) { |
| 2596 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2597 | file, linenum, *res, args[cur_arg]); |
| 2598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2599 | goto out; |
| 2600 | } |
| 2601 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 2602 | cur_arg++; |
| 2603 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2604 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2605 | 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] | 2606 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2608 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2609 | } |
| 2610 | cur_arg++; |
| 2611 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2612 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2613 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 2614 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2615 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2616 | } |
| 2617 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2618 | 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] | 2619 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 2620 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2621 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2622 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 2623 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2624 | 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] | 2625 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 2626 | file, linenum); |
| 2627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2628 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2629 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2630 | else if (!strcmp(args[0], "external-check")) { |
| 2631 | if (*(args[1]) == 0) { |
| 2632 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2633 | file, linenum, args[0]); |
| 2634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2635 | goto out; |
| 2636 | } |
| 2637 | |
| 2638 | if (!strcmp(args[1], "command")) { |
| 2639 | if (*(args[1]) == 0) { |
| 2640 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2641 | file, linenum, args[1]); |
| 2642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2643 | goto out; |
| 2644 | } |
| 2645 | free(curproxy->check_command); |
| 2646 | curproxy->check_command = strdup(args[2]); |
| 2647 | } |
| 2648 | else if (!strcmp(args[1], "path")) { |
| 2649 | if (*(args[1]) == 0) { |
| 2650 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 2651 | file, linenum, args[1]); |
| 2652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2653 | goto out; |
| 2654 | } |
| 2655 | free(curproxy->check_path); |
| 2656 | curproxy->check_path = strdup(args[2]); |
| 2657 | } |
| 2658 | else { |
| 2659 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 2660 | file, linenum, args[1]); |
| 2661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2662 | goto out; |
| 2663 | } |
| 2664 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2665 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 2666 | if (*(args[1]) == 0) { |
| 2667 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 2668 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2670 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 2674 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 2675 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2676 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2677 | const char *beg, *end; |
| 2678 | |
| 2679 | beg = args[1] + 11; |
| 2680 | end = strchr(beg, ')'); |
| 2681 | |
| 2682 | if (!end || end == beg) { |
| 2683 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2684 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2686 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | free(curproxy->rdp_cookie_name); |
| 2690 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 2691 | curproxy->rdp_cookie_len = end-beg; |
| 2692 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 2693 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2694 | free(curproxy->rdp_cookie_name); |
| 2695 | curproxy->rdp_cookie_name = strdup("msts"); |
| 2696 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 2697 | } |
| 2698 | else { /* syntax */ |
| 2699 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 2700 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2702 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | else { |
| 2706 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 2707 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2709 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2710 | } |
| 2711 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2712 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2713 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2714 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 2715 | if (curproxy == &defproxy) { |
| 2716 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2718 | goto out; |
| 2719 | } |
| 2720 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2721 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2722 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2723 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2724 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2725 | 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] | 2726 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2728 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2729 | } |
| 2730 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2731 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2732 | curproxy->appsession_name = strdup(args[1]); |
| 2733 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 2734 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2735 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 2736 | if (err) { |
| 2737 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 2738 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2740 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2741 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 2742 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 2743 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 2744 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 2745 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2746 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2747 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2748 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2749 | |
| 2750 | cur_arg = 6; |
| 2751 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2752 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2753 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2754 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2755 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2756 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 2757 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 2758 | curproxy->options2 |= PR_O2_AS_PFX; |
| 2759 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 2760 | if (!*args[cur_arg + 1]) { |
| 2761 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 2762 | file, linenum, args[0], args[cur_arg]); |
| 2763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2764 | goto out; |
| 2765 | } |
| 2766 | |
| 2767 | cur_arg++; |
| 2768 | if (!strcmp(args[cur_arg], "query-string")) { |
| 2769 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2770 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 2771 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 2772 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 2773 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 2774 | } else { |
| 2775 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 2776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2777 | goto out; |
| 2778 | } |
| 2779 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 2780 | cur_arg++; |
| 2781 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2782 | } /* Url App Session */ |
| 2783 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2784 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2785 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2786 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2787 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2788 | if (curproxy == &defproxy) { |
| 2789 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 2790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2791 | goto out; |
| 2792 | } |
| 2793 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2794 | if (*(args[4]) == 0) { |
| 2795 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 2796 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2798 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2799 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2800 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2801 | curproxy->capture_name = strdup(args[2]); |
| 2802 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 2803 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2804 | curproxy->to_log |= LW_COOKIE; |
| 2805 | } |
| 2806 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 2807 | struct cap_hdr *hdr; |
| 2808 | |
| 2809 | if (curproxy == &defproxy) { |
| 2810 | 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] | 2811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2812 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2816 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2817 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2819 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2823 | hdr->next = curproxy->req_cap; |
| 2824 | hdr->name = strdup(args[3]); |
| 2825 | hdr->namelen = strlen(args[3]); |
| 2826 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2827 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2828 | hdr->index = curproxy->nb_req_cap++; |
| 2829 | curproxy->req_cap = hdr; |
| 2830 | curproxy->to_log |= LW_REQHDR; |
| 2831 | } |
| 2832 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 2833 | struct cap_hdr *hdr; |
| 2834 | |
| 2835 | if (curproxy == &defproxy) { |
| 2836 | 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] | 2837 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2838 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 2842 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 2843 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2845 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2846 | } |
| 2847 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 2848 | hdr->next = curproxy->rsp_cap; |
| 2849 | hdr->name = strdup(args[3]); |
| 2850 | hdr->namelen = strlen(args[3]); |
| 2851 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 2852 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2853 | hdr->index = curproxy->nb_rsp_cap++; |
| 2854 | curproxy->rsp_cap = hdr; |
| 2855 | curproxy->to_log |= LW_RSPHDR; |
| 2856 | } |
| 2857 | else { |
| 2858 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 2859 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2861 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2862 | } |
| 2863 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2864 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2865 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2866 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2867 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2868 | if (*(args[1]) == 0) { |
| 2869 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 2870 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2872 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2873 | } |
| 2874 | curproxy->conn_retries = atol(args[1]); |
| 2875 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2876 | 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] | 2877 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2878 | |
| 2879 | if (curproxy == &defproxy) { |
| 2880 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2882 | goto out; |
| 2883 | } |
| 2884 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 2885 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 2886 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 2887 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 2888 | 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] | 2889 | 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] | 2890 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 2891 | 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] | 2892 | file, linenum, args[0]); |
| 2893 | err_code |= ERR_WARN; |
| 2894 | } |
| 2895 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2896 | 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] | 2897 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2898 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2899 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2900 | goto out; |
| 2901 | } |
| 2902 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 2903 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2904 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2905 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2906 | file, linenum); |
| 2907 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 2908 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 2909 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 2910 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 2911 | struct http_res_rule *rule; |
| 2912 | |
| 2913 | if (curproxy == &defproxy) { |
| 2914 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2916 | goto out; |
| 2917 | } |
| 2918 | |
| 2919 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 2920 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 2921 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 2922 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 2923 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 2924 | file, linenum, args[0]); |
| 2925 | err_code |= ERR_WARN; |
| 2926 | } |
| 2927 | |
| 2928 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 2929 | |
| 2930 | if (!rule) { |
| 2931 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2932 | goto out; |
| 2933 | } |
| 2934 | |
| 2935 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2936 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 2937 | file, linenum); |
| 2938 | |
| 2939 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 2940 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2941 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 2942 | /* set the header name and length into the proxy structure */ |
| 2943 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2944 | err_code |= ERR_WARN; |
| 2945 | |
| 2946 | if (!*args[1]) { |
| 2947 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 2948 | file, linenum, args[0]); |
| 2949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2950 | goto out; |
| 2951 | } |
| 2952 | |
| 2953 | /* set the desired header name */ |
| 2954 | free(curproxy->server_id_hdr_name); |
| 2955 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 2956 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 2957 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2958 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2959 | struct http_req_rule *rule; |
| 2960 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2961 | if (curproxy == &defproxy) { |
| 2962 | 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] | 2963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2964 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 2965 | } |
| 2966 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2967 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 2968 | * be processed before all http-request rules, we put them into their own list |
| 2969 | * and will insert them at the end. |
| 2970 | */ |
| 2971 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 2972 | if (!rule) { |
| 2973 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2974 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2975 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 2976 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 2977 | err_code |= warnif_cond_conflicts(rule->cond, |
| 2978 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 2979 | file, linenum); |
| 2980 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 2981 | |
| 2982 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 2983 | 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]); |
| 2984 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 2985 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2986 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2987 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 2988 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 2989 | if (curproxy == &defproxy) { |
| 2990 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2991 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2992 | goto out; |
| 2993 | } |
| 2994 | |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 2995 | 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] | 2996 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 2997 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2998 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2999 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3000 | } |
| 3001 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3002 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3003 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3004 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3005 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3006 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3007 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3008 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3009 | struct switching_rule *rule; |
| 3010 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3011 | if (curproxy == &defproxy) { |
| 3012 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3014 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3015 | } |
| 3016 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3017 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3018 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3019 | |
| 3020 | if (*(args[1]) == 0) { |
| 3021 | 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] | 3022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3023 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3024 | } |
| 3025 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3026 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3027 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3028 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3029 | file, linenum, errmsg); |
| 3030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3031 | goto out; |
| 3032 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3033 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3034 | 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] | 3035 | } |
| 3036 | |
| 3037 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3038 | rule->cond = cond; |
| 3039 | rule->be.name = strdup(args[1]); |
| 3040 | LIST_INIT(&rule->list); |
| 3041 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3042 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3043 | else if (strcmp(args[0], "use-server") == 0) { |
| 3044 | struct server_rule *rule; |
| 3045 | |
| 3046 | if (curproxy == &defproxy) { |
| 3047 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3049 | goto out; |
| 3050 | } |
| 3051 | |
| 3052 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3053 | err_code |= ERR_WARN; |
| 3054 | |
| 3055 | if (*(args[1]) == 0) { |
| 3056 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3058 | goto out; |
| 3059 | } |
| 3060 | |
| 3061 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3062 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3063 | file, linenum, args[0]); |
| 3064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3065 | goto out; |
| 3066 | } |
| 3067 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3068 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3069 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3070 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3072 | goto out; |
| 3073 | } |
| 3074 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3075 | 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] | 3076 | |
| 3077 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3078 | rule->cond = cond; |
| 3079 | rule->srv.name = strdup(args[1]); |
| 3080 | LIST_INIT(&rule->list); |
| 3081 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3082 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3083 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3084 | else if ((!strcmp(args[0], "force-persist")) || |
| 3085 | (!strcmp(args[0], "ignore-persist"))) { |
| 3086 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3087 | |
| 3088 | if (curproxy == &defproxy) { |
| 3089 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3091 | goto out; |
| 3092 | } |
| 3093 | |
| 3094 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3095 | err_code |= ERR_WARN; |
| 3096 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3097 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3098 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3099 | file, linenum, args[0]); |
| 3100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3101 | goto out; |
| 3102 | } |
| 3103 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3104 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3105 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3106 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3108 | goto out; |
| 3109 | } |
| 3110 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3111 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3112 | * where force-persist is applied. |
| 3113 | */ |
| 3114 | 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] | 3115 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3116 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3117 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3118 | if (!strcmp(args[0], "force-persist")) { |
| 3119 | rule->type = PERSIST_TYPE_FORCE; |
| 3120 | } else { |
| 3121 | rule->type = PERSIST_TYPE_IGNORE; |
| 3122 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3123 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3124 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3125 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3126 | else if (!strcmp(args[0], "stick-table")) { |
| 3127 | int myidx = 1; |
| 3128 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3129 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3130 | curproxy->table.type = (unsigned int)-1; |
| 3131 | while (*args[myidx]) { |
| 3132 | const char *err; |
| 3133 | |
| 3134 | if (strcmp(args[myidx], "size") == 0) { |
| 3135 | myidx++; |
| 3136 | if (!*(args[myidx])) { |
| 3137 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3138 | file, linenum, args[myidx-1]); |
| 3139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3140 | goto out; |
| 3141 | } |
| 3142 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3143 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3144 | file, linenum, *err, args[myidx-1]); |
| 3145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3146 | goto out; |
| 3147 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3148 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3149 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3150 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3151 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3152 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3153 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3154 | file, linenum, args[myidx-1]); |
| 3155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3156 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3157 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3158 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3159 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3160 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3161 | myidx++; |
| 3162 | if (!*(args[myidx])) { |
| 3163 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3164 | file, linenum, args[myidx-1]); |
| 3165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3166 | goto out; |
| 3167 | } |
| 3168 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3169 | if (err) { |
| 3170 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3171 | file, linenum, *err, args[myidx-1]); |
| 3172 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3173 | goto out; |
| 3174 | } |
| 3175 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3176 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3177 | } |
| 3178 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3179 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3180 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3181 | } |
| 3182 | else if (strcmp(args[myidx], "type") == 0) { |
| 3183 | myidx++; |
| 3184 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3185 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3186 | file, linenum, args[myidx]); |
| 3187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3188 | goto out; |
| 3189 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3190 | /* myidx already points to next arg */ |
| 3191 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3192 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3193 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3194 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3195 | |
| 3196 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3197 | nw = args[myidx]; |
| 3198 | while (*nw) { |
| 3199 | /* the "store" keyword supports a comma-separated list */ |
| 3200 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3201 | sa = NULL; /* store arg */ |
| 3202 | while (*nw && *nw != ',') { |
| 3203 | if (*nw == '(') { |
| 3204 | *nw = 0; |
| 3205 | sa = ++nw; |
| 3206 | while (*nw != ')') { |
| 3207 | if (!*nw) { |
| 3208 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3209 | file, linenum, args[0], cw); |
| 3210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3211 | goto out; |
| 3212 | } |
| 3213 | nw++; |
| 3214 | } |
| 3215 | *nw = '\0'; |
| 3216 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3217 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3218 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3219 | if (*nw) |
| 3220 | *nw++ = '\0'; |
| 3221 | type = stktable_get_data_type(cw); |
| 3222 | if (type < 0) { |
| 3223 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3224 | file, linenum, args[0], cw); |
| 3225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3226 | goto out; |
| 3227 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3228 | |
| 3229 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3230 | switch (err) { |
| 3231 | case PE_NONE: break; |
| 3232 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3233 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3234 | file, linenum, args[0], cw); |
| 3235 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3236 | break; |
| 3237 | |
| 3238 | case PE_ARG_MISSING: |
| 3239 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3240 | file, linenum, args[0], cw); |
| 3241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3242 | goto out; |
| 3243 | |
| 3244 | case PE_ARG_NOT_USED: |
| 3245 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3246 | file, linenum, args[0], cw); |
| 3247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3248 | goto out; |
| 3249 | |
| 3250 | default: |
| 3251 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3252 | file, linenum, args[0], cw); |
| 3253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3254 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3255 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3256 | } |
| 3257 | myidx++; |
| 3258 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3259 | else { |
| 3260 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 3261 | file, linenum, args[myidx]); |
| 3262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3263 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3264 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | if (!curproxy->table.size) { |
| 3268 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 3269 | file, linenum); |
| 3270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3271 | goto out; |
| 3272 | } |
| 3273 | |
| 3274 | if (curproxy->table.type == (unsigned int)-1) { |
| 3275 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 3276 | file, linenum); |
| 3277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3278 | goto out; |
| 3279 | } |
| 3280 | } |
| 3281 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3282 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3283 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3284 | int myidx = 0; |
| 3285 | const char *name = NULL; |
| 3286 | int flags; |
| 3287 | |
| 3288 | if (curproxy == &defproxy) { |
| 3289 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3291 | goto out; |
| 3292 | } |
| 3293 | |
| 3294 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 3295 | err_code |= ERR_WARN; |
| 3296 | goto out; |
| 3297 | } |
| 3298 | |
| 3299 | myidx++; |
| 3300 | if ((strcmp(args[myidx], "store") == 0) || |
| 3301 | (strcmp(args[myidx], "store-request") == 0)) { |
| 3302 | myidx++; |
| 3303 | flags = STK_IS_STORE; |
| 3304 | } |
| 3305 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 3306 | myidx++; |
| 3307 | flags = STK_IS_STORE | STK_ON_RSP; |
| 3308 | } |
| 3309 | else if (strcmp(args[myidx], "match") == 0) { |
| 3310 | myidx++; |
| 3311 | flags = STK_IS_MATCH; |
| 3312 | } |
| 3313 | else if (strcmp(args[myidx], "on") == 0) { |
| 3314 | myidx++; |
| 3315 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 3316 | } |
| 3317 | else { |
| 3318 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 3319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3320 | goto out; |
| 3321 | } |
| 3322 | |
| 3323 | if (*(args[myidx]) == 0) { |
| 3324 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 3325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3326 | goto out; |
| 3327 | } |
| 3328 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3329 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 3330 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3331 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 3332 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3334 | goto out; |
| 3335 | } |
| 3336 | |
| 3337 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3338 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 3339 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 3340 | 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] | 3341 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3342 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3343 | goto out; |
| 3344 | } |
| 3345 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 3346 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 3347 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 3348 | 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] | 3349 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3350 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3351 | goto out; |
| 3352 | } |
| 3353 | } |
| 3354 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3355 | /* 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] | 3356 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 3357 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3358 | if (strcmp(args[myidx], "table") == 0) { |
| 3359 | myidx++; |
| 3360 | name = args[myidx++]; |
| 3361 | } |
| 3362 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3363 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3364 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 3365 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 3366 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3367 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3368 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3369 | goto out; |
| 3370 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3371 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3372 | else if (*(args[myidx])) { |
| 3373 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 3374 | file, linenum, args[0], args[myidx]); |
| 3375 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 3376 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3377 | goto out; |
| 3378 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 3379 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3380 | 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] | 3381 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3382 | 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] | 3383 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3384 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 3385 | rule->cond = cond; |
| 3386 | rule->expr = expr; |
| 3387 | rule->flags = flags; |
| 3388 | rule->table.name = name ? strdup(name) : NULL; |
| 3389 | LIST_INIT(&rule->list); |
| 3390 | if (flags & STK_ON_RSP) |
| 3391 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 3392 | else |
| 3393 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 3394 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3395 | else if (!strcmp(args[0], "stats")) { |
| 3396 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 3397 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 3398 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3399 | if (!*args[1]) { |
| 3400 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3401 | } else if (!strcmp(args[1], "admin")) { |
| 3402 | struct stats_admin_rule *rule; |
| 3403 | |
| 3404 | if (curproxy == &defproxy) { |
| 3405 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3407 | goto out; |
| 3408 | } |
| 3409 | |
| 3410 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3411 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3412 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3413 | goto out; |
| 3414 | } |
| 3415 | |
| 3416 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3417 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3418 | file, linenum, args[0], args[1]); |
| 3419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3420 | goto out; |
| 3421 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3422 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3423 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 3424 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3426 | goto out; |
| 3427 | } |
| 3428 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3429 | err_code |= warnif_cond_conflicts(cond, |
| 3430 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3431 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3432 | |
| 3433 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 3434 | rule->cond = cond; |
| 3435 | LIST_INIT(&rule->list); |
| 3436 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3437 | } else if (!strcmp(args[1], "uri")) { |
| 3438 | if (*(args[2]) == 0) { |
| 3439 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3441 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3442 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 3443 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3444 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3445 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3446 | } |
| 3447 | } else if (!strcmp(args[1], "realm")) { |
| 3448 | if (*(args[2]) == 0) { |
| 3449 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3451 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3452 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 3453 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3454 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3455 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3456 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3457 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3458 | unsigned interval; |
| 3459 | |
| 3460 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 3461 | if (err) { |
| 3462 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 3463 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3465 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3466 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 3467 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3468 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3469 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 3470 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3471 | } 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] | 3472 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3473 | |
| 3474 | if (curproxy == &defproxy) { |
| 3475 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3477 | goto out; |
| 3478 | } |
| 3479 | |
| 3480 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3481 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3482 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3483 | goto out; |
| 3484 | } |
| 3485 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3486 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 3487 | !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] | 3488 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 3489 | file, linenum, args[0]); |
| 3490 | err_code |= ERR_WARN; |
| 3491 | } |
| 3492 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3493 | 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] | 3494 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3495 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3496 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3497 | goto out; |
| 3498 | } |
| 3499 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3500 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3501 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3502 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3503 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 3504 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3505 | } else if (!strcmp(args[1], "auth")) { |
| 3506 | if (*(args[2]) == 0) { |
| 3507 | 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] | 3508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3509 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3510 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 3511 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3512 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3513 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3514 | } |
| 3515 | } else if (!strcmp(args[1], "scope")) { |
| 3516 | if (*(args[2]) == 0) { |
| 3517 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3519 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3520 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 3521 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3522 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3523 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3524 | } |
| 3525 | } else if (!strcmp(args[1], "enable")) { |
| 3526 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 3527 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3528 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3529 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3530 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3531 | } else if (!strcmp(args[1], "hide-version")) { |
| 3532 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 3533 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3534 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3535 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 3536 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3537 | } else if (!strcmp(args[1], "show-legends")) { |
| 3538 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 3539 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3540 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3541 | goto out; |
| 3542 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3543 | } else if (!strcmp(args[1], "show-node")) { |
| 3544 | |
| 3545 | if (*args[2]) { |
| 3546 | int i; |
| 3547 | char c; |
| 3548 | |
| 3549 | for (i=0; args[2][i]; i++) { |
| 3550 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 3551 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 3552 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3553 | break; |
| 3554 | } |
| 3555 | |
| 3556 | if (!i || args[2][i]) { |
| 3557 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 3558 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 3559 | file, linenum, args[0], args[1]); |
| 3560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3561 | goto out; |
| 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 3566 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3567 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3568 | goto out; |
| 3569 | } |
| 3570 | } else if (!strcmp(args[1], "show-desc")) { |
| 3571 | char *desc = NULL; |
| 3572 | |
| 3573 | if (*args[2]) { |
| 3574 | int i, len=0; |
| 3575 | char *d; |
| 3576 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3577 | for (i = 2; *args[i]; i++) |
| 3578 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3579 | |
| 3580 | desc = d = (char *)calloc(1, len); |
| 3581 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3582 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 3583 | for (i = 3; *args[i]; i++) |
| 3584 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | if (!*args[2] && !global.desc) |
| 3588 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 3589 | file, linenum, args[1]); |
| 3590 | else { |
| 3591 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 3592 | free(desc); |
| 3593 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3594 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3595 | goto out; |
| 3596 | } |
| 3597 | free(desc); |
| 3598 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3599 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 3600 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3601 | 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] | 3602 | 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] | 3603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3604 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3605 | } |
| 3606 | } |
| 3607 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3608 | int optnum; |
| 3609 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3610 | if (*(args[1]) == '\0') { |
| 3611 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 3612 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3614 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3615 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3616 | |
| 3617 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 3618 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3619 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 3620 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3621 | file, linenum, cfg_opts[optnum].name); |
| 3622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3623 | goto out; |
| 3624 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3625 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 3626 | err_code |= ERR_WARN; |
| 3627 | goto out; |
| 3628 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3629 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3630 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 3631 | curproxy->options &= ~cfg_opts[optnum].val; |
| 3632 | |
| 3633 | switch (kwm) { |
| 3634 | case KWM_STD: |
| 3635 | curproxy->options |= cfg_opts[optnum].val; |
| 3636 | break; |
| 3637 | case KWM_NO: |
| 3638 | curproxy->no_options |= cfg_opts[optnum].val; |
| 3639 | break; |
| 3640 | case KWM_DEF: /* already cleared */ |
| 3641 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3642 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3643 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3644 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3645 | } |
| 3646 | } |
| 3647 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3648 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 3649 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 3650 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 3651 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 3652 | file, linenum, cfg_opts2[optnum].name); |
| 3653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3654 | goto out; |
| 3655 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3656 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 3657 | err_code |= ERR_WARN; |
| 3658 | goto out; |
| 3659 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3660 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3661 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 3662 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 3663 | |
| 3664 | switch (kwm) { |
| 3665 | case KWM_STD: |
| 3666 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 3667 | break; |
| 3668 | case KWM_NO: |
| 3669 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 3670 | break; |
| 3671 | case KWM_DEF: /* already cleared */ |
| 3672 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 3673 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3674 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 3675 | } |
| 3676 | } |
| 3677 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 3678 | /* HTTP options override each other. They can be cancelled using |
| 3679 | * "no option xxx" which only switches to default mode if the mode |
| 3680 | * was this one (useful for cancelling options set in defaults |
| 3681 | * sections). |
| 3682 | */ |
| 3683 | if (strcmp(args[1], "httpclose") == 0) { |
| 3684 | if (kwm == KWM_STD) { |
| 3685 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3686 | curproxy->options |= PR_O_HTTP_PCL; |
| 3687 | goto out; |
| 3688 | } |
| 3689 | else if (kwm == KWM_NO) { |
| 3690 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 3691 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3692 | goto out; |
| 3693 | } |
| 3694 | } |
| 3695 | else if (strcmp(args[1], "forceclose") == 0) { |
| 3696 | if (kwm == KWM_STD) { |
| 3697 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3698 | curproxy->options |= PR_O_HTTP_FCL; |
| 3699 | goto out; |
| 3700 | } |
| 3701 | else if (kwm == KWM_NO) { |
| 3702 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 3703 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3704 | goto out; |
| 3705 | } |
| 3706 | } |
| 3707 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 3708 | if (kwm == KWM_STD) { |
| 3709 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3710 | curproxy->options |= PR_O_HTTP_SCL; |
| 3711 | goto out; |
| 3712 | } |
| 3713 | else if (kwm == KWM_NO) { |
| 3714 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 3715 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3716 | goto out; |
| 3717 | } |
| 3718 | } |
| 3719 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 3720 | if (kwm == KWM_STD) { |
| 3721 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3722 | curproxy->options |= PR_O_HTTP_KAL; |
| 3723 | goto out; |
| 3724 | } |
| 3725 | else if (kwm == KWM_NO) { |
| 3726 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 3727 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3728 | goto out; |
| 3729 | } |
| 3730 | } |
| 3731 | else if (strcmp(args[1], "http-tunnel") == 0) { |
| 3732 | if (kwm == KWM_STD) { |
| 3733 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3734 | curproxy->options |= PR_O_HTTP_TUN; |
| 3735 | goto out; |
| 3736 | } |
| 3737 | else if (kwm == KWM_NO) { |
| 3738 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 3739 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 3740 | goto out; |
| 3741 | } |
| 3742 | } |
| 3743 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 3744 | if (kwm != KWM_STD) { |
| 3745 | 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] | 3746 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3748 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 3749 | } |
| 3750 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3751 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3752 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3753 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3754 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3755 | if (*(args[2]) != '\0') { |
| 3756 | if (!strcmp(args[2], "clf")) { |
| 3757 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 3758 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3759 | } else { |
| 3760 | 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] | 3761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3762 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3763 | } |
| 3764 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3765 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3766 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3767 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3768 | free(curproxy->conf.logformat_string); |
| 3769 | curproxy->conf.logformat_string = logformat; |
| 3770 | |
| 3771 | free(curproxy->conf.lfs_file); |
| 3772 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3773 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 3774 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3775 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3776 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3777 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 3778 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 3779 | curproxy->conf.logformat_string != clf_http_log_format) |
| 3780 | free(curproxy->conf.logformat_string); |
| 3781 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 3782 | |
| 3783 | free(curproxy->conf.lfs_file); |
| 3784 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 3785 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 3786 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3787 | else if (!strcmp(args[1], "tcpka")) { |
| 3788 | /* enable TCP keep-alives on client and server sessions */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3789 | 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] | 3790 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3791 | |
| 3792 | if (curproxy->cap & PR_CAP_FE) |
| 3793 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 3794 | if (curproxy->cap & PR_CAP_BE) |
| 3795 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3796 | } |
| 3797 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3798 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3799 | err_code |= ERR_WARN; |
| 3800 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3801 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3802 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3803 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3804 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3805 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3806 | if (!*args[2]) { /* no argument */ |
| 3807 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 3808 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 3809 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3810 | 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] | 3811 | curproxy->check_req = (char *)malloc(reqlen); |
| 3812 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3813 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3814 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3815 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3816 | if (*args[4]) |
| 3817 | reqlen += strlen(args[4]); |
| 3818 | else |
| 3819 | reqlen += strlen("HTTP/1.0"); |
| 3820 | |
| 3821 | curproxy->check_req = (char *)malloc(reqlen); |
| 3822 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 3823 | "%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] | 3824 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 3825 | } |
| 3826 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 3827 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3828 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3829 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 3830 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3831 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3832 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3833 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 3834 | curproxy->options2 |= PR_O2_SSL3_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3835 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3836 | else if (!strcmp(args[1], "smtpchk")) { |
| 3837 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3838 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3839 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3840 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 3841 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 3842 | |
| 3843 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 3844 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3845 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3846 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 3847 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 3848 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 3849 | curproxy->check_req = (char *)malloc(reqlen); |
| 3850 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 3851 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 3852 | } else { |
| 3853 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 3854 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 3855 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 3856 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 3857 | } |
| 3858 | } |
| 3859 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3860 | else if (!strcmp(args[1], "pgsql-check")) { |
| 3861 | /* use PostgreSQL request to check servers' health */ |
| 3862 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3863 | err_code |= ERR_WARN; |
| 3864 | |
| 3865 | free(curproxy->check_req); |
| 3866 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3867 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 3868 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 3869 | |
| 3870 | if (*(args[2])) { |
| 3871 | int cur_arg = 2; |
| 3872 | |
| 3873 | while (*(args[cur_arg])) { |
| 3874 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3875 | char * packet; |
| 3876 | uint32_t packet_len; |
| 3877 | uint32_t pv; |
| 3878 | |
| 3879 | /* suboption header - needs additional argument for it */ |
| 3880 | if (*(args[cur_arg+1]) == 0) { |
| 3881 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3882 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3884 | goto out; |
| 3885 | } |
| 3886 | |
| 3887 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 3888 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 3889 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 3890 | |
| 3891 | packet = (char*) calloc(1, packet_len); |
| 3892 | |
| 3893 | memcpy(packet + 4, &pv, 4); |
| 3894 | |
| 3895 | /* copy "user" */ |
| 3896 | memcpy(packet + 8, "user", 4); |
| 3897 | |
| 3898 | /* copy username */ |
| 3899 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 3900 | |
| 3901 | free(curproxy->check_req); |
| 3902 | curproxy->check_req = packet; |
| 3903 | curproxy->check_len = packet_len; |
| 3904 | |
| 3905 | packet_len = htonl(packet_len); |
| 3906 | memcpy(packet, &packet_len, 4); |
| 3907 | cur_arg += 2; |
| 3908 | } else { |
| 3909 | /* unknown suboption - catchall */ |
| 3910 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 3911 | file, linenum, args[0], args[1]); |
| 3912 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3913 | goto out; |
| 3914 | } |
| 3915 | } /* end while loop */ |
| 3916 | } |
| 3917 | } |
| 3918 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3919 | else if (!strcmp(args[1], "redis-check")) { |
| 3920 | /* use REDIS PING request to check servers' health */ |
| 3921 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3922 | err_code |= ERR_WARN; |
| 3923 | |
| 3924 | free(curproxy->check_req); |
| 3925 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3926 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 3927 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 3928 | |
| 3929 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3930 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 3931 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
| 3932 | } |
| 3933 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3934 | else if (!strcmp(args[1], "mysql-check")) { |
| 3935 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3936 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 3937 | err_code |= ERR_WARN; |
| 3938 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3939 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 3940 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 3941 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 3942 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3943 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3944 | /* This is an example of a MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3945 | * const char mysql40_client_auth_pkt[] = { |
| 3946 | * "\x0e\x00\x00" // packet length |
| 3947 | * "\x01" // packet number |
| 3948 | * "\x00\x00" // client capabilities |
| 3949 | * "\x00\x00\x01" // max packet |
| 3950 | * "haproxy\x00" // username (null terminated string) |
| 3951 | * "\x00" // filler (always 0x00) |
| 3952 | * "\x01\x00\x00" // packet length |
| 3953 | * "\x00" // packet number |
| 3954 | * "\x01" // COM_QUIT command |
| 3955 | * }; |
| 3956 | */ |
| 3957 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3958 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 3959 | * const char mysql41_client_auth_pkt[] = { |
| 3960 | * "\x0e\x00\x00\" // packet length |
| 3961 | * "\x01" // packet number |
| 3962 | * "\x00\x00\x00\x00" // client capabilities |
| 3963 | * "\x00\x00\x00\x01" // max packet |
| 3964 | * "\x21" // character set (UTF-8) |
| 3965 | * char[23] // All zeroes |
| 3966 | * "haproxy\x00" // username (null terminated string) |
| 3967 | * "\x00" // filler (always 0x00) |
| 3968 | * "\x01\x00\x00" // packet length |
| 3969 | * "\x00" // packet number |
| 3970 | * "\x01" // COM_QUIT command |
| 3971 | * }; |
| 3972 | */ |
| 3973 | |
| 3974 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3975 | if (*(args[2])) { |
| 3976 | int cur_arg = 2; |
| 3977 | |
| 3978 | while (*(args[cur_arg])) { |
| 3979 | if (strcmp(args[cur_arg], "user") == 0) { |
| 3980 | char *mysqluser; |
| 3981 | int packetlen, reqlen, userlen; |
| 3982 | |
| 3983 | /* suboption header - needs additional argument for it */ |
| 3984 | if (*(args[cur_arg+1]) == 0) { |
| 3985 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 3986 | file, linenum, args[0], args[1], args[cur_arg]); |
| 3987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3988 | goto out; |
| 3989 | } |
| 3990 | mysqluser = args[cur_arg + 1]; |
| 3991 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3992 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3993 | if (*(args[cur_arg+2])) { |
| 3994 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 3995 | packetlen = userlen + 7 + 27; |
| 3996 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 3997 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 3998 | free(curproxy->check_req); |
| 3999 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4000 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4001 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4002 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4003 | ((unsigned char) packetlen & 0xff), |
| 4004 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4005 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4006 | |
| 4007 | curproxy->check_req[3] = 1; |
| 4008 | curproxy->check_req[5] = 130; |
| 4009 | curproxy->check_req[11] = 1; |
| 4010 | curproxy->check_req[12] = 33; |
| 4011 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4012 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4013 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4014 | cur_arg += 3; |
| 4015 | } else { |
| 4016 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4018 | goto out; |
| 4019 | } |
| 4020 | } else { |
| 4021 | packetlen = userlen + 7; |
| 4022 | reqlen = packetlen + 9; |
| 4023 | |
| 4024 | free(curproxy->check_req); |
| 4025 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4026 | curproxy->check_len = reqlen; |
| 4027 | |
| 4028 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4029 | ((unsigned char) packetlen & 0xff), |
| 4030 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4031 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4032 | |
| 4033 | curproxy->check_req[3] = 1; |
| 4034 | curproxy->check_req[5] = 128; |
| 4035 | curproxy->check_req[8] = 1; |
| 4036 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4037 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4038 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4039 | cur_arg += 2; |
| 4040 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4041 | } else { |
| 4042 | /* unknown suboption - catchall */ |
| 4043 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4044 | file, linenum, args[0], args[1]); |
| 4045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4046 | goto out; |
| 4047 | } |
| 4048 | } /* end while loop */ |
| 4049 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4050 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4051 | else if (!strcmp(args[1], "ldap-check")) { |
| 4052 | /* use LDAP request to check servers' health */ |
| 4053 | free(curproxy->check_req); |
| 4054 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4055 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4056 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4057 | |
| 4058 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4059 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4060 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
| 4061 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4062 | else if (!strcmp(args[1], "tcp-check")) { |
| 4063 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4064 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4065 | err_code |= ERR_WARN; |
| 4066 | |
| 4067 | free(curproxy->check_req); |
| 4068 | curproxy->check_req = NULL; |
| 4069 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4070 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
| 4071 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4072 | else if (!strcmp(args[1], "external-check")) { |
| 4073 | /* excute an external command to check servers' health */ |
| 4074 | free(curproxy->check_req); |
| 4075 | curproxy->check_req = NULL; |
| 4076 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4077 | curproxy->options2 |= PR_O2_EXT_CHK; |
| 4078 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4079 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4080 | int cur_arg; |
| 4081 | |
| 4082 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4083 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4084 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4085 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4086 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4087 | |
| 4088 | free(curproxy->fwdfor_hdr_name); |
| 4089 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4090 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4091 | |
| 4092 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4093 | cur_arg = 2; |
| 4094 | while (*(args[cur_arg])) { |
| 4095 | if (!strcmp(args[cur_arg], "except")) { |
| 4096 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4097 | 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] | 4098 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4099 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4101 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4102 | } |
| 4103 | /* flush useless bits */ |
| 4104 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4105 | cur_arg += 2; |
| 4106 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4107 | /* suboption header - needs additional argument for it */ |
| 4108 | if (*(args[cur_arg+1]) == 0) { |
| 4109 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4110 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4112 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4113 | } |
| 4114 | free(curproxy->fwdfor_hdr_name); |
| 4115 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4116 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4117 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4118 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4119 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4120 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4121 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4122 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4123 | 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] | 4124 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4126 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4127 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4128 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4129 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4130 | else if (!strcmp(args[1], "originalto")) { |
| 4131 | int cur_arg; |
| 4132 | |
| 4133 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4134 | * set default options (ie: bitfield, header name, etc) |
| 4135 | */ |
| 4136 | |
| 4137 | curproxy->options |= PR_O_ORGTO; |
| 4138 | |
| 4139 | free(curproxy->orgto_hdr_name); |
| 4140 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4141 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4142 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4143 | /* 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] | 4144 | cur_arg = 2; |
| 4145 | while (*(args[cur_arg])) { |
| 4146 | if (!strcmp(args[cur_arg], "except")) { |
| 4147 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4148 | 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] | 4149 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4150 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4152 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4153 | } |
| 4154 | /* flush useless bits */ |
| 4155 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4156 | cur_arg += 2; |
| 4157 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4158 | /* suboption header - needs additional argument for it */ |
| 4159 | if (*(args[cur_arg+1]) == 0) { |
| 4160 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4161 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4163 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4164 | } |
| 4165 | free(curproxy->orgto_hdr_name); |
| 4166 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4167 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4168 | cur_arg += 2; |
| 4169 | } else { |
| 4170 | /* unknown suboption - catchall */ |
| 4171 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4172 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4174 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4175 | } |
| 4176 | } /* end while loop */ |
| 4177 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4178 | else { |
| 4179 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4181 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4182 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4183 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4184 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4185 | else if (!strcmp(args[0], "default_backend")) { |
| 4186 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4187 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4188 | |
| 4189 | if (*(args[1]) == 0) { |
| 4190 | 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] | 4191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4192 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4193 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4194 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4195 | curproxy->defbe.name = strdup(args[1]); |
| 4196 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4197 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4198 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4199 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4200 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 4201 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 4202 | 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] | 4203 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4204 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4205 | /* enable reconnections to dispatch */ |
| 4206 | curproxy->options |= PR_O_REDISP; |
| 4207 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4208 | else if (!strcmp(args[0], "http-check")) { |
| 4209 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4210 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4211 | |
| 4212 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 4213 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 4214 | curproxy->options |= PR_O_DISABLE404; |
| 4215 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 4216 | else if (strcmp(args[1], "send-state") == 0) { |
| 4217 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 4218 | curproxy->options2 |= PR_O2_CHK_SNDST; |
| 4219 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4220 | else if (strcmp(args[1], "expect") == 0) { |
| 4221 | const char *ptr_arg; |
| 4222 | int cur_arg; |
| 4223 | |
| 4224 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4225 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4227 | goto out; |
| 4228 | } |
| 4229 | |
| 4230 | cur_arg = 2; |
| 4231 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4232 | while (*(ptr_arg = args[cur_arg])) { |
| 4233 | while (*ptr_arg == '!') { |
| 4234 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 4235 | ptr_arg++; |
| 4236 | } |
| 4237 | if (*ptr_arg) |
| 4238 | break; |
| 4239 | cur_arg++; |
| 4240 | } |
| 4241 | /* now ptr_arg points to the beginning of a word past any possible |
| 4242 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4243 | */ |
| 4244 | if (strcmp(ptr_arg, "status") == 0) { |
| 4245 | if (!*(args[cur_arg + 1])) { |
| 4246 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4247 | file, linenum, args[0], args[1], ptr_arg); |
| 4248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4249 | goto out; |
| 4250 | } |
| 4251 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4252 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4253 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4254 | } |
| 4255 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4256 | if (!*(args[cur_arg + 1])) { |
| 4257 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4258 | file, linenum, args[0], args[1], ptr_arg); |
| 4259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4260 | goto out; |
| 4261 | } |
| 4262 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4263 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4264 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 4265 | } |
| 4266 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 4267 | if (!*(args[cur_arg + 1])) { |
| 4268 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4269 | file, linenum, args[0], args[1], ptr_arg); |
| 4270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4271 | goto out; |
| 4272 | } |
| 4273 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4274 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4275 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4276 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4277 | free(curproxy->expect_regex); |
| 4278 | curproxy->expect_regex = NULL; |
| 4279 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4280 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4281 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4282 | error = NULL; |
| 4283 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4284 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4285 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4286 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4288 | goto out; |
| 4289 | } |
| 4290 | } |
| 4291 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4292 | if (!*(args[cur_arg + 1])) { |
| 4293 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4294 | file, linenum, args[0], args[1], ptr_arg); |
| 4295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4296 | goto out; |
| 4297 | } |
| 4298 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4299 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4300 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4301 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 4302 | free(curproxy->expect_regex); |
| 4303 | curproxy->expect_regex = NULL; |
| 4304 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4305 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4306 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 4307 | error = NULL; |
| 4308 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 4309 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4310 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4311 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 4312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4313 | goto out; |
| 4314 | } |
| 4315 | } |
| 4316 | else { |
| 4317 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 4318 | file, linenum, args[0], args[1], ptr_arg); |
| 4319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4320 | goto out; |
| 4321 | } |
| 4322 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4323 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 4324 | 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] | 4325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4326 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 4327 | } |
| 4328 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4329 | else if (!strcmp(args[0], "tcp-check")) { |
| 4330 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4331 | err_code |= ERR_WARN; |
| 4332 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4333 | if (strcmp(args[1], "connect") == 0) { |
| 4334 | const char *ptr_arg; |
| 4335 | int cur_arg; |
| 4336 | struct tcpcheck_rule *tcpcheck; |
| 4337 | struct list *l; |
| 4338 | |
| 4339 | /* check if first rule is also a 'connect' action */ |
| 4340 | l = (struct list *)&curproxy->tcpcheck_rules; |
| 4341 | if (l->p != l->n) { |
| 4342 | tcpcheck = (struct tcpcheck_rule *)l->n; |
| 4343 | if (tcpcheck && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 4344 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 4345 | file, linenum); |
| 4346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4347 | goto out; |
| 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | cur_arg = 2; |
| 4352 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4353 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 4354 | |
| 4355 | /* parsing each parameters to fill up the rule */ |
| 4356 | while (*(ptr_arg = args[cur_arg])) { |
| 4357 | /* tcp port */ |
| 4358 | if (strcmp(args[cur_arg], "port") == 0) { |
| 4359 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 4360 | (atol(args[cur_arg + 1]) < 1) ){ |
| 4361 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 4362 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 4363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4364 | goto out; |
| 4365 | } |
| 4366 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 4367 | cur_arg += 2; |
| 4368 | } |
| 4369 | /* send proxy protocol */ |
| 4370 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 4371 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 4372 | cur_arg++; |
| 4373 | } |
| 4374 | #ifdef USE_OPENSSL |
| 4375 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 4376 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 4377 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 4378 | cur_arg++; |
| 4379 | } |
| 4380 | #endif /* USE_OPENSSL */ |
| 4381 | else { |
| 4382 | #ifdef USE_OPENSSL |
| 4383 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
| 4384 | #else /* USE_OPENSSL */ |
| 4385 | Alert("parsing [%s:%d] : '%s %s' expects 'port', 'send-proxy' or but got '%s' as argument.\n", |
| 4386 | #endif /* USE_OPENSSL */ |
| 4387 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4389 | goto out; |
| 4390 | } |
| 4391 | |
| 4392 | } |
| 4393 | |
| 4394 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4395 | } |
| 4396 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4397 | if (! *(args[2]) ) { |
| 4398 | /* SEND string expected */ |
| 4399 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 4400 | file, linenum, args[0], args[1], args[2]); |
| 4401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4402 | goto out; |
| 4403 | } else { |
| 4404 | struct tcpcheck_rule *tcpcheck; |
| 4405 | |
| 4406 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4407 | |
| 4408 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4409 | tcpcheck->string_len = strlen(args[2]); |
| 4410 | tcpcheck->string = strdup(args[2]); |
| 4411 | tcpcheck->expect_regex = NULL; |
| 4412 | |
| 4413 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4414 | } |
| 4415 | } |
| 4416 | else if (strcmp(args[1], "send-binary") == 0) { |
| 4417 | if (! *(args[2]) ) { |
| 4418 | /* SEND binary string expected */ |
| 4419 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 4420 | file, linenum, args[0], args[1], args[2]); |
| 4421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4422 | goto out; |
| 4423 | } else { |
| 4424 | struct tcpcheck_rule *tcpcheck; |
| 4425 | char *err = NULL; |
| 4426 | |
| 4427 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4428 | |
| 4429 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 4430 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4431 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4432 | file, linenum, args[0], args[1], args[2], err); |
| 4433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4434 | goto out; |
| 4435 | } |
| 4436 | tcpcheck->expect_regex = NULL; |
| 4437 | |
| 4438 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4439 | } |
| 4440 | } |
| 4441 | else if (strcmp(args[1], "expect") == 0) { |
| 4442 | const char *ptr_arg; |
| 4443 | int cur_arg; |
| 4444 | int inverse = 0; |
| 4445 | |
| 4446 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 4447 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 4448 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4449 | goto out; |
| 4450 | } |
| 4451 | |
| 4452 | cur_arg = 2; |
| 4453 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 4454 | while (*(ptr_arg = args[cur_arg])) { |
| 4455 | while (*ptr_arg == '!') { |
| 4456 | inverse = !inverse; |
| 4457 | ptr_arg++; |
| 4458 | } |
| 4459 | if (*ptr_arg) |
| 4460 | break; |
| 4461 | cur_arg++; |
| 4462 | } |
| 4463 | /* now ptr_arg points to the beginning of a word past any possible |
| 4464 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 4465 | */ |
| 4466 | if (strcmp(ptr_arg, "binary") == 0) { |
| 4467 | if (!*(args[cur_arg + 1])) { |
| 4468 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 4469 | file, linenum, args[0], args[1], ptr_arg); |
| 4470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4471 | goto out; |
| 4472 | } |
| 4473 | struct tcpcheck_rule *tcpcheck; |
| 4474 | char *err = NULL; |
| 4475 | |
| 4476 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4477 | |
| 4478 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4479 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 4480 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 4481 | file, linenum, args[0], args[1], args[2], err); |
| 4482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4483 | goto out; |
| 4484 | } |
| 4485 | tcpcheck->expect_regex = NULL; |
| 4486 | tcpcheck->inverse = inverse; |
| 4487 | |
| 4488 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4489 | } |
| 4490 | else if (strcmp(ptr_arg, "string") == 0) { |
| 4491 | if (!*(args[cur_arg + 1])) { |
| 4492 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 4493 | file, linenum, args[0], args[1], ptr_arg); |
| 4494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4495 | goto out; |
| 4496 | } |
| 4497 | struct tcpcheck_rule *tcpcheck; |
| 4498 | |
| 4499 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4500 | |
| 4501 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4502 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 4503 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 4504 | tcpcheck->expect_regex = NULL; |
| 4505 | tcpcheck->inverse = inverse; |
| 4506 | |
| 4507 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4508 | } |
| 4509 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 4510 | if (!*(args[cur_arg + 1])) { |
| 4511 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 4512 | file, linenum, args[0], args[1], ptr_arg); |
| 4513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4514 | goto out; |
| 4515 | } |
| 4516 | struct tcpcheck_rule *tcpcheck; |
| 4517 | |
| 4518 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 4519 | |
| 4520 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 4521 | tcpcheck->string_len = 0; |
| 4522 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 4523 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 4524 | error = NULL; |
| 4525 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 4526 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 4527 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 4528 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4530 | goto out; |
| 4531 | } |
| 4532 | tcpcheck->inverse = inverse; |
| 4533 | |
| 4534 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 4535 | } |
| 4536 | else { |
| 4537 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 4538 | file, linenum, args[0], args[1], ptr_arg); |
| 4539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4540 | goto out; |
| 4541 | } |
| 4542 | } |
| 4543 | else { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 4544 | 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] | 4545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4546 | goto out; |
| 4547 | } |
| 4548 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4549 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4550 | if (curproxy == &defproxy) { |
| 4551 | 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] | 4552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4553 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 4554 | } |
| 4555 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4556 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4557 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4558 | |
| 4559 | if (strcmp(args[1], "fail") == 0) { |
| 4560 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4561 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4562 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4563 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4565 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4566 | } |
| 4567 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4568 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4569 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 4570 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4572 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4573 | } |
| 4574 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 4575 | } |
| 4576 | else { |
| 4577 | 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] | 4578 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4579 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 4580 | } |
| 4581 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4582 | #ifdef TPROXY |
| 4583 | else if (!strcmp(args[0], "transparent")) { |
| 4584 | /* enable transparent proxy connections */ |
| 4585 | curproxy->options |= PR_O_TRANSP; |
| 4586 | } |
| 4587 | #endif |
| 4588 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4589 | 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] | 4590 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4591 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4592 | if (*(args[1]) == 0) { |
| 4593 | 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] | 4594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4595 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4596 | } |
| 4597 | curproxy->maxconn = atol(args[1]); |
| 4598 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4599 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 4600 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4601 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4602 | |
| 4603 | if (*(args[1]) == 0) { |
| 4604 | 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] | 4605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4606 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 4607 | } |
| 4608 | curproxy->backlog = atol(args[1]); |
| 4609 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4610 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4611 | 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] | 4612 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4613 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4614 | if (*(args[1]) == 0) { |
| 4615 | 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] | 4616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4617 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 4618 | } |
| 4619 | curproxy->fullconn = atol(args[1]); |
| 4620 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4621 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 4622 | if (*(args[1]) == 0) { |
| 4623 | 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] | 4624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4625 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4626 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4627 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 4628 | if (err) { |
| 4629 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 4630 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4632 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4633 | } |
| 4634 | curproxy->grace = val; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4635 | } |
| 4636 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4637 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4638 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4639 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4640 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4641 | if (curproxy == &defproxy) { |
| 4642 | 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] | 4643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4644 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4645 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4646 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4647 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4648 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4649 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4650 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4651 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4652 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4653 | goto out; |
| 4654 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 4655 | |
| 4656 | proto = protocol_by_family(sk->ss_family); |
| 4657 | if (!proto || !proto->connect) { |
| 4658 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 4659 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4660 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4661 | goto out; |
| 4662 | } |
| 4663 | |
| 4664 | if (port1 != port2) { |
| 4665 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 4666 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4668 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4669 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4670 | |
| 4671 | if (!port1) { |
| 4672 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 4673 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4675 | goto out; |
| 4676 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4677 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4678 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4679 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4680 | } |
| 4681 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4682 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4683 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4684 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 4685 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 4686 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4688 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 4689 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4690 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4691 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4692 | /** |
| 4693 | * The syntax for hash-type config element is |
| 4694 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 4695 | * |
| 4696 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 4697 | */ |
| 4698 | 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] | 4699 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4700 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4701 | err_code |= ERR_WARN; |
| 4702 | |
| 4703 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4704 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 4705 | } |
| 4706 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4707 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 4708 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4709 | else if (strcmp(args[1], "avalanche") == 0) { |
| 4710 | 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]); |
| 4711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4712 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 4713 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 4714 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4715 | 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] | 4716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4717 | goto out; |
| 4718 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4719 | |
| 4720 | /* set the hash function to use */ |
| 4721 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4722 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4723 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4724 | |
| 4725 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 4726 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 4727 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 4728 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4729 | /* set the hash function */ |
| 4730 | if (!strcmp(args[2], "sdbm")) { |
| 4731 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 4732 | } |
| 4733 | else if (!strcmp(args[2], "djb2")) { |
| 4734 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4735 | } else if (!strcmp(args[2], "wt6")) { |
| 4736 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 4737 | } |
| 4738 | else { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 4739 | 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] | 4740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4741 | goto out; |
| 4742 | } |
| 4743 | |
| 4744 | /* set the hash modifier */ |
| 4745 | if (!strcmp(args[3], "avalanche")) { |
| 4746 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 4747 | } |
| 4748 | else if (*args[3]) { |
| 4749 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 4750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4751 | goto out; |
| 4752 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 4753 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4754 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4755 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 4756 | if (!*(args[1])) { |
| 4757 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4759 | goto out; |
| 4760 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4761 | if (*(args[2])) { |
| 4762 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4764 | goto out; |
| 4765 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4766 | free(curproxy->conf.uniqueid_format_string); |
| 4767 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4768 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4769 | free(curproxy->conf.uif_file); |
| 4770 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 4771 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4772 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 4773 | |
| 4774 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 4775 | if (!*(args[1])) { |
| 4776 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4778 | goto out; |
| 4779 | } |
| 4780 | free(curproxy->header_unique_id); |
| 4781 | curproxy->header_unique_id = strdup(args[1]); |
| 4782 | } |
| 4783 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4784 | else if (strcmp(args[0], "log-format") == 0) { |
| 4785 | if (!*(args[1])) { |
| 4786 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 4787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4788 | goto out; |
| 4789 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 4790 | if (*(args[2])) { |
| 4791 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 4792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4793 | goto out; |
| 4794 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 4795 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4796 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4797 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4798 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4799 | free(curproxy->conf.logformat_string); |
| 4800 | curproxy->conf.logformat_string = strdup(args[1]); |
| 4801 | |
| 4802 | free(curproxy->conf.lfs_file); |
| 4803 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4804 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4805 | |
| 4806 | /* get a chance to improve log-format error reporting by |
| 4807 | * reporting the correct line-number when possible. |
| 4808 | */ |
| 4809 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4810 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 4811 | file, linenum, curproxy->id); |
| 4812 | err_code |= ERR_WARN; |
| 4813 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4814 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4815 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4816 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 4817 | /* delete previous herited or defined syslog servers */ |
| 4818 | struct logsrv *back; |
| 4819 | |
| 4820 | if (*(args[1]) != 0) { |
| 4821 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 4822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4823 | goto out; |
| 4824 | } |
| 4825 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4826 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 4827 | LIST_DEL(&tmplogsrv->list); |
| 4828 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4829 | } |
| 4830 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4831 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4832 | struct logsrv *logsrv; |
| 4833 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4834 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4835 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4836 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4837 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4838 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4839 | LIST_INIT(&node->list); |
| 4840 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 4841 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4842 | } |
| 4843 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4844 | struct sockaddr_storage *sk; |
| 4845 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4846 | |
| 4847 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4848 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4849 | logsrv->facility = get_log_facility(args[2]); |
| 4850 | if (logsrv->facility < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4851 | 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] | 4852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4853 | goto out; |
| 4854 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4855 | } |
| 4856 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4857 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4858 | if (*(args[3])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4859 | logsrv->level = get_log_level(args[3]); |
| 4860 | if (logsrv->level < 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4861 | 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] | 4862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4863 | goto out; |
| 4864 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4865 | } |
| 4866 | } |
| 4867 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4868 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4869 | if (*(args[4])) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4870 | logsrv->minlvl = get_log_level(args[4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 4871 | if (logsrv->minlvl < 0) { |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4872 | 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] | 4873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4874 | goto out; |
| 4875 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 4876 | } |
| 4877 | } |
| 4878 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4879 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4880 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4881 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4882 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4883 | goto out; |
| 4884 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4885 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4886 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4887 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 4888 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4889 | if (port1 != port2) { |
| 4890 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4891 | file, linenum, args[0], args[1]); |
| 4892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4893 | goto out; |
| 4894 | } |
| 4895 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4896 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4897 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4898 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 4899 | |
| 4900 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4901 | } |
| 4902 | else { |
| 4903 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 4904 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4905 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4906 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4907 | } |
| 4908 | } |
| 4909 | 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] | 4910 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4911 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 4912 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4913 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4914 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4915 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4916 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 4917 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4918 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4919 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 4920 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4922 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4923 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4924 | |
| 4925 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4926 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4927 | free(curproxy->conn_src.iface_name); |
| 4928 | curproxy->conn_src.iface_name = NULL; |
| 4929 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 4930 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4931 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4932 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4933 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 4934 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4935 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4936 | goto out; |
| 4937 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 4938 | |
| 4939 | proto = protocol_by_family(sk->ss_family); |
| 4940 | if (!proto || !proto->connect) { |
| 4941 | 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] | 4942 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 4943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4944 | goto out; |
| 4945 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 4946 | |
| 4947 | if (port1 != port2) { |
| 4948 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 4949 | file, linenum, args[0], args[1]); |
| 4950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4951 | goto out; |
| 4952 | } |
| 4953 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4954 | curproxy->conn_src.source_addr = *sk; |
| 4955 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4956 | |
| 4957 | cur_arg = 2; |
| 4958 | while (*(args[cur_arg])) { |
| 4959 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 4960 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 4961 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 4962 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4963 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 4964 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4966 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4967 | } |
| 4968 | #endif |
| 4969 | if (!*args[cur_arg + 1]) { |
| 4970 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 4971 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4973 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4977 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4978 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 4979 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4980 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4981 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 4982 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 4983 | char *name, *end; |
| 4984 | |
| 4985 | name = args[cur_arg+1] + 7; |
| 4986 | while (isspace(*name)) |
| 4987 | name++; |
| 4988 | |
| 4989 | end = name; |
| 4990 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 4991 | end++; |
| 4992 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 4993 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 4994 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 4995 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 4996 | curproxy->conn_src.bind_hdr_len = end - name; |
| 4997 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 4998 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 4999 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5000 | |
| 5001 | /* now look for an occurrence number */ |
| 5002 | while (isspace(*end)) |
| 5003 | end++; |
| 5004 | if (*end == ',') { |
| 5005 | end++; |
| 5006 | name = end; |
| 5007 | if (*end == '-') |
| 5008 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 5009 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5010 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5011 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5012 | } |
| 5013 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5014 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5015 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 5016 | " occurrences values smaller than %d.\n", |
| 5017 | file, linenum, MAX_HDR_HISTORY); |
| 5018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5019 | goto out; |
| 5020 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5021 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5022 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5023 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5024 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5025 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5026 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5027 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5028 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5029 | goto out; |
| 5030 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5031 | |
| 5032 | proto = protocol_by_family(sk->ss_family); |
| 5033 | if (!proto || !proto->connect) { |
| 5034 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5035 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5037 | goto out; |
| 5038 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5039 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5040 | if (port1 != port2) { |
| 5041 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5042 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5044 | goto out; |
| 5045 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5046 | curproxy->conn_src.tproxy_addr = *sk; |
| 5047 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5048 | } |
| 5049 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5050 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5051 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5052 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5053 | #else /* no TPROXY support */ |
| 5054 | 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] | 5055 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5057 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5058 | #endif |
| 5059 | cur_arg += 2; |
| 5060 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 5061 | } |
| 5062 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5063 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 5064 | #ifdef SO_BINDTODEVICE |
| 5065 | if (!*args[cur_arg + 1]) { |
| 5066 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 5067 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5069 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5070 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5071 | free(curproxy->conn_src.iface_name); |
| 5072 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 5073 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5074 | global.last_checks |= LSTCHK_NETADM; |
| 5075 | #else |
| 5076 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 5077 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5078 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5079 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 5080 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5081 | cur_arg += 2; |
| 5082 | continue; |
| 5083 | } |
| 5084 | 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] | 5085 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5086 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5087 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5088 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5089 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5090 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 5091 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 5092 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5094 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 5095 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5096 | 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] | 5097 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5098 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5099 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5101 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5102 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5103 | |
| 5104 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5105 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5106 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5107 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5108 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5109 | } |
| 5110 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5111 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5112 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5113 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5114 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5115 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5116 | } |
| 5117 | 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] | 5118 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5119 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5120 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5121 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5122 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5123 | } |
| 5124 | 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] | 5125 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5126 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5127 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5128 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5129 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5130 | } |
| 5131 | 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] | 5132 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5133 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5134 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5135 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5136 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5137 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5138 | 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] | 5139 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5140 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5141 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5142 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5143 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5144 | } |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 5145 | 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] | 5146 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5147 | SMP_OPT_DIR_REQ, ACT_SETBE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5148 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5149 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5150 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5151 | |
| 5152 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5153 | 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] | 5154 | } |
| 5155 | 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] | 5156 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5157 | SMP_OPT_DIR_REQ, ACT_SETBE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5158 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5159 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5160 | goto out; |
Willy Tarreau | 40bac83 | 2014-04-28 22:37:06 +0200 | [diff] [blame] | 5161 | |
| 5162 | if (!already_warned(WARN_REQSETBE_DEPRECATED)) |
| 5163 | 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] | 5164 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5165 | 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] | 5166 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5167 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5168 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5169 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5170 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5171 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5172 | |
| 5173 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5174 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5175 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5176 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5177 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5178 | } |
| 5179 | 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] | 5180 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5181 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5182 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5183 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5184 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5185 | } |
| 5186 | 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] | 5187 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5188 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5189 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5190 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5191 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5192 | } |
| 5193 | 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] | 5194 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5195 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5196 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5197 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5198 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5199 | } |
| 5200 | 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] | 5201 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5202 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5203 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5204 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5205 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5206 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5207 | 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] | 5208 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5209 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 5210 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5211 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5212 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 5213 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5214 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5215 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5216 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5217 | if (curproxy == &defproxy) { |
| 5218 | 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] | 5219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5220 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5221 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5222 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5223 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5224 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5225 | if (*(args[1]) == 0) { |
| 5226 | 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] | 5227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5228 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5229 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5230 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5231 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5232 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5233 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5234 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5236 | goto out; |
| 5237 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5238 | err_code |= warnif_cond_conflicts(cond, |
| 5239 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 5240 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5241 | } |
| 5242 | else if (*args[2]) { |
| 5243 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5244 | file, linenum, args[0], args[2]); |
| 5245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5246 | goto out; |
| 5247 | } |
| 5248 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5249 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 5250 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5251 | wl->s = strdup(args[1]); |
| 5252 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 5253 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5254 | } |
| 5255 | 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] | 5256 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5257 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5258 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5260 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5261 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5262 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5263 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5264 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5265 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5266 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5267 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5268 | } |
| 5269 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5270 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5271 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5272 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5273 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5274 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5275 | } |
| 5276 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5277 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5278 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5279 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5280 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5281 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5282 | } |
| 5283 | else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5284 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5285 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 5286 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5288 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5289 | } |
| 5290 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5291 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5292 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5293 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5294 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5295 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5296 | } |
| 5297 | else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5298 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5299 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5300 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5301 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5302 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5303 | } |
| 5304 | 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] | 5305 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 5306 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5307 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 5308 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5309 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5310 | } |
| 5311 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 5312 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5313 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5314 | if (curproxy == &defproxy) { |
| 5315 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5316 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5317 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5318 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5319 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5320 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5321 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5322 | if (*(args[1]) == 0) { |
| 5323 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5325 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5326 | } |
| 5327 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5328 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5329 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 5330 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 5331 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5333 | goto out; |
| 5334 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 5335 | err_code |= warnif_cond_conflicts(cond, |
| 5336 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 5337 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5338 | } |
| 5339 | else if (*args[2]) { |
| 5340 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 5341 | file, linenum, args[0], args[2]); |
| 5342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5343 | goto out; |
| 5344 | } |
| 5345 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5346 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 5347 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 5348 | wl->s = strdup(args[1]); |
| 5349 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5350 | } |
| 5351 | else if (!strcmp(args[0], "errorloc") || |
| 5352 | !strcmp(args[0], "errorloc302") || |
| 5353 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 5354 | int errnum, errlen; |
| 5355 | char *err; |
| 5356 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5357 | 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] | 5358 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5359 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5360 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5361 | 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] | 5362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5363 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5364 | } |
| 5365 | |
| 5366 | errnum = atol(args[1]); |
| 5367 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5368 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 5369 | err = malloc(errlen); |
| 5370 | 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] | 5371 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 5372 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 5373 | err = malloc(errlen); |
| 5374 | 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] | 5375 | } |
| 5376 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5377 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5378 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5379 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5380 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5381 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5382 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5383 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 5384 | |
| 5385 | if (rc >= HTTP_ERR_SIZE) { |
| 5386 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 5387 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5388 | free(err); |
| 5389 | } |
| 5390 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5391 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 5392 | int errnum, errlen, fd; |
| 5393 | char *err; |
| 5394 | struct stat stat; |
| 5395 | |
| 5396 | 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] | 5397 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5398 | |
| 5399 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5400 | 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] | 5401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5402 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | fd = open(args[2], O_RDONLY); |
| 5406 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 5407 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 5408 | file, linenum, args[2], args[1]); |
| 5409 | if (fd >= 0) |
| 5410 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5412 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5413 | } |
| 5414 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5415 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5416 | errlen = stat.st_size; |
| 5417 | } else { |
| 5418 | 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] | 5419 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5420 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 5421 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 5425 | errnum = read(fd, err, errlen); |
| 5426 | if (errnum != errlen) { |
| 5427 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 5428 | file, linenum, args[2], args[1]); |
| 5429 | close(fd); |
| 5430 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5431 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5432 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5433 | } |
| 5434 | close(fd); |
| 5435 | |
| 5436 | errnum = atol(args[1]); |
| 5437 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 5438 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5439 | chunk_destroy(&curproxy->errmsg[rc]); |
| 5440 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5441 | break; |
| 5442 | } |
| 5443 | } |
| 5444 | |
| 5445 | if (rc >= HTTP_ERR_SIZE) { |
| 5446 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 5447 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5448 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 5449 | free(err); |
| 5450 | } |
| 5451 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5452 | else if (!strcmp(args[0], "compression")) { |
| 5453 | struct comp *comp; |
| 5454 | if (curproxy->comp == NULL) { |
| 5455 | comp = calloc(1, sizeof(struct comp)); |
| 5456 | curproxy->comp = comp; |
| 5457 | } else { |
| 5458 | comp = curproxy->comp; |
| 5459 | } |
| 5460 | |
| 5461 | if (!strcmp(args[1], "algo")) { |
| 5462 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 5463 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5464 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5465 | cur_arg = 2; |
| 5466 | if (!*args[cur_arg]) { |
| 5467 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 5468 | file, linenum, args[0]); |
| 5469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5470 | goto out; |
| 5471 | } |
| 5472 | while (*(args[cur_arg])) { |
| 5473 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 5474 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 5475 | file, linenum, args[0], args[cur_arg]); |
| 5476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5477 | goto out; |
| 5478 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 5479 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 5480 | curproxy->comp->algos->end(&ctx); |
| 5481 | } else { |
| 5482 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 5483 | file, linenum, args[0], args[cur_arg]); |
| 5484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5485 | goto out; |
| 5486 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5487 | cur_arg ++; |
| 5488 | continue; |
| 5489 | } |
| 5490 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5491 | else if (!strcmp(args[1], "offload")) { |
| 5492 | comp->offload = 1; |
| 5493 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5494 | else if (!strcmp(args[1], "type")) { |
| 5495 | int cur_arg; |
| 5496 | cur_arg = 2; |
| 5497 | if (!*args[cur_arg]) { |
| 5498 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 5499 | file, linenum, args[0]); |
| 5500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5501 | goto out; |
| 5502 | } |
| 5503 | while (*(args[cur_arg])) { |
| 5504 | comp_append_type(comp, args[cur_arg]); |
| 5505 | cur_arg ++; |
| 5506 | continue; |
| 5507 | } |
| 5508 | } |
| 5509 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 5510 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5511 | file, linenum, args[0]); |
| 5512 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5513 | goto out; |
| 5514 | } |
| 5515 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5516 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5517 | struct cfg_kw_list *kwl; |
| 5518 | int index; |
| 5519 | |
| 5520 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 5521 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 5522 | if (kwl->kw[index].section != CFG_LISTEN) |
| 5523 | continue; |
| 5524 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 5525 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 5526 | 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] | 5527 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5528 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5530 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5531 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5532 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 5533 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5534 | err_code |= ERR_WARN; |
| 5535 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 5536 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5537 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 5538 | } |
| 5539 | } |
| 5540 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 5541 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5542 | 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] | 5543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5544 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5545 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5546 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 5547 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5548 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5549 | } |
| 5550 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5551 | int |
| 5552 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 5553 | { |
| 5554 | |
| 5555 | int err_code = 0; |
| 5556 | const char *err; |
| 5557 | |
| 5558 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 5559 | struct userlist *newul; |
| 5560 | |
| 5561 | if (!*args[1]) { |
| 5562 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5563 | file, linenum, args[0]); |
| 5564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5565 | goto out; |
| 5566 | } |
| 5567 | |
| 5568 | err = invalid_char(args[1]); |
| 5569 | if (err) { |
| 5570 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5571 | file, linenum, *err, args[0], args[1]); |
| 5572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5573 | goto out; |
| 5574 | } |
| 5575 | |
| 5576 | for (newul = userlist; newul; newul = newul->next) |
| 5577 | if (!strcmp(newul->name, args[1])) { |
| 5578 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 5579 | file, linenum, args[1]); |
| 5580 | err_code |= ERR_WARN; |
| 5581 | goto out; |
| 5582 | } |
| 5583 | |
| 5584 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 5585 | if (!newul) { |
| 5586 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5587 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5588 | goto out; |
| 5589 | } |
| 5590 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5591 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5592 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5593 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5594 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5595 | goto out; |
| 5596 | } |
| 5597 | |
| 5598 | newul->next = userlist; |
| 5599 | userlist = newul; |
| 5600 | |
| 5601 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5602 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5603 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5604 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5605 | |
| 5606 | if (!*args[1]) { |
| 5607 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5608 | file, linenum, args[0]); |
| 5609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5610 | goto out; |
| 5611 | } |
| 5612 | |
| 5613 | err = invalid_char(args[1]); |
| 5614 | if (err) { |
| 5615 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 5616 | file, linenum, *err, args[0], args[1]); |
| 5617 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5618 | goto out; |
| 5619 | } |
| 5620 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5621 | for (ag = userlist->groups; ag; ag = ag->next) |
| 5622 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5623 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 5624 | file, linenum, args[1], userlist->name); |
| 5625 | err_code |= ERR_ALERT; |
| 5626 | goto out; |
| 5627 | } |
| 5628 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5629 | ag = calloc(1, sizeof(*ag)); |
| 5630 | if (!ag) { |
| 5631 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5632 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5633 | goto out; |
| 5634 | } |
| 5635 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5636 | ag->name = strdup(args[1]); |
| 5637 | if (!ag) { |
| 5638 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5639 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5640 | goto out; |
| 5641 | } |
| 5642 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5643 | cur_arg = 2; |
| 5644 | |
| 5645 | while (*args[cur_arg]) { |
| 5646 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5647 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5648 | cur_arg += 2; |
| 5649 | continue; |
| 5650 | } else { |
| 5651 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 5652 | file, linenum, args[0]); |
| 5653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5654 | goto out; |
| 5655 | } |
| 5656 | } |
| 5657 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5658 | ag->next = userlist->groups; |
| 5659 | userlist->groups = ag; |
| 5660 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5661 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 5662 | struct auth_users *newuser; |
| 5663 | int cur_arg; |
| 5664 | |
| 5665 | if (!*args[1]) { |
| 5666 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 5667 | file, linenum, args[0]); |
| 5668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5669 | goto out; |
| 5670 | } |
| 5671 | |
| 5672 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 5673 | if (!strcmp(newuser->user, args[1])) { |
| 5674 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 5675 | file, linenum, args[1], userlist->name); |
| 5676 | err_code |= ERR_ALERT; |
| 5677 | goto out; |
| 5678 | } |
| 5679 | |
| 5680 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 5681 | if (!newuser) { |
| 5682 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 5683 | err_code |= ERR_ALERT | ERR_ABORT; |
| 5684 | goto out; |
| 5685 | } |
| 5686 | |
| 5687 | newuser->user = strdup(args[1]); |
| 5688 | |
| 5689 | newuser->next = userlist->users; |
| 5690 | userlist->users = newuser; |
| 5691 | |
| 5692 | cur_arg = 2; |
| 5693 | |
| 5694 | while (*args[cur_arg]) { |
| 5695 | if (!strcmp(args[cur_arg], "password")) { |
| 5696 | #ifndef CONFIG_HAP_CRYPT |
| 5697 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 5698 | file, linenum); |
| 5699 | err_code |= ERR_ALERT; |
| 5700 | #endif |
| 5701 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5702 | cur_arg += 2; |
| 5703 | continue; |
| 5704 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 5705 | newuser->pass = strdup(args[cur_arg + 1]); |
| 5706 | newuser->flags |= AU_O_INSECURE; |
| 5707 | cur_arg += 2; |
| 5708 | continue; |
| 5709 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5710 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5711 | cur_arg += 2; |
| 5712 | continue; |
| 5713 | } else { |
| 5714 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 5715 | file, linenum, args[0]); |
| 5716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5717 | goto out; |
| 5718 | } |
| 5719 | } |
| 5720 | } else { |
| 5721 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 5722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5723 | } |
| 5724 | |
| 5725 | out: |
| 5726 | return err_code; |
| 5727 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5728 | |
| 5729 | /* |
| 5730 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5731 | * Returns the error code, 0 if OK, or any combination of : |
| 5732 | * - ERR_ABORT: must abort ASAP |
| 5733 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5734 | * - ERR_WARN: a warning has been emitted |
| 5735 | * - ERR_ALERT: an alert has been emitted |
| 5736 | * Only the two first ones can stop processing, the two others are just |
| 5737 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5738 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 5739 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5740 | { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5741 | char thisline[LINESIZE]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5742 | FILE *f; |
| 5743 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5744 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5745 | struct cfg_section *cs = NULL; |
| 5746 | struct cfg_section *ics; |
| 5747 | |
| 5748 | /* Register internal sections */ |
| 5749 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 5750 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 5751 | !cfg_register_section("backend", cfg_parse_listen) || |
| 5752 | !cfg_register_section("ruleset", cfg_parse_listen) || |
| 5753 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 5754 | !cfg_register_section("global", cfg_parse_global) || |
| 5755 | !cfg_register_section("userlist", cfg_parse_users) || |
| 5756 | !cfg_register_section("peers", cfg_parse_peers)) |
| 5757 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5758 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5759 | if ((f=fopen(file,"r")) == NULL) |
| 5760 | return -1; |
| 5761 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5762 | while (fgets(thisline, sizeof(thisline), f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5763 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5764 | char *end; |
| 5765 | char *args[MAX_LINE_ARGS + 1]; |
| 5766 | char *line = thisline; |
| 5767 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5768 | linenum++; |
| 5769 | |
| 5770 | end = line + strlen(line); |
| 5771 | |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5772 | if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { |
| 5773 | /* Check if we reached the limit and the last char is not \n. |
| 5774 | * Watch out for the last line without the terminating '\n'! |
| 5775 | */ |
| 5776 | Alert("parsing [%s:%d]: line too long, limit: %d.\n", |
Willy Tarreau | 5e4a6f1 | 2009-04-11 19:42:49 +0200 | [diff] [blame] | 5777 | file, linenum, (int)sizeof(thisline)-1); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5778 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5779 | } |
| 5780 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5781 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5782 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5783 | line++; |
| 5784 | |
| 5785 | arg = 0; |
| 5786 | args[arg] = line; |
| 5787 | |
| 5788 | while (*line && arg < MAX_LINE_ARGS) { |
| 5789 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 5790 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 5791 | */ |
| 5792 | if (*line == '\\') { |
| 5793 | int skip = 0; |
| 5794 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 5795 | *line = line[1]; |
| 5796 | skip = 1; |
| 5797 | } |
| 5798 | else if (line[1] == 'r') { |
| 5799 | *line = '\r'; |
| 5800 | skip = 1; |
| 5801 | } |
| 5802 | else if (line[1] == 'n') { |
| 5803 | *line = '\n'; |
| 5804 | skip = 1; |
| 5805 | } |
| 5806 | else if (line[1] == 't') { |
| 5807 | *line = '\t'; |
| 5808 | skip = 1; |
| 5809 | } |
| 5810 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5811 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5812 | unsigned char hex1, hex2; |
| 5813 | hex1 = toupper(line[2]) - '0'; |
| 5814 | hex2 = toupper(line[3]) - '0'; |
| 5815 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 5816 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 5817 | *line = (hex1<<4) + hex2; |
| 5818 | skip = 3; |
| 5819 | } |
| 5820 | else { |
| 5821 | 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] | 5822 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5823 | } |
| 5824 | } |
| 5825 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 5826 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5827 | end -= skip; |
| 5828 | } |
| 5829 | line++; |
| 5830 | } |
| 5831 | else if (*line == '#' || *line == '\n' || *line == '\r') { |
| 5832 | /* end of string, end of loop */ |
| 5833 | *line = 0; |
| 5834 | break; |
| 5835 | } |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5836 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5837 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 5838 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 5839 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5840 | line++; |
| 5841 | args[++arg] = line; |
| 5842 | } |
| 5843 | else { |
| 5844 | line++; |
| 5845 | } |
| 5846 | } |
| 5847 | |
| 5848 | /* empty line */ |
| 5849 | if (!**args) |
| 5850 | continue; |
| 5851 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5852 | if (*line) { |
| 5853 | /* we had to stop due to too many args. |
| 5854 | * Let's terminate the string, print the offending part then cut the |
| 5855 | * last arg. |
| 5856 | */ |
| 5857 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 5858 | line++; |
| 5859 | *line = '\0'; |
| 5860 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 5861 | 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] | 5862 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 5863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5864 | args[arg] = line; |
| 5865 | } |
| 5866 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 5867 | /* zero out remaining args and ensure that at least one entry |
| 5868 | * is zeroed out. |
| 5869 | */ |
| 5870 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5871 | args[arg] = line; |
| 5872 | } |
| 5873 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5874 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5875 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5876 | char *tmp; |
| 5877 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5878 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5879 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5880 | for (arg=0; *args[arg+1]; arg++) |
| 5881 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5882 | *tmp = '\0'; // fix the next arg to \0 |
| 5883 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5884 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 5885 | else if (!strcmp(args[0], "default")) { |
| 5886 | kwm = KWM_DEF; |
| 5887 | for (arg=0; *args[arg+1]; arg++) |
| 5888 | args[arg] = args[arg+1]; // shift args after inversion |
| 5889 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5890 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5891 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 5892 | strcmp(args[0], "log") != 0) { |
| 5893 | 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] | 5894 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5895 | } |
| 5896 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5897 | /* detect section start */ |
| 5898 | list_for_each_entry(ics, §ions, list) { |
| 5899 | if (strcmp(args[0], ics->section_name) == 0) { |
| 5900 | cursection = ics->section_name; |
| 5901 | cs = ics; |
| 5902 | break; |
| 5903 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 5904 | } |
| 5905 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5906 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 5907 | if (cs) |
| 5908 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 5909 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 5910 | 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] | 5911 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5912 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5913 | |
| 5914 | if (err_code & ERR_ABORT) |
| 5915 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5916 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 5917 | cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5918 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 5919 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5920 | } |
| 5921 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5922 | /* |
| 5923 | * Returns the error code, 0 if OK, or any combination of : |
| 5924 | * - ERR_ABORT: must abort ASAP |
| 5925 | * - ERR_FATAL: we can continue parsing but not start the service |
| 5926 | * - ERR_WARN: a warning has been emitted |
| 5927 | * - ERR_ALERT: an alert has been emitted |
| 5928 | * Only the two first ones can stop processing, the two others are just |
| 5929 | * indicators. |
| 5930 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 5931 | int check_config_validity() |
| 5932 | { |
| 5933 | int cfgerr = 0; |
| 5934 | struct proxy *curproxy = NULL; |
| 5935 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 5936 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5937 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5938 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5939 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 5940 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5941 | /* |
| 5942 | * Now, check for the integrity of all that we have collected. |
| 5943 | */ |
| 5944 | |
| 5945 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 5946 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5947 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 5948 | if (!global.tune.max_http_hdr) |
| 5949 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 5950 | |
| 5951 | if (!global.tune.cookie_len) |
| 5952 | global.tune.cookie_len = CAPTURE_LEN; |
| 5953 | |
| 5954 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 5955 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 5956 | /* Post initialisation of the users and groups lists. */ |
| 5957 | err_code = userlist_postinit(); |
| 5958 | if (err_code != ERR_NONE) |
| 5959 | goto out; |
| 5960 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 5961 | /* first, we will invert the proxy list order */ |
| 5962 | curproxy = NULL; |
| 5963 | while (proxy) { |
| 5964 | struct proxy *next; |
| 5965 | |
| 5966 | next = proxy->next; |
| 5967 | proxy->next = curproxy; |
| 5968 | curproxy = proxy; |
| 5969 | if (!next) |
| 5970 | break; |
| 5971 | proxy = next; |
| 5972 | } |
| 5973 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5974 | while (curproxy != NULL) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5975 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 5976 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 5977 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 5978 | struct tcp_rule *trule; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5979 | struct listener *listener; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5980 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 5981 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5982 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 5983 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5984 | /* proxy ID not set, use automatic numbering with first |
| 5985 | * spare entry starting with next_pxid. |
| 5986 | */ |
| 5987 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 5988 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 5989 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 5990 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 5991 | next_pxid++; |
| 5992 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 5993 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5994 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 5995 | /* ensure we don't keep listeners uselessly bound */ |
| 5996 | stop_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5997 | curproxy = curproxy->next; |
| 5998 | continue; |
| 5999 | } |
| 6000 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6001 | /* Check multi-process mode compatibility for the current proxy */ |
| 6002 | |
| 6003 | if (curproxy->bind_proc) { |
| 6004 | /* an explicit bind-process was specified, let's check how many |
| 6005 | * processes remain. |
| 6006 | */ |
| 6007 | nbproc = popcount(curproxy->bind_proc); |
| 6008 | |
| 6009 | curproxy->bind_proc &= nbits(global.nbproc); |
| 6010 | if (!curproxy->bind_proc && nbproc == 1) { |
| 6011 | 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); |
| 6012 | curproxy->bind_proc = 1; |
| 6013 | } |
| 6014 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 6015 | 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); |
| 6016 | curproxy->bind_proc = 0; |
| 6017 | } |
| 6018 | } |
| 6019 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 6020 | /* check and reduce the bind-proc of each listener */ |
| 6021 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 6022 | unsigned long mask; |
| 6023 | |
| 6024 | if (!bind_conf->bind_proc) |
| 6025 | continue; |
| 6026 | |
| 6027 | mask = nbits(global.nbproc); |
| 6028 | if (curproxy->bind_proc) |
| 6029 | mask &= curproxy->bind_proc; |
| 6030 | /* mask cannot be null here thanks to the previous checks */ |
| 6031 | |
| 6032 | nbproc = popcount(bind_conf->bind_proc); |
| 6033 | bind_conf->bind_proc &= mask; |
| 6034 | |
| 6035 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 6036 | 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", |
| 6037 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6038 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 6039 | } |
| 6040 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 6041 | 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", |
| 6042 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 6043 | bind_conf->bind_proc = 0; |
| 6044 | } |
| 6045 | } |
| 6046 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 6047 | /* here, if bind_proc is null, it means no limit, otherwise it's explicit. |
| 6048 | * We now check how many processes the proxy will effectively run on. |
| 6049 | */ |
| 6050 | |
| 6051 | nbproc = global.nbproc; |
| 6052 | if (curproxy->bind_proc) |
| 6053 | nbproc = popcount(curproxy->bind_proc & nbits(global.nbproc)); |
| 6054 | |
| 6055 | if (global.nbproc > 1 && curproxy->table.peers.name) { |
| 6056 | Alert("Proxy '%s': peers can't be used in multi-process mode (nbproc > 1).\n", |
| 6057 | curproxy->id); |
| 6058 | cfgerr++; |
| 6059 | } |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 6060 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6061 | switch (curproxy->mode) { |
| 6062 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6063 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6064 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6065 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 6066 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6067 | cfgerr++; |
| 6068 | } |
| 6069 | |
| 6070 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6071 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 6072 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6073 | break; |
| 6074 | |
| 6075 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6076 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6077 | break; |
| 6078 | |
| 6079 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 6080 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 6081 | break; |
| 6082 | } |
| 6083 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6084 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6085 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6086 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6087 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 6088 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6089 | cfgerr++; |
| 6090 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6091 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6092 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6093 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 6094 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6095 | cfgerr++; |
| 6096 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6097 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6098 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6099 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 6100 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6101 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 6102 | } |
| 6103 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6104 | 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] | 6105 | /* If no LB algo is set in a backend, and we're not in |
| 6106 | * transparent mode, dispatch mode nor proxy mode, we |
| 6107 | * want to use balance roundrobin by default. |
| 6108 | */ |
| 6109 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 6110 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6111 | } |
| 6112 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 6113 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6114 | if (curproxy->options & PR_O_DISPATCH) |
| 6115 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 6116 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 6117 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 6118 | else if (curproxy->options & PR_O_TRANSP) |
| 6119 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 6120 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6121 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 6122 | if (curproxy->options & PR_O_DISABLE404) { |
| 6123 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6124 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 6125 | err_code |= ERR_WARN; |
| 6126 | curproxy->options &= ~PR_O_DISABLE404; |
| 6127 | } |
| 6128 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 6129 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 6130 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 6131 | err_code |= ERR_WARN; |
| 6132 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 6133 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 6134 | } |
| 6135 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 6136 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 6137 | if (!global.external_check) { |
| 6138 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 6139 | curproxy->id, "option external-check"); |
| 6140 | cfgerr++; |
| 6141 | } |
| 6142 | if (!curproxy->check_command) { |
| 6143 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 6144 | curproxy->id, "option external-check"); |
| 6145 | cfgerr++; |
| 6146 | } |
| 6147 | } |
| 6148 | |
| 6149 | if (curproxy->check_command) { |
| 6150 | int clear = 0; |
| 6151 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6152 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6153 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 6154 | err_code |= ERR_WARN; |
| 6155 | clear = 1; |
| 6156 | } |
| 6157 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
| 6158 | Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-command path' is not set.\n", |
| 6159 | curproxy->id, "external-check command"); |
| 6160 | cfgerr++; |
| 6161 | } |
| 6162 | if (clear) { |
| 6163 | free(curproxy->check_command); |
| 6164 | curproxy->check_command = NULL; |
| 6165 | } |
| 6166 | } |
| 6167 | |
| 6168 | if (curproxy->check_path) { |
| 6169 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 6170 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 6171 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 6172 | err_code |= ERR_WARN; |
| 6173 | free(curproxy->check_path); |
| 6174 | curproxy->check_path = NULL; |
| 6175 | } |
| 6176 | } |
| 6177 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6178 | /* if a default backend was specified, let's find it */ |
| 6179 | if (curproxy->defbe.name) { |
| 6180 | struct proxy *target; |
| 6181 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6182 | target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6183 | if (!target) { |
| 6184 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 6185 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6186 | cfgerr++; |
| 6187 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6188 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 6189 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6190 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6191 | } else { |
| 6192 | free(curproxy->defbe.name); |
| 6193 | curproxy->defbe.be = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6194 | /* we force the backend to be present on at least all of |
| 6195 | * the frontend's processes. |
| 6196 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6197 | if (target->bind_proc) |
| 6198 | target->bind_proc = curproxy->bind_proc ? |
| 6199 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 6200 | |
| 6201 | /* Emit a warning if this proxy also has some servers */ |
| 6202 | if (curproxy->srv) { |
| 6203 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 6204 | curproxy->id); |
| 6205 | err_code |= ERR_WARN; |
| 6206 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6207 | } |
| 6208 | } |
| 6209 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 6210 | /* find the target proxy in setbe */ |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6211 | if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) { |
| 6212 | /* map jump target for ACT_SETBE in req_rep chain */ |
| 6213 | struct hdr_exp *exp; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6214 | for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6215 | struct proxy *target; |
| 6216 | |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6217 | if (exp->action != ACT_SETBE) |
| 6218 | continue; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6219 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6220 | target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6221 | if (!target) { |
| 6222 | Alert("Proxy '%s': unable to find required setbe: '%s'.\n", |
| 6223 | curproxy->id, exp->replace); |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6224 | cfgerr++; |
| 6225 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6226 | Alert("Proxy '%s': loop detected for setbe: '%s'.\n", |
| 6227 | curproxy->id, exp->replace); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6228 | cfgerr++; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6229 | } else { |
| 6230 | free((void *)exp->replace); |
| 6231 | exp->replace = (const char *)target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6232 | /* we force the backend to be present on at least all of |
| 6233 | * the frontend's processes. |
| 6234 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6235 | if (target->bind_proc) |
| 6236 | target->bind_proc = curproxy->bind_proc ? |
| 6237 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | a496b60 | 2006-12-17 23:15:24 +0100 | [diff] [blame] | 6238 | } |
| 6239 | } |
| 6240 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6241 | |
| 6242 | /* find the target proxy for 'use_backend' rules */ |
| 6243 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6244 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 6245 | struct logformat_node *node; |
| 6246 | char *pxname; |
| 6247 | |
| 6248 | /* Try to parse the string as a log format expression. If the result |
| 6249 | * of the parsing is only one entry containing a simple string, then |
| 6250 | * it's a standard string corresponding to a static rule, thus the |
| 6251 | * parsing is cancelled and be.name is restored to be resolved. |
| 6252 | */ |
| 6253 | pxname = rule->be.name; |
| 6254 | LIST_INIT(&rule->be.expr); |
| 6255 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 6256 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 6257 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 6258 | |
| 6259 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 6260 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 6261 | rule->dynamic = 1; |
| 6262 | free(pxname); |
| 6263 | continue; |
| 6264 | } |
| 6265 | /* simple string: free the expression and fall back to static rule */ |
| 6266 | free(node->arg); |
| 6267 | free(node); |
| 6268 | } |
| 6269 | |
| 6270 | rule->dynamic = 0; |
| 6271 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6272 | |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 6273 | target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6274 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6275 | if (!target) { |
| 6276 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 6277 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6278 | cfgerr++; |
| 6279 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 6280 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 6281 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6282 | cfgerr++; |
| 6283 | } else { |
| 6284 | free((void *)rule->be.name); |
| 6285 | rule->be.backend = target; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 6286 | /* we force the backend to be present on at least all of |
| 6287 | * the frontend's processes. |
| 6288 | */ |
Willy Tarreau | 3507d5d | 2014-05-09 13:54:22 +0200 | [diff] [blame] | 6289 | if (target->bind_proc) |
| 6290 | target->bind_proc = curproxy->bind_proc ? |
| 6291 | (target->bind_proc | curproxy->bind_proc) : 0; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6292 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | /* find the target proxy for 'use_backend' rules */ |
| 6296 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 6297 | struct server *target = findserver(curproxy, srule->srv.name); |
| 6298 | |
| 6299 | if (!target) { |
| 6300 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 6301 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 6302 | cfgerr++; |
| 6303 | continue; |
| 6304 | } |
| 6305 | free((void *)srule->srv.name); |
| 6306 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 6307 | } |
| 6308 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6309 | /* find the target table for 'stick' rules */ |
| 6310 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 6311 | struct proxy *target; |
| 6312 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6313 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 6314 | if (mrule->flags & STK_IS_STORE) |
| 6315 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6316 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6317 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6318 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6319 | else |
| 6320 | target = curproxy; |
| 6321 | |
| 6322 | if (!target) { |
| 6323 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 6324 | curproxy->id, mrule->table.name); |
| 6325 | cfgerr++; |
| 6326 | } |
| 6327 | else if (target->table.size == 0) { |
| 6328 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6329 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6330 | cfgerr++; |
| 6331 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6332 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6333 | 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] | 6334 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6335 | cfgerr++; |
| 6336 | } |
| 6337 | else { |
| 6338 | free((void *)mrule->table.name); |
| 6339 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6340 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | /* find the target table for 'store response' rules */ |
| 6345 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 6346 | struct proxy *target; |
| 6347 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 6348 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 6349 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6350 | if (mrule->table.name) |
Willy Tarreau | c00cdc2 | 2010-06-06 16:48:26 +0200 | [diff] [blame] | 6351 | target = findproxy(mrule->table.name, 0); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6352 | else |
| 6353 | target = curproxy; |
| 6354 | |
| 6355 | if (!target) { |
| 6356 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 6357 | curproxy->id, mrule->table.name); |
| 6358 | cfgerr++; |
| 6359 | } |
| 6360 | else if (target->table.size == 0) { |
| 6361 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 6362 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6363 | cfgerr++; |
| 6364 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 6365 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 6366 | 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] | 6367 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 6368 | cfgerr++; |
| 6369 | } |
| 6370 | else { |
| 6371 | free((void *)mrule->table.name); |
| 6372 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 6373 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6374 | } |
| 6375 | } |
| 6376 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6377 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 6378 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 6379 | struct proxy *target; |
| 6380 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6381 | 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] | 6382 | continue; |
| 6383 | |
| 6384 | if (trule->act_prm.trk_ctr.table.n) |
| 6385 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6386 | else |
| 6387 | target = curproxy; |
| 6388 | |
| 6389 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6390 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6391 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6392 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6393 | cfgerr++; |
| 6394 | } |
| 6395 | else if (target->table.size == 0) { |
| 6396 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6397 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6398 | cfgerr++; |
| 6399 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6400 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6401 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6402 | 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] | 6403 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6404 | cfgerr++; |
| 6405 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 6406 | else { |
| 6407 | free(trule->act_prm.trk_ctr.table.n); |
| 6408 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6409 | /* 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] | 6410 | * to pass a list of counters to track and allocate them right here using |
| 6411 | * stktable_alloc_data_type(). |
| 6412 | */ |
| 6413 | } |
| 6414 | } |
| 6415 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6416 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 6417 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 6418 | struct proxy *target; |
| 6419 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 6420 | 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] | 6421 | continue; |
| 6422 | |
| 6423 | if (trule->act_prm.trk_ctr.table.n) |
| 6424 | target = findproxy(trule->act_prm.trk_ctr.table.n, 0); |
| 6425 | else |
| 6426 | target = curproxy; |
| 6427 | |
| 6428 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6429 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 6430 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 6431 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6432 | cfgerr++; |
| 6433 | } |
| 6434 | else if (target->table.size == 0) { |
| 6435 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 6436 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 6437 | cfgerr++; |
| 6438 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6439 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 6440 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 6441 | 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] | 6442 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 6443 | cfgerr++; |
| 6444 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 6445 | else { |
| 6446 | free(trule->act_prm.trk_ctr.table.n); |
| 6447 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 6448 | /* 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] | 6449 | * to pass a list of counters to track and allocate them right here using |
| 6450 | * stktable_alloc_data_type(). |
| 6451 | */ |
| 6452 | } |
| 6453 | } |
| 6454 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 6455 | /* move any "block" rules at the beginning of the http-request rules */ |
| 6456 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 6457 | /* insert block_rules into http_req_rules at the beginning */ |
| 6458 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 6459 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 6460 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 6461 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 6462 | LIST_INIT(&curproxy->block_rules); |
| 6463 | } |
| 6464 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6465 | if (curproxy->table.peers.name) { |
| 6466 | struct peers *curpeers = peers; |
| 6467 | |
| 6468 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 6469 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 6470 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 6471 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6472 | break; |
| 6473 | } |
| 6474 | } |
| 6475 | |
| 6476 | if (!curpeers) { |
| 6477 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 6478 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6479 | free((void *)curproxy->table.peers.name); |
| 6480 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6481 | cfgerr++; |
| 6482 | } |
| 6483 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 6484 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 6485 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 6486 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 6487 | cfgerr++; |
| 6488 | } |
| 6489 | } |
| 6490 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6491 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6492 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6493 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 6494 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 6495 | "proxy", curproxy->id); |
| 6496 | cfgerr++; |
| 6497 | goto out_uri_auth_compat; |
| 6498 | } |
| 6499 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6500 | 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] | 6501 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6502 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6503 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6504 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6505 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 6506 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6507 | |
| 6508 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6509 | uri_auth_compat_req[i++] = "realm"; |
| 6510 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 6511 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6512 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6513 | uri_auth_compat_req[i++] = "unless"; |
| 6514 | uri_auth_compat_req[i++] = "{"; |
| 6515 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 6516 | uri_auth_compat_req[i++] = "}"; |
| 6517 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6518 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6519 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 6520 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6521 | cfgerr++; |
| 6522 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6523 | } |
| 6524 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 6525 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 6526 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6527 | if (curproxy->uri_auth->auth_realm) { |
| 6528 | free(curproxy->uri_auth->auth_realm); |
| 6529 | curproxy->uri_auth->auth_realm = NULL; |
| 6530 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 6531 | |
| 6532 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 6533 | } |
| 6534 | out_uri_auth_compat: |
| 6535 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6536 | /* compile the log format */ |
| 6537 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6538 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6539 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6540 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6541 | free(curproxy->conf.logformat_string); |
| 6542 | curproxy->conf.logformat_string = NULL; |
| 6543 | free(curproxy->conf.lfs_file); |
| 6544 | curproxy->conf.lfs_file = NULL; |
| 6545 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6546 | } |
| 6547 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6548 | if (curproxy->conf.logformat_string) { |
| 6549 | curproxy->conf.args.ctx = ARGC_LOG; |
| 6550 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 6551 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 6552 | 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] | 6553 | 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] | 6554 | curproxy->conf.args.file = NULL; |
| 6555 | curproxy->conf.args.line = 0; |
| 6556 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6557 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6558 | if (curproxy->conf.uniqueid_format_string) { |
| 6559 | curproxy->conf.args.ctx = ARGC_UIF; |
| 6560 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 6561 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 6562 | 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] | 6563 | (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6564 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6565 | curproxy->conf.args.file = NULL; |
| 6566 | curproxy->conf.args.line = 0; |
| 6567 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6568 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6569 | /* only now we can check if some args remain unresolved. |
| 6570 | * This must be done after the users and groups resolution. |
| 6571 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6572 | cfgerr += smp_resolve_args(curproxy); |
| 6573 | if (!cfgerr) |
| 6574 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 6575 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6576 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6577 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 6578 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 6579 | (!curproxy->timeout.connect || |
| 6580 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6581 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6582 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 6583 | " | 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] | 6584 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6585 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6586 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 6587 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6588 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6589 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 6590 | * We must still support older configurations, so let's find out whether those |
| 6591 | * parameters have been set or must be copied from contimeouts. |
| 6592 | */ |
| 6593 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6594 | if (!curproxy->timeout.tarpit || |
| 6595 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6596 | /* tarpit timeout not set. We search in the following order: |
| 6597 | * default.tarpit, curr.connect, default.connect. |
| 6598 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6599 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6600 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6601 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6602 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6603 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6604 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6605 | } |
| 6606 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6607 | (!curproxy->timeout.queue || |
| 6608 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6609 | /* queue timeout not set. We search in the following order: |
| 6610 | * default.queue, curr.connect, default.connect. |
| 6611 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6612 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6613 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6614 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6615 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 6616 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 6617 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 6618 | } |
| 6619 | } |
| 6620 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 6621 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 6622 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 6623 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 6624 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 6625 | } |
| 6626 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 6627 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 6628 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 6629 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 6630 | proxy_type_str(curproxy), curproxy->id); |
| 6631 | err_code |= ERR_WARN; |
| 6632 | } |
| 6633 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 6634 | /* ensure that cookie capture length is not too large */ |
| 6635 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 6636 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 6637 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 6638 | err_code |= ERR_WARN; |
| 6639 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 6640 | } |
| 6641 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6642 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6643 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6644 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 6645 | curproxy->nb_req_cap * sizeof(char *), |
| 6646 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 6650 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 6651 | curproxy->nb_rsp_cap * sizeof(char *), |
| 6652 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 6653 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 6654 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6655 | /* first, we will invert the servers list order */ |
| 6656 | newsrv = NULL; |
| 6657 | while (curproxy->srv) { |
| 6658 | struct server *next; |
| 6659 | |
| 6660 | next = curproxy->srv->next; |
| 6661 | curproxy->srv->next = newsrv; |
| 6662 | newsrv = curproxy->srv; |
| 6663 | if (!next) |
| 6664 | break; |
| 6665 | curproxy->srv = next; |
| 6666 | } |
| 6667 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 6668 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 6669 | * We only emit a warning for the first conflict affecting each server, |
| 6670 | * in order to avoid combinatory explosion if all servers have the same |
| 6671 | * name. We do that only for servers which do not have an explicit ID, |
| 6672 | * because these IDs were made also for distinguishing them and we don't |
| 6673 | * want to annoy people who correctly manage them. |
| 6674 | */ |
| 6675 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 6676 | struct server *other_srv; |
| 6677 | |
| 6678 | if (newsrv->puid) |
| 6679 | continue; |
| 6680 | |
| 6681 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 6682 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 6683 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 6684 | newsrv->conf.file, newsrv->conf.line, |
| 6685 | proxy_type_str(curproxy), curproxy->id, |
| 6686 | newsrv->id, other_srv->conf.line); |
| 6687 | break; |
| 6688 | } |
| 6689 | } |
| 6690 | } |
| 6691 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 6692 | /* assign automatic UIDs to servers which don't have one yet */ |
| 6693 | next_id = 1; |
| 6694 | newsrv = curproxy->srv; |
| 6695 | while (newsrv != NULL) { |
| 6696 | if (!newsrv->puid) { |
| 6697 | /* server ID not set, use automatic numbering with first |
| 6698 | * spare entry starting with next_svid. |
| 6699 | */ |
| 6700 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 6701 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 6702 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 6703 | } |
| 6704 | next_id++; |
| 6705 | newsrv = newsrv->next; |
| 6706 | } |
| 6707 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 6708 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 6709 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6710 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6711 | /* |
| 6712 | * If this server supports a maxconn parameter, it needs a dedicated |
| 6713 | * tasks to fill the emptied slots when a connection leaves. |
| 6714 | * Also, resolve deferred tracking dependency if needed. |
| 6715 | */ |
| 6716 | newsrv = curproxy->srv; |
| 6717 | while (newsrv != NULL) { |
| 6718 | if (newsrv->minconn > newsrv->maxconn) { |
| 6719 | /* Only 'minconn' was specified, or it was higher than or equal |
| 6720 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 6721 | * this will avoid further useless expensive computations. |
| 6722 | */ |
| 6723 | newsrv->maxconn = newsrv->minconn; |
| 6724 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 6725 | /* minconn was not specified, so we set it to maxconn */ |
| 6726 | newsrv->minconn = newsrv->maxconn; |
| 6727 | } |
| 6728 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6729 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6730 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 6731 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 6732 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 6733 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 6734 | /* set the check type on the server */ |
| 6735 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 6736 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6737 | if (newsrv->trackit) { |
| 6738 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6739 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6740 | char *pname, *sname; |
| 6741 | |
| 6742 | pname = newsrv->trackit; |
| 6743 | sname = strrchr(pname, '/'); |
| 6744 | |
| 6745 | if (sname) |
| 6746 | *sname++ = '\0'; |
| 6747 | else { |
| 6748 | sname = pname; |
| 6749 | pname = NULL; |
| 6750 | } |
| 6751 | |
| 6752 | if (pname) { |
| 6753 | px = findproxy(pname, PR_CAP_BE); |
| 6754 | if (!px) { |
| 6755 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 6756 | proxy_type_str(curproxy), curproxy->id, |
| 6757 | newsrv->id, pname); |
| 6758 | cfgerr++; |
| 6759 | goto next_srv; |
| 6760 | } |
| 6761 | } else |
| 6762 | px = curproxy; |
| 6763 | |
| 6764 | srv = findserver(px, sname); |
| 6765 | if (!srv) { |
| 6766 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 6767 | proxy_type_str(curproxy), curproxy->id, |
| 6768 | newsrv->id, sname); |
| 6769 | cfgerr++; |
| 6770 | goto next_srv; |
| 6771 | } |
| 6772 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6773 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 6774 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 6775 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6776 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 6777 | "tracking as it does not have any check nor agent enabled.\n", |
| 6778 | proxy_type_str(curproxy), curproxy->id, |
| 6779 | newsrv->id, px->id, srv->id); |
| 6780 | cfgerr++; |
| 6781 | goto next_srv; |
| 6782 | } |
| 6783 | |
| 6784 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 6785 | |
| 6786 | if (loop) { |
| 6787 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 6788 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 6789 | proxy_type_str(curproxy), curproxy->id, |
| 6790 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6791 | cfgerr++; |
| 6792 | goto next_srv; |
| 6793 | } |
| 6794 | |
| 6795 | if (curproxy != px && |
| 6796 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 6797 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 6798 | "tracking: disable-on-404 option inconsistency.\n", |
| 6799 | proxy_type_str(curproxy), curproxy->id, |
| 6800 | newsrv->id, px->id, srv->id); |
| 6801 | cfgerr++; |
| 6802 | goto next_srv; |
| 6803 | } |
| 6804 | |
| 6805 | /* 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] | 6806 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 6807 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 6808 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 6809 | newsrv->check.health = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 6810 | newsrv->agent.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 6814 | newsrv->tracknext = srv->trackers; |
| 6815 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 6816 | |
| 6817 | free(newsrv->trackit); |
| 6818 | newsrv->trackit = NULL; |
| 6819 | } |
| 6820 | next_srv: |
| 6821 | newsrv = newsrv->next; |
| 6822 | } |
| 6823 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6824 | /* We have to initialize the server lookup mechanism depending |
| 6825 | * on what LB algorithm was choosen. |
| 6826 | */ |
| 6827 | |
| 6828 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 6829 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 6830 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 6831 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 6832 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6833 | init_server_map(curproxy); |
| 6834 | } else { |
| 6835 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 6836 | fwrr_init_server_groups(curproxy); |
| 6837 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6838 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6839 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 6840 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 6841 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 6842 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 6843 | fwlc_init_server_tree(curproxy); |
| 6844 | } else { |
| 6845 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 6846 | fas_init_server_tree(curproxy); |
| 6847 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6848 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6849 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6850 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6851 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 6852 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 6853 | chash_init_server_tree(curproxy); |
| 6854 | } else { |
| 6855 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 6856 | init_server_map(curproxy); |
| 6857 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 6858 | break; |
| 6859 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6860 | |
| 6861 | if (curproxy->options & PR_O_LOGASAP) |
| 6862 | curproxy->to_log &= ~LW_BYTES; |
| 6863 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 6864 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 6865 | (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] | 6866 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 6867 | proxy_type_str(curproxy), curproxy->id); |
| 6868 | err_code |= ERR_WARN; |
| 6869 | } |
| 6870 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6871 | if (curproxy->mode != PR_MODE_HTTP) { |
| 6872 | int optnum; |
| 6873 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6874 | if (curproxy->uri_auth) { |
| 6875 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 6876 | proxy_type_str(curproxy), curproxy->id); |
| 6877 | err_code |= ERR_WARN; |
| 6878 | curproxy->uri_auth = NULL; |
| 6879 | } |
| 6880 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6881 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6882 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6883 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 6884 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 6885 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6886 | } |
| 6887 | |
| 6888 | if (curproxy->options & PR_O_ORGTO) { |
| 6889 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6890 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 6891 | err_code |= ERR_WARN; |
| 6892 | curproxy->options &= ~PR_O_ORGTO; |
| 6893 | } |
| 6894 | |
| 6895 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 6896 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 6897 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 6898 | (curproxy->options & cfg_opts[optnum].val)) { |
| 6899 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6900 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6901 | err_code |= ERR_WARN; |
| 6902 | curproxy->options &= ~cfg_opts[optnum].val; |
| 6903 | } |
| 6904 | } |
| 6905 | |
| 6906 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 6907 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 6908 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 6909 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 6910 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 6911 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 6912 | err_code |= ERR_WARN; |
| 6913 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 6914 | } |
| 6915 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6916 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6917 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6918 | if (curproxy->conn_src.bind_hdr_occ) { |
| 6919 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6920 | 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] | 6921 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6922 | err_code |= ERR_WARN; |
| 6923 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6924 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 6925 | } |
| 6926 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6927 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6928 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 6929 | */ |
| 6930 | newsrv = curproxy->srv; |
| 6931 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6932 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 6933 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 6934 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 6935 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6936 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6937 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 6938 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 6939 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 6940 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6941 | err_code |= ERR_WARN; |
| 6942 | } |
| 6943 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 6944 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 6945 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 6946 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 6947 | err_code |= ERR_WARN; |
| 6948 | } |
| 6949 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6950 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6951 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 6952 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6953 | 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] | 6954 | 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] | 6955 | err_code |= ERR_WARN; |
| 6956 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 6957 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 6958 | newsrv = newsrv->next; |
| 6959 | } |
| 6960 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6961 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 6962 | if (!curproxy->accept) |
| 6963 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 6964 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6965 | if (curproxy->tcp_req.inspect_delay || |
| 6966 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6967 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6968 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6969 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6970 | 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] | 6971 | 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] | 6972 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6973 | |
| 6974 | /* both TCP and HTTP must check switching rules */ |
| 6975 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 6976 | } |
| 6977 | |
| 6978 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 6979 | if (curproxy->tcp_req.inspect_delay || |
| 6980 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 6981 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 6982 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 6983 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 6984 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 6985 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 6986 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6987 | 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] | 6988 | 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] | 6989 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 6990 | |
| 6991 | /* If the backend does requires RDP cookie persistence, we have to |
| 6992 | * enable the corresponding analyser. |
| 6993 | */ |
| 6994 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 6995 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 6996 | } |
| 6997 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 6998 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 6999 | /* Configure SSL for each bind line. |
| 7000 | * Note: if configuration fails at some point, the ->ctx member |
| 7001 | * remains NULL so that listeners can later detach. |
| 7002 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7003 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7004 | int alloc_ctx; |
| 7005 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7006 | if (!bind_conf->is_ssl) { |
| 7007 | if (bind_conf->default_ctx) { |
| 7008 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 7009 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7010 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7011 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7012 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7013 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7014 | 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] | 7015 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7016 | cfgerr++; |
| 7017 | continue; |
| 7018 | } |
| 7019 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 7020 | 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] | 7021 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7022 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 7023 | 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"); |
| 7024 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 7025 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 7026 | cfgerr++; |
| 7027 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7028 | } |
| 7029 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 7030 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7031 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7032 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 7033 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7034 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7035 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7036 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 7037 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7038 | if (!listener->luid) { |
| 7039 | /* listener ID not set, use automatic numbering with first |
| 7040 | * spare entry starting with next_luid. |
| 7041 | */ |
| 7042 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 7043 | listener->conf.id.key = listener->luid = next_id; |
| 7044 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7045 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7046 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7047 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7048 | /* enable separate counters */ |
| 7049 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 7050 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7051 | if (!listener->name) |
| 7052 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 7053 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 7054 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7055 | if (curproxy->options & PR_O_TCP_NOLING) |
| 7056 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 7057 | if (!listener->maxconn) |
| 7058 | listener->maxconn = curproxy->maxconn; |
| 7059 | if (!listener->backlog) |
| 7060 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7061 | if (!listener->maxaccept) |
| 7062 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 7063 | |
| 7064 | /* we want to have an optimal behaviour on single process mode to |
| 7065 | * maximize the work at once, but in multi-process we want to keep |
| 7066 | * some fairness between processes, so we target half of the max |
| 7067 | * number of events to be balanced over all the processes the proxy |
| 7068 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 7069 | * used to disable the limit. |
| 7070 | */ |
| 7071 | if (listener->maxaccept > 0) { |
| 7072 | if (nbproc > 1) |
| 7073 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 7074 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 7075 | } |
| 7076 | |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7077 | listener->timeout = &curproxy->timeout.client; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 7078 | listener->accept = session_accept; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7079 | listener->handler = process_session; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 7080 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 7081 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 7082 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 7083 | listener->options |= LI_O_TCP_RULES; |
| 7084 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 7085 | if (curproxy->mon_mask.s_addr) |
| 7086 | listener->options |= LI_O_CHK_MONNET; |
| 7087 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7088 | /* smart accept mode is automatic in HTTP mode */ |
| 7089 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7090 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 7091 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 7092 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 7093 | } |
| 7094 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7095 | /* Release unused SSL configs */ |
| 7096 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7097 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7098 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7099 | #ifdef USE_OPENSSL |
| 7100 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7101 | free(bind_conf->ca_file); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7102 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 7103 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 7104 | free(bind_conf->crl_file); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7105 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7106 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 7107 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7108 | if (nbproc > 1) { |
| 7109 | if (curproxy->uri_auth) { |
| 7110 | Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", |
| 7111 | curproxy->id); |
| 7112 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 7113 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 7114 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7115 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7116 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7117 | if (curproxy->appsession_name) { |
| 7118 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 7119 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7120 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7121 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 7122 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 7123 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7124 | } |
| 7125 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 7126 | |
| 7127 | /* create the task associated with the proxy */ |
| 7128 | curproxy->task = task_new(); |
| 7129 | if (curproxy->task) { |
| 7130 | curproxy->task->context = curproxy; |
| 7131 | curproxy->task->process = manage_proxy; |
| 7132 | /* no need to queue, it will be done automatically if some |
| 7133 | * listener gets limited. |
| 7134 | */ |
| 7135 | curproxy->task->expire = TICK_ETERNITY; |
| 7136 | } else { |
| 7137 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 7138 | curproxy->id); |
| 7139 | cfgerr++; |
| 7140 | } |
| 7141 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7142 | curproxy = curproxy->next; |
| 7143 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7144 | |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 7145 | /* Check multi-process mode compatibility */ |
Willy Tarreau | 4e5ed29 | 2014-05-13 13:37:54 +0200 | [diff] [blame] | 7146 | if (global.nbproc > 1 && global.stats_fe) { |
Willy Tarreau | 67c2abc | 2014-05-09 18:48:46 +0200 | [diff] [blame] | 7147 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 7148 | unsigned long mask; |
| 7149 | |
| 7150 | mask = nbits(global.nbproc); |
| 7151 | if (global.stats_fe->bind_proc) |
| 7152 | mask &= global.stats_fe->bind_proc; |
| 7153 | |
| 7154 | if (bind_conf->bind_proc) |
| 7155 | mask &= bind_conf->bind_proc; |
| 7156 | |
| 7157 | /* stop here if more than one process is used */ |
| 7158 | if (popcount(mask) > 1) |
| 7159 | break; |
| 7160 | } |
| 7161 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 7162 | 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] | 7163 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | /* automatically compute fullconn if not set. We must not do it in the |
| 7167 | * loop above because cross-references are not yet fully resolved. |
| 7168 | */ |
| 7169 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 7170 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 7171 | * the possible incoming frontend's maxconns. |
| 7172 | */ |
| 7173 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 7174 | struct proxy *fe; |
| 7175 | int total = 0; |
| 7176 | |
| 7177 | /* sum up the number of maxconns of frontends which |
| 7178 | * reference this backend at least once or which are |
| 7179 | * the same one ('listen'). |
| 7180 | */ |
| 7181 | for (fe = proxy; fe; fe = fe->next) { |
| 7182 | struct switching_rule *rule; |
| 7183 | struct hdr_exp *exp; |
| 7184 | int found = 0; |
| 7185 | |
| 7186 | if (!(fe->cap & PR_CAP_FE)) |
| 7187 | continue; |
| 7188 | |
| 7189 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 7190 | found = 1; |
| 7191 | |
| 7192 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 7193 | found = 1; |
| 7194 | |
| 7195 | /* check if a "use_backend" rule matches */ |
| 7196 | if (!found) { |
| 7197 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7198 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7199 | found = 1; |
| 7200 | break; |
| 7201 | } |
| 7202 | } |
| 7203 | } |
| 7204 | |
| 7205 | /* check if a "reqsetbe" rule matches */ |
| 7206 | for (exp = fe->req_exp; !found && exp; exp = exp->next) { |
| 7207 | if (exp->action == ACT_SETBE && |
| 7208 | (struct proxy *)exp->replace == curproxy) { |
| 7209 | found = 1; |
| 7210 | break; |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | /* now we've checked all possible ways to reference a backend |
| 7215 | * from a frontend. |
| 7216 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7217 | if (!found) |
| 7218 | continue; |
| 7219 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7220 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 7221 | /* we have the sum of the maxconns in <total>. We only |
| 7222 | * keep 10% of that sum to set the default fullconn, with |
| 7223 | * a hard minimum of 1 (to avoid a divide by zero). |
| 7224 | */ |
| 7225 | curproxy->fullconn = (total + 9) / 10; |
| 7226 | if (!curproxy->fullconn) |
| 7227 | curproxy->fullconn = 1; |
| 7228 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7229 | } |
| 7230 | |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7231 | /* initialize stick-tables on backend capable proxies. This must not |
| 7232 | * be done earlier because the data size may be discovered while parsing |
| 7233 | * other proxies. |
| 7234 | */ |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7235 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 5830213 | 2014-02-24 20:59:47 +0100 | [diff] [blame] | 7236 | if (curproxy->state == PR_STSTOPPED) |
| 7237 | continue; |
| 7238 | |
Godbach | 9703e66 | 2013-12-11 21:11:41 +0800 | [diff] [blame] | 7239 | if (!stktable_init(&curproxy->table)) { |
| 7240 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 7241 | cfgerr++; |
| 7242 | } |
| 7243 | } |
Willy Tarreau | 056f568 | 2010-06-06 15:51:11 +0200 | [diff] [blame] | 7244 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7245 | /* |
| 7246 | * Recount currently required checks. |
| 7247 | */ |
| 7248 | |
| 7249 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 7250 | int optnum; |
| 7251 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7252 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 7253 | if (curproxy->options & cfg_opts[optnum].val) |
| 7254 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7255 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 7256 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 7257 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 7258 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7259 | } |
| 7260 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7261 | if (peers) { |
| 7262 | struct peers *curpeers = peers, **last; |
| 7263 | struct peer *p, *pb; |
| 7264 | |
| 7265 | /* Remove all peers sections which don't have a valid listener. |
| 7266 | * This can happen when a peers section is never referenced and |
| 7267 | * does not contain a local peer. |
| 7268 | */ |
| 7269 | last = &peers; |
| 7270 | while (*last) { |
| 7271 | curpeers = *last; |
| 7272 | if (curpeers->peers_fe) { |
| 7273 | last = &curpeers->next; |
| 7274 | continue; |
| 7275 | } |
| 7276 | |
| 7277 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 7278 | curpeers->id, localpeer); |
| 7279 | |
| 7280 | p = curpeers->remote; |
| 7281 | while (p) { |
| 7282 | pb = p->next; |
| 7283 | free(p->id); |
| 7284 | free(p); |
| 7285 | p = pb; |
| 7286 | } |
| 7287 | |
| 7288 | /* Destroy and unlink this curpeers section. |
| 7289 | * Note: curpeers is backed up into *last. |
| 7290 | */ |
| 7291 | free(curpeers->id); |
| 7292 | curpeers = curpeers->next; |
| 7293 | free(*last); |
| 7294 | *last = curpeers; |
| 7295 | } |
| 7296 | } |
| 7297 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7298 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 7299 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 7300 | MEM_F_SHARED); |
| 7301 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7302 | if (cfgerr > 0) |
| 7303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7304 | out: |
| 7305 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7306 | } |
| 7307 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7308 | /* |
| 7309 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 7310 | * parsing sessions. |
| 7311 | */ |
| 7312 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 7313 | { |
| 7314 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 7315 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7316 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 7317 | /* |
| 7318 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 7319 | */ |
| 7320 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 7321 | { |
| 7322 | LIST_DEL(&kwl->list); |
| 7323 | LIST_INIT(&kwl->list); |
| 7324 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7325 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7326 | /* this function register new section in the haproxy configuration file. |
| 7327 | * <section_name> is the name of this new section and <section_parser> |
| 7328 | * is the called parser. If two section declaration have the same name, |
| 7329 | * only the first declared is used. |
| 7330 | */ |
| 7331 | int cfg_register_section(char *section_name, |
| 7332 | int (*section_parser)(const char *, int, char **, int)) |
| 7333 | { |
| 7334 | struct cfg_section *cs; |
| 7335 | |
| 7336 | cs = calloc(1, sizeof(*cs)); |
| 7337 | if (!cs) { |
| 7338 | Alert("register section '%s': out of memory.\n", section_name); |
| 7339 | return 0; |
| 7340 | } |
| 7341 | |
| 7342 | cs->section_name = section_name; |
| 7343 | cs->section_parser = section_parser; |
| 7344 | |
| 7345 | LIST_ADDQ(§ions, &cs->list); |
| 7346 | |
| 7347 | return 1; |
| 7348 | } |
| 7349 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7350 | /* |
| 7351 | * Local variables: |
| 7352 | * c-indent-level: 8 |
| 7353 | * c-basic-offset: 8 |
| 7354 | * End: |
| 7355 | */ |