blob: a262404bb92094518260cbdb3b7f55b42a8781b3 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Configuration parser
3 *
Willy Tarreauff011f22011-01-06 17:51:27 +01004 * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Cyril Bonté1a0191d2014-08-29 20:20:02 +020013#ifdef CONFIG_HAP_CRYPT
14/* This is to have crypt() defined on Linux */
15#define _GNU_SOURCE
16
17#ifdef NEED_CRYPT_H
18/* some platforms such as Solaris need this */
19#include <crypt.h>
20#endif
21#endif /* CONFIG_HAP_CRYPT */
22
Willy Tarreaubaaee002006-06-26 02:48:02 +020023#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <netdb.h>
27#include <ctype.h>
Willy Tarreau95c20ac2007-03-25 15:39:23 +020028#include <pwd.h>
29#include <grp.h>
Willy Tarreau0b4ed902007-03-26 00:18:40 +020030#include <errno.h>
Willy Tarreau3f49b302007-06-11 00:29:26 +020031#include <sys/types.h>
32#include <sys/stat.h>
33#include <fcntl.h>
34#include <unistd.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020035
Willy Tarreau2dd0d472006-06-29 17:53:05 +020036#include <common/cfgparse.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020037#include <common/chunk.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020038#include <common/config.h>
Willy Tarreau058e9072009-07-20 09:30:05 +020039#include <common/errors.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020040#include <common/memory.h>
41#include <common/standard.h>
42#include <common/time.h>
43#include <common/uri_auth.h>
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +010044#include <common/namespace.h>
Emeric Brunc60def82017-09-27 14:59:38 +020045#include <common/hathreads.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020046
47#include <types/capture.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020048#include <types/compression.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020049#include <types/filters.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020050#include <types/global.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010051#include <types/obj_type.h>
Emeric Brun32da3c42010-09-23 18:39:19 +020052#include <types/peers.h>
Simon Horman0d16a402015-01-30 11:22:58 +090053#include <types/mailers.h>
Baptiste Assmann325137d2015-04-13 23:40:55 +020054#include <types/dns.h>
William Lallemand9ed62032016-11-21 17:49:11 +010055#include <types/stats.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020056
Willy Tarreaueb0c6142007-05-07 00:53:22 +020057#include <proto/acl.h>
Christopher Faulet4fce0d82017-09-18 11:57:31 +020058#include <proto/action.h>
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +010059#include <proto/auth.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020060#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020061#include <proto/channel.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020062#include <proto/checks.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020063#include <proto/compression.h>
Baptiste Assmann201c07f2017-05-22 15:17:15 +020064#include <proto/dns.h>
William Lallemand9ed62032016-11-21 17:49:11 +010065#include <proto/stats.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020066#include <proto/filters.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020067#include <proto/frontend.h>
Willy Tarreau34eb6712011-10-24 18:15:04 +020068#include <proto/hdr_idx.h>
Willy Tarreau61c112a2018-10-02 16:43:32 +020069#include <proto/http_rules.h>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020070#include <proto/lb_chash.h>
Willy Tarreauf09c6602012-02-13 17:12:08 +010071#include <proto/lb_fas.h>
Willy Tarreauf89c1872009-10-01 11:19:37 +020072#include <proto/lb_fwlc.h>
73#include <proto/lb_fwrr.h>
74#include <proto/lb_map.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020075#include <proto/listener.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020076#include <proto/log.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020077#include <proto/protocol.h>
Willy Tarreaue6b98942007-10-29 01:09:36 +010078#include <proto/proto_http.h>
Willy Tarreau2b5652f2006-12-31 17:46:05 +010079#include <proto/proxy.h>
Emeric Brun32da3c42010-09-23 18:39:19 +020080#include <proto/peers.h>
Willy Tarreaucd3b0942012-04-27 21:52:18 +020081#include <proto/sample.h>
Willy Tarreau9903f0e2015-04-04 18:50:31 +020082#include <proto/session.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020083#include <proto/server.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020084#include <proto/stream.h>
Emeric Brunb982a3d2010-01-04 15:45:53 +010085#include <proto/stick_table.h>
Willy Tarreau39713102016-11-25 15:49:32 +010086#include <proto/task.h>
87#include <proto/tcp_rules.h>
Olivier Houchard673867c2018-05-25 16:58:52 +020088#include <proto/connection.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020089
90
Willy Tarreauf3c69202006-07-09 16:42:34 +020091/* This is the SSLv3 CLIENT HELLO packet used in conjunction with the
92 * ssl-hello-chk option to ensure that the remote server speaks SSL.
93 *
94 * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details.
95 */
96const char sslv3_client_hello_pkt[] = {
97 "\x16" /* ContentType : 0x16 = Hanshake */
98 "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */
99 "\x00\x79" /* ContentLength : 0x79 bytes after this one */
100 "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */
101 "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */
102 "\x03\x00" /* Hello Version : 0x0300 = v3 */
103 "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */
104 "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */
105 "\x00" /* Session ID length : empty (no session ID) */
106 "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */
107 "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */
108 "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */
109 "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */
110 "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */
111 "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */
112 "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18"
113 "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F"
114 "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33"
115 "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37"
116 "\x00\x38" "\x00\x39" "\x00\x3A"
117 "\x01" /* Compression Length : 0x01 = 1 byte for types */
118 "\x00" /* Compression Type : 0x00 = NULL compression */
119};
120
Willy Tarreau3842f002009-06-14 11:39:52 +0200121/* various keyword modifiers */
122enum kw_mod {
123 KWM_STD = 0, /* normal */
124 KWM_NO, /* "no" prefixed before the keyword */
125 KWM_DEF, /* "default" prefixed before the keyword */
126};
127
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +0100128/* permit to store configuration section */
129struct cfg_section {
130 struct list list;
131 char *section_name;
132 int (*section_parser)(const char *, int, char **, int);
William Lallemandd2ff56d2017-10-16 11:06:50 +0200133 int (*post_section_parser)();
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +0100134};
135
136/* Used to chain configuration sections definitions. This list
137 * stores struct cfg_section
138 */
139struct list sections = LIST_HEAD_INIT(sections);
140
William Lallemand48b4bb42017-10-23 14:36:34 +0200141/* store post configuration parsing */
142
143struct cfg_postparser {
144 struct list list;
145 char *name;
146 int (*func)();
147};
148
149struct list postparsers = LIST_HEAD_INIT(postparsers);
150
Willy Tarreau13943ab2006-12-31 00:24:10 +0100151/* some of the most common options which are also the easiest to handle */
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100152struct cfg_opt {
Willy Tarreau13943ab2006-12-31 00:24:10 +0100153 const char *name;
154 unsigned int val;
155 unsigned int cap;
Willy Tarreau4fee4e92007-01-06 21:09:17 +0100156 unsigned int checks;
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100157 unsigned int mode;
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100158};
159
160/* proxy->options */
161static const struct cfg_opt cfg_opts[] =
Willy Tarreau13943ab2006-12-31 00:24:10 +0100162{
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100163 { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 },
164 { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 },
165 { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP },
166 { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 },
167 { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 },
168 { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100169 { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau9fbe18e2015-05-01 22:42:08 +0200170 { "http-buffer-request", PR_O_WREQ_BODY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau0f228a02015-05-01 15:37:53 +0200171 { "http-ignore-probes", PR_O_IGNORE_PRB, PR_CAP_FE, 0, PR_MODE_HTTP },
Willy Tarreau9420b122013-12-15 18:58:25 +0100172 { "prefer-last-server", PR_O_PREF_LAST, PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100173 { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 },
174 { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 },
175 { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100176 { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 },
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100177#ifdef TPROXY
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100178 { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 },
Cyril Bonté62846b22010-11-01 19:26:00 +0100179#else
180 { "transparent", 0, 0, 0, 0 },
Willy Tarreau8f922fc2007-01-06 21:11:49 +0100181#endif
182
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100183 { NULL, 0, 0, 0, 0 }
Willy Tarreau13943ab2006-12-31 00:24:10 +0100184};
185
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100186/* proxy->options2 */
187static const struct cfg_opt cfg_opts2[] =
188{
189#ifdef CONFIG_HAP_LINUX_SPLICE
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100190 { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 },
191 { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 },
192 { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 },
Cyril Bonté62846b22010-11-01 19:26:00 +0100193#else
194 { "splice-request", 0, 0, 0, 0 },
195 { "splice-response", 0, 0, 0, 0 },
196 { "splice-auto", 0, 0, 0, 0 },
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100197#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100198 { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP },
199 { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP },
200 { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 },
201 { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 },
202 { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 },
203 { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 },
204 { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 },
205 { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 },
206 { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 },
Jamie Gloudon801a0a32012-08-25 00:18:33 -0400207 { "independent-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100208 { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP },
Christopher Faulet98db9762018-09-21 10:25:19 +0200209 { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau96e31212011-05-30 18:10:30 +0200210 { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100211 { NULL, 0, 0, 0 }
212};
Willy Tarreaubaaee002006-06-26 02:48:02 +0200213
Willy Tarreau6daf3432008-01-22 16:44:08 +0100214static char *cursection = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200215static struct proxy defproxy; /* fake proxy used to assign default values on all instances */
216int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */
Willy Tarreau5af24ef2009-03-15 15:23:16 +0100217int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
Christopher Faulet79bdef32016-11-04 22:36:15 +0100218char *cfg_scope = NULL; /* the current scope during the configuration parsing */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200219
Willy Tarreau5b2c3362008-07-09 19:39:06 +0200220/* List head of all known configuration keywords */
221static struct cfg_kw_list cfg_keywords = {
222 .list = LIST_HEAD_INIT(cfg_keywords.list)
223};
224
Willy Tarreaubaaee002006-06-26 02:48:02 +0200225/*
226 * converts <str> to a list of listeners which are dynamically allocated.
227 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
228 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
229 * - <port> is a numerical port from 1 to 65535 ;
230 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
231 * This can be repeated as many times as necessary, separated by a coma.
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200232 * Function returns 1 for success or 0 if error. In case of errors, if <err> is
233 * not NULL, it must be a valid pointer to either NULL or a freeable area that
234 * will be replaced with an error message.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200235 */
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200236int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200237{
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100238 char *next, *dupstr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200239 int port, end;
240
241 next = dupstr = strdup(str);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200242
Willy Tarreaubaaee002006-06-26 02:48:02 +0200243 while (next && *next) {
William Lallemand75ea0a02017-11-15 19:02:58 +0100244 int inherited = 0;
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200245 struct sockaddr_storage *ss2;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100246 int fd = -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200247
248 str = next;
249 /* 1) look for the end of the first address */
Krzysztof Piotr Oledzki52d522b2009-01-27 16:57:08 +0100250 if ((next = strchr(str, ',')) != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200251 *next++ = 0;
252 }
253
Willy Tarreau48ef4c92017-01-06 18:32:38 +0100254 ss2 = str2sa_range(str, NULL, &port, &end, err,
Willy Tarreau72b8c1f2015-09-08 15:50:19 +0200255 curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
Thierry FOURNIER7fe3be72015-09-26 20:03:36 +0200256 NULL, 1);
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100257 if (!ss2)
258 goto fail;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200259
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100260 if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100261 if (!port && !end) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200262 memprintf(err, "missing port number: '%s'\n", str);
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100263 goto fail;
Emeric Bruned760922010-10-22 17:59:25 +0200264 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200265
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100266 if (!port || !end) {
267 memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str);
268 goto fail;
269 }
270
Emeric Bruned760922010-10-22 17:59:25 +0200271 if (port < 1 || port > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200272 memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str);
Emeric Bruned760922010-10-22 17:59:25 +0200273 goto fail;
274 }
275
276 if (end < 1 || end > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200277 memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str);
Emeric Bruned760922010-10-22 17:59:25 +0200278 goto fail;
279 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200280 }
Willy Tarreau40aa0702013-03-10 23:51:38 +0100281 else if (ss2->ss_family == AF_UNSPEC) {
282 socklen_t addr_len;
William Lallemand75ea0a02017-11-15 19:02:58 +0100283 inherited = 1;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100284
285 /* We want to attach to an already bound fd whose number
286 * is in the addr part of ss2 when cast to sockaddr_in.
287 * Note that by definition there is a single listener.
288 * We still have to determine the address family to
289 * register the correct protocol.
290 */
291 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
292 addr_len = sizeof(*ss2);
293 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
294 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
295 goto fail;
296 }
297
298 port = end = get_host_port(ss2);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200299
300 } else if (ss2->ss_family == AF_CUST_SOCKPAIR) {
301 socklen_t addr_len;
302 inherited = 1;
303
304 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
305 addr_len = sizeof(*ss2);
306 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
307 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
308 goto fail;
309 }
310
311 ss2->ss_family = AF_CUST_SOCKPAIR; /* reassign AF_CUST_SOCKPAIR because of getsockname */
312 port = end = 0;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100313 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200314
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100315 /* OK the address looks correct */
William Lallemand75ea0a02017-11-15 19:02:58 +0100316 if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) {
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200317 memprintf(err, "%s for address '%s'.\n", *err, str);
318 goto fail;
319 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200320 } /* end while(next) */
321 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200322 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200323 fail:
324 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200325 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200326}
327
William Lallemand6e62fb62015-04-28 16:55:23 +0200328/*
Willy Tarreauece9b072016-12-21 22:41:44 +0100329 * Report an error in <msg> when there are too many arguments. This version is
330 * intended to be used by keyword parsers so that the message will be included
331 * into the general error message. The index is the current keyword in args.
332 * Return 0 if the number of argument is correct, otherwise build a message and
333 * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The
334 * message may also be null, it will simply not be produced (useful to check only).
335 * <msg> and <err_code> are only affected on error.
336 */
337int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code)
338{
339 int i;
340
341 if (!*args[index + maxarg + 1])
342 return 0;
343
344 if (msg) {
345 *msg = NULL;
346 memprintf(msg, "%s", args[0]);
347 for (i = 1; i <= index; i++)
348 memprintf(msg, "%s %s", *msg, args[i]);
349
350 memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]);
351 }
352 if (err_code)
353 *err_code |= ERR_ALERT | ERR_FATAL;
354
355 return 1;
356}
357
358/*
359 * same as too_many_args_idx with a 0 index
360 */
361int too_many_args(int maxarg, char **args, char **msg, int *err_code)
362{
363 return too_many_args_idx(maxarg, 0, args, msg, err_code);
364}
365
366/*
William Lallemand6e62fb62015-04-28 16:55:23 +0200367 * Report a fatal Alert when there is too much arguments
368 * The index is the current keyword in args
369 * Return 0 if the number of argument is correct, otherwise emit an alert and return 1
370 * Fill err_code with an ERR_ALERT and an ERR_FATAL
371 */
372int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code)
373{
374 char *kw = NULL;
375 int i;
376
377 if (!*args[index + maxarg + 1])
378 return 0;
379
380 memprintf(&kw, "%s", args[0]);
381 for (i = 1; i <= index; i++) {
382 memprintf(&kw, "%s %s", kw, args[i]);
383 }
384
Christopher Faulet767a84b2017-11-24 16:50:31 +0100385 ha_alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]);
William Lallemand6e62fb62015-04-28 16:55:23 +0200386 free(kw);
387 *err_code |= ERR_ALERT | ERR_FATAL;
388 return 1;
389}
390
391/*
392 * same as alertif_too_many_args_idx with a 0 index
393 */
394int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code)
395{
396 return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code);
397}
398
Willy Tarreau620408f2016-10-21 16:37:51 +0200399/* Report a warning if a rule is placed after a 'tcp-request session' rule.
400 * Return 1 if the warning has been emitted, otherwise 0.
401 */
402int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
403{
404 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100405 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
406 file, line, arg);
Willy Tarreau620408f2016-10-21 16:37:51 +0200407 return 1;
408 }
409 return 0;
410}
411
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200412/* Report a warning if a rule is placed after a 'tcp-request content' rule.
413 * Return 1 if the warning has been emitted, otherwise 0.
414 */
415int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
416{
417 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100418 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
419 file, line, arg);
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200420 return 1;
421 }
422 return 0;
423}
424
Willy Tarreau721d8e02017-12-01 18:25:08 +0100425/* Report a warning if a rule is placed after a 'monitor fail' rule.
426 * Return 1 if the warning has been emitted, otherwise 0.
427 */
428int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
429{
430 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
431 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
432 file, line, arg);
433 return 1;
434 }
435 return 0;
436}
437
Willy Tarreau61d18892009-03-31 10:49:21 +0200438/* Report a warning if a rule is placed after a 'block' rule.
439 * Return 1 if the warning has been emitted, otherwise 0.
440 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100441int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200442{
Willy Tarreau353bc9f2014-04-28 22:05:31 +0200443 if (!LIST_ISEMPTY(&proxy->block_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100444 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n",
445 file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200446 return 1;
447 }
448 return 0;
449}
450
Willy Tarreau5002f572014-04-23 01:32:02 +0200451/* Report a warning if a rule is placed after an 'http_request' rule.
452 * Return 1 if the warning has been emitted, otherwise 0.
453 */
454int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
455{
456 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100457 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
458 file, line, arg);
Willy Tarreau5002f572014-04-23 01:32:02 +0200459 return 1;
460 }
461 return 0;
462}
463
Willy Tarreau61d18892009-03-31 10:49:21 +0200464/* Report a warning if a rule is placed after a reqrewrite rule.
465 * Return 1 if the warning has been emitted, otherwise 0.
466 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100467int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200468{
469 if (proxy->req_exp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100470 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n",
471 file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200472 return 1;
473 }
474 return 0;
475}
476
477/* Report a warning if a rule is placed after a reqadd rule.
478 * Return 1 if the warning has been emitted, otherwise 0.
479 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100480int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200481{
Willy Tarreaudeb9ed82010-01-03 21:03:22 +0100482 if (!LIST_ISEMPTY(&proxy->req_add)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100483 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n",
484 file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200485 return 1;
486 }
487 return 0;
488}
489
490/* Report a warning if a rule is placed after a redirect rule.
491 * Return 1 if the warning has been emitted, otherwise 0.
492 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100493int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200494{
495 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100496 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
497 file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200498 return 1;
499 }
500 return 0;
501}
502
503/* Report a warning if a rule is placed after a 'use_backend' rule.
504 * Return 1 if the warning has been emitted, otherwise 0.
505 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100506int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200507{
508 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100509 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
510 file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200511 return 1;
512 }
513 return 0;
514}
515
Willy Tarreauee445d92014-04-23 01:39:04 +0200516/* Report a warning if a rule is placed after a 'use-server' rule.
517 * Return 1 if the warning has been emitted, otherwise 0.
518 */
519int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
520{
521 if (!LIST_ISEMPTY(&proxy->server_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100522 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
523 file, line, arg);
Willy Tarreauee445d92014-04-23 01:39:04 +0200524 return 1;
525 }
526 return 0;
527}
528
Willy Tarreaud39ad442016-11-25 15:16:12 +0100529/* report a warning if a redirect rule is dangerously placed */
530int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau620408f2016-10-21 16:37:51 +0200531{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100532 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200533 warnif_rule_after_use_server(proxy, file, line, arg);
534}
535
Willy Tarreaud39ad442016-11-25 15:16:12 +0100536/* report a warning if a reqadd rule is dangerously placed */
537int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200538{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100539 return warnif_rule_after_redirect(proxy, file, line, arg) ||
540 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200541}
542
Willy Tarreaud39ad442016-11-25 15:16:12 +0100543/* report a warning if a reqxxx rule is dangerously placed */
544int warnif_misplaced_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200545{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100546 return warnif_rule_after_reqadd(proxy, file, line, arg) ||
547 warnif_misplaced_reqadd(proxy, file, line, arg);
Willy Tarreau5002f572014-04-23 01:32:02 +0200548}
549
550/* report a warning if an http-request rule is dangerously placed */
551int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
552{
Willy Tarreau61d18892009-03-31 10:49:21 +0200553 return warnif_rule_after_reqxxx(proxy, file, line, arg) ||
Willy Tarreaud39ad442016-11-25 15:16:12 +0100554 warnif_misplaced_reqxxx(proxy, file, line, arg);;
Willy Tarreau61d18892009-03-31 10:49:21 +0200555}
556
Willy Tarreaud39ad442016-11-25 15:16:12 +0100557/* report a warning if a block rule is dangerously placed */
558int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200559{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100560 return warnif_rule_after_http_req(proxy, file, line, arg) ||
561 warnif_misplaced_http_req(proxy, file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200562}
563
Willy Tarreau721d8e02017-12-01 18:25:08 +0100564/* report a warning if a block rule is dangerously placed */
565int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200566{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100567 return warnif_rule_after_block(proxy, file, line, arg) ||
568 warnif_misplaced_block(proxy, file, line, arg);
Willy Tarreauee445d92014-04-23 01:39:04 +0200569}
570
Willy Tarreau721d8e02017-12-01 18:25:08 +0100571/* report a warning if a "tcp request content" rule is dangerously placed */
572int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
573{
574 return warnif_rule_after_monitor(proxy, file, line, arg) ||
575 warnif_misplaced_monitor(proxy, file, line, arg);
576}
577
Willy Tarreaud39ad442016-11-25 15:16:12 +0100578/* report a warning if a "tcp request session" rule is dangerously placed */
579int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreauee445d92014-04-23 01:39:04 +0200580{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100581 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
582 warnif_misplaced_tcp_cont(proxy, file, line, arg);
583}
584
585/* report a warning if a "tcp request connection" rule is dangerously placed */
586int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
587{
588 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
589 warnif_misplaced_tcp_sess(proxy, file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200590}
591
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100592/* Report it if a request ACL condition uses some keywords that are incompatible
593 * with the place where the ACL is used. It returns either 0 or ERR_WARN so that
594 * its result can be or'ed with err_code. Note that <cond> may be NULL and then
595 * will be ignored.
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100596 */
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100597static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100598{
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100599 const struct acl *acl;
Willy Tarreau93fddf12013-03-31 22:59:32 +0200600 const char *kw;
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100601
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100602 if (!cond)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100603 return 0;
604
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100605 acl = acl_cond_conflicts(cond, where);
606 if (acl) {
607 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100608 ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n",
609 file, line, acl->name, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100610 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100611 ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
612 file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100613 return ERR_WARN;
614 }
615 if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100616 return 0;
617
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100618 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100619 ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
620 file, line, acl->name, kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100621 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100622 ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
623 file, line, kw, sample_ckp_names(where));
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100624 return ERR_WARN;
625}
626
Christopher Faulet62519022017-10-16 15:49:32 +0200627/* Parse a string representing a process number or a set of processes. It must
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100628 * be "all", "odd", "even", a number between 1 and <LONGBITS> or a range with
Christopher Faulet5ab51772017-11-22 11:21:58 +0100629 * two such numbers delimited by a dash ('-'). On success, it returns
630 * 0. otherwise it returns 1 with an error message in <err>.
Christopher Faulet62519022017-10-16 15:49:32 +0200631 *
632 * Note: this function can also be used to parse a thread number or a set of
633 * threads.
634 */
Christopher Faulet26028f62017-11-22 15:01:51 +0100635int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200636{
Christopher Faulet26028f62017-11-22 15:01:51 +0100637 if (autoinc) {
638 *autoinc = 0;
639 if (strncmp(arg, "auto:", 5) == 0) {
640 arg += 5;
641 *autoinc = 1;
642 }
643 }
644
Christopher Faulet62519022017-10-16 15:49:32 +0200645 if (strcmp(arg, "all") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100646 *proc |= ~0UL;
Christopher Faulet62519022017-10-16 15:49:32 +0200647 else if (strcmp(arg, "odd") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100648 *proc |= ~0UL/3UL; /* 0x555....555 */
Christopher Faulet62519022017-10-16 15:49:32 +0200649 else if (strcmp(arg, "even") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100650 *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Christopher Faulet62519022017-10-16 15:49:32 +0200651 else {
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100652 char *dash;
653 unsigned int low, high;
654
Christopher Faulet5ab51772017-11-22 11:21:58 +0100655 if (!isdigit((int)*arg)) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100656 memprintf(err, "'%s' is not a valid number.\n", arg);
Christopher Faulet5ab51772017-11-22 11:21:58 +0100657 return -1;
658 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100659
660 low = high = str2uic(arg);
661 if ((dash = strchr(arg, '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100662 high = ((!*(dash+1)) ? LONGBITS : str2uic(dash + 1));
663
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100664 if (high < low) {
665 unsigned int swap = low;
666 low = high;
667 high = swap;
668 }
669
Christopher Faulet5ab51772017-11-22 11:21:58 +0100670 if (low < 1 || low > LONGBITS || high > LONGBITS) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100671 memprintf(err, "'%s' is not a valid number/range."
672 " It supports numbers from 1 to %d.\n",
Christopher Faulet5ab51772017-11-22 11:21:58 +0100673 arg, LONGBITS);
674 return 1;
675 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100676
677 for (;low <= high; low++)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100678 *proc |= 1UL << (low-1);
Christopher Faulet62519022017-10-16 15:49:32 +0200679 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100680
Christopher Faulet5ab51772017-11-22 11:21:58 +0100681 return 0;
Christopher Faulet62519022017-10-16 15:49:32 +0200682}
683
David Carlier7e351ee2017-12-01 09:14:02 +0000684#ifdef USE_CPU_AFFINITY
Christopher Faulet62519022017-10-16 15:49:32 +0200685/* Parse cpu sets. Each CPU set is either a unique number between 0 and
686 * <LONGBITS> or a range with two such numbers delimited by a dash
687 * ('-'). Multiple CPU numbers or ranges may be specified. On success, it
688 * returns 0. otherwise it returns 1 with an error message in <err>.
689 */
690static unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err)
691{
692 int cur_arg = 0;
693
694 *cpu_set = 0;
695 while (*args[cur_arg]) {
696 char *dash;
697 unsigned int low, high;
698
699 if (!isdigit((int)*args[cur_arg])) {
700 memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]);
701 return -1;
702 }
703
704 low = high = str2uic(args[cur_arg]);
705 if ((dash = strchr(args[cur_arg], '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100706 high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1));
Christopher Faulet62519022017-10-16 15:49:32 +0200707
708 if (high < low) {
709 unsigned int swap = low;
710 low = high;
711 high = swap;
712 }
713
714 if (high >= LONGBITS) {
715 memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1);
716 return 1;
717 }
718
719 while (low <= high)
720 *cpu_set |= 1UL << low++;
721
722 cur_arg++;
723 }
724 return 0;
725}
David Carlier7e351ee2017-12-01 09:14:02 +0000726#endif
727
Willy Tarreaubaaee002006-06-26 02:48:02 +0200728/*
Willy Tarreau058e9072009-07-20 09:30:05 +0200729 * parse a line in a <global> section. Returns the error code, 0 if OK, or
730 * any combination of :
731 * - ERR_ABORT: must abort ASAP
732 * - ERR_FATAL: we can continue parsing but not start the service
733 * - ERR_WARN: a warning has been emitted
734 * - ERR_ALERT: an alert has been emitted
735 * Only the two first ones can stop processing, the two others are just
736 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200737 */
Willy Tarreau3842f002009-06-14 11:39:52 +0200738int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200739{
Willy Tarreau058e9072009-07-20 09:30:05 +0200740 int err_code = 0;
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200741 char *errmsg = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200742
743 if (!strcmp(args[0], "global")) { /* new section */
744 /* no option, nothing special to do */
William Lallemand6e62fb62015-04-28 16:55:23 +0200745 alertif_too_many_args(0, file, linenum, args, &err_code);
Willy Tarreau058e9072009-07-20 09:30:05 +0200746 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200747 }
748 else if (!strcmp(args[0], "daemon")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200749 if (alertif_too_many_args(0, file, linenum, args, &err_code))
750 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200751 global.mode |= MODE_DAEMON;
752 }
William Lallemand095ba4c2017-06-01 17:38:50 +0200753 else if (!strcmp(args[0], "master-worker")) {
William Lallemand69f9b3b2017-06-01 17:38:54 +0200754 if (alertif_too_many_args(1, file, linenum, args, &err_code))
William Lallemand095ba4c2017-06-01 17:38:50 +0200755 goto out;
William Lallemand69f9b3b2017-06-01 17:38:54 +0200756 if (*args[1]) {
William Lallemand4cfede82017-11-24 22:02:34 +0100757 if (!strcmp(args[1], "no-exit-on-failure")) {
758 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
William Lallemand69f9b3b2017-06-01 17:38:54 +0200759 } else {
Tim Duesterhusc578d9a2017-12-05 18:14:12 +0100760 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
William Lallemand69f9b3b2017-06-01 17:38:54 +0200761 err_code |= ERR_ALERT | ERR_FATAL;
762 goto out;
763 }
764 }
William Lallemand095ba4c2017-06-01 17:38:50 +0200765 global.mode |= MODE_MWORKER;
766 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200767 else if (!strcmp(args[0], "debug")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200768 if (alertif_too_many_args(0, file, linenum, args, &err_code))
769 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200770 global.mode |= MODE_DEBUG;
771 }
772 else if (!strcmp(args[0], "noepoll")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200773 if (alertif_too_many_args(0, file, linenum, args, &err_code))
774 goto out;
Willy Tarreau43b78992009-01-25 15:42:27 +0100775 global.tune.options &= ~GTUNE_USE_EPOLL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200776 }
Willy Tarreaude99e992007-04-16 00:53:59 +0200777 else if (!strcmp(args[0], "nokqueue")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200778 if (alertif_too_many_args(0, file, linenum, args, &err_code))
779 goto out;
Willy Tarreau43b78992009-01-25 15:42:27 +0100780 global.tune.options &= ~GTUNE_USE_KQUEUE;
Willy Tarreaude99e992007-04-16 00:53:59 +0200781 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200782 else if (!strcmp(args[0], "nopoll")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200783 if (alertif_too_many_args(0, file, linenum, args, &err_code))
784 goto out;
Willy Tarreau43b78992009-01-25 15:42:27 +0100785 global.tune.options &= ~GTUNE_USE_POLL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200786 }
Willy Tarreau3ab68cf2009-01-25 16:03:28 +0100787 else if (!strcmp(args[0], "nosplice")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200788 if (alertif_too_many_args(0, file, linenum, args, &err_code))
789 goto out;
Willy Tarreau3ab68cf2009-01-25 16:03:28 +0100790 global.tune.options &= ~GTUNE_USE_SPLICE;
791 }
Nenad Merdanovic88afe032014-04-14 15:56:58 +0200792 else if (!strcmp(args[0], "nogetaddrinfo")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200793 if (alertif_too_many_args(0, file, linenum, args, &err_code))
794 goto out;
Nenad Merdanovic88afe032014-04-14 15:56:58 +0200795 global.tune.options &= ~GTUNE_USE_GAI;
796 }
Lukas Tribusa0bcbdc2016-09-12 21:42:20 +0000797 else if (!strcmp(args[0], "noreuseport")) {
798 if (alertif_too_many_args(0, file, linenum, args, &err_code))
799 goto out;
800 global.tune.options &= ~GTUNE_USE_REUSEPORT;
801 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200802 else if (!strcmp(args[0], "quiet")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200803 if (alertif_too_many_args(0, file, linenum, args, &err_code))
804 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200805 global.mode |= MODE_QUIET;
806 }
Olivier Houchard1599b802018-05-24 18:59:04 +0200807 else if (!strcmp(args[0], "tune.runqueue-depth")) {
808 if (alertif_too_many_args(1, file, linenum, args, &err_code))
809 goto out;
810 if (global.tune.runqueue_depth != 0) {
811 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
812 err_code |= ERR_ALERT;
813 goto out;
814 }
815 if (*(args[1]) == 0) {
816 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
817 err_code |= ERR_ALERT | ERR_FATAL;
818 goto out;
819 }
820 global.tune.runqueue_depth = atol(args[1]);
821
822 }
Willy Tarreau1db37712007-06-03 17:16:49 +0200823 else if (!strcmp(args[0], "tune.maxpollevents")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200824 if (alertif_too_many_args(1, file, linenum, args, &err_code))
825 goto out;
Willy Tarreau1db37712007-06-03 17:16:49 +0200826 if (global.tune.maxpollevents != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100827 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200828 err_code |= ERR_ALERT;
829 goto out;
Willy Tarreau1db37712007-06-03 17:16:49 +0200830 }
831 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100832 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200833 err_code |= ERR_ALERT | ERR_FATAL;
834 goto out;
Willy Tarreau1db37712007-06-03 17:16:49 +0200835 }
836 global.tune.maxpollevents = atol(args[1]);
837 }
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100838 else if (!strcmp(args[0], "tune.maxaccept")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200839 if (alertif_too_many_args(1, file, linenum, args, &err_code))
840 goto out;
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100841 if (global.tune.maxaccept != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100842 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200843 err_code |= ERR_ALERT;
844 goto out;
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100845 }
846 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100847 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200848 err_code |= ERR_ALERT | ERR_FATAL;
849 goto out;
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100850 }
851 global.tune.maxaccept = atol(args[1]);
852 }
Willy Tarreau43961d52010-10-04 20:39:20 +0200853 else if (!strcmp(args[0], "tune.chksize")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200854 if (alertif_too_many_args(1, file, linenum, args, &err_code))
855 goto out;
Willy Tarreau43961d52010-10-04 20:39:20 +0200856 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100857 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau43961d52010-10-04 20:39:20 +0200858 err_code |= ERR_ALERT | ERR_FATAL;
859 goto out;
860 }
861 global.tune.chksize = atol(args[1]);
862 }
Willy Tarreaub22fc302015-12-14 12:04:35 +0100863 else if (!strcmp(args[0], "tune.recv_enough")) {
864 if (alertif_too_many_args(1, file, linenum, args, &err_code))
865 goto out;
866 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100867 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreaub22fc302015-12-14 12:04:35 +0100868 err_code |= ERR_ALERT | ERR_FATAL;
869 goto out;
870 }
871 global.tune.recv_enough = atol(args[1]);
872 }
Willy Tarreau33cb0652014-12-23 22:52:37 +0100873 else if (!strcmp(args[0], "tune.buffers.limit")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200874 if (alertif_too_many_args(1, file, linenum, args, &err_code))
875 goto out;
Willy Tarreau33cb0652014-12-23 22:52:37 +0100876 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100877 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau33cb0652014-12-23 22:52:37 +0100878 err_code |= ERR_ALERT | ERR_FATAL;
879 goto out;
880 }
881 global.tune.buf_limit = atol(args[1]);
882 if (global.tune.buf_limit) {
883 if (global.tune.buf_limit < 3)
884 global.tune.buf_limit = 3;
885 if (global.tune.buf_limit <= global.tune.reserved_bufs)
886 global.tune.buf_limit = global.tune.reserved_bufs + 1;
887 }
888 }
Willy Tarreau1058ae72014-12-23 22:40:40 +0100889 else if (!strcmp(args[0], "tune.buffers.reserve")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200890 if (alertif_too_many_args(1, file, linenum, args, &err_code))
891 goto out;
Willy Tarreau1058ae72014-12-23 22:40:40 +0100892 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100893 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau1058ae72014-12-23 22:40:40 +0100894 err_code |= ERR_ALERT | ERR_FATAL;
895 goto out;
896 }
897 global.tune.reserved_bufs = atol(args[1]);
898 if (global.tune.reserved_bufs < 2)
899 global.tune.reserved_bufs = 2;
Willy Tarreau33cb0652014-12-23 22:52:37 +0100900 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
901 global.tune.buf_limit = global.tune.reserved_bufs + 1;
Willy Tarreau1058ae72014-12-23 22:40:40 +0100902 }
Willy Tarreau27a674e2009-08-17 07:23:33 +0200903 else if (!strcmp(args[0], "tune.bufsize")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200904 if (alertif_too_many_args(1, file, linenum, args, &err_code))
905 goto out;
Willy Tarreau27a674e2009-08-17 07:23:33 +0200906 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100907 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau27a674e2009-08-17 07:23:33 +0200908 err_code |= ERR_ALERT | ERR_FATAL;
909 goto out;
910 }
911 global.tune.bufsize = atol(args[1]);
Willy Tarreau9b694542015-09-28 13:49:53 +0200912 if (global.tune.bufsize <= 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100913 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
Willy Tarreau9b694542015-09-28 13:49:53 +0200914 err_code |= ERR_ALERT | ERR_FATAL;
915 goto out;
916 }
Willy Tarreau27a674e2009-08-17 07:23:33 +0200917 }
918 else if (!strcmp(args[0], "tune.maxrewrite")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200919 if (alertif_too_many_args(1, file, linenum, args, &err_code))
920 goto out;
Willy Tarreau27a674e2009-08-17 07:23:33 +0200921 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100922 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau27a674e2009-08-17 07:23:33 +0200923 err_code |= ERR_ALERT | ERR_FATAL;
924 goto out;
925 }
926 global.tune.maxrewrite = atol(args[1]);
Willy Tarreau27097842015-09-28 13:53:23 +0200927 if (global.tune.maxrewrite < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100928 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
Willy Tarreau27097842015-09-28 13:53:23 +0200929 err_code |= ERR_ALERT | ERR_FATAL;
930 goto out;
931 }
Willy Tarreau27a674e2009-08-17 07:23:33 +0200932 }
Willy Tarreau7e312732014-02-12 16:35:14 +0100933 else if (!strcmp(args[0], "tune.idletimer")) {
934 unsigned int idle;
935 const char *res;
936
William Lallemand1a748ae2015-05-19 16:37:23 +0200937 if (alertif_too_many_args(1, file, linenum, args, &err_code))
938 goto out;
Willy Tarreau7e312732014-02-12 16:35:14 +0100939 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100940 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
Willy Tarreau7e312732014-02-12 16:35:14 +0100941 err_code |= ERR_ALERT | ERR_FATAL;
942 goto out;
943 }
944
945 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
946 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100947 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau7e312732014-02-12 16:35:14 +0100948 file, linenum, *res, args[0]);
949 err_code |= ERR_ALERT | ERR_FATAL;
950 goto out;
951 }
952
953 if (idle > 65535) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100954 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
Willy Tarreau7e312732014-02-12 16:35:14 +0100955 err_code |= ERR_ALERT | ERR_FATAL;
956 goto out;
957 }
958 global.tune.idle_timer = idle;
959 }
Willy Tarreaue803de22010-01-21 17:43:04 +0100960 else if (!strcmp(args[0], "tune.rcvbuf.client")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200961 if (alertif_too_many_args(1, file, linenum, args, &err_code))
962 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +0100963 if (global.tune.client_rcvbuf != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100964 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +0100965 err_code |= ERR_ALERT;
966 goto out;
967 }
968 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100969 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +0100970 err_code |= ERR_ALERT | ERR_FATAL;
971 goto out;
972 }
973 global.tune.client_rcvbuf = atol(args[1]);
974 }
975 else if (!strcmp(args[0], "tune.rcvbuf.server")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200976 if (alertif_too_many_args(1, file, linenum, args, &err_code))
977 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +0100978 if (global.tune.server_rcvbuf != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100979 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +0100980 err_code |= ERR_ALERT;
981 goto out;
982 }
983 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100984 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +0100985 err_code |= ERR_ALERT | ERR_FATAL;
986 goto out;
987 }
988 global.tune.server_rcvbuf = atol(args[1]);
989 }
990 else if (!strcmp(args[0], "tune.sndbuf.client")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200991 if (alertif_too_many_args(1, file, linenum, args, &err_code))
992 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +0100993 if (global.tune.client_sndbuf != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100994 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +0100995 err_code |= ERR_ALERT;
996 goto out;
997 }
998 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100999 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +01001000 err_code |= ERR_ALERT | ERR_FATAL;
1001 goto out;
1002 }
1003 global.tune.client_sndbuf = atol(args[1]);
1004 }
1005 else if (!strcmp(args[0], "tune.sndbuf.server")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001006 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1007 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +01001008 if (global.tune.server_sndbuf != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001009 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +01001010 err_code |= ERR_ALERT;
1011 goto out;
1012 }
1013 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001014 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreaue803de22010-01-21 17:43:04 +01001015 err_code |= ERR_ALERT | ERR_FATAL;
1016 goto out;
1017 }
1018 global.tune.server_sndbuf = atol(args[1]);
1019 }
Willy Tarreaubd9a0a72011-10-23 21:14:29 +02001020 else if (!strcmp(args[0], "tune.pipesize")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001021 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1022 goto out;
Willy Tarreaubd9a0a72011-10-23 21:14:29 +02001023 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001024 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreaubd9a0a72011-10-23 21:14:29 +02001025 err_code |= ERR_ALERT | ERR_FATAL;
1026 goto out;
1027 }
1028 global.tune.pipesize = atol(args[1]);
1029 }
Willy Tarreau193b8c62012-11-22 00:17:38 +01001030 else if (!strcmp(args[0], "tune.http.cookielen")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001031 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1032 goto out;
Willy Tarreau193b8c62012-11-22 00:17:38 +01001033 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001034 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau193b8c62012-11-22 00:17:38 +01001035 err_code |= ERR_ALERT | ERR_FATAL;
1036 goto out;
1037 }
1038 global.tune.cookie_len = atol(args[1]) + 1;
1039 }
Stéphane Cottin23e9e932017-05-18 08:58:41 +02001040 else if (!strcmp(args[0], "tune.http.logurilen")) {
1041 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1042 goto out;
1043 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001044 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Stéphane Cottin23e9e932017-05-18 08:58:41 +02001045 err_code |= ERR_ALERT | ERR_FATAL;
1046 goto out;
1047 }
1048 global.tune.requri_len = atol(args[1]) + 1;
1049 }
Willy Tarreauac1932d2011-10-24 19:14:41 +02001050 else if (!strcmp(args[0], "tune.http.maxhdr")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001051 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1052 goto out;
Willy Tarreauac1932d2011-10-24 19:14:41 +02001053 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001054 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreauac1932d2011-10-24 19:14:41 +02001055 err_code |= ERR_ALERT | ERR_FATAL;
1056 goto out;
1057 }
Christopher Faulet50174f32017-06-21 16:31:35 +02001058 global.tune.max_http_hdr = atoi(args[1]);
1059 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001060 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
1061 file, linenum, args[0]);
Christopher Faulet50174f32017-06-21 16:31:35 +02001062 err_code |= ERR_ALERT | ERR_FATAL;
1063 goto out;
1064 }
Willy Tarreauac1932d2011-10-24 19:14:41 +02001065 }
William Lallemandf3747832012-11-09 12:33:10 +01001066 else if (!strcmp(args[0], "tune.comp.maxlevel")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001067 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1068 goto out;
William Lallemandf3747832012-11-09 12:33:10 +01001069 if (*args[1]) {
1070 global.tune.comp_maxlevel = atoi(args[1]);
1071 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001072 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
1073 file, linenum, args[0]);
William Lallemandf3747832012-11-09 12:33:10 +01001074 err_code |= ERR_ALERT | ERR_FATAL;
1075 goto out;
1076 }
1077 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001078 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
1079 file, linenum, args[0]);
William Lallemandf3747832012-11-09 12:33:10 +01001080 err_code |= ERR_ALERT | ERR_FATAL;
1081 goto out;
1082 }
1083 }
Willy Tarreauf3045d22015-04-29 16:24:50 +02001084 else if (!strcmp(args[0], "tune.pattern.cache-size")) {
1085 if (*args[1]) {
1086 global.tune.pattern_cache = atoi(args[1]);
1087 if (global.tune.pattern_cache < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001088 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
1089 file, linenum, args[0]);
Willy Tarreauf3045d22015-04-29 16:24:50 +02001090 err_code |= ERR_ALERT | ERR_FATAL;
1091 goto out;
1092 }
1093 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001094 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
1095 file, linenum, args[0]);
Willy Tarreauf3045d22015-04-29 16:24:50 +02001096 err_code |= ERR_ALERT | ERR_FATAL;
1097 goto out;
1098 }
1099 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001100 else if (!strcmp(args[0], "uid")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001101 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1102 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001103 if (global.uid != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001104 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001105 err_code |= ERR_ALERT;
1106 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001107 }
1108 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001109 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001110 err_code |= ERR_ALERT | ERR_FATAL;
1111 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001112 }
Baptiste Assmann79fee6a2016-03-11 17:10:04 +01001113 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001114 ha_warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]);
Baptiste Assmann79fee6a2016-03-11 17:10:04 +01001115 err_code |= ERR_WARN;
1116 goto out;
1117 }
1118
Willy Tarreaubaaee002006-06-26 02:48:02 +02001119 }
1120 else if (!strcmp(args[0], "gid")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001121 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1122 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001123 if (global.gid != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001124 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001125 err_code |= ERR_ALERT;
1126 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001127 }
1128 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001129 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001130 err_code |= ERR_ALERT | ERR_FATAL;
1131 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001132 }
Baptiste Assmann776e5182016-03-11 17:21:15 +01001133 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001134 ha_warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]);
Baptiste Assmann776e5182016-03-11 17:21:15 +01001135 err_code |= ERR_WARN;
1136 goto out;
1137 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001138 }
Simon Horman98637e52014-06-20 12:30:16 +09001139 else if (!strcmp(args[0], "external-check")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001140 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1141 goto out;
Simon Horman98637e52014-06-20 12:30:16 +09001142 global.external_check = 1;
1143 }
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001144 /* user/group name handling */
1145 else if (!strcmp(args[0], "user")) {
1146 struct passwd *ha_user;
William Lallemand1a748ae2015-05-19 16:37:23 +02001147 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1148 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001149 if (global.uid != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001150 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001151 err_code |= ERR_ALERT;
1152 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001153 }
1154 errno = 0;
1155 ha_user = getpwnam(args[1]);
1156 if (ha_user != NULL) {
1157 global.uid = (int)ha_user->pw_uid;
1158 }
1159 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001160 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
Willy Tarreau058e9072009-07-20 09:30:05 +02001161 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001162 }
1163 }
1164 else if (!strcmp(args[0], "group")) {
1165 struct group *ha_group;
William Lallemand1a748ae2015-05-19 16:37:23 +02001166 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1167 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001168 if (global.gid != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001169 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001170 err_code |= ERR_ALERT;
1171 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001172 }
1173 errno = 0;
1174 ha_group = getgrnam(args[1]);
1175 if (ha_group != NULL) {
1176 global.gid = (int)ha_group->gr_gid;
1177 }
1178 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001179 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
Willy Tarreau058e9072009-07-20 09:30:05 +02001180 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001181 }
1182 }
1183 /* end of user/group name handling*/
Willy Tarreaubaaee002006-06-26 02:48:02 +02001184 else if (!strcmp(args[0], "nbproc")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001185 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1186 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001187 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001188 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001189 err_code |= ERR_ALERT | ERR_FATAL;
1190 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001191 }
1192 global.nbproc = atol(args[1]);
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001193 if (global.nbproc < 1 || global.nbproc > LONGBITS) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001194 ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
1195 file, linenum, args[0], LONGBITS, global.nbproc);
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001196 err_code |= ERR_ALERT | ERR_FATAL;
1197 goto out;
1198 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001199 }
Christopher Fauletbe0faa22017-08-29 15:37:10 +02001200 else if (!strcmp(args[0], "nbthread")) {
1201 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1202 goto out;
1203 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001204 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Christopher Fauletbe0faa22017-08-29 15:37:10 +02001205 err_code |= ERR_ALERT | ERR_FATAL;
1206 goto out;
1207 }
Willy Tarreau0ccd3222018-07-30 10:34:35 +02001208 global.nbthread = parse_nbthread(args[1], &errmsg);
1209 if (!global.nbthread) {
1210 ha_alert("parsing [%s:%d] : '%s' %s.\n",
1211 file, linenum, args[0], errmsg);
Willy Tarreau421f02e2018-01-20 18:19:22 +01001212 err_code |= ERR_ALERT | ERR_FATAL;
1213 goto out;
1214 }
Christopher Fauletbe0faa22017-08-29 15:37:10 +02001215 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001216 else if (!strcmp(args[0], "maxconn")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001217 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1218 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001219 if (global.maxconn != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001220 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001221 err_code |= ERR_ALERT;
1222 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001223 }
1224 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001225 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001226 err_code |= ERR_ALERT | ERR_FATAL;
1227 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001228 }
1229 global.maxconn = atol(args[1]);
1230#ifdef SYSTEM_MAXCONN
1231 if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001232 ha_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);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001233 global.maxconn = DEFAULT_MAXCONN;
Willy Tarreau058e9072009-07-20 09:30:05 +02001234 err_code |= ERR_ALERT;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001235 }
1236#endif /* SYSTEM_MAXCONN */
1237 }
Emeric Brun850efd52014-01-29 12:24:34 +01001238 else if (!strcmp(args[0], "ssl-server-verify")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001239 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1240 goto out;
Emeric Brun850efd52014-01-29 12:24:34 +01001241 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001242 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Emeric Brun850efd52014-01-29 12:24:34 +01001243 err_code |= ERR_ALERT | ERR_FATAL;
1244 goto out;
1245 }
1246 if (strcmp(args[1],"none") == 0)
1247 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
1248 else if (strcmp(args[1],"required") == 0)
1249 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
1250 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001251 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
Emeric Brun850efd52014-01-29 12:24:34 +01001252 err_code |= ERR_ALERT | ERR_FATAL;
1253 goto out;
1254 }
1255 }
Willy Tarreau81c25d02011-09-07 15:17:21 +02001256 else if (!strcmp(args[0], "maxconnrate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001257 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1258 goto out;
Willy Tarreau81c25d02011-09-07 15:17:21 +02001259 if (global.cps_lim != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001260 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau81c25d02011-09-07 15:17:21 +02001261 err_code |= ERR_ALERT;
1262 goto out;
1263 }
1264 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001265 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau81c25d02011-09-07 15:17:21 +02001266 err_code |= ERR_ALERT | ERR_FATAL;
1267 goto out;
1268 }
1269 global.cps_lim = atol(args[1]);
1270 }
Willy Tarreau93e7c002013-10-07 18:51:07 +02001271 else if (!strcmp(args[0], "maxsessrate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001272 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1273 goto out;
Willy Tarreau93e7c002013-10-07 18:51:07 +02001274 if (global.sps_lim != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001275 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau93e7c002013-10-07 18:51:07 +02001276 err_code |= ERR_ALERT;
1277 goto out;
1278 }
1279 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001280 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93e7c002013-10-07 18:51:07 +02001281 err_code |= ERR_ALERT | ERR_FATAL;
1282 goto out;
1283 }
1284 global.sps_lim = atol(args[1]);
1285 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001286 else if (!strcmp(args[0], "maxsslrate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001287 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1288 goto out;
Willy Tarreaue43d5322013-10-07 20:01:52 +02001289 if (global.ssl_lim != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001290 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreaue43d5322013-10-07 20:01:52 +02001291 err_code |= ERR_ALERT;
1292 goto out;
1293 }
1294 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001295 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreaue43d5322013-10-07 20:01:52 +02001296 err_code |= ERR_ALERT | ERR_FATAL;
1297 goto out;
1298 }
1299 global.ssl_lim = atol(args[1]);
1300 }
William Lallemandd85f9172012-11-09 17:05:39 +01001301 else if (!strcmp(args[0], "maxcomprate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001302 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1303 goto out;
William Lallemandd85f9172012-11-09 17:05:39 +01001304 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001305 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
William Lallemandd85f9172012-11-09 17:05:39 +01001306 err_code |= ERR_ALERT | ERR_FATAL;
1307 goto out;
1308 }
1309 global.comp_rate_lim = atoi(args[1]) * 1024;
1310 }
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001311 else if (!strcmp(args[0], "maxpipes")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001312 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1313 goto out;
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001314 if (global.maxpipes != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001315 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001316 err_code |= ERR_ALERT;
1317 goto out;
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001318 }
1319 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001320 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001321 err_code |= ERR_ALERT | ERR_FATAL;
1322 goto out;
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001323 }
1324 global.maxpipes = atol(args[1]);
1325 }
William Lallemand9d5f5482012-11-07 16:12:57 +01001326 else if (!strcmp(args[0], "maxzlibmem")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001327 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1328 goto out;
William Lallemand9d5f5482012-11-07 16:12:57 +01001329 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001330 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
William Lallemand9d5f5482012-11-07 16:12:57 +01001331 err_code |= ERR_ALERT | ERR_FATAL;
1332 goto out;
1333 }
William Lallemande3a7d992012-11-20 11:25:20 +01001334 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
William Lallemand9d5f5482012-11-07 16:12:57 +01001335 }
William Lallemand072a2bf2012-11-20 17:01:01 +01001336 else if (!strcmp(args[0], "maxcompcpuusage")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001337 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1338 goto out;
William Lallemand072a2bf2012-11-20 17:01:01 +01001339 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001340 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
William Lallemand072a2bf2012-11-20 17:01:01 +01001341 err_code |= ERR_ALERT | ERR_FATAL;
1342 goto out;
1343 }
1344 compress_min_idle = 100 - atoi(args[1]);
Willy Tarreaucb2699a2013-01-24 16:25:38 +01001345 if (compress_min_idle > 100) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001346 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
William Lallemand072a2bf2012-11-20 17:01:01 +01001347 err_code |= ERR_ALERT | ERR_FATAL;
1348 goto out;
1349 }
William Lallemand1a748ae2015-05-19 16:37:23 +02001350 }
William Lallemand072a2bf2012-11-20 17:01:01 +01001351
Willy Tarreaubaaee002006-06-26 02:48:02 +02001352 else if (!strcmp(args[0], "ulimit-n")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001353 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1354 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001355 if (global.rlimit_nofile != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001356 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001357 err_code |= ERR_ALERT;
1358 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001359 }
1360 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001361 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001362 err_code |= ERR_ALERT | ERR_FATAL;
1363 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001364 }
1365 global.rlimit_nofile = atol(args[1]);
1366 }
1367 else if (!strcmp(args[0], "chroot")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001368 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1369 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001370 if (global.chroot != NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001371 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001372 err_code |= ERR_ALERT;
1373 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001374 }
1375 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001376 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001377 err_code |= ERR_ALERT | ERR_FATAL;
1378 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001379 }
1380 global.chroot = strdup(args[1]);
1381 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001382 else if (!strcmp(args[0], "description")) {
1383 int i, len=0;
1384 char *d;
1385
1386 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001387 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
1388 file, linenum, args[0]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001389 err_code |= ERR_ALERT | ERR_FATAL;
1390 goto out;
1391 }
1392
Willy Tarreau348acfe2014-04-14 15:00:39 +02001393 for (i = 1; *args[i]; i++)
1394 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001395
1396 if (global.desc)
1397 free(global.desc);
1398
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02001399 global.desc = d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001400
Willy Tarreau348acfe2014-04-14 15:00:39 +02001401 d += snprintf(d, global.desc + len - d, "%s", args[1]);
1402 for (i = 2; *args[i]; i++)
1403 d += snprintf(d, global.desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001404 }
1405 else if (!strcmp(args[0], "node")) {
1406 int i;
1407 char c;
1408
William Lallemand1a748ae2015-05-19 16:37:23 +02001409 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1410 goto out;
1411
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001412 for (i=0; args[1][i]; i++) {
1413 c = args[1][i];
Willy Tarreau88e05812010-03-03 00:16:00 +01001414 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1415 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001416 break;
1417 }
1418
1419 if (!i || args[1][i]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001420 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
1421 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
1422 file, linenum, args[0]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001423 err_code |= ERR_ALERT | ERR_FATAL;
1424 goto out;
1425 }
1426
1427 if (global.node)
1428 free(global.node);
1429
1430 global.node = strdup(args[1]);
1431 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001432 else if (!strcmp(args[0], "pidfile")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001433 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1434 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001435 if (global.pidfile != NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001436 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001437 err_code |= ERR_ALERT;
1438 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001439 }
1440 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001441 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001442 err_code |= ERR_ALERT | ERR_FATAL;
1443 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001444 }
1445 global.pidfile = strdup(args[1]);
1446 }
Emeric Bruned760922010-10-22 17:59:25 +02001447 else if (!strcmp(args[0], "unix-bind")) {
1448 int cur_arg = 1;
1449 while (*(args[cur_arg])) {
1450 if (!strcmp(args[cur_arg], "prefix")) {
1451 if (global.unix_bind.prefix != NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001452 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
Emeric Bruned760922010-10-22 17:59:25 +02001453 err_code |= ERR_ALERT;
1454 cur_arg += 2;
1455 continue;
1456 }
1457
1458 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001459 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
Emeric Bruned760922010-10-22 17:59:25 +02001460 err_code |= ERR_ALERT | ERR_FATAL;
1461 goto out;
1462 }
1463 global.unix_bind.prefix = strdup(args[cur_arg+1]);
1464 cur_arg += 2;
1465 continue;
1466 }
1467
1468 if (!strcmp(args[cur_arg], "mode")) {
1469
1470 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
1471 cur_arg += 2;
1472 continue;
1473 }
1474
1475 if (!strcmp(args[cur_arg], "uid")) {
1476
1477 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
1478 cur_arg += 2;
1479 continue;
1480 }
1481
1482 if (!strcmp(args[cur_arg], "gid")) {
1483
1484 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
1485 cur_arg += 2;
1486 continue;
1487 }
1488
1489 if (!strcmp(args[cur_arg], "user")) {
1490 struct passwd *user;
1491
1492 user = getpwnam(args[cur_arg + 1]);
1493 if (!user) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001494 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
1495 file, linenum, args[0], args[cur_arg + 1 ]);
Emeric Bruned760922010-10-22 17:59:25 +02001496 err_code |= ERR_ALERT | ERR_FATAL;
1497 goto out;
1498 }
1499
1500 global.unix_bind.ux.uid = user->pw_uid;
1501 cur_arg += 2;
1502 continue;
1503 }
1504
1505 if (!strcmp(args[cur_arg], "group")) {
1506 struct group *group;
1507
1508 group = getgrnam(args[cur_arg + 1]);
1509 if (!group) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001510 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
1511 file, linenum, args[0], args[cur_arg + 1 ]);
Emeric Bruned760922010-10-22 17:59:25 +02001512 err_code |= ERR_ALERT | ERR_FATAL;
1513 goto out;
1514 }
1515
1516 global.unix_bind.ux.gid = group->gr_gid;
1517 cur_arg += 2;
1518 continue;
1519 }
1520
Christopher Faulet767a84b2017-11-24 16:50:31 +01001521 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
1522 file, linenum, args[0]);
Emeric Bruned760922010-10-22 17:59:25 +02001523 err_code |= ERR_ALERT | ERR_FATAL;
1524 goto out;
1525 }
1526 }
Christopher Faulet4b0b79d2018-03-26 15:54:32 +02001527 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
1528 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) {
1529 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
Willy Tarreau9b435bc2013-03-06 15:02:49 +01001530 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau9b435bc2013-03-06 15:02:49 +01001531 goto out;
1532 }
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001533 }
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001534 else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */
1535 char *name;
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001536
1537 if (global.log_send_hostname != NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001538 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001539 err_code |= ERR_ALERT;
1540 goto out;
1541 }
1542
1543 if (*(args[1]))
1544 name = args[1];
1545 else
1546 name = hostname;
1547
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001548 free(global.log_send_hostname);
Dragan Dosenc8cfa7b2015-09-28 13:28:21 +02001549 global.log_send_hostname = strdup(name);
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001550 }
Baptiste Assmann6bc89362015-08-23 09:22:25 +02001551 else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */
1552 if (global.server_state_base != NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001553 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Baptiste Assmann6bc89362015-08-23 09:22:25 +02001554 err_code |= ERR_ALERT;
1555 goto out;
1556 }
1557
1558 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001559 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
Baptiste Assmann6bc89362015-08-23 09:22:25 +02001560 err_code |= ERR_FATAL;
1561 goto out;
1562 }
1563
1564 global.server_state_base = strdup(args[1]);
1565 }
Baptiste Assmanne0882262015-08-23 09:54:31 +02001566 else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */
1567 if (global.server_state_file != NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001568 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Baptiste Assmanne0882262015-08-23 09:54:31 +02001569 err_code |= ERR_ALERT;
1570 goto out;
1571 }
1572
1573 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001574 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
Baptiste Assmanne0882262015-08-23 09:54:31 +02001575 err_code |= ERR_FATAL;
1576 goto out;
1577 }
1578
1579 global.server_state_file = strdup(args[1]);
1580 }
Kevinm48936af2010-12-22 16:08:21 +00001581 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
William Lallemand1a748ae2015-05-19 16:37:23 +02001582 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1583 goto out;
Kevinm48936af2010-12-22 16:08:21 +00001584 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001585 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
Kevinm48936af2010-12-22 16:08:21 +00001586 err_code |= ERR_ALERT | ERR_FATAL;
1587 goto out;
1588 }
Dragan Dosen43885c72015-10-01 13:18:13 +02001589 chunk_destroy(&global.log_tag);
1590 chunk_initstr(&global.log_tag, strdup(args[1]));
Kevinm48936af2010-12-22 16:08:21 +00001591 }
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001592 else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */
William Lallemand1a748ae2015-05-19 16:37:23 +02001593 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1594 goto out;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001595 if (global.spread_checks != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001596 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001597 err_code |= ERR_ALERT;
1598 goto out;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001599 }
1600 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001601 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001602 err_code |= ERR_ALERT | ERR_FATAL;
1603 goto out;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001604 }
1605 global.spread_checks = atol(args[1]);
1606 if (global.spread_checks < 0 || global.spread_checks > 50) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001607 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001608 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001609 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001610 }
Willy Tarreau1746eec2014-04-25 10:46:47 +02001611 else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */
1612 const char *err;
1613 unsigned int val;
1614
William Lallemand1a748ae2015-05-19 16:37:23 +02001615 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1616 goto out;
Willy Tarreau1746eec2014-04-25 10:46:47 +02001617 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001618 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
Willy Tarreau1746eec2014-04-25 10:46:47 +02001619 err_code |= ERR_ALERT | ERR_FATAL;
1620 goto out;
1621 }
1622
1623 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
1624 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001625 ha_alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]);
Willy Tarreau1746eec2014-04-25 10:46:47 +02001626 err_code |= ERR_ALERT | ERR_FATAL;
1627 }
1628 global.max_spread_checks = val;
1629 if (global.max_spread_checks < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001630 ha_alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]);
Willy Tarreau1746eec2014-04-25 10:46:47 +02001631 err_code |= ERR_ALERT | ERR_FATAL;
1632 }
1633 }
Christopher Faulet62519022017-10-16 15:49:32 +02001634 else if (strcmp(args[0], "cpu-map") == 0) {
1635 /* map a process list to a CPU set */
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001636#ifdef USE_CPU_AFFINITY
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001637 char *slash;
1638 unsigned long proc = 0, thread = 0, cpus;
1639 int i, j, n, autoinc;
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001640
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +01001641 if (!*args[1] || !*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001642 ha_alert("parsing [%s:%d] : %s expects a process number "
1643 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1644 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
1645 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001646 err_code |= ERR_ALERT | ERR_FATAL;
1647 goto out;
1648 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +01001649
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001650 if ((slash = strchr(args[1], '/')) != NULL)
1651 *slash = 0;
1652
Christopher Faulet26028f62017-11-22 15:01:51 +01001653 if (parse_process_number(args[1], &proc, &autoinc, &errmsg)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001654 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +01001655 err_code |= ERR_ALERT | ERR_FATAL;
1656 goto out;
1657 }
1658
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001659 if (slash) {
1660 if (parse_process_number(slash+1, &thread, NULL, &errmsg)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001661 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001662 err_code |= ERR_ALERT | ERR_FATAL;
1663 goto out;
1664 }
1665 *slash = '/';
1666
Willy Tarreau9504dd62018-10-15 09:37:03 +02001667 if (autoinc && atleast2(proc) && atleast2(thread)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001668 ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
1669 "a process range _AND_ a thread range\n",
1670 file, linenum, args[0], args[1]);
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001671 err_code |= ERR_ALERT | ERR_FATAL;
1672 goto out;
1673 }
1674 }
1675
Christopher Faulet62519022017-10-16 15:49:32 +02001676 if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001677 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
Christopher Faulet62519022017-10-16 15:49:32 +02001678 err_code |= ERR_ALERT | ERR_FATAL;
1679 goto out;
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001680 }
Christopher Faulet26028f62017-11-22 15:01:51 +01001681
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001682 if (autoinc &&
1683 my_popcountl(proc) != my_popcountl(cpus) &&
1684 my_popcountl(thread) != my_popcountl(cpus)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001685 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1686 "must have the same size to be automatically bound\n",
1687 file, linenum, args[0]);
Christopher Faulet26028f62017-11-22 15:01:51 +01001688 err_code |= ERR_ALERT | ERR_FATAL;
1689 goto out;
1690 }
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001691
Christopher Faulet26028f62017-11-22 15:01:51 +01001692 for (i = n = 0; i < LONGBITS; i++) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001693 /* No mapping for this process */
1694 if (!(proc & (1UL << i)))
1695 continue;
1696
1697 /* Mapping at the process level */
1698 if (!thread) {
1699 if (!autoinc)
1700 global.cpu_map.proc[i] = cpus;
1701 else {
1702 n += my_ffsl(cpus >> n);
1703 global.cpu_map.proc[i] = (1UL << (n-1));
1704 }
1705 continue;
1706 }
1707
1708 /* Mapping at the thread level */
Willy Tarreau421f02e2018-01-20 18:19:22 +01001709 for (j = 0; j < MAX_THREADS; j++) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001710 /* Np mapping for this thread */
1711 if (!(thread & (1UL << j)))
1712 continue;
1713
1714 if (!autoinc)
1715 global.cpu_map.thread[i][j] = cpus;
1716 else {
Christopher Faulet26028f62017-11-22 15:01:51 +01001717 n += my_ffsl(cpus >> n);
Christopher Fauletcb6a9452017-11-22 16:50:41 +01001718 global.cpu_map.thread[i][j] = (1UL << (n-1));
Christopher Faulet26028f62017-11-22 15:01:51 +01001719 }
Christopher Faulet26028f62017-11-22 15:01:51 +01001720 }
1721 }
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001722#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001723 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1724 file, linenum, args[0]);
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001725 err_code |= ERR_ALERT | ERR_FATAL;
1726 goto out;
Christopher Faulet62519022017-10-16 15:49:32 +02001727#endif /* ! USE_CPU_AFFINITY */
1728 }
Willy Tarreau1d549722016-02-16 12:41:57 +01001729 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1730 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1731 goto out;
1732
1733 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001734 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
Willy Tarreau1d549722016-02-16 12:41:57 +01001735 err_code |= ERR_ALERT | ERR_FATAL;
1736 goto out;
1737 }
1738
1739 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1740 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001741 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
Willy Tarreau1d549722016-02-16 12:41:57 +01001742 err_code |= ERR_ALERT | ERR_FATAL;
1743 goto out;
1744 }
1745 }
1746 else if (!strcmp(args[0], "unsetenv")) {
1747 int arg;
1748
1749 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001750 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
Willy Tarreau1d549722016-02-16 12:41:57 +01001751 err_code |= ERR_ALERT | ERR_FATAL;
1752 goto out;
1753 }
1754
1755 for (arg = 1; *args[arg]; arg++) {
1756 if (unsetenv(args[arg]) != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001757 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
Willy Tarreau1d549722016-02-16 12:41:57 +01001758 err_code |= ERR_ALERT | ERR_FATAL;
1759 goto out;
1760 }
1761 }
1762 }
1763 else if (!strcmp(args[0], "resetenv")) {
1764 extern char **environ;
1765 char **env = environ;
1766
1767 /* args contain variable names to keep, one per argument */
1768 while (*env) {
1769 int arg;
1770
1771 /* look for current variable in among all those we want to keep */
1772 for (arg = 1; *args[arg]; arg++) {
1773 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1774 (*env)[strlen(args[arg])] == '=')
1775 break;
1776 }
1777
1778 /* delete this variable */
1779 if (!*args[arg]) {
1780 char *delim = strchr(*env, '=');
1781
1782 if (!delim || delim - *env >= trash.size) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001783 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
Willy Tarreau1d549722016-02-16 12:41:57 +01001784 err_code |= ERR_ALERT | ERR_FATAL;
1785 goto out;
1786 }
1787
Willy Tarreau843b7cb2018-07-13 10:54:26 +02001788 memcpy(trash.area, *env, delim - *env);
1789 trash.area[delim - *env] = 0;
Willy Tarreau1d549722016-02-16 12:41:57 +01001790
Willy Tarreau843b7cb2018-07-13 10:54:26 +02001791 if (unsetenv(trash.area) != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001792 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
Willy Tarreau1d549722016-02-16 12:41:57 +01001793 err_code |= ERR_ALERT | ERR_FATAL;
1794 goto out;
1795 }
1796 }
1797 else
1798 env++;
1799 }
1800 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001801 else {
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001802 struct cfg_kw_list *kwl;
1803 int index;
Willy Tarreau39f23b62008-07-09 20:22:56 +02001804 int rc;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001805
1806 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1807 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1808 if (kwl->kw[index].section != CFG_GLOBAL)
1809 continue;
1810 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Willy Tarreau28a47d62012-09-18 20:02:48 +02001811 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
Willy Tarreau39f23b62008-07-09 20:22:56 +02001812 if (rc < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001813 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau058e9072009-07-20 09:30:05 +02001814 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001815 }
Willy Tarreau39f23b62008-07-09 20:22:56 +02001816 else if (rc > 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001817 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau058e9072009-07-20 09:30:05 +02001818 err_code |= ERR_WARN;
1819 goto out;
Willy Tarreau39f23b62008-07-09 20:22:56 +02001820 }
Willy Tarreau058e9072009-07-20 09:30:05 +02001821 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001822 }
1823 }
1824 }
1825
Christopher Faulet767a84b2017-11-24 16:50:31 +01001826 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau058e9072009-07-20 09:30:05 +02001827 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001828 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001829
Willy Tarreau058e9072009-07-20 09:30:05 +02001830 out:
Willy Tarreau0a3dd742012-05-08 19:47:01 +02001831 free(errmsg);
Willy Tarreau058e9072009-07-20 09:30:05 +02001832 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001833}
1834
Willy Tarreau915e1eb2009-06-22 15:48:36 +02001835void init_default_instance()
Willy Tarreaubaaee002006-06-26 02:48:02 +02001836{
Willy Tarreau97cb7802010-01-03 20:23:58 +01001837 init_new_proxy(&defproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001838 defproxy.mode = PR_MODE_TCP;
1839 defproxy.state = PR_STNEW;
1840 defproxy.maxconn = cfg_maxpconn;
1841 defproxy.conn_retries = CONN_RETRIES;
Joseph Lynch726ab712015-05-11 23:25:34 -07001842 defproxy.redispatch_after = 0;
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04001843 defproxy.lbprm.chash.balance_factor = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01001844
Simon Horman66183002013-02-23 10:16:43 +09001845 defproxy.defsrv.check.inter = DEF_CHKINTR;
1846 defproxy.defsrv.check.fastinter = 0;
1847 defproxy.defsrv.check.downinter = 0;
Simon Hormand60d6912013-11-25 10:46:36 +09001848 defproxy.defsrv.agent.inter = DEF_CHKINTR;
1849 defproxy.defsrv.agent.fastinter = 0;
1850 defproxy.defsrv.agent.downinter = 0;
Simon Horman58c32972013-11-25 10:46:38 +09001851 defproxy.defsrv.check.rise = DEF_RISETIME;
1852 defproxy.defsrv.check.fall = DEF_FALLTIME;
1853 defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
1854 defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
Willy Tarreau5b3a2022012-09-28 15:01:02 +02001855 defproxy.defsrv.check.port = 0;
Simon Hormand60d6912013-11-25 10:46:36 +09001856 defproxy.defsrv.agent.port = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01001857 defproxy.defsrv.maxqueue = 0;
1858 defproxy.defsrv.minconn = 0;
1859 defproxy.defsrv.maxconn = 0;
1860 defproxy.defsrv.slowstart = 0;
1861 defproxy.defsrv.onerror = DEF_HANA_ONERR;
1862 defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
1863 defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
Simon Horman64e34162015-02-06 11:11:57 +09001864
1865 defproxy.email_alert.level = LOG_ALERT;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02001866 defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001867}
1868
Willy Tarreauade5ec42010-01-28 19:33:49 +01001869
Willy Tarreau63af98d2014-05-18 08:11:41 +02001870/* This function createss a new req* or rsp* rule to the proxy. It compiles the
1871 * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and
1872 * ERR_FATAL in case of error.
1873 */
Willy Tarreauade5ec42010-01-28 19:33:49 +01001874static int create_cond_regex_rule(const char *file, int line,
1875 struct proxy *px, int dir, int action, int flags,
1876 const char *cmd, const char *reg, const char *repl,
1877 const char **cond_start)
1878{
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001879 struct my_regex *preg = NULL;
Willy Tarreaub7451bb2012-04-27 12:38:15 +02001880 char *errmsg = NULL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001881 const char *err;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001882 char *error;
Willy Tarreau63af98d2014-05-18 08:11:41 +02001883 int ret_code = 0;
Willy Tarreau5321c422010-01-28 20:35:13 +01001884 struct acl_cond *cond = NULL;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001885 int cs;
1886 int cap;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001887
1888 if (px == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001889 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001890 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001891 goto err;
1892 }
1893
1894 if (*reg == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001895 ha_alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001896 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001897 goto err;
1898 }
1899
Christopher Faulet898566e2016-10-26 11:06:28 +02001900 if (warnifnotcap(px, PR_CAP_FE | PR_CAP_BE, file, line, cmd, NULL))
Willy Tarreau63af98d2014-05-18 08:11:41 +02001901 ret_code |= ERR_WARN;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001902
Willy Tarreau5321c422010-01-28 20:35:13 +01001903 if (cond_start &&
1904 (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) {
Christopher Faulet1b421ea2017-09-22 14:38:56 +02001905 if ((cond = build_acl_cond(file, line, &px->acl, px, cond_start, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001906 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
1907 file, line, cmd, errmsg);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001908 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau5321c422010-01-28 20:35:13 +01001909 goto err;
1910 }
1911 }
1912 else if (cond_start && **cond_start) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001913 ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
1914 file, line, cmd, *cond_start);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001915 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau5321c422010-01-28 20:35:13 +01001916 goto err;
1917 }
1918
Willy Tarreau63af98d2014-05-18 08:11:41 +02001919 ret_code |= warnif_cond_conflicts(cond,
Willy Tarreaua91d0a52013-03-25 08:12:18 +01001920 (dir == SMP_OPT_DIR_REQ) ?
1921 ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) :
1922 ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR),
1923 file, line);
Willy Tarreau5321c422010-01-28 20:35:13 +01001924
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001925 preg = calloc(1, sizeof(*preg));
Willy Tarreauade5ec42010-01-28 19:33:49 +01001926 if (!preg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001927 ha_alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001928 ret_code = ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001929 goto err;
1930 }
1931
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001932 cs = !(flags & REG_ICASE);
1933 cap = !(flags & REG_NOSUB);
1934 error = NULL;
1935 if (!regex_comp(reg, preg, cs, cap, &error)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001936 ha_alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001937 free(error);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001938 ret_code = ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001939 goto err;
1940 }
1941
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02001942 err = chain_regex((dir == SMP_OPT_DIR_REQ) ? &px->req_exp : &px->rsp_exp,
Willy Tarreau5321c422010-01-28 20:35:13 +01001943 preg, action, repl ? strdup(repl) : NULL, cond);
Willy Tarreauade5ec42010-01-28 19:33:49 +01001944 if (repl && err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001945 ha_alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n",
1946 file, line, cmd, *err);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001947 ret_code |= ERR_ALERT | ERR_FATAL;
1948 goto err_free;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001949 }
1950
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02001951 if (dir == SMP_OPT_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd))
Willy Tarreau63af98d2014-05-18 08:11:41 +02001952 ret_code |= ERR_WARN;
1953
1954 return ret_code;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001955
Willy Tarreau63af98d2014-05-18 08:11:41 +02001956 err_free:
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001957 regex_free(preg);
Willy Tarreauade5ec42010-01-28 19:33:49 +01001958 err:
1959 free(preg);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001960 free(errmsg);
1961 return ret_code;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001962}
1963
Willy Tarreaubaaee002006-06-26 02:48:02 +02001964/*
William Lallemand51097192015-04-14 16:35:22 +02001965 * Parse a line in a <listen>, <frontend> or <backend> section.
Willy Tarreau93893792009-07-23 13:19:11 +02001966 * Returns the error code, 0 if OK, or any combination of :
1967 * - ERR_ABORT: must abort ASAP
1968 * - ERR_FATAL: we can continue parsing but not start the service
1969 * - ERR_WARN: a warning has been emitted
1970 * - ERR_ALERT: an alert has been emitted
1971 * Only the two first ones can stop processing, the two others are just
1972 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001973 */
Emeric Brun32da3c42010-09-23 18:39:19 +02001974int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
1975{
1976 static struct peers *curpeers = NULL;
1977 struct peer *newpeer = NULL;
1978 const char *err;
Willy Tarreau4348fad2012-09-20 16:48:07 +02001979 struct bind_conf *bind_conf;
1980 struct listener *l;
Emeric Brun32da3c42010-09-23 18:39:19 +02001981 int err_code = 0;
Willy Tarreau902636f2013-03-10 19:44:48 +01001982 char *errmsg = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02001983
1984 if (strcmp(args[0], "peers") == 0) { /* new peers section */
Willy Tarreau0dbbf312013-03-05 11:31:55 +01001985 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001986 ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum);
Willy Tarreau54984722014-02-16 08:20:13 +01001987 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +01001988 goto out;
1989 }
Emeric Brun32da3c42010-09-23 18:39:19 +02001990
William Lallemand6e62fb62015-04-28 16:55:23 +02001991 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1992 goto out;
1993
Emeric Brun32da3c42010-09-23 18:39:19 +02001994 err = invalid_char(args[1]);
1995 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001996 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1997 file, linenum, *err, args[0], args[1]);
Willy Tarreau54984722014-02-16 08:20:13 +01001998 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +01001999 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +02002000 }
2001
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002002 for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +02002003 /*
2004 * If there are two proxies with the same name only following
2005 * combinations are allowed:
2006 */
2007 if (strcmp(curpeers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002008 ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n",
2009 file, linenum, args[1], curpeers->conf.file, curpeers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02002010 err_code |= ERR_ALERT | ERR_FATAL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002011 }
2012 }
2013
Vincent Bernat02779b62016-04-03 13:48:43 +02002014 if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002015 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +02002016 err_code |= ERR_ALERT | ERR_ABORT;
2017 goto out;
2018 }
2019
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002020 curpeers->next = cfg_peers;
2021 cfg_peers = curpeers;
Willy Tarreau8113a5d2012-10-04 08:01:43 +02002022 curpeers->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +02002023 curpeers->conf.line = linenum;
2024 curpeers->last_change = now.tv_sec;
2025 curpeers->id = strdup(args[1]);
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002026 curpeers->state = PR_STNEW;
Emeric Brun32da3c42010-09-23 18:39:19 +02002027 }
2028 else if (strcmp(args[0], "peer") == 0) { /* peer definition */
David du Colombier6f5ccb12011-03-10 22:26:24 +01002029 struct sockaddr_storage *sk;
Willy Tarreau2aa38802013-02-20 19:20:59 +01002030 int port1, port2;
Willy Tarreaub36487e2013-03-10 18:37:42 +01002031 struct protocol *proto;
Emeric Brun32da3c42010-09-23 18:39:19 +02002032
2033 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002034 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
2035 file, linenum, args[0]);
Emeric Brun32da3c42010-09-23 18:39:19 +02002036 err_code |= ERR_ALERT | ERR_FATAL;
2037 goto out;
2038 }
2039
2040 err = invalid_char(args[1]);
2041 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002042 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
2043 file, linenum, *err, args[1]);
Emeric Brun32da3c42010-09-23 18:39:19 +02002044 err_code |= ERR_ALERT | ERR_FATAL;
2045 goto out;
2046 }
2047
Vincent Bernat02779b62016-04-03 13:48:43 +02002048 if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002049 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +02002050 err_code |= ERR_ALERT | ERR_ABORT;
2051 goto out;
2052 }
2053
2054 /* the peers are linked backwards first */
2055 curpeers->count++;
2056 newpeer->next = curpeers->remote;
2057 curpeers->remote = newpeer;
Willy Tarreau8113a5d2012-10-04 08:01:43 +02002058 newpeer->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +02002059 newpeer->conf.line = linenum;
2060
2061 newpeer->last_change = now.tv_sec;
2062 newpeer->id = strdup(args[1]);
2063
Willy Tarreau48ef4c92017-01-06 18:32:38 +01002064 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau2aa38802013-02-20 19:20:59 +01002065 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002066 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Willy Tarreau2aa38802013-02-20 19:20:59 +01002067 err_code |= ERR_ALERT | ERR_FATAL;
2068 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +02002069 }
Willy Tarreaub36487e2013-03-10 18:37:42 +01002070
2071 proto = protocol_by_family(sk->ss_family);
2072 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002073 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2074 file, linenum, args[0], args[1]);
Willy Tarreaub36487e2013-03-10 18:37:42 +01002075 err_code |= ERR_ALERT | ERR_FATAL;
2076 goto out;
2077 }
Willy Tarreau2aa38802013-02-20 19:20:59 +01002078
2079 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002080 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
2081 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +02002082 err_code |= ERR_ALERT | ERR_FATAL;
2083 goto out;
2084 }
2085
Willy Tarreau2aa38802013-02-20 19:20:59 +01002086 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002087 ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
2088 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +02002089 err_code |= ERR_ALERT | ERR_FATAL;
2090 goto out;
2091 }
Willy Tarreau2aa38802013-02-20 19:20:59 +01002092
Emeric Brun32da3c42010-09-23 18:39:19 +02002093 newpeer->addr = *sk;
Willy Tarreaub36487e2013-03-10 18:37:42 +01002094 newpeer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002095 newpeer->xprt = xprt_get(XPRT_RAW);
Willy Tarreaud02394b2012-05-11 18:32:18 +02002096 newpeer->sock_init_arg = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002097 HA_SPIN_INIT(&newpeer->lock);
Willy Tarreau26d8c592012-05-07 18:12:14 +02002098
Emeric Brun32da3c42010-09-23 18:39:19 +02002099 if (strcmp(newpeer->id, localpeer) == 0) {
2100 /* Current is local peer, it define a frontend */
2101 newpeer->local = 1;
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002102 cfg_peers->local = newpeer;
Emeric Brun32da3c42010-09-23 18:39:19 +02002103
2104 if (!curpeers->peers_fe) {
2105 if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002106 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +02002107 err_code |= ERR_ALERT | ERR_ABORT;
2108 goto out;
2109 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002110
Willy Tarreau237250c2011-07-29 01:49:03 +02002111 init_new_proxy(curpeers->peers_fe);
2112 curpeers->peers_fe->parent = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002113 curpeers->peers_fe->id = strdup(args[1]);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002114 curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file);
2115 curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum;
Willy Tarreau91d96282015-03-13 15:47:26 +01002116 peers_setup_frontend(curpeers->peers_fe);
Willy Tarreau4348fad2012-09-20 16:48:07 +02002117
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002118 bind_conf = bind_conf_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW));
Willy Tarreau4348fad2012-09-20 16:48:07 +02002119
Willy Tarreau902636f2013-03-10 19:44:48 +01002120 if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
2121 if (errmsg && *errmsg) {
2122 indent_msg(&errmsg, 2);
Christopher Faulet767a84b2017-11-24 16:50:31 +01002123 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Willy Tarreau4fbb2282012-09-20 20:01:39 +02002124 }
2125 else
Christopher Faulet767a84b2017-11-24 16:50:31 +01002126 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
2127 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +02002128 err_code |= ERR_FATAL;
2129 goto out;
2130 }
Willy Tarreau4348fad2012-09-20 16:48:07 +02002131
2132 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
Willy Tarreauacf3bf92013-01-18 10:51:07 +01002133 l->maxaccept = 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02002134 l->maxconn = curpeers->peers_fe->maxconn;
2135 l->backlog = curpeers->peers_fe->backlog;
Willy Tarreau9903f0e2015-04-04 18:50:31 +02002136 l->accept = session_accept_fd;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02002137 l->analysers |= curpeers->peers_fe->fe_req_ana;
2138 l->default_target = curpeers->peers_fe->default_target;
Willy Tarreau4348fad2012-09-20 16:48:07 +02002139 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
2140 global.maxsock += l->maxconn;
2141 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002142 }
Willy Tarreau8b8fd562013-01-18 11:12:27 +01002143 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002144 ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n",
2145 file, linenum, args[0], args[1],
2146 curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line);
Willy Tarreau8b8fd562013-01-18 11:12:27 +01002147 err_code |= ERR_FATAL;
2148 goto out;
2149 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002150 }
2151 } /* neither "peer" nor "peers" */
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002152 else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
2153 curpeers->state = PR_STSTOPPED;
2154 }
2155 else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
2156 curpeers->state = PR_STNEW;
2157 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002158 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002159 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Emeric Brun32da3c42010-09-23 18:39:19 +02002160 err_code |= ERR_ALERT | ERR_FATAL;
2161 goto out;
2162 }
2163
2164out:
Willy Tarreau902636f2013-03-10 19:44:48 +01002165 free(errmsg);
Emeric Brun32da3c42010-09-23 18:39:19 +02002166 return err_code;
2167}
2168
Baptiste Assmann325137d2015-04-13 23:40:55 +02002169/*
2170 * Parse a <resolvers> section.
2171 * Returns the error code, 0 if OK, or any combination of :
2172 * - ERR_ABORT: must abort ASAP
2173 * - ERR_FATAL: we can continue parsing but not start the service
2174 * - ERR_WARN: a warning has been emitted
2175 * - ERR_ALERT: an alert has been emitted
2176 * Only the two first ones can stop processing, the two others are just
2177 * indicators.
2178 */
2179int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
2180{
2181 static struct dns_resolvers *curr_resolvers = NULL;
2182 struct dns_nameserver *newnameserver = NULL;
2183 const char *err;
2184 int err_code = 0;
2185 char *errmsg = NULL;
2186
2187 if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */
2188 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002189 ha_alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002190 err_code |= ERR_ALERT | ERR_ABORT;
2191 goto out;
2192 }
2193
2194 err = invalid_char(args[1]);
2195 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002196 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
2197 file, linenum, *err, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002198 err_code |= ERR_ALERT | ERR_ABORT;
2199 goto out;
2200 }
2201
2202 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
2203 /* Error if two resolvers owns the same name */
2204 if (strcmp(curr_resolvers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002205 ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n",
2206 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002207 err_code |= ERR_ALERT | ERR_ABORT;
2208 }
2209 }
2210
Vincent Bernat02779b62016-04-03 13:48:43 +02002211 if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002212 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002213 err_code |= ERR_ALERT | ERR_ABORT;
2214 goto out;
2215 }
2216
2217 /* default values */
2218 LIST_ADDQ(&dns_resolvers, &curr_resolvers->list);
2219 curr_resolvers->conf.file = strdup(file);
2220 curr_resolvers->conf.line = linenum;
2221 curr_resolvers->id = strdup(args[1]);
2222 curr_resolvers->query_ids = EB_ROOT;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02002223 /* default maximum response size */
2224 curr_resolvers->accepted_payload_size = 512;
Baptiste Assmann987e16d2016-11-02 22:23:31 +01002225 /* default hold period for nx, other, refuse and timeout is 30s */
2226 curr_resolvers->hold.nx = 30000;
2227 curr_resolvers->hold.other = 30000;
2228 curr_resolvers->hold.refused = 30000;
2229 curr_resolvers->hold.timeout = 30000;
Baptiste Assmann686408b2017-08-18 10:15:42 +02002230 curr_resolvers->hold.obsolete = 0;
Baptiste Assmann325137d2015-04-13 23:40:55 +02002231 /* default hold period for valid is 10s */
Baptiste Assmann4c5490a2015-07-14 21:42:49 +02002232 curr_resolvers->hold.valid = 10000;
Christopher Faulet67957bd2017-09-27 11:00:59 +02002233 curr_resolvers->timeout.resolve = 1000;
2234 curr_resolvers->timeout.retry = 1000;
Baptiste Assmann325137d2015-04-13 23:40:55 +02002235 curr_resolvers->resolve_retries = 3;
Christopher Faulet67957bd2017-09-27 11:00:59 +02002236 curr_resolvers->nb_nameservers = 0;
2237 LIST_INIT(&curr_resolvers->nameservers);
2238 LIST_INIT(&curr_resolvers->resolutions.curr);
2239 LIST_INIT(&curr_resolvers->resolutions.wait);
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002240 HA_SPIN_INIT(&curr_resolvers->lock);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002241 }
2242 else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
2243 struct sockaddr_storage *sk;
2244 int port1, port2;
2245 struct protocol *proto;
2246
2247 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002248 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
2249 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002250 err_code |= ERR_ALERT | ERR_FATAL;
2251 goto out;
2252 }
2253
2254 err = invalid_char(args[1]);
2255 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002256 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
2257 file, linenum, *err, args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002258 err_code |= ERR_ALERT | ERR_FATAL;
2259 goto out;
2260 }
2261
Christopher Faulet67957bd2017-09-27 11:00:59 +02002262 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
Baptiste Assmanna315c552015-11-02 22:55:49 +01002263 /* Error if two resolvers owns the same name */
2264 if (strcmp(newnameserver->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002265 ha_alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n",
Ben Draut44e609b2018-05-29 15:40:08 -06002266 file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line);
Baptiste Assmanna315c552015-11-02 22:55:49 +01002267 err_code |= ERR_ALERT | ERR_FATAL;
2268 }
2269 }
2270
Vincent Bernat02779b62016-04-03 13:48:43 +02002271 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002272 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002273 err_code |= ERR_ALERT | ERR_ABORT;
2274 goto out;
2275 }
2276
2277 /* the nameservers are linked backward first */
Christopher Faulet67957bd2017-09-27 11:00:59 +02002278 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002279 newnameserver->resolvers = curr_resolvers;
2280 newnameserver->conf.file = strdup(file);
2281 newnameserver->conf.line = linenum;
2282 newnameserver->id = strdup(args[1]);
2283
Willy Tarreau48ef4c92017-01-06 18:32:38 +01002284 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002285 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002286 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002287 err_code |= ERR_ALERT | ERR_FATAL;
2288 goto out;
2289 }
2290
2291 proto = protocol_by_family(sk->ss_family);
2292 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002293 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
Baptiste Assmann325137d2015-04-13 23:40:55 +02002294 file, linenum, args[0], args[1]);
2295 err_code |= ERR_ALERT | ERR_FATAL;
2296 goto out;
2297 }
2298
2299 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002300 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
2301 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002302 err_code |= ERR_ALERT | ERR_FATAL;
2303 goto out;
2304 }
2305
Baptiste Assmann7f43fa92016-01-21 00:59:46 +01002306 if (!port1 && !port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002307 ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n",
2308 file, linenum, args[0], args[1]);
Baptiste Assmann7f43fa92016-01-21 00:59:46 +01002309 err_code |= ERR_ALERT | ERR_FATAL;
2310 goto out;
2311 }
2312
Baptiste Assmann325137d2015-04-13 23:40:55 +02002313 newnameserver->addr = *sk;
2314 }
Ben Draut44e609b2018-05-29 15:40:08 -06002315 else if (strcmp(args[0], "parse-resolv-conf") == 0) {
2316 const char *whitespace = "\r\n\t ";
2317 char *resolv_line = NULL;
2318 int resolv_linenum = 0;
2319 FILE *f = NULL;
2320 char *address = NULL;
2321 struct sockaddr_storage *sk = NULL;
2322 struct protocol *proto;
2323 int duplicate_name = 0;
2324
2325 if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) {
2326 ha_alert("parsing [%s:%d] : out of memory.\n",
2327 file, linenum);
2328 err_code |= ERR_ALERT | ERR_FATAL;
2329 goto resolv_out;
2330 }
2331
2332 if ((f = fopen("/etc/resolv.conf", "r")) == NULL) {
2333 ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n",
2334 file, linenum);
2335 err_code |= ERR_ALERT | ERR_FATAL;
2336 goto resolv_out;
2337 }
2338
2339 sk = calloc(1, sizeof(*sk));
2340 if (sk == NULL) {
2341 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n",
2342 resolv_linenum);
2343 err_code |= ERR_ALERT | ERR_FATAL;
2344 goto resolv_out;
2345 }
2346
2347 while (fgets(resolv_line, LINESIZE, f) != NULL) {
2348 resolv_linenum++;
2349 if (strncmp(resolv_line, "nameserver", 10) != 0)
2350 continue;
2351
2352 address = strtok(resolv_line + 10, whitespace);
2353 if (address == resolv_line + 10)
2354 continue;
2355
2356 if (address == NULL) {
2357 ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n",
2358 resolv_linenum);
2359 err_code |= ERR_WARN;
2360 continue;
2361 }
2362
2363 duplicate_name = 0;
2364 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
2365 if (strcmp(newnameserver->id, address) == 0) {
2366 ha_warning("Parsing [/etc/resolv.conf:%d] : generated name for /etc/resolv.conf nameserver '%s' conflicts with another nameserver (declared at %s:%d), it appears to be a duplicate and will be excluded.\n",
2367 resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line);
2368 err_code |= ERR_WARN;
2369 duplicate_name = 1;
2370 }
2371 }
2372
2373 if (duplicate_name)
2374 continue;
2375
2376 memset(sk, 0, sizeof(*sk));
2377 sk = str2ip2(address, sk, 1);
2378 if (!sk) {
2379 ha_warning("parsing [/etc/resolv.conf:%d] : address '%s' could not be recognized, namerserver will be excluded.\n",
2380 resolv_linenum, address);
2381 err_code |= ERR_WARN;
2382 continue;
2383 }
2384
2385 set_host_port(sk, 53);
2386
2387 proto = protocol_by_family(sk->ss_family);
2388 if (!proto || !proto->connect) {
2389 ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n",
2390 resolv_linenum, address);
2391 err_code |= ERR_WARN;
2392 continue;
2393 }
2394
2395 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
2396 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
2397 err_code |= ERR_ALERT | ERR_FATAL;
2398 goto resolv_out;
2399 }
2400
2401 newnameserver->conf.file = strdup("/etc/resolv.conf");
2402 if (newnameserver->conf.file == NULL) {
2403 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
2404 err_code |= ERR_ALERT | ERR_FATAL;
2405 goto resolv_out;
2406 }
2407
2408 newnameserver->id = strdup(address);
2409 if (newnameserver->id == NULL) {
2410 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
2411 err_code |= ERR_ALERT | ERR_FATAL;
2412 goto resolv_out;
2413 }
2414
2415 newnameserver->resolvers = curr_resolvers;
2416 newnameserver->conf.line = resolv_linenum;
2417 newnameserver->addr = *sk;
2418
2419 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
2420 }
2421
2422resolv_out:
2423 free(sk);
2424 free(resolv_line);
2425 if (f != NULL)
2426 fclose(f);
2427 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02002428 else if (strcmp(args[0], "hold") == 0) { /* hold periods */
2429 const char *res;
2430 unsigned int time;
2431
2432 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002433 ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n",
2434 file, linenum, args[0]);
2435 ha_alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n");
Baptiste Assmann325137d2015-04-13 23:40:55 +02002436 err_code |= ERR_ALERT | ERR_FATAL;
2437 goto out;
2438 }
2439 res = parse_time_err(args[2], &time, TIME_UNIT_MS);
2440 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002441 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
2442 file, linenum, *res, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002443 err_code |= ERR_ALERT | ERR_FATAL;
2444 goto out;
2445 }
Baptiste Assmann987e16d2016-11-02 22:23:31 +01002446 if (strcmp(args[1], "nx") == 0)
2447 curr_resolvers->hold.nx = time;
2448 else if (strcmp(args[1], "other") == 0)
2449 curr_resolvers->hold.other = time;
2450 else if (strcmp(args[1], "refused") == 0)
2451 curr_resolvers->hold.refused = time;
2452 else if (strcmp(args[1], "timeout") == 0)
2453 curr_resolvers->hold.timeout = time;
2454 else if (strcmp(args[1], "valid") == 0)
Baptiste Assmann325137d2015-04-13 23:40:55 +02002455 curr_resolvers->hold.valid = time;
Olivier Houcharda8c6db82017-07-06 18:46:47 +02002456 else if (strcmp(args[1], "obsolete") == 0)
2457 curr_resolvers->hold.obsolete = time;
Baptiste Assmann325137d2015-04-13 23:40:55 +02002458 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002459 ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n",
2460 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002461 err_code |= ERR_ALERT | ERR_FATAL;
2462 goto out;
2463 }
2464
2465 }
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02002466 else if (strcmp(args[0], "accepted_payload_size") == 0) {
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02002467 int i = 0;
2468
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02002469 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002470 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
2471 file, linenum, args[0]);
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02002472 err_code |= ERR_ALERT | ERR_FATAL;
2473 goto out;
2474 }
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02002475
2476 i = atoi(args[1]);
Willy Tarreau0c219be2017-08-22 12:01:26 +02002477 if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002478 ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n",
2479 file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]);
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02002480 err_code |= ERR_ALERT | ERR_FATAL;
2481 goto out;
2482 }
2483
2484 curr_resolvers->accepted_payload_size = i;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02002485 }
Baptiste Assmann201c07f2017-05-22 15:17:15 +02002486 else if (strcmp(args[0], "resolution_pool_size") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002487 ha_warning("parsing [%s:%d] : '%s' directive is now deprecated and ignored.\n",
2488 file, linenum, args[0]);
Christopher Faulet67957bd2017-09-27 11:00:59 +02002489 err_code |= ERR_WARN;
2490 goto out;
Baptiste Assmann201c07f2017-05-22 15:17:15 +02002491 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02002492 else if (strcmp(args[0], "resolve_retries") == 0) {
2493 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002494 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
2495 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002496 err_code |= ERR_ALERT | ERR_FATAL;
2497 goto out;
2498 }
2499 curr_resolvers->resolve_retries = atoi(args[1]);
2500 }
2501 else if (strcmp(args[0], "timeout") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002502 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002503 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n",
2504 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002505 err_code |= ERR_ALERT | ERR_FATAL;
2506 goto out;
2507 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02002508 else if (strcmp(args[1], "retry") == 0 ||
2509 strcmp(args[1], "resolve") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002510 const char *res;
Christopher Faulet67957bd2017-09-27 11:00:59 +02002511 unsigned int tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002512
2513 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002514 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
2515 file, linenum, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002516 err_code |= ERR_ALERT | ERR_FATAL;
2517 goto out;
2518 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02002519 res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002520 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002521 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
2522 file, linenum, *res, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002523 err_code |= ERR_ALERT | ERR_FATAL;
2524 goto out;
2525 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02002526 if (args[1][2] == 't')
2527 curr_resolvers->timeout.retry = tout;
2528 else
2529 curr_resolvers->timeout.resolve = tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002530 }
2531 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002532 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n",
2533 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002534 err_code |= ERR_ALERT | ERR_FATAL;
2535 goto out;
2536 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02002537 } /* neither "nameserver" nor "resolvers" */
2538 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002539 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002540 err_code |= ERR_ALERT | ERR_FATAL;
2541 goto out;
2542 }
2543
2544 out:
2545 free(errmsg);
2546 return err_code;
2547}
Simon Horman0d16a402015-01-30 11:22:58 +09002548
2549/*
William Lallemand51097192015-04-14 16:35:22 +02002550 * Parse a line in a <listen>, <frontend> or <backend> section.
Simon Horman0d16a402015-01-30 11:22:58 +09002551 * Returns the error code, 0 if OK, or any combination of :
2552 * - ERR_ABORT: must abort ASAP
2553 * - ERR_FATAL: we can continue parsing but not start the service
2554 * - ERR_WARN: a warning has been emitted
2555 * - ERR_ALERT: an alert has been emitted
2556 * Only the two first ones can stop processing, the two others are just
2557 * indicators.
2558 */
2559int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
2560{
2561 static struct mailers *curmailers = NULL;
2562 struct mailer *newmailer = NULL;
2563 const char *err;
2564 int err_code = 0;
2565 char *errmsg = NULL;
2566
2567 if (strcmp(args[0], "mailers") == 0) { /* new mailers section */
2568 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002569 ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09002570 err_code |= ERR_ALERT | ERR_ABORT;
2571 goto out;
2572 }
2573
2574 err = invalid_char(args[1]);
2575 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002576 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
2577 file, linenum, *err, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09002578 err_code |= ERR_ALERT | ERR_ABORT;
2579 goto out;
2580 }
2581
2582 for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) {
2583 /*
2584 * If there are two proxies with the same name only following
2585 * combinations are allowed:
2586 */
2587 if (strcmp(curmailers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002588 ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n",
2589 file, linenum, args[1], curmailers->conf.file, curmailers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02002590 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman0d16a402015-01-30 11:22:58 +09002591 }
2592 }
2593
Vincent Bernat02779b62016-04-03 13:48:43 +02002594 if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002595 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09002596 err_code |= ERR_ALERT | ERR_ABORT;
2597 goto out;
2598 }
2599
2600 curmailers->next = mailers;
2601 mailers = curmailers;
2602 curmailers->conf.file = strdup(file);
2603 curmailers->conf.line = linenum;
2604 curmailers->id = strdup(args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002605 curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
2606 * But need enough time so that timeouts don't occur
2607 * during tcp procssing. For now just us an arbitrary default. */
Simon Horman0d16a402015-01-30 11:22:58 +09002608 }
2609 else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
2610 struct sockaddr_storage *sk;
2611 int port1, port2;
2612 struct protocol *proto;
2613
2614 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002615 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
2616 file, linenum, args[0]);
Simon Horman0d16a402015-01-30 11:22:58 +09002617 err_code |= ERR_ALERT | ERR_FATAL;
2618 goto out;
2619 }
2620
2621 err = invalid_char(args[1]);
2622 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002623 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
2624 file, linenum, *err, args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09002625 err_code |= ERR_ALERT | ERR_FATAL;
2626 goto out;
2627 }
2628
Vincent Bernat02779b62016-04-03 13:48:43 +02002629 if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002630 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09002631 err_code |= ERR_ALERT | ERR_ABORT;
2632 goto out;
2633 }
2634
2635 /* the mailers are linked backwards first */
2636 curmailers->count++;
2637 newmailer->next = curmailers->mailer_list;
2638 curmailers->mailer_list = newmailer;
2639 newmailer->mailers = curmailers;
2640 newmailer->conf.file = strdup(file);
2641 newmailer->conf.line = linenum;
2642
2643 newmailer->id = strdup(args[1]);
2644
Willy Tarreau48ef4c92017-01-06 18:32:38 +01002645 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Simon Horman0d16a402015-01-30 11:22:58 +09002646 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002647 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Simon Horman0d16a402015-01-30 11:22:58 +09002648 err_code |= ERR_ALERT | ERR_FATAL;
2649 goto out;
2650 }
2651
2652 proto = protocol_by_family(sk->ss_family);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002653 if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002654 ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n",
2655 file, linenum, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09002656 err_code |= ERR_ALERT | ERR_FATAL;
2657 goto out;
2658 }
2659
2660 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002661 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
2662 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09002663 err_code |= ERR_ALERT | ERR_FATAL;
2664 goto out;
2665 }
2666
2667 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002668 ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
2669 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09002670 err_code |= ERR_ALERT | ERR_FATAL;
2671 goto out;
2672 }
2673
2674 newmailer->addr = *sk;
2675 newmailer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002676 newmailer->xprt = xprt_get(XPRT_RAW);
Simon Horman0d16a402015-01-30 11:22:58 +09002677 newmailer->sock_init_arg = NULL;
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002678 }
2679 else if (strcmp(args[0], "timeout") == 0) {
2680 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002681 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
2682 file, linenum, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002683 err_code |= ERR_ALERT | ERR_FATAL;
2684 goto out;
2685 }
2686 else if (strcmp(args[1], "mail") == 0) {
2687 const char *res;
2688 unsigned int timeout_mail;
2689 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002690 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
2691 file, linenum, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002692 err_code |= ERR_ALERT | ERR_FATAL;
2693 goto out;
2694 }
2695 res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
2696 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002697 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
2698 file, linenum, *res, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002699 err_code |= ERR_ALERT | ERR_FATAL;
2700 goto out;
2701 }
2702 if (timeout_mail <= 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002703 ha_alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002704 err_code |= ERR_ALERT | ERR_FATAL;
2705 goto out;
2706 }
2707 curmailers->timeout.mail = timeout_mail;
2708 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002709 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002710 file, linenum, args[0], args[1]);
2711 err_code |= ERR_ALERT | ERR_FATAL;
2712 goto out;
2713 }
2714 }
Simon Horman0d16a402015-01-30 11:22:58 +09002715 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002716 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Simon Horman0d16a402015-01-30 11:22:58 +09002717 err_code |= ERR_ALERT | ERR_FATAL;
2718 goto out;
2719 }
2720
2721out:
2722 free(errmsg);
2723 return err_code;
2724}
2725
Simon Horman9dc49962015-01-30 11:22:59 +09002726static void free_email_alert(struct proxy *p)
2727{
2728 free(p->email_alert.mailers.name);
2729 p->email_alert.mailers.name = NULL;
2730 free(p->email_alert.from);
2731 p->email_alert.from = NULL;
2732 free(p->email_alert.to);
2733 p->email_alert.to = NULL;
2734 free(p->email_alert.myhostname);
2735 p->email_alert.myhostname = NULL;
2736}
2737
Willy Tarreau3842f002009-06-14 11:39:52 +02002738int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
Willy Tarreaubaaee002006-06-26 02:48:02 +02002739{
2740 static struct proxy *curproxy = NULL;
Willy Tarreaub17916e2006-10-15 15:17:57 +02002741 const char *err;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02002742 char *error;
Willy Tarreaub3f32f52007-12-02 22:15:14 +01002743 int rc;
2744 unsigned val;
Willy Tarreau93893792009-07-23 13:19:11 +02002745 int err_code = 0;
Willy Tarreau3ec18a02010-01-28 19:01:34 +01002746 struct acl_cond *cond = NULL;
William Lallemand723b73a2012-02-08 16:37:49 +01002747 struct logsrv *tmplogsrv;
Willy Tarreauf4068b62012-05-08 17:37:49 +02002748 char *errmsg = NULL;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002749 struct bind_conf *bind_conf;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002750
Willy Tarreau977b8e42006-12-29 14:19:17 +01002751 if (!strcmp(args[0], "listen"))
2752 rc = PR_CAP_LISTEN;
2753 else if (!strcmp(args[0], "frontend"))
Christopher Faulet898566e2016-10-26 11:06:28 +02002754 rc = PR_CAP_FE;
Baptiste Assmann22b09d22015-05-01 08:03:04 +02002755 else if (!strcmp(args[0], "backend"))
Christopher Faulet898566e2016-10-26 11:06:28 +02002756 rc = PR_CAP_BE;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002757 else
2758 rc = PR_CAP_NONE;
2759
2760 if (rc != PR_CAP_NONE) { /* new proxy */
Willy Tarreaubaaee002006-06-26 02:48:02 +02002761 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002762 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
2763 " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
2764 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002765 err_code |= ERR_ALERT | ERR_ABORT;
2766 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002767 }
Krzysztof Oledzki365d1cd2007-10-21 02:55:17 +02002768
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01002769 err = invalid_char(args[1]);
2770 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002771 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
2772 file, linenum, *err, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02002773 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01002774 }
2775
Willy Tarreau8f50b682015-05-26 11:45:02 +02002776 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
2777 if (curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002778 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
2779 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
2780 curproxy->id, curproxy->conf.file, curproxy->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02002781 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki365d1cd2007-10-21 02:55:17 +02002782 }
2783
Vincent Bernat02779b62016-04-03 13:48:43 +02002784 if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002785 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02002786 err_code |= ERR_ALERT | ERR_ABORT;
2787 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002788 }
Willy Tarreau5af24ef2009-03-15 15:23:16 +01002789
Willy Tarreau97cb7802010-01-03 20:23:58 +01002790 init_new_proxy(curproxy);
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002791 curproxy->next = proxies_list;
2792 proxies_list = curproxy;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002793 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
2794 curproxy->conf.args.line = curproxy->conf.line = linenum;
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002795 curproxy->last_change = now.tv_sec;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002796 curproxy->id = strdup(args[1]);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002797 curproxy->cap = rc;
Willy Tarreauf79d9502014-03-15 07:22:35 +01002798 proxy_store_name(curproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002799
William Lallemand6e62fb62015-04-28 16:55:23 +02002800 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
2801 if (curproxy->cap & PR_CAP_FE)
Christopher Faulet767a84b2017-11-24 16:50:31 +01002802 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
William Lallemand6e62fb62015-04-28 16:55:23 +02002803 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002804 }
2805
2806 /* set default values */
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002807 memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv));
Willy Tarreau70160202010-04-07 16:06:40 +02002808 curproxy->defsrv.id = "default-server";
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002809
Willy Tarreaubaaee002006-06-26 02:48:02 +02002810 curproxy->state = defproxy.state;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002811 curproxy->options = defproxy.options;
Willy Tarreau66aa61f2009-01-18 21:44:07 +01002812 curproxy->options2 = defproxy.options2;
Willy Tarreau84b57da2009-06-14 11:10:45 +02002813 curproxy->no_options = defproxy.no_options;
2814 curproxy->no_options2 = defproxy.no_options2;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002815 curproxy->bind_proc = defproxy.bind_proc;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02002816 curproxy->except_net = defproxy.except_net;
2817 curproxy->except_mask = defproxy.except_mask;
Maik Broemme36db02e2009-05-08 17:02:07 +02002818 curproxy->except_to = defproxy.except_to;
Maik Broemme2850cb42009-04-17 18:53:21 +02002819 curproxy->except_mask_to = defproxy.except_mask_to;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002820
Willy Tarreau79f5fe82008-08-23 08:18:21 +02002821 if (defproxy.fwdfor_hdr_len) {
2822 curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len;
2823 curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name);
2824 }
2825
Willy Tarreaub86db342009-11-30 11:50:16 +01002826 if (defproxy.orgto_hdr_len) {
2827 curproxy->orgto_hdr_len = defproxy.orgto_hdr_len;
2828 curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name);
2829 }
2830
Mark Lamourinec2247f02012-01-04 13:02:01 -05002831 if (defproxy.server_id_hdr_len) {
2832 curproxy->server_id_hdr_len = defproxy.server_id_hdr_len;
2833 curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name);
2834 }
2835
Willy Tarreau977b8e42006-12-29 14:19:17 +01002836 if (curproxy->cap & PR_CAP_FE) {
2837 curproxy->maxconn = defproxy.maxconn;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01002838 curproxy->backlog = defproxy.backlog;
Willy Tarreau13a34bd2009-05-10 18:52:49 +02002839 curproxy->fe_sps_lim = defproxy.fe_sps_lim;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002840
2841 /* initialize error relocations */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002842 for (rc = 0; rc < HTTP_ERR_SIZE; rc++)
2843 chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002844
2845 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
2846 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002847
Willy Tarreau977b8e42006-12-29 14:19:17 +01002848 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreau743c1282014-11-18 15:04:29 +01002849 curproxy->lbprm.algo = defproxy.lbprm.algo;
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04002850 curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002851 curproxy->fullconn = defproxy.fullconn;
2852 curproxy->conn_retries = defproxy.conn_retries;
Joseph Lynch726ab712015-05-11 23:25:34 -07002853 curproxy->redispatch_after = defproxy.redispatch_after;
Willy Tarreauc35362a2014-04-25 13:58:37 +02002854 curproxy->max_ka_queue = defproxy.max_ka_queue;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002855
Willy Tarreauaa2f3892010-10-22 16:15:31 +02002856 if (defproxy.check_req) {
2857 curproxy->check_req = calloc(1, defproxy.check_len);
2858 memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len);
2859 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002860 curproxy->check_len = defproxy.check_len;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002861
Willy Tarreau1ee51a62011-08-19 20:04:17 +02002862 if (defproxy.expect_str) {
2863 curproxy->expect_str = strdup(defproxy.expect_str);
2864 if (defproxy.expect_regex) {
2865 /* note: this regex is known to be valid */
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02002866 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
2867 regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL);
Willy Tarreau1ee51a62011-08-19 20:04:17 +02002868 }
2869 }
2870
Willy Tarreau67402132012-05-31 20:40:20 +02002871 curproxy->ck_opts = defproxy.ck_opts;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002872 if (defproxy.cookie_name)
2873 curproxy->cookie_name = strdup(defproxy.cookie_name);
2874 curproxy->cookie_len = defproxy.cookie_len;
Olivier Houchard4e694042017-03-14 20:01:29 +01002875
2876 if (defproxy.dyncookie_key)
2877 curproxy->dyncookie_key = strdup(defproxy.dyncookie_key);
Willy Tarreau4d187ac2009-12-03 23:13:06 +01002878 if (defproxy.cookie_domain)
2879 curproxy->cookie_domain = strdup(defproxy.cookie_domain);
Willy Tarreau01732802007-11-01 22:48:15 +01002880
Willy Tarreau31936852010-10-06 16:59:56 +02002881 if (defproxy.cookie_maxidle)
2882 curproxy->cookie_maxidle = defproxy.cookie_maxidle;
2883
2884 if (defproxy.cookie_maxlife)
2885 curproxy->cookie_maxlife = defproxy.cookie_maxlife;
2886
Emeric Brun647caf12009-06-30 17:57:00 +02002887 if (defproxy.rdp_cookie_name)
2888 curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name);
2889 curproxy->rdp_cookie_len = defproxy.rdp_cookie_len;
2890
Willy Tarreau01732802007-11-01 22:48:15 +01002891 if (defproxy.url_param_name)
2892 curproxy->url_param_name = strdup(defproxy.url_param_name);
2893 curproxy->url_param_len = defproxy.url_param_len;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01002894
Benoitaffb4812009-03-25 13:02:10 +01002895 if (defproxy.hh_name)
2896 curproxy->hh_name = strdup(defproxy.hh_name);
2897 curproxy->hh_len = defproxy.hh_len;
2898 curproxy->hh_match_domain = defproxy.hh_match_domain;
2899
Willy Tarreauef9a3602012-12-08 22:29:20 +01002900 if (defproxy.conn_src.iface_name)
2901 curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name);
2902 curproxy->conn_src.iface_len = defproxy.conn_src.iface_len;
Godbach9f048532013-04-23 15:27:57 +08002903 curproxy->conn_src.opts = defproxy.conn_src.opts;
Willy Tarreau29fbe512015-08-20 19:35:14 +02002904#if defined(CONFIG_HAP_TRANSPARENT)
Godbach9f048532013-04-23 15:27:57 +08002905 curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr;
Willy Tarreauc621d362013-04-25 17:35:22 +02002906#endif
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02002907 curproxy->load_server_state_from_file = defproxy.load_server_state_from_file;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002908 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002909
Willy Tarreau3b6b1a92009-07-23 13:24:23 +02002910 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002911 if (defproxy.capture_name)
2912 curproxy->capture_name = strdup(defproxy.capture_name);
2913 curproxy->capture_namelen = defproxy.capture_namelen;
2914 curproxy->capture_len = defproxy.capture_len;
Willy Tarreau0f772532006-12-23 20:51:41 +01002915 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002916
Willy Tarreau977b8e42006-12-29 14:19:17 +01002917 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002918 curproxy->timeout.client = defproxy.timeout.client;
Simone Gotti1b48cc92014-06-11 12:25:28 +02002919 curproxy->timeout.clientfin = defproxy.timeout.clientfin;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002920 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau036fae02008-01-06 13:24:40 +01002921 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
Willy Tarreaub16a5742010-01-10 14:46:16 +01002922 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002923 curproxy->mon_net = defproxy.mon_net;
2924 curproxy->mon_mask = defproxy.mon_mask;
2925 if (defproxy.monitor_uri)
2926 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
2927 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002928 if (defproxy.defbe.name)
2929 curproxy->defbe.name = strdup(defproxy.defbe.name);
Willy Tarreau99a7ca22012-05-31 19:39:23 +02002930
2931 /* get either a pointer to the logformat string or a copy of it */
Willy Tarreau62a61232013-04-12 18:13:46 +02002932 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
2933 if (curproxy->conf.logformat_string &&
2934 curproxy->conf.logformat_string != default_http_log_format &&
2935 curproxy->conf.logformat_string != default_tcp_log_format &&
2936 curproxy->conf.logformat_string != clf_http_log_format)
2937 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
2938
2939 if (defproxy.conf.lfs_file) {
2940 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
2941 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
2942 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002943
2944 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
2945 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
2946 if (curproxy->conf.logformat_sd_string &&
2947 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2948 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
2949
2950 if (defproxy.conf.lfsd_file) {
2951 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
2952 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
2953 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002954 }
2955
2956 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002957 curproxy->timeout.connect = defproxy.timeout.connect;
2958 curproxy->timeout.server = defproxy.timeout.server;
Simone Gotti1b48cc92014-06-11 12:25:28 +02002959 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01002960 curproxy->timeout.check = defproxy.timeout.check;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002961 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau51c9bde2008-01-06 13:40:03 +01002962 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreaucd7afc02009-07-12 10:03:17 +02002963 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
Willy Tarreaub16a5742010-01-10 14:46:16 +01002964 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreauce887fd2012-05-12 12:50:00 +02002965 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
Willy Tarreauef9a3602012-12-08 22:29:20 +01002966 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002967 }
2968
Willy Tarreaubaaee002006-06-26 02:48:02 +02002969 curproxy->mode = defproxy.mode;
Willy Tarreaued2119c2014-04-24 22:10:39 +02002970 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
William Lallemand0f99e342011-10-12 17:50:54 +02002971
2972 /* copy default logsrvs to curproxy */
William Lallemand723b73a2012-02-08 16:37:49 +01002973 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
Vincent Bernat02779b62016-04-03 13:48:43 +02002974 struct logsrv *node = malloc(sizeof(*node));
William Lallemand723b73a2012-02-08 16:37:49 +01002975 memcpy(node, tmplogsrv, sizeof(struct logsrv));
Christopher Faulet28ac0992018-03-26 16:09:19 +02002976 node->ref = tmplogsrv->ref;
William Lallemand0f99e342011-10-12 17:50:54 +02002977 LIST_INIT(&node->list);
2978 LIST_ADDQ(&curproxy->logsrvs, &node->list);
2979 }
2980
Willy Tarreau62a61232013-04-12 18:13:46 +02002981 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
2982 if (curproxy->conf.uniqueid_format_string)
2983 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
2984
Dragan Dosen43885c72015-10-01 13:18:13 +02002985 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
Willy Tarreau094af4e2015-01-07 15:03:42 +01002986
Willy Tarreau62a61232013-04-12 18:13:46 +02002987 if (defproxy.conf.uif_file) {
2988 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
2989 curproxy->conf.uif_line = defproxy.conf.uif_line;
2990 }
William Lallemanda73203e2012-03-12 12:48:57 +01002991
2992 /* copy default header unique id */
2993 if (defproxy.header_unique_id)
2994 curproxy->header_unique_id = strdup(defproxy.header_unique_id);
2995
William Lallemand82fe75c2012-10-23 10:25:10 +02002996 /* default compression options */
2997 if (defproxy.comp != NULL) {
2998 curproxy->comp = calloc(1, sizeof(struct comp));
2999 curproxy->comp->algos = defproxy.comp->algos;
3000 curproxy->comp->types = defproxy.comp->types;
3001 }
3002
Willy Tarreaubaaee002006-06-26 02:48:02 +02003003 curproxy->grace = defproxy.grace;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003004 curproxy->conf.used_listener_id = EB_ROOT;
3005 curproxy->conf.used_server_id = EB_ROOT;
Willy Tarreau1c47f852006-07-09 08:22:27 +02003006
Simon Horman98637e52014-06-20 12:30:16 +09003007 if (defproxy.check_path)
3008 curproxy->check_path = strdup(defproxy.check_path);
3009 if (defproxy.check_command)
3010 curproxy->check_command = strdup(defproxy.check_command);
3011
Simon Horman9dc49962015-01-30 11:22:59 +09003012 if (defproxy.email_alert.mailers.name)
3013 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
3014 if (defproxy.email_alert.from)
3015 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
3016 if (defproxy.email_alert.to)
3017 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
3018 if (defproxy.email_alert.myhostname)
3019 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
Simon Horman64e34162015-02-06 11:11:57 +09003020 curproxy->email_alert.level = defproxy.email_alert.level;
Cyril Bonté7e084702015-12-04 03:07:06 +01003021 curproxy->email_alert.set = defproxy.email_alert.set;
Simon Horman9dc49962015-01-30 11:22:59 +09003022
Willy Tarreau93893792009-07-23 13:19:11 +02003023 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003024 }
3025 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
3026 /* some variables may have already been initialized earlier */
Willy Tarreau5fdfb912007-01-01 23:11:07 +01003027 /* FIXME-20070101: we should do this too at the end of the
3028 * config parsing to free all default values.
3029 */
William Lallemand6e62fb62015-04-28 16:55:23 +02003030 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
3031 err_code |= ERR_ABORT;
3032 goto out;
3033 }
3034
Willy Tarreaua534fea2008-08-03 12:19:50 +02003035 free(defproxy.check_req);
Simon Horman98637e52014-06-20 12:30:16 +09003036 free(defproxy.check_command);
3037 free(defproxy.check_path);
Willy Tarreaua534fea2008-08-03 12:19:50 +02003038 free(defproxy.cookie_name);
Emeric Brun647caf12009-06-30 17:57:00 +02003039 free(defproxy.rdp_cookie_name);
Olivier Houchard4e694042017-03-14 20:01:29 +01003040 free(defproxy.dyncookie_key);
Willy Tarreau4d187ac2009-12-03 23:13:06 +01003041 free(defproxy.cookie_domain);
Willy Tarreaua534fea2008-08-03 12:19:50 +02003042 free(defproxy.url_param_name);
Benoitaffb4812009-03-25 13:02:10 +01003043 free(defproxy.hh_name);
Willy Tarreaua534fea2008-08-03 12:19:50 +02003044 free(defproxy.capture_name);
3045 free(defproxy.monitor_uri);
3046 free(defproxy.defbe.name);
Willy Tarreauef9a3602012-12-08 22:29:20 +01003047 free(defproxy.conn_src.iface_name);
Willy Tarreau79f5fe82008-08-23 08:18:21 +02003048 free(defproxy.fwdfor_hdr_name);
3049 defproxy.fwdfor_hdr_len = 0;
Willy Tarreaub86db342009-11-30 11:50:16 +01003050 free(defproxy.orgto_hdr_name);
3051 defproxy.orgto_hdr_len = 0;
Mark Lamourinec2247f02012-01-04 13:02:01 -05003052 free(defproxy.server_id_hdr_name);
3053 defproxy.server_id_hdr_len = 0;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02003054 free(defproxy.expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02003055 if (defproxy.expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02003056 regex_free(defproxy.expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02003057 free(defproxy.expect_regex);
3058 defproxy.expect_regex = NULL;
3059 }
Willy Tarreau0f772532006-12-23 20:51:41 +01003060
Willy Tarreau62a61232013-04-12 18:13:46 +02003061 if (defproxy.conf.logformat_string != default_http_log_format &&
3062 defproxy.conf.logformat_string != default_tcp_log_format &&
3063 defproxy.conf.logformat_string != clf_http_log_format)
3064 free(defproxy.conf.logformat_string);
Willy Tarreau196729e2012-05-31 19:30:26 +02003065
Willy Tarreau62a61232013-04-12 18:13:46 +02003066 free(defproxy.conf.uniqueid_format_string);
3067 free(defproxy.conf.lfs_file);
3068 free(defproxy.conf.uif_file);
Dragan Dosen43885c72015-10-01 13:18:13 +02003069 chunk_destroy(&defproxy.log_tag);
Simon Horman9dc49962015-01-30 11:22:59 +09003070 free_email_alert(&defproxy);
Willy Tarreau196729e2012-05-31 19:30:26 +02003071
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003072 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
3073 free(defproxy.conf.logformat_sd_string);
3074 free(defproxy.conf.lfsd_file);
3075
Willy Tarreaua534fea2008-08-03 12:19:50 +02003076 for (rc = 0; rc < HTTP_ERR_SIZE; rc++)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003077 chunk_destroy(&defproxy.errmsg[rc]);
Willy Tarreau0f772532006-12-23 20:51:41 +01003078
Willy Tarreaubaaee002006-06-26 02:48:02 +02003079 /* we cannot free uri_auth because it might already be used */
3080 init_default_instance();
3081 curproxy = &defproxy;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02003082 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
3083 curproxy->conf.args.line = curproxy->conf.line = linenum;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003084 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
Willy Tarreau93893792009-07-23 13:19:11 +02003085 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003086 }
3087 else if (curproxy == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003088 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003089 err_code |= ERR_ALERT | ERR_FATAL;
3090 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003091 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02003092
3093 /* update the current file and line being parsed */
3094 curproxy->conf.args.file = curproxy->conf.file;
3095 curproxy->conf.args.line = linenum;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003096
3097 /* Now let's parse the proxy-specific keywords */
Frédéric Lécailleb82f7422017-04-13 18:24:23 +02003098 if (!strcmp(args[0], "server") ||
3099 !strcmp(args[0], "default-server") ||
3100 !strcmp(args[0], "server-template")) {
Willy Tarreau272adea2014-03-31 10:39:59 +02003101 err_code |= parse_server(file, linenum, args, curproxy, &defproxy);
3102 if (err_code & ERR_FATAL)
3103 goto out;
3104 }
3105 else if (!strcmp(args[0], "bind")) { /* new listen addresses */
Willy Tarreau4348fad2012-09-20 16:48:07 +02003106 struct listener *l;
Willy Tarreau5e6e2042009-02-04 17:19:29 +01003107 int cur_arg;
3108
Willy Tarreaubaaee002006-06-26 02:48:02 +02003109 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003110 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003111 err_code |= ERR_ALERT | ERR_FATAL;
3112 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003113 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01003114 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003115 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003116
Willy Tarreau24709282013-03-10 21:32:12 +01003117 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003118 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
3119 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003120 err_code |= ERR_ALERT | ERR_FATAL;
3121 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003122 }
Willy Tarreaub1e52e82008-01-13 14:49:51 +01003123
Willy Tarreaua261e9b2016-12-22 20:44:00 +01003124 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Willy Tarreau8dc21fa2013-01-24 15:17:20 +01003125
3126 /* use default settings for unix sockets */
3127 bind_conf->ux.uid = global.unix_bind.ux.uid;
3128 bind_conf->ux.gid = global.unix_bind.ux.gid;
3129 bind_conf->ux.mode = global.unix_bind.ux.mode;
Willy Tarreau8a956912010-10-15 14:27:08 +02003130
3131 /* NOTE: the following line might create several listeners if there
3132 * are comma-separated IPs or port ranges. So all further processing
3133 * will have to be applied to all listeners created after last_listen.
3134 */
Willy Tarreau902636f2013-03-10 19:44:48 +01003135 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
3136 if (errmsg && *errmsg) {
3137 indent_msg(&errmsg, 2);
Christopher Faulet767a84b2017-11-24 16:50:31 +01003138 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
Willy Tarreau4fbb2282012-09-20 20:01:39 +02003139 }
3140 else
Christopher Faulet767a84b2017-11-24 16:50:31 +01003141 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
3142 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003143 err_code |= ERR_ALERT | ERR_FATAL;
3144 goto out;
3145 }
Willy Tarreau5e6e2042009-02-04 17:19:29 +01003146
Willy Tarreau4348fad2012-09-20 16:48:07 +02003147 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
3148 /* Set default global rights and owner for unix bind */
Willy Tarreauc8b11092011-02-16 11:08:57 +01003149 global.maxsock++;
Willy Tarreau90a570f2009-10-04 20:54:54 +02003150 }
3151
Willy Tarreau5e6e2042009-02-04 17:19:29 +01003152 cur_arg = 2;
3153 while (*(args[cur_arg])) {
Willy Tarreau8638f482012-09-18 18:01:17 +02003154 static int bind_dumped;
Willy Tarreau26982662012-09-12 23:17:10 +02003155 struct bind_kw *kw;
Willy Tarreau8638f482012-09-18 18:01:17 +02003156 char *err;
3157
Willy Tarreau26982662012-09-12 23:17:10 +02003158 kw = bind_find_kw(args[cur_arg]);
3159 if (kw) {
3160 char *err = NULL;
3161 int code;
3162
3163 if (!kw->parse) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003164 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
3165 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau26982662012-09-12 23:17:10 +02003166 cur_arg += 1 + kw->skip ;
3167 err_code |= ERR_ALERT | ERR_FATAL;
3168 goto out;
3169 }
3170
Willy Tarreau4348fad2012-09-20 16:48:07 +02003171 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
Willy Tarreau26982662012-09-12 23:17:10 +02003172 err_code |= code;
3173
3174 if (code) {
3175 if (err && *err) {
3176 indent_msg(&err, 2);
Christopher Faulet767a84b2017-11-24 16:50:31 +01003177 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau26982662012-09-12 23:17:10 +02003178 }
3179 else
Christopher Faulet767a84b2017-11-24 16:50:31 +01003180 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
3181 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau26982662012-09-12 23:17:10 +02003182 if (code & ERR_FATAL) {
3183 free(err);
3184 cur_arg += 1 + kw->skip;
3185 goto out;
3186 }
3187 }
3188 free(err);
3189 cur_arg += 1 + kw->skip;
3190 continue;
3191 }
3192
Willy Tarreau8638f482012-09-18 18:01:17 +02003193 err = NULL;
3194 if (!bind_dumped) {
3195 bind_dump_kws(&err);
3196 indent_msg(&err, 4);
3197 bind_dumped = 1;
3198 }
3199
Christopher Faulet767a84b2017-11-24 16:50:31 +01003200 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
3201 file, linenum, args[0], args[1], args[cur_arg],
3202 err ? " Registered keywords :" : "", err ? err : "");
Willy Tarreau8638f482012-09-18 18:01:17 +02003203 free(err);
3204
Willy Tarreau93893792009-07-23 13:19:11 +02003205 err_code |= ERR_ALERT | ERR_FATAL;
3206 goto out;
Willy Tarreaub1e52e82008-01-13 14:49:51 +01003207 }
Willy Tarreau93893792009-07-23 13:19:11 +02003208 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003209 }
3210 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01003211 if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003212 ha_alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
3213 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003214 err_code |= ERR_ALERT | ERR_FATAL;
3215 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003216 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01003217 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003218 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003219
Willy Tarreaubaaee002006-06-26 02:48:02 +02003220 /* flush useless bits */
3221 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
Willy Tarreau93893792009-07-23 13:19:11 +02003222 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003223 }
Willy Tarreau1c47f852006-07-09 08:22:27 +02003224 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
Willy Tarreau977b8e42006-12-29 14:19:17 +01003225 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003226 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003227
William Lallemanddf1425a2015-04-28 20:17:49 +02003228 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3229 goto out;
3230
Willy Tarreau1c47f852006-07-09 08:22:27 +02003231 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003232 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
3233 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003234 err_code |= ERR_ALERT | ERR_FATAL;
3235 goto out;
Willy Tarreau1c47f852006-07-09 08:22:27 +02003236 }
3237
Willy Tarreaua534fea2008-08-03 12:19:50 +02003238 free(curproxy->monitor_uri);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +01003239 curproxy->monitor_uri_len = strlen(args[1]);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003240 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +01003241 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
Willy Tarreau1c47f852006-07-09 08:22:27 +02003242 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
3243
Willy Tarreau93893792009-07-23 13:19:11 +02003244 goto out;
Willy Tarreau1c47f852006-07-09 08:22:27 +02003245 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003246 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
William Lallemanddf1425a2015-04-28 20:17:49 +02003247 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3248 goto out;
3249
Willy Tarreaubaaee002006-06-26 02:48:02 +02003250 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
3251 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
3252 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
3253 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003254 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003255 err_code |= ERR_ALERT | ERR_FATAL;
3256 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003257 }
3258 }
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003259 else if (!strcmp(args[0], "id")) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003260 struct eb32_node *node;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003261
3262 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003263 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003264 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003265 err_code |= ERR_ALERT | ERR_FATAL;
3266 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003267 }
3268
William Lallemanddf1425a2015-04-28 20:17:49 +02003269 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3270 goto out;
3271
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003272 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003273 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
3274 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003275 err_code |= ERR_ALERT | ERR_FATAL;
3276 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003277 }
3278
3279 curproxy->uuid = atol(args[1]);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003280 curproxy->conf.id.key = curproxy->uuid;
Willy Tarreau0d1fdf72015-05-27 16:44:02 +02003281 curproxy->options |= PR_O_FORCED_ID;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003282
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003283 if (curproxy->uuid <= 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003284 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
3285 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003286 err_code |= ERR_ALERT | ERR_FATAL;
3287 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003288 }
3289
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003290 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
3291 if (node) {
3292 struct proxy *target = container_of(node, struct proxy, conf.id);
Christopher Faulet767a84b2017-11-24 16:50:31 +01003293 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
3294 file, linenum, proxy_type_str(curproxy), curproxy->id,
3295 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003296 err_code |= ERR_ALERT | ERR_FATAL;
3297 goto out;
3298 }
3299 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003300 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003301 else if (!strcmp(args[0], "description")) {
3302 int i, len=0;
3303 char *d;
3304
Cyril Bonté99ed3272010-01-24 23:29:44 +01003305 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003306 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
Cyril Bonté99ed3272010-01-24 23:29:44 +01003307 file, linenum, args[0]);
3308 err_code |= ERR_ALERT | ERR_FATAL;
3309 goto out;
3310 }
3311
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003312 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003313 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
3314 file, linenum, args[0]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003315 return -1;
3316 }
3317
Willy Tarreau348acfe2014-04-14 15:00:39 +02003318 for (i = 1; *args[i]; i++)
3319 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003320
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003321 d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003322 curproxy->desc = d;
3323
Willy Tarreau348acfe2014-04-14 15:00:39 +02003324 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
3325 for (i = 2; *args[i]; i++)
3326 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003327
3328 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003329 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
William Lallemanddf1425a2015-04-28 20:17:49 +02003330 if (alertif_too_many_args(0, file, linenum, args, &err_code))
3331 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003332 curproxy->state = PR_STSTOPPED;
3333 }
3334 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
William Lallemanddf1425a2015-04-28 20:17:49 +02003335 if (alertif_too_many_args(0, file, linenum, args, &err_code))
3336 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003337 curproxy->state = PR_STNEW;
3338 }
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003339 else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */
3340 int cur_arg = 1;
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003341 unsigned long set = 0;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003342
3343 while (*args[cur_arg]) {
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003344 if (strcmp(args[cur_arg], "all") == 0) {
3345 set = 0;
3346 break;
3347 }
Christopher Faulet26028f62017-11-22 15:01:51 +01003348 if (parse_process_number(args[cur_arg], &set, NULL, &errmsg)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003349 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
Willy Tarreau110ecc12012-11-15 17:50:01 +01003350 err_code |= ERR_ALERT | ERR_FATAL;
3351 goto out;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003352 }
3353 cur_arg++;
3354 }
3355 curproxy->bind_proc = set;
3356 }
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003357 else if (!strcmp(args[0], "acl")) { /* add an ACL */
Willy Tarreaub099aca2008-10-12 17:26:37 +02003358 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003359 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003360 err_code |= ERR_ALERT | ERR_FATAL;
3361 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003362 }
3363
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01003364 err = invalid_char(args[1]);
3365 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003366 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
3367 file, linenum, *err, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003368 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau1822e8c2017-04-12 18:54:00 +02003369 goto out;
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01003370 }
3371
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +01003372 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003373 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
3374 file, linenum, args[1], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02003375 err_code |= ERR_ALERT | ERR_FATAL;
3376 goto out;
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003377 }
Olivier Houchard4e694042017-03-14 20:01:29 +01003378 }
3379 else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */
3380
3381 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3382 err_code |= ERR_WARN;
3383
3384 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003385 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
3386 file, linenum, args[0]);
Olivier Houchard4e694042017-03-14 20:01:29 +01003387 err_code |= ERR_ALERT | ERR_FATAL;
3388 goto out;
3389 }
3390 free(curproxy->dyncookie_key);
3391 curproxy->dyncookie_key = strdup(args[1]);
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003392 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003393 else if (!strcmp(args[0], "cookie")) { /* cookie name */
3394 int cur_arg;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003395
Willy Tarreau977b8e42006-12-29 14:19:17 +01003396 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003397 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003398
Willy Tarreaubaaee002006-06-26 02:48:02 +02003399 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003400 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
3401 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003402 err_code |= ERR_ALERT | ERR_FATAL;
3403 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003404 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02003405
Willy Tarreau67402132012-05-31 20:40:20 +02003406 curproxy->ck_opts = 0;
Willy Tarreauc63d4bb2010-10-23 11:37:27 +02003407 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau4d187ac2009-12-03 23:13:06 +01003408 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
Willy Tarreaua534fea2008-08-03 12:19:50 +02003409 free(curproxy->cookie_name);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003410 curproxy->cookie_name = strdup(args[1]);
3411 curproxy->cookie_len = strlen(curproxy->cookie_name);
Willy Tarreauc63d4bb2010-10-23 11:37:27 +02003412
Willy Tarreaubaaee002006-06-26 02:48:02 +02003413 cur_arg = 2;
3414 while (*(args[cur_arg])) {
3415 if (!strcmp(args[cur_arg], "rewrite")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003416 curproxy->ck_opts |= PR_CK_RW;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003417 }
3418 else if (!strcmp(args[cur_arg], "indirect")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003419 curproxy->ck_opts |= PR_CK_IND;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003420 }
3421 else if (!strcmp(args[cur_arg], "insert")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003422 curproxy->ck_opts |= PR_CK_INS;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003423 }
3424 else if (!strcmp(args[cur_arg], "nocache")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003425 curproxy->ck_opts |= PR_CK_NOC;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003426 }
3427 else if (!strcmp(args[cur_arg], "postonly")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003428 curproxy->ck_opts |= PR_CK_POST;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003429 }
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003430 else if (!strcmp(args[cur_arg], "preserve")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003431 curproxy->ck_opts |= PR_CK_PSV;
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003432 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003433 else if (!strcmp(args[cur_arg], "prefix")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003434 curproxy->ck_opts |= PR_CK_PFX;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003435 }
Willy Tarreau4992dd22012-05-31 21:02:17 +02003436 else if (!strcmp(args[cur_arg], "httponly")) {
3437 curproxy->ck_opts |= PR_CK_HTTPONLY;
3438 }
3439 else if (!strcmp(args[cur_arg], "secure")) {
3440 curproxy->ck_opts |= PR_CK_SECURE;
3441 }
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003442 else if (!strcmp(args[cur_arg], "domain")) {
3443 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003444 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
3445 file, linenum, args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02003446 err_code |= ERR_ALERT | ERR_FATAL;
3447 goto out;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003448 }
3449
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003450 if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) {
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003451 /* rfc2109, 4.3.2 Rejecting Cookies */
Christopher Faulet767a84b2017-11-24 16:50:31 +01003452 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded"
3453 " dots nor does not start with a dot."
3454 " RFC forbids it, this configuration may not work properly.\n",
3455 file, linenum, args[cur_arg + 1]);
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003456 err_code |= ERR_WARN;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003457 }
3458
3459 err = invalid_domainchar(args[cur_arg + 1]);
3460 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003461 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
3462 file, linenum, *err, args[cur_arg + 1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003463 err_code |= ERR_ALERT | ERR_FATAL;
3464 goto out;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003465 }
3466
Willy Tarreau68a897b2009-12-03 23:28:34 +01003467 if (!curproxy->cookie_domain) {
3468 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
3469 } else {
3470 /* one domain was already specified, add another one by
3471 * building the string which will be returned along with
3472 * the cookie.
3473 */
3474 char *new_ptr;
3475 int new_len = strlen(curproxy->cookie_domain) +
3476 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
3477 new_ptr = malloc(new_len);
3478 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
3479 free(curproxy->cookie_domain);
3480 curproxy->cookie_domain = new_ptr;
3481 }
Willy Tarreau31936852010-10-06 16:59:56 +02003482 cur_arg++;
3483 }
3484 else if (!strcmp(args[cur_arg], "maxidle")) {
3485 unsigned int maxidle;
3486 const char *res;
3487
3488 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003489 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
3490 file, linenum, args[cur_arg]);
Willy Tarreau31936852010-10-06 16:59:56 +02003491 err_code |= ERR_ALERT | ERR_FATAL;
3492 goto out;
3493 }
3494
3495 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
3496 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003497 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
3498 file, linenum, *res, args[cur_arg]);
Willy Tarreau31936852010-10-06 16:59:56 +02003499 err_code |= ERR_ALERT | ERR_FATAL;
3500 goto out;
3501 }
3502 curproxy->cookie_maxidle = maxidle;
3503 cur_arg++;
3504 }
3505 else if (!strcmp(args[cur_arg], "maxlife")) {
3506 unsigned int maxlife;
3507 const char *res;
3508
3509 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003510 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
3511 file, linenum, args[cur_arg]);
Willy Tarreau31936852010-10-06 16:59:56 +02003512 err_code |= ERR_ALERT | ERR_FATAL;
3513 goto out;
3514 }
3515
3516 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
3517 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003518 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
3519 file, linenum, *res, args[cur_arg]);
Willy Tarreau31936852010-10-06 16:59:56 +02003520 err_code |= ERR_ALERT | ERR_FATAL;
3521 goto out;
3522 }
3523 curproxy->cookie_maxlife = maxlife;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003524 cur_arg++;
3525 }
Olivier Houcharda5938f72017-03-15 15:12:06 +01003526 else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */
Olivier Houchard4e694042017-03-14 20:01:29 +01003527
3528 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
3529 err_code |= ERR_WARN;
3530 curproxy->ck_opts |= PR_CK_DYNAMIC;
3531 }
3532
Willy Tarreaubaaee002006-06-26 02:48:02 +02003533 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003534 ha_alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic' and 'maxlife' options.\n",
3535 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003536 err_code |= ERR_ALERT | ERR_FATAL;
3537 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003538 }
3539 cur_arg++;
3540 }
Willy Tarreau67402132012-05-31 20:40:20 +02003541 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003542 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
3543 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003544 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003545 }
3546
Willy Tarreau67402132012-05-31 20:40:20 +02003547 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003548 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
3549 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003550 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003551 }
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003552
Willy Tarreau67402132012-05-31 20:40:20 +02003553 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003554 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
3555 file, linenum);
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003556 err_code |= ERR_ALERT | ERR_FATAL;
3557 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003558 }/* end else if (!strcmp(args[0], "cookie")) */
Simon Horman9dc49962015-01-30 11:22:59 +09003559 else if (!strcmp(args[0], "email-alert")) {
3560 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003561 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3562 file, linenum, args[0]);
Simon Horman9dc49962015-01-30 11:22:59 +09003563 err_code |= ERR_ALERT | ERR_FATAL;
3564 goto out;
3565 }
3566
3567 if (!strcmp(args[1], "from")) {
3568 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003569 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3570 file, linenum, args[1]);
Simon Horman9dc49962015-01-30 11:22:59 +09003571 err_code |= ERR_ALERT | ERR_FATAL;
3572 goto out;
3573 }
3574 free(curproxy->email_alert.from);
3575 curproxy->email_alert.from = strdup(args[2]);
3576 }
3577 else if (!strcmp(args[1], "mailers")) {
3578 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003579 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3580 file, linenum, args[1]);
Simon Horman9dc49962015-01-30 11:22:59 +09003581 err_code |= ERR_ALERT | ERR_FATAL;
3582 goto out;
3583 }
3584 free(curproxy->email_alert.mailers.name);
3585 curproxy->email_alert.mailers.name = strdup(args[2]);
3586 }
3587 else if (!strcmp(args[1], "myhostname")) {
3588 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003589 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3590 file, linenum, args[1]);
Simon Horman9dc49962015-01-30 11:22:59 +09003591 err_code |= ERR_ALERT | ERR_FATAL;
3592 goto out;
3593 }
3594 free(curproxy->email_alert.myhostname);
3595 curproxy->email_alert.myhostname = strdup(args[2]);
3596 }
Simon Horman64e34162015-02-06 11:11:57 +09003597 else if (!strcmp(args[1], "level")) {
3598 curproxy->email_alert.level = get_log_level(args[2]);
3599 if (curproxy->email_alert.level < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003600 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
3601 file, linenum, args[1], args[2]);
Simon Horman64e34162015-02-06 11:11:57 +09003602 err_code |= ERR_ALERT | ERR_FATAL;
3603 goto out;
3604 }
3605 }
Simon Horman9dc49962015-01-30 11:22:59 +09003606 else if (!strcmp(args[1], "to")) {
3607 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003608 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3609 file, linenum, args[1]);
Simon Horman9dc49962015-01-30 11:22:59 +09003610 err_code |= ERR_ALERT | ERR_FATAL;
3611 goto out;
3612 }
3613 free(curproxy->email_alert.to);
3614 curproxy->email_alert.to = strdup(args[2]);
3615 }
3616 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003617 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
3618 file, linenum, args[1]);
Simon Horman9dc49962015-01-30 11:22:59 +09003619 err_code |= ERR_ALERT | ERR_FATAL;
3620 goto out;
3621 }
Simon Horman64e34162015-02-06 11:11:57 +09003622 /* Indicate that the email_alert is at least partially configured */
3623 curproxy->email_alert.set = 1;
Simon Horman9dc49962015-01-30 11:22:59 +09003624 }/* end else if (!strcmp(args[0], "email-alert")) */
Simon Horman98637e52014-06-20 12:30:16 +09003625 else if (!strcmp(args[0], "external-check")) {
3626 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003627 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3628 file, linenum, args[0]);
Simon Horman98637e52014-06-20 12:30:16 +09003629 err_code |= ERR_ALERT | ERR_FATAL;
3630 goto out;
3631 }
3632
3633 if (!strcmp(args[1], "command")) {
Ben Cabot49795eb2015-09-16 12:07:51 +01003634 if (alertif_too_many_args(2, file, linenum, args, &err_code))
William Lallemanddf1425a2015-04-28 20:17:49 +02003635 goto out;
Ben Cabot49795eb2015-09-16 12:07:51 +01003636 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003637 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3638 file, linenum, args[1]);
Simon Horman98637e52014-06-20 12:30:16 +09003639 err_code |= ERR_ALERT | ERR_FATAL;
3640 goto out;
3641 }
3642 free(curproxy->check_command);
3643 curproxy->check_command = strdup(args[2]);
3644 }
3645 else if (!strcmp(args[1], "path")) {
Ben Cabot49795eb2015-09-16 12:07:51 +01003646 if (alertif_too_many_args(2, file, linenum, args, &err_code))
William Lallemanddf1425a2015-04-28 20:17:49 +02003647 goto out;
Ben Cabot49795eb2015-09-16 12:07:51 +01003648 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003649 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
3650 file, linenum, args[1]);
Simon Horman98637e52014-06-20 12:30:16 +09003651 err_code |= ERR_ALERT | ERR_FATAL;
3652 goto out;
3653 }
3654 free(curproxy->check_path);
3655 curproxy->check_path = strdup(args[2]);
3656 }
3657 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003658 ha_alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n",
3659 file, linenum, args[1]);
Simon Horman98637e52014-06-20 12:30:16 +09003660 err_code |= ERR_ALERT | ERR_FATAL;
3661 goto out;
3662 }
3663 }/* end else if (!strcmp(args[0], "external-check")) */
Emeric Brun647caf12009-06-30 17:57:00 +02003664 else if (!strcmp(args[0], "persist")) { /* persist */
3665 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003666 ha_alert("parsing [%s:%d] : missing persist method.\n",
3667 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003668 err_code |= ERR_ALERT | ERR_FATAL;
3669 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003670 }
3671
3672 if (!strncmp(args[1], "rdp-cookie", 10)) {
3673 curproxy->options2 |= PR_O2_RDPC_PRST;
3674
Emeric Brunb982a3d2010-01-04 15:45:53 +01003675 if (*(args[1] + 10) == '(') { /* cookie name */
Emeric Brun647caf12009-06-30 17:57:00 +02003676 const char *beg, *end;
3677
3678 beg = args[1] + 11;
3679 end = strchr(beg, ')');
3680
William Lallemanddf1425a2015-04-28 20:17:49 +02003681 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3682 goto out;
3683
Emeric Brun647caf12009-06-30 17:57:00 +02003684 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003685 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
3686 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003687 err_code |= ERR_ALERT | ERR_FATAL;
3688 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003689 }
3690
3691 free(curproxy->rdp_cookie_name);
3692 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
3693 curproxy->rdp_cookie_len = end-beg;
3694 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003695 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
Emeric Brun647caf12009-06-30 17:57:00 +02003696 free(curproxy->rdp_cookie_name);
3697 curproxy->rdp_cookie_name = strdup("msts");
3698 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
3699 }
3700 else { /* syntax */
Christopher Faulet767a84b2017-11-24 16:50:31 +01003701 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
3702 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003703 err_code |= ERR_ALERT | ERR_FATAL;
3704 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003705 }
3706 }
3707 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003708 ha_alert("parsing [%s:%d] : unknown persist method.\n",
3709 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003710 err_code |= ERR_ALERT | ERR_FATAL;
3711 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003712 }
3713 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003714 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Christopher Faulet767a84b2017-11-24 16:50:31 +01003715 ha_alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]);
Willy Tarreau6db62c52015-08-10 19:04:29 +02003716 err_code |= ERR_ALERT | ERR_FATAL;
3717 goto out;
3718 }
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003719 else if (!strcmp(args[0], "load-server-state-from-file")) {
3720 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3721 err_code |= ERR_WARN;
3722 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
3723 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
3724 }
3725 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
3726 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
3727 }
3728 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
3729 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
3730 }
3731 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003732 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
3733 file, linenum, args[0], args[1]);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003734 err_code |= ERR_ALERT | ERR_FATAL;
3735 goto out;
3736 }
3737 }
3738 else if (!strcmp(args[0], "server-state-file-name")) {
3739 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3740 err_code |= ERR_WARN;
3741 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003742 ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
3743 file, linenum, args[0]);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003744 err_code |= ERR_ALERT | ERR_FATAL;
3745 goto out;
3746 }
3747 else if (!strcmp(args[1], "use-backend-name"))
3748 curproxy->server_state_file_name = strdup(curproxy->id);
3749 else
3750 curproxy->server_state_file_name = strdup(args[1]);
3751 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003752 else if (!strcmp(args[0], "capture")) {
Willy Tarreau3b6b1a92009-07-23 13:24:23 +02003753 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003754 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003755
Willy Tarreaubaaee002006-06-26 02:48:02 +02003756 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
Cyril Bonté99ed3272010-01-24 23:29:44 +01003757 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003758 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
Cyril Bonté99ed3272010-01-24 23:29:44 +01003759 err_code |= ERR_ALERT | ERR_FATAL;
3760 goto out;
3761 }
3762
William Lallemand1a748ae2015-05-19 16:37:23 +02003763 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3764 goto out;
3765
Willy Tarreaubaaee002006-06-26 02:48:02 +02003766 if (*(args[4]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003767 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
3768 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003769 err_code |= ERR_ALERT | ERR_FATAL;
3770 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003771 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02003772 free(curproxy->capture_name);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003773 curproxy->capture_name = strdup(args[2]);
3774 curproxy->capture_namelen = strlen(curproxy->capture_name);
3775 curproxy->capture_len = atol(args[4]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003776 curproxy->to_log |= LW_COOKIE;
3777 }
3778 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
3779 struct cap_hdr *hdr;
3780
3781 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003782 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003783 err_code |= ERR_ALERT | ERR_FATAL;
3784 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003785 }
3786
William Lallemand1a748ae2015-05-19 16:37:23 +02003787 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3788 goto out;
3789
Willy Tarreaubaaee002006-06-26 02:48:02 +02003790 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003791 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
3792 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003793 err_code |= ERR_ALERT | ERR_FATAL;
3794 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003795 }
3796
Vincent Bernat02779b62016-04-03 13:48:43 +02003797 hdr = calloc(1, sizeof(*hdr));
Willy Tarreaubaaee002006-06-26 02:48:02 +02003798 hdr->next = curproxy->req_cap;
3799 hdr->name = strdup(args[3]);
3800 hdr->namelen = strlen(args[3]);
3801 hdr->len = atol(args[5]);
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003802 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003803 hdr->index = curproxy->nb_req_cap++;
3804 curproxy->req_cap = hdr;
3805 curproxy->to_log |= LW_REQHDR;
3806 }
3807 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
3808 struct cap_hdr *hdr;
3809
3810 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003811 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003812 err_code |= ERR_ALERT | ERR_FATAL;
3813 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003814 }
3815
William Lallemand1a748ae2015-05-19 16:37:23 +02003816 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3817 goto out;
3818
Willy Tarreaubaaee002006-06-26 02:48:02 +02003819 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003820 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
3821 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003822 err_code |= ERR_ALERT | ERR_FATAL;
3823 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003824 }
Vincent Bernat02779b62016-04-03 13:48:43 +02003825 hdr = calloc(1, sizeof(*hdr));
Willy Tarreaubaaee002006-06-26 02:48:02 +02003826 hdr->next = curproxy->rsp_cap;
3827 hdr->name = strdup(args[3]);
3828 hdr->namelen = strlen(args[3]);
3829 hdr->len = atol(args[5]);
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003830 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003831 hdr->index = curproxy->nb_rsp_cap++;
3832 curproxy->rsp_cap = hdr;
3833 curproxy->to_log |= LW_RSPHDR;
3834 }
3835 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003836 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
3837 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003838 err_code |= ERR_ALERT | ERR_FATAL;
3839 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003840 }
3841 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003842 else if (!strcmp(args[0], "retries")) { /* connection retries */
Willy Tarreau977b8e42006-12-29 14:19:17 +01003843 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003844 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003845
William Lallemanddf1425a2015-04-28 20:17:49 +02003846 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3847 goto out;
3848
Willy Tarreaubaaee002006-06-26 02:48:02 +02003849 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003850 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
3851 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003852 err_code |= ERR_ALERT | ERR_FATAL;
3853 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003854 }
3855 curproxy->conn_retries = atol(args[1]);
3856 }
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003857 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003858 struct act_rule *rule;
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003859
3860 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003861 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003862 err_code |= ERR_ALERT | ERR_FATAL;
3863 goto out;
3864 }
3865
Willy Tarreau20b0de52012-12-24 15:45:22 +01003866 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003867 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02003868 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW ||
3869 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY ||
3870 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR ||
3871 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REQ_AUTH)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003872 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
3873 file, linenum, args[0]);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003874 err_code |= ERR_WARN;
3875 }
3876
Willy Tarreauff011f22011-01-06 17:51:27 +01003877 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003878
Willy Tarreauff011f22011-01-06 17:51:27 +01003879 if (!rule) {
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003880 err_code |= ERR_ALERT | ERR_ABORT;
3881 goto out;
3882 }
3883
Willy Tarreau5002f572014-04-23 01:32:02 +02003884 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003885 err_code |= warnif_cond_conflicts(rule->cond,
3886 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3887 file, linenum);
3888
Willy Tarreauff011f22011-01-06 17:51:27 +01003889 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003890 }
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003891 else if (!strcmp(args[0], "http-response")) { /* response access control */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003892 struct act_rule *rule;
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003893
3894 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003895 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003896 err_code |= ERR_ALERT | ERR_FATAL;
3897 goto out;
3898 }
3899
3900 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003901 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02003902 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW ||
3903 LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_DENY)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003904 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
3905 file, linenum, args[0]);
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003906 err_code |= ERR_WARN;
3907 }
3908
3909 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
3910
3911 if (!rule) {
3912 err_code |= ERR_ALERT | ERR_ABORT;
3913 goto out;
3914 }
3915
3916 err_code |= warnif_cond_conflicts(rule->cond,
3917 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
3918 file, linenum);
3919
3920 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
3921 }
Mark Lamourinec2247f02012-01-04 13:02:01 -05003922 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
3923 /* set the header name and length into the proxy structure */
3924 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3925 err_code |= ERR_WARN;
3926
3927 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003928 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
3929 file, linenum, args[0]);
Mark Lamourinec2247f02012-01-04 13:02:01 -05003930 err_code |= ERR_ALERT | ERR_FATAL;
3931 goto out;
3932 }
3933
3934 /* set the desired header name */
3935 free(curproxy->server_id_hdr_name);
3936 curproxy->server_id_hdr_name = strdup(args[1]);
3937 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
3938 }
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003939 else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003940 struct act_rule *rule;
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003941
Willy Tarreaub099aca2008-10-12 17:26:37 +02003942 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003943 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003944 err_code |= ERR_ALERT | ERR_FATAL;
3945 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003946 }
3947
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003948 /* emulate "block" using "http-request block". Since these rules are supposed to
3949 * be processed before all http-request rules, we put them into their own list
3950 * and will insert them at the end.
3951 */
3952 rule = parse_http_req_cond((const char **)args, file, linenum, curproxy);
3953 if (!rule) {
3954 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau93893792009-07-23 13:19:11 +02003955 goto out;
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003956 }
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003957 err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]);
3958 err_code |= warnif_cond_conflicts(rule->cond,
3959 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3960 file, linenum);
3961 LIST_ADDQ(&curproxy->block_rules, &rule->list);
Willy Tarreaude9d2d72014-04-28 22:28:02 +02003962
3963 if (!already_warned(WARN_BLOCK_DEPRECATED))
Christopher Faulet767a84b2017-11-24 16:50:31 +01003964 ha_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]);
Willy Tarreaude9d2d72014-04-28 22:28:02 +02003965
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003966 }
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003967 else if (!strcmp(args[0], "redirect")) {
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003968 struct redirect_rule *rule;
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003969
Cyril Bonté99ed3272010-01-24 23:29:44 +01003970 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003971 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Cyril Bonté99ed3272010-01-24 23:29:44 +01003972 err_code |= ERR_ALERT | ERR_FATAL;
3973 goto out;
3974 }
3975
Willy Tarreaube4653b2015-05-28 15:26:58 +02003976 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003977 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
3978 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02003979 err_code |= ERR_ALERT | ERR_FATAL;
3980 goto out;
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003981 }
3982
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003983 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
Willy Tarreauee445d92014-04-23 01:39:04 +02003984 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003985 err_code |= warnif_cond_conflicts(rule->cond,
3986 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3987 file, linenum);
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003988 }
Krzysztof Piotr Oledzki7b723ef2009-01-27 21:09:41 +01003989 else if (!strcmp(args[0], "use_backend")) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02003990 struct switching_rule *rule;
3991
Willy Tarreaub099aca2008-10-12 17:26:37 +02003992 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003993 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003994 err_code |= ERR_ALERT | ERR_FATAL;
3995 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003996 }
3997
Willy Tarreau55ea7572007-06-17 19:56:27 +02003998 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003999 err_code |= ERR_WARN;
Willy Tarreau55ea7572007-06-17 19:56:27 +02004000
4001 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004002 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02004003 err_code |= ERR_ALERT | ERR_FATAL;
4004 goto out;
Willy Tarreau55ea7572007-06-17 19:56:27 +02004005 }
4006
Willy Tarreauf51658d2014-04-23 01:21:56 +02004007 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
Christopher Faulet1b421ea2017-09-22 14:38:56 +02004008 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004009 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
4010 file, linenum, errmsg);
Willy Tarreauf51658d2014-04-23 01:21:56 +02004011 err_code |= ERR_ALERT | ERR_FATAL;
4012 goto out;
4013 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02004014
Willy Tarreauf51658d2014-04-23 01:21:56 +02004015 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
Willy Tarreau55ea7572007-06-17 19:56:27 +02004016 }
Willy Tarreau4f862642017-02-28 09:34:39 +01004017 else if (*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004018 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
4019 file, linenum, args[2]);
Willy Tarreau4f862642017-02-28 09:34:39 +01004020 err_code |= ERR_ALERT | ERR_FATAL;
4021 goto out;
4022 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02004023
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004024 rule = calloc(1, sizeof(*rule));
Thierry FOURNIER / OZON.IO5948b012016-11-24 23:58:32 +01004025 if (!rule) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004026 ha_alert("Out of memory error.\n");
Thierry FOURNIER / OZON.IO5948b012016-11-24 23:58:32 +01004027 goto out;
4028 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02004029 rule->cond = cond;
4030 rule->be.name = strdup(args[1]);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01004031 rule->line = linenum;
4032 rule->file = strdup(file);
4033 if (!rule->file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004034 ha_alert("Out of memory error.\n");
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01004035 goto out;
4036 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02004037 LIST_INIT(&rule->list);
4038 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
4039 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02004040 else if (strcmp(args[0], "use-server") == 0) {
4041 struct server_rule *rule;
4042
4043 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004044 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02004045 err_code |= ERR_ALERT | ERR_FATAL;
4046 goto out;
4047 }
4048
4049 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
4050 err_code |= ERR_WARN;
4051
4052 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004053 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02004054 err_code |= ERR_ALERT | ERR_FATAL;
4055 goto out;
4056 }
4057
4058 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004059 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
4060 file, linenum, args[0]);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02004061 err_code |= ERR_ALERT | ERR_FATAL;
4062 goto out;
4063 }
4064
Christopher Faulet1b421ea2017-09-22 14:38:56 +02004065 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004066 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
4067 file, linenum, errmsg);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02004068 err_code |= ERR_ALERT | ERR_FATAL;
4069 goto out;
4070 }
4071
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004072 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02004073
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004074 rule = calloc(1, sizeof(*rule));
Willy Tarreau4a5cade2012-04-05 21:09:48 +02004075 rule->cond = cond;
4076 rule->srv.name = strdup(args[1]);
4077 LIST_INIT(&rule->list);
4078 LIST_ADDQ(&curproxy->server_rules, &rule->list);
4079 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
4080 }
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02004081 else if ((!strcmp(args[0], "force-persist")) ||
4082 (!strcmp(args[0], "ignore-persist"))) {
4083 struct persist_rule *rule;
Willy Tarreau4de91492010-01-22 19:10:05 +01004084
4085 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004086 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau4de91492010-01-22 19:10:05 +01004087 err_code |= ERR_ALERT | ERR_FATAL;
4088 goto out;
4089 }
4090
Cyril Bonté4288c5a2018-03-12 22:02:59 +01004091 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau4de91492010-01-22 19:10:05 +01004092 err_code |= ERR_WARN;
4093
Willy Tarreauef6494c2010-01-28 17:12:36 +01004094 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004095 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
4096 file, linenum, args[0]);
Willy Tarreau4de91492010-01-22 19:10:05 +01004097 err_code |= ERR_ALERT | ERR_FATAL;
4098 goto out;
4099 }
4100
Christopher Faulet1b421ea2017-09-22 14:38:56 +02004101 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004102 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
4103 file, linenum, args[0], errmsg);
Willy Tarreau4de91492010-01-22 19:10:05 +01004104 err_code |= ERR_ALERT | ERR_FATAL;
4105 goto out;
4106 }
4107
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004108 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
4109 * where force-persist is applied.
4110 */
4111 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
Willy Tarreau4de91492010-01-22 19:10:05 +01004112
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004113 rule = calloc(1, sizeof(*rule));
Willy Tarreau4de91492010-01-22 19:10:05 +01004114 rule->cond = cond;
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02004115 if (!strcmp(args[0], "force-persist")) {
4116 rule->type = PERSIST_TYPE_FORCE;
4117 } else {
4118 rule->type = PERSIST_TYPE_IGNORE;
4119 }
Willy Tarreau4de91492010-01-22 19:10:05 +01004120 LIST_INIT(&rule->list);
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02004121 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
Willy Tarreau4de91492010-01-22 19:10:05 +01004122 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004123 else if (!strcmp(args[0], "stick-table")) {
4124 int myidx = 1;
Willy Tarreaue45288c2015-05-26 10:49:46 +02004125 struct proxy *other;
4126
Willy Tarreauc7867682018-07-27 10:26:22 +02004127 if (curproxy == &defproxy) {
4128 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
4129 file, linenum);
4130 err_code |= ERR_ALERT | ERR_FATAL;
4131 goto out;
4132 }
4133
Willy Tarreaue2dc1fa2015-05-26 12:08:07 +02004134 other = proxy_tbl_by_name(curproxy->id);
Willy Tarreaue45288c2015-05-26 10:49:46 +02004135 if (other) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004136 ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
4137 file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line);
Willy Tarreaue45288c2015-05-26 10:49:46 +02004138 err_code |= ERR_ALERT | ERR_FATAL;
4139 goto out;
4140 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004141
Emeric Brun32da3c42010-09-23 18:39:19 +02004142 curproxy->table.id = curproxy->id;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004143 curproxy->table.type = (unsigned int)-1;
4144 while (*args[myidx]) {
4145 const char *err;
4146
4147 if (strcmp(args[myidx], "size") == 0) {
4148 myidx++;
4149 if (!*(args[myidx])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004150 ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
4151 file, linenum, args[myidx-1]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004152 err_code |= ERR_ALERT | ERR_FATAL;
4153 goto out;
4154 }
4155 if ((err = parse_size_err(args[myidx], &curproxy->table.size))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004156 ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n",
4157 file, linenum, *err, args[myidx-1]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004158 err_code |= ERR_ALERT | ERR_FATAL;
4159 goto out;
4160 }
Willy Tarreau0c559312010-01-26 18:36:26 +01004161 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004162 }
Emeric Brun32da3c42010-09-23 18:39:19 +02004163 else if (strcmp(args[myidx], "peers") == 0) {
4164 myidx++;
Godbach50523162013-12-11 19:48:57 +08004165 if (!*(args[myidx])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004166 ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
4167 file, linenum, args[myidx-1]);
Godbachff115542014-04-21 21:52:23 +08004168 err_code |= ERR_ALERT | ERR_FATAL;
4169 goto out;
Godbach50523162013-12-11 19:48:57 +08004170 }
Emeric Brun32da3c42010-09-23 18:39:19 +02004171 curproxy->table.peers.name = strdup(args[myidx++]);
4172 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004173 else if (strcmp(args[myidx], "expire") == 0) {
4174 myidx++;
4175 if (!*(args[myidx])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004176 ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
4177 file, linenum, args[myidx-1]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004178 err_code |= ERR_ALERT | ERR_FATAL;
4179 goto out;
4180 }
4181 err = parse_time_err(args[myidx], &val, TIME_UNIT_MS);
4182 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004183 ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n",
4184 file, linenum, *err, args[myidx-1]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004185 err_code |= ERR_ALERT | ERR_FATAL;
4186 goto out;
4187 }
Ben Cabot3b90f0a2016-01-20 09:44:39 +00004188 if (val > INT_MAX) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004189 ha_alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n",
4190 file, linenum, val);
Ben Cabot3b90f0a2016-01-20 09:44:39 +00004191 err_code |= ERR_ALERT | ERR_FATAL;
4192 goto out;
4193 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004194 curproxy->table.expire = val;
Willy Tarreau0c559312010-01-26 18:36:26 +01004195 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004196 }
4197 else if (strcmp(args[myidx], "nopurge") == 0) {
4198 curproxy->table.nopurge = 1;
Willy Tarreau0c559312010-01-26 18:36:26 +01004199 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004200 }
4201 else if (strcmp(args[myidx], "type") == 0) {
4202 myidx++;
4203 if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004204 ha_alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n",
4205 file, linenum, args[myidx]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004206 err_code |= ERR_ALERT | ERR_FATAL;
4207 goto out;
4208 }
Willy Tarreau0c559312010-01-26 18:36:26 +01004209 /* myidx already points to next arg */
4210 }
Willy Tarreau08d5f982010-06-06 13:34:54 +02004211 else if (strcmp(args[myidx], "store") == 0) {
Willy Tarreauac782882010-06-20 10:41:54 +02004212 int type, err;
Willy Tarreau888617d2010-06-20 09:11:39 +02004213 char *cw, *nw, *sa;
Willy Tarreau08d5f982010-06-06 13:34:54 +02004214
4215 myidx++;
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004216 nw = args[myidx];
4217 while (*nw) {
4218 /* the "store" keyword supports a comma-separated list */
4219 cw = nw;
Willy Tarreau888617d2010-06-20 09:11:39 +02004220 sa = NULL; /* store arg */
4221 while (*nw && *nw != ',') {
4222 if (*nw == '(') {
4223 *nw = 0;
4224 sa = ++nw;
4225 while (*nw != ')') {
4226 if (!*nw) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004227 ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n",
4228 file, linenum, args[0], cw);
Willy Tarreau888617d2010-06-20 09:11:39 +02004229 err_code |= ERR_ALERT | ERR_FATAL;
4230 goto out;
4231 }
4232 nw++;
4233 }
4234 *nw = '\0';
4235 }
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004236 nw++;
Willy Tarreau888617d2010-06-20 09:11:39 +02004237 }
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004238 if (*nw)
4239 *nw++ = '\0';
4240 type = stktable_get_data_type(cw);
4241 if (type < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004242 ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n",
4243 file, linenum, args[0], cw);
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004244 err_code |= ERR_ALERT | ERR_FATAL;
4245 goto out;
4246 }
Willy Tarreauac782882010-06-20 10:41:54 +02004247
4248 err = stktable_alloc_data_type(&curproxy->table, type, sa);
4249 switch (err) {
4250 case PE_NONE: break;
4251 case PE_EXIST:
Christopher Faulet767a84b2017-11-24 16:50:31 +01004252 ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n",
4253 file, linenum, args[0], cw);
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004254 err_code |= ERR_WARN;
Willy Tarreauac782882010-06-20 10:41:54 +02004255 break;
4256
4257 case PE_ARG_MISSING:
Christopher Faulet767a84b2017-11-24 16:50:31 +01004258 ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n",
4259 file, linenum, args[0], cw);
Willy Tarreauac782882010-06-20 10:41:54 +02004260 err_code |= ERR_ALERT | ERR_FATAL;
4261 goto out;
4262
4263 case PE_ARG_NOT_USED:
Christopher Faulet767a84b2017-11-24 16:50:31 +01004264 ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n",
4265 file, linenum, args[0], cw);
Willy Tarreauac782882010-06-20 10:41:54 +02004266 err_code |= ERR_ALERT | ERR_FATAL;
4267 goto out;
4268
4269 default:
Christopher Faulet767a84b2017-11-24 16:50:31 +01004270 ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n",
4271 file, linenum, args[0], cw);
Willy Tarreauac782882010-06-20 10:41:54 +02004272 err_code |= ERR_ALERT | ERR_FATAL;
4273 goto out;
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004274 }
Willy Tarreau08d5f982010-06-06 13:34:54 +02004275 }
4276 myidx++;
4277 }
Willy Tarreau0c559312010-01-26 18:36:26 +01004278 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004279 ha_alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n",
4280 file, linenum, args[myidx]);
Willy Tarreau0c559312010-01-26 18:36:26 +01004281 err_code |= ERR_ALERT | ERR_FATAL;
4282 goto out;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004283 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004284 }
4285
4286 if (!curproxy->table.size) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004287 ha_alert("parsing [%s:%d] : stick-table: missing size.\n",
4288 file, linenum);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004289 err_code |= ERR_ALERT | ERR_FATAL;
4290 goto out;
4291 }
4292
4293 if (curproxy->table.type == (unsigned int)-1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004294 ha_alert("parsing [%s:%d] : stick-table: missing type.\n",
4295 file, linenum);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004296 err_code |= ERR_ALERT | ERR_FATAL;
4297 goto out;
4298 }
4299 }
4300 else if (!strcmp(args[0], "stick")) {
Emeric Brunb982a3d2010-01-04 15:45:53 +01004301 struct sticking_rule *rule;
Willy Tarreau12785782012-04-27 21:37:17 +02004302 struct sample_expr *expr;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004303 int myidx = 0;
4304 const char *name = NULL;
4305 int flags;
4306
4307 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004308 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004309 err_code |= ERR_ALERT | ERR_FATAL;
4310 goto out;
4311 }
4312
4313 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
4314 err_code |= ERR_WARN;
4315 goto out;
4316 }
4317
4318 myidx++;
4319 if ((strcmp(args[myidx], "store") == 0) ||
4320 (strcmp(args[myidx], "store-request") == 0)) {
4321 myidx++;
4322 flags = STK_IS_STORE;
4323 }
4324 else if (strcmp(args[myidx], "store-response") == 0) {
4325 myidx++;
4326 flags = STK_IS_STORE | STK_ON_RSP;
4327 }
4328 else if (strcmp(args[myidx], "match") == 0) {
4329 myidx++;
4330 flags = STK_IS_MATCH;
4331 }
4332 else if (strcmp(args[myidx], "on") == 0) {
4333 myidx++;
4334 flags = STK_IS_MATCH | STK_IS_STORE;
4335 }
4336 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004337 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004338 err_code |= ERR_ALERT | ERR_FATAL;
4339 goto out;
4340 }
4341
4342 if (*(args[myidx]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004343 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004344 err_code |= ERR_ALERT | ERR_FATAL;
4345 goto out;
4346 }
4347
Willy Tarreaua4312fa2013-04-02 16:34:32 +02004348 curproxy->conf.args.ctx = ARGC_STK;
Thierry FOURNIEReeaa9512014-02-11 14:00:19 +01004349 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004350 if (!expr) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004351 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004352 err_code |= ERR_ALERT | ERR_FATAL;
4353 goto out;
4354 }
4355
4356 if (flags & STK_ON_RSP) {
Willy Tarreau80aca902013-01-07 15:42:20 +01004357 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004358 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
4359 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004360 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004361 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004362 goto out;
4363 }
4364 } else {
Willy Tarreau80aca902013-01-07 15:42:20 +01004365 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004366 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
4367 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004368 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004369 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004370 goto out;
4371 }
4372 }
4373
Willy Tarreau1b6c00c2012-10-05 22:41:26 +02004374 /* check if we need to allocate an hdr_idx struct for HTTP parsing */
Willy Tarreau25320b22013-03-24 07:22:08 +01004375 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
Willy Tarreau1b6c00c2012-10-05 22:41:26 +02004376
Emeric Brunb982a3d2010-01-04 15:45:53 +01004377 if (strcmp(args[myidx], "table") == 0) {
4378 myidx++;
4379 name = args[myidx++];
4380 }
4381
Willy Tarreauef6494c2010-01-28 17:12:36 +01004382 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
Christopher Faulet1b421ea2017-09-22 14:38:56 +02004383 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004384 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
4385 file, linenum, args[0], errmsg);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004386 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004387 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004388 goto out;
4389 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004390 }
Willy Tarreauef6494c2010-01-28 17:12:36 +01004391 else if (*(args[myidx])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004392 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
4393 file, linenum, args[0], args[myidx]);
Willy Tarreauef6494c2010-01-28 17:12:36 +01004394 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004395 free(expr);
Willy Tarreauef6494c2010-01-28 17:12:36 +01004396 goto out;
4397 }
Emeric Brun97679e72010-09-23 17:56:44 +02004398 if (flags & STK_ON_RSP)
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004399 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
Emeric Brun97679e72010-09-23 17:56:44 +02004400 else
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004401 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
Willy Tarreauf1e98b82010-01-28 17:59:39 +01004402
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004403 rule = calloc(1, sizeof(*rule));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004404 rule->cond = cond;
4405 rule->expr = expr;
4406 rule->flags = flags;
4407 rule->table.name = name ? strdup(name) : NULL;
4408 LIST_INIT(&rule->list);
4409 if (flags & STK_ON_RSP)
4410 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
4411 else
4412 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
4413 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004414 else if (!strcmp(args[0], "stats")) {
4415 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
4416 curproxy->uri_auth = NULL; /* we must detach from the default config */
4417
Krzysztof Piotr Oledzki260a3bb2010-01-06 16:25:05 +01004418 if (!*args[1]) {
4419 goto stats_error_parsing;
Cyril Bonté474be412010-10-12 00:14:36 +02004420 } else if (!strcmp(args[1], "admin")) {
4421 struct stats_admin_rule *rule;
4422
4423 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004424 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
Cyril Bonté474be412010-10-12 00:14:36 +02004425 err_code |= ERR_ALERT | ERR_FATAL;
4426 goto out;
4427 }
4428
4429 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004430 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Cyril Bonté474be412010-10-12 00:14:36 +02004431 err_code |= ERR_ALERT | ERR_ABORT;
4432 goto out;
4433 }
4434
4435 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004436 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
4437 file, linenum, args[0], args[1]);
Cyril Bonté474be412010-10-12 00:14:36 +02004438 err_code |= ERR_ALERT | ERR_FATAL;
4439 goto out;
4440 }
Christopher Faulet1b421ea2017-09-22 14:38:56 +02004441 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004442 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
4443 file, linenum, args[0], args[1], errmsg);
Cyril Bonté474be412010-10-12 00:14:36 +02004444 err_code |= ERR_ALERT | ERR_FATAL;
4445 goto out;
4446 }
4447
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004448 err_code |= warnif_cond_conflicts(cond,
4449 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
4450 file, linenum);
Cyril Bonté474be412010-10-12 00:14:36 +02004451
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004452 rule = calloc(1, sizeof(*rule));
Cyril Bonté474be412010-10-12 00:14:36 +02004453 rule->cond = cond;
4454 LIST_INIT(&rule->list);
4455 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004456 } else if (!strcmp(args[1], "uri")) {
4457 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004458 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004459 err_code |= ERR_ALERT | ERR_FATAL;
4460 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004461 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004462 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004463 err_code |= ERR_ALERT | ERR_ABORT;
4464 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004465 }
4466 } else if (!strcmp(args[1], "realm")) {
4467 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004468 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004469 err_code |= ERR_ALERT | ERR_FATAL;
4470 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004471 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004472 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004473 err_code |= ERR_ALERT | ERR_ABORT;
4474 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004475 }
Willy Tarreaubbd42122007-07-25 07:26:38 +02004476 } else if (!strcmp(args[1], "refresh")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +01004477 unsigned interval;
4478
4479 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
4480 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004481 ha_alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n",
4482 file, linenum, *err);
Willy Tarreau93893792009-07-23 13:19:11 +02004483 err_code |= ERR_ALERT | ERR_FATAL;
4484 goto out;
Willy Tarreaubbd42122007-07-25 07:26:38 +02004485 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004486 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004487 err_code |= ERR_ALERT | ERR_ABORT;
4488 goto out;
Willy Tarreaubbd42122007-07-25 07:26:38 +02004489 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004490 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004491 struct act_rule *rule;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004492
4493 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004494 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004495 err_code |= ERR_ALERT | ERR_FATAL;
4496 goto out;
4497 }
4498
4499 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004500 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004501 err_code |= ERR_ALERT | ERR_ABORT;
4502 goto out;
4503 }
4504
Willy Tarreauff011f22011-01-06 17:51:27 +01004505 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004506 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004507 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
4508 file, linenum, args[0]);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004509 err_code |= ERR_WARN;
4510 }
4511
Willy Tarreauff011f22011-01-06 17:51:27 +01004512 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004513
Willy Tarreauff011f22011-01-06 17:51:27 +01004514 if (!rule) {
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004515 err_code |= ERR_ALERT | ERR_ABORT;
4516 goto out;
4517 }
4518
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004519 err_code |= warnif_cond_conflicts(rule->cond,
4520 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
4521 file, linenum);
Willy Tarreauff011f22011-01-06 17:51:27 +01004522 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004523
Willy Tarreaubaaee002006-06-26 02:48:02 +02004524 } else if (!strcmp(args[1], "auth")) {
4525 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004526 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004527 err_code |= ERR_ALERT | ERR_FATAL;
4528 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004529 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004530 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004531 err_code |= ERR_ALERT | ERR_ABORT;
4532 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004533 }
4534 } else if (!strcmp(args[1], "scope")) {
4535 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004536 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004537 err_code |= ERR_ALERT | ERR_FATAL;
4538 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004539 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004540 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004541 err_code |= ERR_ALERT | ERR_ABORT;
4542 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004543 }
4544 } else if (!strcmp(args[1], "enable")) {
4545 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004546 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004547 err_code |= ERR_ALERT | ERR_ABORT;
4548 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004549 }
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +02004550 } else if (!strcmp(args[1], "hide-version")) {
4551 if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004552 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004553 err_code |= ERR_ALERT | ERR_ABORT;
4554 goto out;
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +02004555 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004556 } else if (!strcmp(args[1], "show-legends")) {
4557 if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004558 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004559 err_code |= ERR_ALERT | ERR_ABORT;
4560 goto out;
4561 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004562 } else if (!strcmp(args[1], "show-node")) {
4563
4564 if (*args[2]) {
4565 int i;
4566 char c;
4567
4568 for (i=0; args[2][i]; i++) {
4569 c = args[2][i];
Willy Tarreau88e05812010-03-03 00:16:00 +01004570 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
4571 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004572 break;
4573 }
4574
4575 if (!i || args[2][i]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004576 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
4577 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
4578 file, linenum, args[0], args[1]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004579 err_code |= ERR_ALERT | ERR_FATAL;
4580 goto out;
4581 }
4582 }
4583
4584 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004585 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004586 err_code |= ERR_ALERT | ERR_ABORT;
4587 goto out;
4588 }
4589 } else if (!strcmp(args[1], "show-desc")) {
4590 char *desc = NULL;
4591
4592 if (*args[2]) {
4593 int i, len=0;
4594 char *d;
4595
Willy Tarreau348acfe2014-04-14 15:00:39 +02004596 for (i = 2; *args[i]; i++)
4597 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004598
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004599 desc = d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004600
Willy Tarreau348acfe2014-04-14 15:00:39 +02004601 d += snprintf(d, desc + len - d, "%s", args[2]);
4602 for (i = 3; *args[i]; i++)
4603 d += snprintf(d, desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004604 }
4605
4606 if (!*args[2] && !global.desc)
Christopher Faulet767a84b2017-11-24 16:50:31 +01004607 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
4608 file, linenum, args[1]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004609 else {
4610 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
4611 free(desc);
Christopher Faulet767a84b2017-11-24 16:50:31 +01004612 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004613 err_code |= ERR_ALERT | ERR_ABORT;
4614 goto out;
4615 }
4616 free(desc);
4617 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004618 } else {
Krzysztof Piotr Oledzki260a3bb2010-01-06 16:25:05 +01004619stats_error_parsing:
Christopher Faulet767a84b2017-11-24 16:50:31 +01004620 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
4621 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
Willy Tarreau93893792009-07-23 13:19:11 +02004622 err_code |= ERR_ALERT | ERR_FATAL;
4623 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004624 }
4625 }
4626 else if (!strcmp(args[0], "option")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +01004627 int optnum;
4628
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004629 if (*(args[1]) == '\0') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004630 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
4631 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02004632 err_code |= ERR_ALERT | ERR_FATAL;
4633 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004634 }
Willy Tarreau13943ab2006-12-31 00:24:10 +01004635
4636 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
4637 if (!strcmp(args[1], cfg_opts[optnum].name)) {
Cyril Bonté62846b22010-11-01 19:26:00 +01004638 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004639 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
4640 file, linenum, cfg_opts[optnum].name);
Cyril Bonté62846b22010-11-01 19:26:00 +01004641 err_code |= ERR_ALERT | ERR_FATAL;
4642 goto out;
4643 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004644 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4645 goto out;
4646
Willy Tarreau93893792009-07-23 13:19:11 +02004647 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
4648 err_code |= ERR_WARN;
4649 goto out;
4650 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004651
Willy Tarreau3842f002009-06-14 11:39:52 +02004652 curproxy->no_options &= ~cfg_opts[optnum].val;
4653 curproxy->options &= ~cfg_opts[optnum].val;
4654
4655 switch (kwm) {
4656 case KWM_STD:
4657 curproxy->options |= cfg_opts[optnum].val;
4658 break;
4659 case KWM_NO:
4660 curproxy->no_options |= cfg_opts[optnum].val;
4661 break;
4662 case KWM_DEF: /* already cleared */
4663 break;
Willy Tarreau84b57da2009-06-14 11:10:45 +02004664 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004665
Willy Tarreau93893792009-07-23 13:19:11 +02004666 goto out;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004667 }
4668 }
4669
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004670 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
4671 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
Cyril Bonté62846b22010-11-01 19:26:00 +01004672 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004673 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
4674 file, linenum, cfg_opts2[optnum].name);
Cyril Bonté62846b22010-11-01 19:26:00 +01004675 err_code |= ERR_ALERT | ERR_FATAL;
4676 goto out;
4677 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004678 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4679 goto out;
Willy Tarreau93893792009-07-23 13:19:11 +02004680 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
4681 err_code |= ERR_WARN;
4682 goto out;
4683 }
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004684
Willy Tarreau3842f002009-06-14 11:39:52 +02004685 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
4686 curproxy->options2 &= ~cfg_opts2[optnum].val;
4687
4688 switch (kwm) {
4689 case KWM_STD:
4690 curproxy->options2 |= cfg_opts2[optnum].val;
4691 break;
4692 case KWM_NO:
4693 curproxy->no_options2 |= cfg_opts2[optnum].val;
4694 break;
4695 case KWM_DEF: /* already cleared */
4696 break;
Willy Tarreau84b57da2009-06-14 11:10:45 +02004697 }
Willy Tarreau93893792009-07-23 13:19:11 +02004698 goto out;
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004699 }
4700 }
4701
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004702 /* HTTP options override each other. They can be cancelled using
4703 * "no option xxx" which only switches to default mode if the mode
4704 * was this one (useful for cancelling options set in defaults
4705 * sections).
4706 */
Christopher Faulet315b39c2018-09-21 16:26:19 +02004707 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004708 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4709 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004710 if (kwm == KWM_STD) {
4711 curproxy->options &= ~PR_O_HTTP_MODE;
Christopher Faulet315b39c2018-09-21 16:26:19 +02004712 curproxy->options |= PR_O_HTTP_CLO;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004713 goto out;
4714 }
4715 else if (kwm == KWM_NO) {
Christopher Faulet315b39c2018-09-21 16:26:19 +02004716 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004717 curproxy->options &= ~PR_O_HTTP_MODE;
4718 goto out;
4719 }
4720 }
4721 else if (strcmp(args[1], "http-server-close") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004722 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4723 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004724 if (kwm == KWM_STD) {
4725 curproxy->options &= ~PR_O_HTTP_MODE;
4726 curproxy->options |= PR_O_HTTP_SCL;
4727 goto out;
4728 }
4729 else if (kwm == KWM_NO) {
4730 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
4731 curproxy->options &= ~PR_O_HTTP_MODE;
4732 goto out;
4733 }
4734 }
4735 else if (strcmp(args[1], "http-keep-alive") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004736 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4737 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004738 if (kwm == KWM_STD) {
4739 curproxy->options &= ~PR_O_HTTP_MODE;
4740 curproxy->options |= PR_O_HTTP_KAL;
4741 goto out;
4742 }
4743 else if (kwm == KWM_NO) {
4744 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
4745 curproxy->options &= ~PR_O_HTTP_MODE;
4746 goto out;
4747 }
4748 }
4749 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet4212a302018-09-21 10:42:19 +02004750 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[1], NULL)) {
4751 err_code |= ERR_WARN;
4752 goto out;
4753 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004754 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4755 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004756 if (kwm == KWM_STD) {
4757 curproxy->options &= ~PR_O_HTTP_MODE;
4758 curproxy->options |= PR_O_HTTP_TUN;
4759 goto out;
4760 }
4761 else if (kwm == KWM_NO) {
4762 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
4763 curproxy->options &= ~PR_O_HTTP_MODE;
4764 goto out;
4765 }
4766 }
4767
Joseph Lynch726ab712015-05-11 23:25:34 -07004768 /* Redispatch can take an integer argument that control when the
4769 * resispatch occurs. All values are relative to the retries option.
4770 * This can be cancelled using "no option xxx".
4771 */
4772 if (strcmp(args[1], "redispatch") == 0) {
4773 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
4774 err_code |= ERR_WARN;
4775 goto out;
4776 }
4777
4778 curproxy->no_options &= ~PR_O_REDISP;
4779 curproxy->options &= ~PR_O_REDISP;
4780
4781 switch (kwm) {
4782 case KWM_STD:
4783 curproxy->options |= PR_O_REDISP;
4784 curproxy->redispatch_after = -1;
4785 if(*args[2]) {
4786 curproxy->redispatch_after = atol(args[2]);
4787 }
4788 break;
4789 case KWM_NO:
4790 curproxy->no_options |= PR_O_REDISP;
4791 curproxy->redispatch_after = 0;
4792 break;
4793 case KWM_DEF: /* already cleared */
4794 break;
4795 }
4796 goto out;
4797 }
4798
Willy Tarreau3842f002009-06-14 11:39:52 +02004799 if (kwm != KWM_STD) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004800 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
4801 file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004802 err_code |= ERR_ALERT | ERR_FATAL;
4803 goto out;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004804 }
4805
Emeric Brun3a058f32009-06-30 18:26:00 +02004806 if (!strcmp(args[1], "httplog")) {
William Lallemand723b73a2012-02-08 16:37:49 +01004807 char *logformat;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004808 /* generate a complete HTTP log */
William Lallemand723b73a2012-02-08 16:37:49 +01004809 logformat = default_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004810 if (*(args[2]) != '\0') {
4811 if (!strcmp(args[2], "clf")) {
4812 curproxy->options2 |= PR_O2_CLFLOG;
William Lallemand723b73a2012-02-08 16:37:49 +01004813 logformat = clf_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004814 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004815 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004816 err_code |= ERR_ALERT | ERR_FATAL;
4817 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004818 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004819 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
4820 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004821 }
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004822 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
4823 char *oldlogformat = "log-format";
4824 char *clflogformat = "";
4825
4826 if (curproxy->conf.logformat_string == default_http_log_format)
4827 oldlogformat = "option httplog";
4828 else if (curproxy->conf.logformat_string == default_tcp_log_format)
4829 oldlogformat = "option tcplog";
4830 else if (curproxy->conf.logformat_string == clf_http_log_format)
4831 oldlogformat = "option httplog clf";
4832 if (logformat == clf_http_log_format)
4833 clflogformat = " clf";
Christopher Faulet767a84b2017-11-24 16:50:31 +01004834 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
4835 file, linenum, clflogformat, oldlogformat);
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004836 }
Willy Tarreau62a61232013-04-12 18:13:46 +02004837 if (curproxy->conf.logformat_string != default_http_log_format &&
4838 curproxy->conf.logformat_string != default_tcp_log_format &&
4839 curproxy->conf.logformat_string != clf_http_log_format)
4840 free(curproxy->conf.logformat_string);
4841 curproxy->conf.logformat_string = logformat;
4842
4843 free(curproxy->conf.lfs_file);
4844 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4845 curproxy->conf.lfs_line = curproxy->conf.args.line;
Tim Duesterhus9ad9f352018-02-05 20:52:27 +01004846
4847 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
4848 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
4849 file, linenum, curproxy->id);
4850 err_code |= ERR_WARN;
4851 }
Emeric Brun3a058f32009-06-30 18:26:00 +02004852 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01004853 else if (!strcmp(args[1], "tcplog")) {
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004854 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
4855 char *oldlogformat = "log-format";
4856
4857 if (curproxy->conf.logformat_string == default_http_log_format)
4858 oldlogformat = "option httplog";
4859 else if (curproxy->conf.logformat_string == default_tcp_log_format)
4860 oldlogformat = "option tcplog";
4861 else if (curproxy->conf.logformat_string == clf_http_log_format)
4862 oldlogformat = "option httplog clf";
Christopher Faulet767a84b2017-11-24 16:50:31 +01004863 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
4864 file, linenum, oldlogformat);
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004865 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004866 /* generate a detailed TCP log */
Willy Tarreau62a61232013-04-12 18:13:46 +02004867 if (curproxy->conf.logformat_string != default_http_log_format &&
4868 curproxy->conf.logformat_string != default_tcp_log_format &&
4869 curproxy->conf.logformat_string != clf_http_log_format)
4870 free(curproxy->conf.logformat_string);
4871 curproxy->conf.logformat_string = default_tcp_log_format;
4872
4873 free(curproxy->conf.lfs_file);
4874 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4875 curproxy->conf.lfs_line = curproxy->conf.args.line;
William Lallemanddf1425a2015-04-28 20:17:49 +02004876
4877 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4878 goto out;
Tim Duesterhus9ad9f352018-02-05 20:52:27 +01004879
4880 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
4881 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
4882 file, linenum, curproxy->id);
4883 err_code |= ERR_WARN;
4884 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01004885 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004886 else if (!strcmp(args[1], "tcpka")) {
Willy Tarreau87b09662015-04-03 00:22:06 +02004887 /* enable TCP keep-alives on client and server streams */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004888 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004889 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004890
William Lallemanddf1425a2015-04-28 20:17:49 +02004891 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4892 goto out;
4893
Willy Tarreau13943ab2006-12-31 00:24:10 +01004894 if (curproxy->cap & PR_CAP_FE)
4895 curproxy->options |= PR_O_TCP_CLI_KA;
4896 if (curproxy->cap & PR_CAP_BE)
4897 curproxy->options |= PR_O_TCP_SRV_KA;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004898 }
4899 else if (!strcmp(args[1], "httpchk")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +01004900 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004901 err_code |= ERR_WARN;
4902
Willy Tarreaubaaee002006-06-26 02:48:02 +02004903 /* use HTTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004904 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004905 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004906 curproxy->options2 &= ~PR_O2_CHK_ANY;
4907 curproxy->options2 |= PR_O2_HTTP_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004908 if (!*args[2]) { /* no argument */
4909 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
4910 curproxy->check_len = strlen(DEF_CHECK_REQ);
4911 } else if (!*args[3]) { /* one argument : URI */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004912 int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004913 curproxy->check_req = malloc(reqlen);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004914 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Willy Tarreaue9d87882010-01-27 11:28:42 +01004915 "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */
Willy Tarreaubaaee002006-06-26 02:48:02 +02004916 } else { /* more arguments : METHOD URI [HTTP_VER] */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004917 int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004918 if (*args[4])
4919 reqlen += strlen(args[4]);
4920 else
4921 reqlen += strlen("HTTP/1.0");
4922
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004923 curproxy->check_req = malloc(reqlen);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004924 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Willy Tarreaue9d87882010-01-27 11:28:42 +01004925 "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004926 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004927 if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code))
4928 goto out;
Willy Tarreauf3c69202006-07-09 16:42:34 +02004929 }
4930 else if (!strcmp(args[1], "ssl-hello-chk")) {
4931 /* use SSLv3 CLIENT HELLO to check servers' health */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004932 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004933 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004934
Willy Tarreaua534fea2008-08-03 12:19:50 +02004935 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004936 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004937 curproxy->options2 &= ~PR_O2_CHK_ANY;
Willy Tarreau07a54902010-03-29 18:33:29 +02004938 curproxy->options2 |= PR_O2_SSL3_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004939
4940 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4941 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004942 }
Willy Tarreau23677902007-05-08 23:50:35 +02004943 else if (!strcmp(args[1], "smtpchk")) {
4944 /* use SMTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004945 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004946 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004947 curproxy->options2 &= ~PR_O2_CHK_ANY;
4948 curproxy->options2 |= PR_O2_SMTP_CHK;
Willy Tarreau23677902007-05-08 23:50:35 +02004949
4950 if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */
4951 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4952 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4953 } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */
4954 if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) {
4955 int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004956 curproxy->check_req = malloc(reqlen);
Willy Tarreau23677902007-05-08 23:50:35 +02004957 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
4958 "%s %s\r\n", args[2], args[3]); /* HELO hostname */
4959 } else {
4960 /* this just hits the default for now, but you could potentially expand it to allow for other stuff
4961 though, it's unlikely you'd want to send anything other than an EHLO or HELO */
4962 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4963 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4964 }
4965 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004966 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
4967 goto out;
Willy Tarreau23677902007-05-08 23:50:35 +02004968 }
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004969 else if (!strcmp(args[1], "pgsql-check")) {
4970 /* use PostgreSQL request to check servers' health */
4971 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4972 err_code |= ERR_WARN;
4973
4974 free(curproxy->check_req);
4975 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004976 curproxy->options2 &= ~PR_O2_CHK_ANY;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004977 curproxy->options2 |= PR_O2_PGSQL_CHK;
4978
4979 if (*(args[2])) {
4980 int cur_arg = 2;
4981
4982 while (*(args[cur_arg])) {
4983 if (strcmp(args[cur_arg], "user") == 0) {
4984 char * packet;
4985 uint32_t packet_len;
4986 uint32_t pv;
4987
4988 /* suboption header - needs additional argument for it */
4989 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004990 ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
4991 file, linenum, args[0], args[1], args[cur_arg]);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004992 err_code |= ERR_ALERT | ERR_FATAL;
4993 goto out;
4994 }
4995
4996 /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */
4997 packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1;
4998 pv = htonl(0x30000); /* protocol version 3.0 */
4999
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005000 packet = calloc(1, packet_len);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01005001
5002 memcpy(packet + 4, &pv, 4);
5003
5004 /* copy "user" */
5005 memcpy(packet + 8, "user", 4);
5006
5007 /* copy username */
5008 memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1]));
5009
5010 free(curproxy->check_req);
5011 curproxy->check_req = packet;
5012 curproxy->check_len = packet_len;
5013
5014 packet_len = htonl(packet_len);
5015 memcpy(packet, &packet_len, 4);
5016 cur_arg += 2;
5017 } else {
5018 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005019 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
5020 file, linenum, args[0], args[1]);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01005021 err_code |= ERR_ALERT | ERR_FATAL;
5022 goto out;
5023 }
5024 } /* end while loop */
5025 }
William Lallemanddf1425a2015-04-28 20:17:49 +02005026 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
5027 goto out;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01005028 }
5029
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005030 else if (!strcmp(args[1], "redis-check")) {
5031 /* use REDIS PING request to check servers' health */
5032 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
5033 err_code |= ERR_WARN;
5034
5035 free(curproxy->check_req);
5036 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005037 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005038 curproxy->options2 |= PR_O2_REDIS_CHK;
5039
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005040 curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1);
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005041 memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1);
5042 curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02005043
5044 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5045 goto out;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005046 }
5047
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005048 else if (!strcmp(args[1], "mysql-check")) {
5049 /* use MYSQL request to check servers' health */
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005050 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
5051 err_code |= ERR_WARN;
5052
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005053 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01005054 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005055 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005056 curproxy->options2 |= PR_O2_MYSQL_CHK;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005057
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005058 /* This is an example of a MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte.
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005059 * const char mysql40_client_auth_pkt[] = {
5060 * "\x0e\x00\x00" // packet length
5061 * "\x01" // packet number
5062 * "\x00\x00" // client capabilities
5063 * "\x00\x00\x01" // max packet
5064 * "haproxy\x00" // username (null terminated string)
5065 * "\x00" // filler (always 0x00)
5066 * "\x01\x00\x00" // packet length
5067 * "\x00" // packet number
5068 * "\x01" // COM_QUIT command
5069 * };
5070 */
5071
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005072 /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic.
5073 * const char mysql41_client_auth_pkt[] = {
5074 * "\x0e\x00\x00\" // packet length
5075 * "\x01" // packet number
5076 * "\x00\x00\x00\x00" // client capabilities
5077 * "\x00\x00\x00\x01" // max packet
5078 * "\x21" // character set (UTF-8)
5079 * char[23] // All zeroes
5080 * "haproxy\x00" // username (null terminated string)
5081 * "\x00" // filler (always 0x00)
5082 * "\x01\x00\x00" // packet length
5083 * "\x00" // packet number
5084 * "\x01" // COM_QUIT command
5085 * };
5086 */
5087
5088
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005089 if (*(args[2])) {
5090 int cur_arg = 2;
5091
5092 while (*(args[cur_arg])) {
5093 if (strcmp(args[cur_arg], "user") == 0) {
5094 char *mysqluser;
5095 int packetlen, reqlen, userlen;
5096
5097 /* suboption header - needs additional argument for it */
5098 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005099 ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
5100 file, linenum, args[0], args[1], args[cur_arg]);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005101 err_code |= ERR_ALERT | ERR_FATAL;
5102 goto out;
5103 }
5104 mysqluser = args[cur_arg + 1];
5105 userlen = strlen(mysqluser);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005106
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005107 if (*(args[cur_arg+2])) {
5108 if (!strcmp(args[cur_arg+2], "post-41")) {
5109 packetlen = userlen + 7 + 27;
5110 reqlen = packetlen + 9;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005111
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005112 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005113 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005114 curproxy->check_len = reqlen;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005115
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005116 snprintf(curproxy->check_req, 4, "%c%c%c",
5117 ((unsigned char) packetlen & 0xff),
5118 ((unsigned char) (packetlen >> 8) & 0xff),
5119 ((unsigned char) (packetlen >> 16) & 0xff));
5120
5121 curproxy->check_req[3] = 1;
Olivier Houchard33320902018-10-16 18:39:38 +02005122 curproxy->check_req[5] = 0x82; // 130
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005123 curproxy->check_req[11] = 1;
5124 curproxy->check_req[12] = 33;
5125 memcpy(&curproxy->check_req[36], mysqluser, userlen);
5126 curproxy->check_req[36 + userlen + 1 + 1] = 1;
5127 curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1;
5128 cur_arg += 3;
5129 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005130 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005131 err_code |= ERR_ALERT | ERR_FATAL;
5132 goto out;
5133 }
5134 } else {
5135 packetlen = userlen + 7;
5136 reqlen = packetlen + 9;
5137
5138 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005139 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005140 curproxy->check_len = reqlen;
5141
5142 snprintf(curproxy->check_req, 4, "%c%c%c",
5143 ((unsigned char) packetlen & 0xff),
5144 ((unsigned char) (packetlen >> 8) & 0xff),
5145 ((unsigned char) (packetlen >> 16) & 0xff));
5146
5147 curproxy->check_req[3] = 1;
Olivier Houchard33320902018-10-16 18:39:38 +02005148 curproxy->check_req[5] = 0x80;
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005149 curproxy->check_req[8] = 1;
5150 memcpy(&curproxy->check_req[9], mysqluser, userlen);
5151 curproxy->check_req[9 + userlen + 1 + 1] = 1;
5152 curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1;
5153 cur_arg += 2;
5154 }
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005155 } else {
5156 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005157 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
5158 file, linenum, args[0], args[1]);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005159 err_code |= ERR_ALERT | ERR_FATAL;
5160 goto out;
5161 }
5162 } /* end while loop */
5163 }
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005164 }
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005165 else if (!strcmp(args[1], "ldap-check")) {
5166 /* use LDAP request to check servers' health */
5167 free(curproxy->check_req);
5168 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005169 curproxy->options2 &= ~PR_O2_CHK_ANY;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005170 curproxy->options2 |= PR_O2_LDAP_CHK;
5171
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005172 curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1);
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005173 memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1);
5174 curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02005175 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5176 goto out;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005177 }
Christopher Fauletba7bc162016-11-07 21:07:38 +01005178 else if (!strcmp(args[1], "spop-check")) {
5179 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005180 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n",
5181 file, linenum, args[0], args[1]);
Christopher Fauletba7bc162016-11-07 21:07:38 +01005182 err_code |= ERR_ALERT | ERR_FATAL;
5183 goto out;
5184 }
5185 if (curproxy->cap & PR_CAP_FE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005186 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n",
5187 file, linenum, args[0], args[1]);
Christopher Fauletba7bc162016-11-07 21:07:38 +01005188 err_code |= ERR_ALERT | ERR_FATAL;
5189 goto out;
5190 }
5191
5192 /* use SPOE request to check servers' health */
5193 free(curproxy->check_req);
5194 curproxy->check_req = NULL;
5195 curproxy->options2 &= ~PR_O2_CHK_ANY;
5196 curproxy->options2 |= PR_O2_SPOP_CHK;
5197
Christopher Faulet8ef75252017-02-20 22:56:03 +01005198 if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005199 ha_alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum);
Christopher Fauletba7bc162016-11-07 21:07:38 +01005200 err_code |= ERR_ALERT | ERR_FATAL;
5201 goto out;
5202 }
5203 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5204 goto out;
5205 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005206 else if (!strcmp(args[1], "tcp-check")) {
5207 /* use raw TCPCHK send/expect to check servers' health */
5208 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
5209 err_code |= ERR_WARN;
5210
5211 free(curproxy->check_req);
5212 curproxy->check_req = NULL;
5213 curproxy->options2 &= ~PR_O2_CHK_ANY;
5214 curproxy->options2 |= PR_O2_TCPCHK_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02005215 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5216 goto out;
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005217 }
Simon Horman98637e52014-06-20 12:30:16 +09005218 else if (!strcmp(args[1], "external-check")) {
5219 /* excute an external command to check servers' health */
5220 free(curproxy->check_req);
5221 curproxy->check_req = NULL;
5222 curproxy->options2 &= ~PR_O2_CHK_ANY;
5223 curproxy->options2 |= PR_O2_EXT_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02005224 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5225 goto out;
Simon Horman98637e52014-06-20 12:30:16 +09005226 }
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005227 else if (!strcmp(args[1], "forwardfor")) {
Ross Westaf72a1d2008-08-03 10:51:45 +02005228 int cur_arg;
5229
5230 /* insert x-forwarded-for field, but not for the IP address listed as an except.
5231 * set default options (ie: bitfield, header name, etc)
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005232 */
Ross Westaf72a1d2008-08-03 10:51:45 +02005233
Willy Tarreau87cf5142011-08-19 22:57:24 +02005234 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
Ross Westaf72a1d2008-08-03 10:51:45 +02005235
5236 free(curproxy->fwdfor_hdr_name);
5237 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
5238 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
5239
5240 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
5241 cur_arg = 2;
5242 while (*(args[cur_arg])) {
5243 if (!strcmp(args[cur_arg], "except")) {
5244 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01005245 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005246 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
5247 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005248 err_code |= ERR_ALERT | ERR_FATAL;
5249 goto out;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005250 }
5251 /* flush useless bits */
5252 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
Ross Westaf72a1d2008-08-03 10:51:45 +02005253 cur_arg += 2;
5254 } else if (!strcmp(args[cur_arg], "header")) {
5255 /* suboption header - needs additional argument for it */
5256 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005257 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
5258 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005259 err_code |= ERR_ALERT | ERR_FATAL;
5260 goto out;
Ross Westaf72a1d2008-08-03 10:51:45 +02005261 }
5262 free(curproxy->fwdfor_hdr_name);
5263 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
5264 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
5265 cur_arg += 2;
Willy Tarreau87cf5142011-08-19 22:57:24 +02005266 } else if (!strcmp(args[cur_arg], "if-none")) {
5267 curproxy->options &= ~PR_O_FF_ALWAYS;
5268 cur_arg += 1;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005269 } else {
Ross Westaf72a1d2008-08-03 10:51:45 +02005270 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005271 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
5272 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005273 err_code |= ERR_ALERT | ERR_FATAL;
5274 goto out;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005275 }
Ross Westaf72a1d2008-08-03 10:51:45 +02005276 } /* end while loop */
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005277 }
Maik Broemme2850cb42009-04-17 18:53:21 +02005278 else if (!strcmp(args[1], "originalto")) {
5279 int cur_arg;
5280
5281 /* insert x-original-to field, but not for the IP address listed as an except.
5282 * set default options (ie: bitfield, header name, etc)
5283 */
5284
5285 curproxy->options |= PR_O_ORGTO;
5286
5287 free(curproxy->orgto_hdr_name);
5288 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
5289 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
5290
Willy Tarreau87cf5142011-08-19 22:57:24 +02005291 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
Maik Broemme2850cb42009-04-17 18:53:21 +02005292 cur_arg = 2;
5293 while (*(args[cur_arg])) {
5294 if (!strcmp(args[cur_arg], "except")) {
5295 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01005296 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005297 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
5298 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005299 err_code |= ERR_ALERT | ERR_FATAL;
5300 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005301 }
5302 /* flush useless bits */
5303 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
5304 cur_arg += 2;
5305 } else if (!strcmp(args[cur_arg], "header")) {
5306 /* suboption header - needs additional argument for it */
5307 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005308 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
5309 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005310 err_code |= ERR_ALERT | ERR_FATAL;
5311 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005312 }
5313 free(curproxy->orgto_hdr_name);
5314 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
5315 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
5316 cur_arg += 2;
5317 } else {
5318 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005319 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
5320 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005321 err_code |= ERR_ALERT | ERR_FATAL;
5322 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005323 }
5324 } /* end while loop */
5325 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005326 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005327 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005328 err_code |= ERR_ALERT | ERR_FATAL;
5329 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005330 }
Willy Tarreau93893792009-07-23 13:19:11 +02005331 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005332 }
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005333 else if (!strcmp(args[0], "default_backend")) {
5334 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005335 err_code |= ERR_WARN;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005336
5337 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005338 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005339 err_code |= ERR_ALERT | ERR_FATAL;
5340 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005341 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02005342 free(curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005343 curproxy->defbe.name = strdup(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005344
5345 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5346 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005347 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005348 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01005349 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005350 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005351
Willy Tarreaua3c504c2014-04-28 22:37:32 +02005352 if (!already_warned(WARN_REDISPATCH_DEPRECATED))
Christopher Faulet767a84b2017-11-24 16:50:31 +01005353 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n",
5354 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005355 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005356 /* enable reconnections to dispatch */
5357 curproxy->options |= PR_O_REDISP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005358
5359 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5360 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005361 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005362 else if (!strcmp(args[0], "http-reuse")) {
5363 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5364 err_code |= ERR_WARN;
5365
5366 if (strcmp(args[1], "never") == 0) {
5367 /* enable a graceful server shutdown on an HTTP 404 response */
5368 curproxy->options &= ~PR_O_REUSE_MASK;
5369 curproxy->options |= PR_O_REUSE_NEVR;
5370 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5371 goto out;
5372 }
Willy Tarreau161d45f2015-08-05 16:02:46 +02005373 else if (strcmp(args[1], "safe") == 0) {
5374 /* enable a graceful server shutdown on an HTTP 404 response */
5375 curproxy->options &= ~PR_O_REUSE_MASK;
5376 curproxy->options |= PR_O_REUSE_SAFE;
5377 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5378 goto out;
5379 }
Willy Tarreau449d74a2015-08-05 17:16:33 +02005380 else if (strcmp(args[1], "aggressive") == 0) {
5381 curproxy->options &= ~PR_O_REUSE_MASK;
5382 curproxy->options |= PR_O_REUSE_AGGR;
5383 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5384 goto out;
5385 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005386 else if (strcmp(args[1], "always") == 0) {
5387 /* enable a graceful server shutdown on an HTTP 404 response */
5388 curproxy->options &= ~PR_O_REUSE_MASK;
5389 curproxy->options |= PR_O_REUSE_ALWS;
5390 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5391 goto out;
5392 }
5393 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005394 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005395 err_code |= ERR_ALERT | ERR_FATAL;
5396 goto out;
5397 }
5398 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005399 else if (!strcmp(args[0], "http-check")) {
5400 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005401 err_code |= ERR_WARN;
Willy Tarreau48494c02007-11-30 10:41:39 +01005402
5403 if (strcmp(args[1], "disable-on-404") == 0) {
5404 /* enable a graceful server shutdown on an HTTP 404 response */
5405 curproxy->options |= PR_O_DISABLE404;
William Lallemanddf1425a2015-04-28 20:17:49 +02005406 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5407 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005408 }
Willy Tarreauef781042010-01-27 11:53:01 +01005409 else if (strcmp(args[1], "send-state") == 0) {
5410 /* enable emission of the apparent state of a server in HTTP checks */
5411 curproxy->options2 |= PR_O2_CHK_SNDST;
William Lallemanddf1425a2015-04-28 20:17:49 +02005412 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5413 goto out;
Willy Tarreauef781042010-01-27 11:53:01 +01005414 }
Willy Tarreaubd741542010-03-16 18:46:54 +01005415 else if (strcmp(args[1], "expect") == 0) {
5416 const char *ptr_arg;
5417 int cur_arg;
5418
5419 if (curproxy->options2 & PR_O2_EXP_TYPE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005420 ha_alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
Willy Tarreaubd741542010-03-16 18:46:54 +01005421 err_code |= ERR_ALERT | ERR_FATAL;
5422 goto out;
5423 }
5424
5425 cur_arg = 2;
5426 /* consider exclamation marks, sole or at the beginning of a word */
5427 while (*(ptr_arg = args[cur_arg])) {
5428 while (*ptr_arg == '!') {
5429 curproxy->options2 ^= PR_O2_EXP_INV;
5430 ptr_arg++;
5431 }
5432 if (*ptr_arg)
5433 break;
5434 cur_arg++;
5435 }
5436 /* now ptr_arg points to the beginning of a word past any possible
5437 * exclamation mark, and cur_arg is the argument which holds this word.
5438 */
5439 if (strcmp(ptr_arg, "status") == 0) {
5440 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005441 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5442 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005443 err_code |= ERR_ALERT | ERR_FATAL;
5444 goto out;
5445 }
5446 curproxy->options2 |= PR_O2_EXP_STS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005447 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005448 curproxy->expect_str = strdup(args[cur_arg + 1]);
5449 }
5450 else if (strcmp(ptr_arg, "string") == 0) {
5451 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005452 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5453 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005454 err_code |= ERR_ALERT | ERR_FATAL;
5455 goto out;
5456 }
5457 curproxy->options2 |= PR_O2_EXP_STR;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005458 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005459 curproxy->expect_str = strdup(args[cur_arg + 1]);
5460 }
5461 else if (strcmp(ptr_arg, "rstatus") == 0) {
5462 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005463 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5464 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005465 err_code |= ERR_ALERT | ERR_FATAL;
5466 goto out;
5467 }
5468 curproxy->options2 |= PR_O2_EXP_RSTS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005469 free(curproxy->expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005470 if (curproxy->expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005471 regex_free(curproxy->expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005472 free(curproxy->expect_regex);
5473 curproxy->expect_regex = NULL;
5474 }
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005475 curproxy->expect_str = strdup(args[cur_arg + 1]);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005476 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
5477 error = NULL;
5478 if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005479 ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5480 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005481 free(error);
Willy Tarreaubd741542010-03-16 18:46:54 +01005482 err_code |= ERR_ALERT | ERR_FATAL;
5483 goto out;
5484 }
5485 }
5486 else if (strcmp(ptr_arg, "rstring") == 0) {
5487 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005488 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5489 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005490 err_code |= ERR_ALERT | ERR_FATAL;
5491 goto out;
5492 }
5493 curproxy->options2 |= PR_O2_EXP_RSTR;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005494 free(curproxy->expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005495 if (curproxy->expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005496 regex_free(curproxy->expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005497 free(curproxy->expect_regex);
5498 curproxy->expect_regex = NULL;
5499 }
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005500 curproxy->expect_str = strdup(args[cur_arg + 1]);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005501 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
5502 error = NULL;
5503 if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005504 ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5505 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005506 free(error);
Willy Tarreaubd741542010-03-16 18:46:54 +01005507 err_code |= ERR_ALERT | ERR_FATAL;
5508 goto out;
5509 }
5510 }
5511 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005512 ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n",
5513 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005514 err_code |= ERR_ALERT | ERR_FATAL;
5515 goto out;
5516 }
5517 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005518 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005519 ha_alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'send-state', 'expect'.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005520 err_code |= ERR_ALERT | ERR_FATAL;
5521 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005522 }
5523 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005524 else if (!strcmp(args[0], "tcp-check")) {
5525 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5526 err_code |= ERR_WARN;
5527
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005528 if (strcmp(args[1], "comment") == 0) {
5529 int cur_arg;
5530 struct tcpcheck_rule *tcpcheck;
5531
5532 cur_arg = 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005533 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005534 tcpcheck->action = TCPCHK_ACT_COMMENT;
5535
5536 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005537 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5538 file, linenum, args[cur_arg]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005539 err_code |= ERR_ALERT | ERR_FATAL;
5540 goto out;
5541 }
5542
5543 tcpcheck->comment = strdup(args[cur_arg + 1]);
5544
5545 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
William Lallemanddf1425a2015-04-28 20:17:49 +02005546 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
5547 goto out;
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005548 }
5549 else if (strcmp(args[1], "connect") == 0) {
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005550 const char *ptr_arg;
5551 int cur_arg;
5552 struct tcpcheck_rule *tcpcheck;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005553
5554 /* check if first rule is also a 'connect' action */
Willy Tarreau5581c272015-05-13 12:24:53 +02005555 tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list);
5556 while (&tcpcheck->list != &curproxy->tcpcheck_rules &&
5557 tcpcheck->action == TCPCHK_ACT_COMMENT) {
5558 tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list);
5559 }
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005560
Willy Tarreau5581c272015-05-13 12:24:53 +02005561 if (&tcpcheck->list != &curproxy->tcpcheck_rules
5562 && tcpcheck->action != TCPCHK_ACT_CONNECT) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005563 ha_alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n",
5564 file, linenum);
Willy Tarreau5581c272015-05-13 12:24:53 +02005565 err_code |= ERR_ALERT | ERR_FATAL;
5566 goto out;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005567 }
5568
5569 cur_arg = 2;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005570 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005571 tcpcheck->action = TCPCHK_ACT_CONNECT;
5572
5573 /* parsing each parameters to fill up the rule */
5574 while (*(ptr_arg = args[cur_arg])) {
5575 /* tcp port */
5576 if (strcmp(args[cur_arg], "port") == 0) {
5577 if ( (atol(args[cur_arg + 1]) > 65535) ||
5578 (atol(args[cur_arg + 1]) < 1) ){
Christopher Faulet767a84b2017-11-24 16:50:31 +01005579 ha_alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n",
5580 file, linenum, args[0], args[1], "port", args[cur_arg + 1]);
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005581 err_code |= ERR_ALERT | ERR_FATAL;
5582 goto out;
5583 }
5584 tcpcheck->port = atol(args[cur_arg + 1]);
5585 cur_arg += 2;
5586 }
5587 /* send proxy protocol */
5588 else if (strcmp(args[cur_arg], "send-proxy") == 0) {
5589 tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY;
5590 cur_arg++;
5591 }
5592#ifdef USE_OPENSSL
5593 else if (strcmp(args[cur_arg], "ssl") == 0) {
5594 curproxy->options |= PR_O_TCPCHK_SSL;
5595 tcpcheck->conn_opts |= TCPCHK_OPT_SSL;
5596 cur_arg++;
5597 }
5598#endif /* USE_OPENSSL */
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005599 /* comment for this tcpcheck line */
5600 else if (strcmp(args[cur_arg], "comment") == 0) {
5601 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005602 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5603 file, linenum, args[cur_arg]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005604 err_code |= ERR_ALERT | ERR_FATAL;
5605 goto out;
5606 }
5607 tcpcheck->comment = strdup(args[cur_arg + 1]);
5608 cur_arg += 2;
5609 }
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005610 else {
5611#ifdef USE_OPENSSL
Christopher Faulet767a84b2017-11-24 16:50:31 +01005612 ha_alert("parsing [%s:%d] : '%s %s' expects 'comment', 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n",
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005613#else /* USE_OPENSSL */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005614 ha_alert("parsing [%s:%d] : '%s %s' expects 'comment', 'port', 'send-proxy' or but got '%s' as argument.\n",
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005615#endif /* USE_OPENSSL */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005616 file, linenum, args[0], args[1], args[cur_arg]);
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005617 err_code |= ERR_ALERT | ERR_FATAL;
5618 goto out;
5619 }
5620
5621 }
5622
5623 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5624 }
5625 else if (strcmp(args[1], "send") == 0) {
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005626 if (! *(args[2]) ) {
5627 /* SEND string expected */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005628 ha_alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n",
5629 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005630 err_code |= ERR_ALERT | ERR_FATAL;
5631 goto out;
5632 } else {
5633 struct tcpcheck_rule *tcpcheck;
5634
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005635 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005636
5637 tcpcheck->action = TCPCHK_ACT_SEND;
5638 tcpcheck->string_len = strlen(args[2]);
5639 tcpcheck->string = strdup(args[2]);
5640 tcpcheck->expect_regex = NULL;
5641
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005642 /* comment for this tcpcheck line */
5643 if (strcmp(args[3], "comment") == 0) {
5644 if (!*args[4]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005645 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5646 file, linenum, args[3]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005647 err_code |= ERR_ALERT | ERR_FATAL;
5648 goto out;
5649 }
5650 tcpcheck->comment = strdup(args[4]);
5651 }
5652
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005653 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5654 }
5655 }
5656 else if (strcmp(args[1], "send-binary") == 0) {
5657 if (! *(args[2]) ) {
5658 /* SEND binary string expected */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005659 ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n",
5660 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005661 err_code |= ERR_ALERT | ERR_FATAL;
5662 goto out;
5663 } else {
5664 struct tcpcheck_rule *tcpcheck;
5665 char *err = NULL;
5666
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005667 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005668
5669 tcpcheck->action = TCPCHK_ACT_SEND;
5670 if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005671 ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5672 file, linenum, args[0], args[1], args[2], err);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005673 err_code |= ERR_ALERT | ERR_FATAL;
5674 goto out;
5675 }
5676 tcpcheck->expect_regex = NULL;
5677
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005678 /* comment for this tcpcheck line */
5679 if (strcmp(args[3], "comment") == 0) {
5680 if (!*args[4]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005681 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5682 file, linenum, args[3]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005683 err_code |= ERR_ALERT | ERR_FATAL;
5684 goto out;
5685 }
5686 tcpcheck->comment = strdup(args[4]);
5687 }
5688
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005689 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5690 }
5691 }
5692 else if (strcmp(args[1], "expect") == 0) {
5693 const char *ptr_arg;
5694 int cur_arg;
5695 int inverse = 0;
5696
5697 if (curproxy->options2 & PR_O2_EXP_TYPE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005698 ha_alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005699 err_code |= ERR_ALERT | ERR_FATAL;
5700 goto out;
5701 }
5702
5703 cur_arg = 2;
5704 /* consider exclamation marks, sole or at the beginning of a word */
5705 while (*(ptr_arg = args[cur_arg])) {
5706 while (*ptr_arg == '!') {
5707 inverse = !inverse;
5708 ptr_arg++;
5709 }
5710 if (*ptr_arg)
5711 break;
5712 cur_arg++;
5713 }
5714 /* now ptr_arg points to the beginning of a word past any possible
5715 * exclamation mark, and cur_arg is the argument which holds this word.
5716 */
5717 if (strcmp(ptr_arg, "binary") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005718 struct tcpcheck_rule *tcpcheck;
5719 char *err = NULL;
5720
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005721 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005722 ha_alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n",
5723 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005724 err_code |= ERR_ALERT | ERR_FATAL;
5725 goto out;
5726 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005727
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005728 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005729
5730 tcpcheck->action = TCPCHK_ACT_EXPECT;
5731 if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005732 ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5733 file, linenum, args[0], args[1], args[2], err);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005734 err_code |= ERR_ALERT | ERR_FATAL;
5735 goto out;
5736 }
5737 tcpcheck->expect_regex = NULL;
5738 tcpcheck->inverse = inverse;
5739
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005740 /* tcpcheck comment */
5741 cur_arg += 2;
5742 if (strcmp(args[cur_arg], "comment") == 0) {
5743 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005744 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5745 file, linenum, args[cur_arg + 1]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005746 err_code |= ERR_ALERT | ERR_FATAL;
5747 goto out;
5748 }
5749 tcpcheck->comment = strdup(args[cur_arg + 1]);
5750 }
5751
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005752 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5753 }
5754 else if (strcmp(ptr_arg, "string") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005755 struct tcpcheck_rule *tcpcheck;
5756
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005757 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005758 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5759 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005760 err_code |= ERR_ALERT | ERR_FATAL;
5761 goto out;
5762 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005763
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005764 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005765
5766 tcpcheck->action = TCPCHK_ACT_EXPECT;
5767 tcpcheck->string_len = strlen(args[cur_arg + 1]);
5768 tcpcheck->string = strdup(args[cur_arg + 1]);
5769 tcpcheck->expect_regex = NULL;
5770 tcpcheck->inverse = inverse;
5771
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005772 /* tcpcheck comment */
5773 cur_arg += 2;
5774 if (strcmp(args[cur_arg], "comment") == 0) {
5775 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005776 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5777 file, linenum, args[cur_arg + 1]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005778 err_code |= ERR_ALERT | ERR_FATAL;
5779 goto out;
5780 }
5781 tcpcheck->comment = strdup(args[cur_arg + 1]);
5782 }
5783
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005784 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5785 }
5786 else if (strcmp(ptr_arg, "rstring") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005787 struct tcpcheck_rule *tcpcheck;
5788
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005789 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005790 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5791 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005792 err_code |= ERR_ALERT | ERR_FATAL;
5793 goto out;
5794 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005795
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005796 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005797
5798 tcpcheck->action = TCPCHK_ACT_EXPECT;
5799 tcpcheck->string_len = 0;
5800 tcpcheck->string = NULL;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005801 tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex));
5802 error = NULL;
5803 if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005804 ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5805 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005806 free(error);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005807 err_code |= ERR_ALERT | ERR_FATAL;
5808 goto out;
5809 }
5810 tcpcheck->inverse = inverse;
5811
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005812 /* tcpcheck comment */
5813 cur_arg += 2;
5814 if (strcmp(args[cur_arg], "comment") == 0) {
5815 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005816 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5817 file, linenum, args[cur_arg + 1]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005818 err_code |= ERR_ALERT | ERR_FATAL;
5819 goto out;
5820 }
5821 tcpcheck->comment = strdup(args[cur_arg + 1]);
5822 }
5823
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005824 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5825 }
5826 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005827 ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n",
5828 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005829 err_code |= ERR_ALERT | ERR_FATAL;
5830 goto out;
5831 }
5832 }
5833 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005834 ha_alert("parsing [%s:%d] : '%s' only supports 'comment', 'connect', 'send' or 'expect'.\n", file, linenum, args[0]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005835 err_code |= ERR_ALERT | ERR_FATAL;
5836 goto out;
5837 }
5838 }
Willy Tarreaub80c2302007-11-30 20:51:32 +01005839 else if (!strcmp(args[0], "monitor")) {
Willy Tarreaub099aca2008-10-12 17:26:37 +02005840 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005841 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005842 err_code |= ERR_ALERT | ERR_FATAL;
5843 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02005844 }
5845
Willy Tarreaub80c2302007-11-30 20:51:32 +01005846 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005847 err_code |= ERR_WARN;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005848
5849 if (strcmp(args[1], "fail") == 0) {
5850 /* add a condition to fail monitor requests */
Willy Tarreauef6494c2010-01-28 17:12:36 +01005851 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005852 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
5853 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005854 err_code |= ERR_ALERT | ERR_FATAL;
5855 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005856 }
5857
Willy Tarreau721d8e02017-12-01 18:25:08 +01005858 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
Christopher Faulet1b421ea2017-09-22 14:38:56 +02005859 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005860 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
5861 file, linenum, args[0], args[1], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02005862 err_code |= ERR_ALERT | ERR_FATAL;
5863 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005864 }
5865 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
5866 }
5867 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005868 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005869 err_code |= ERR_ALERT | ERR_FATAL;
5870 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005871 }
5872 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005873#ifdef TPROXY
5874 else if (!strcmp(args[0], "transparent")) {
5875 /* enable transparent proxy connections */
5876 curproxy->options |= PR_O_TRANSP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005877 if (alertif_too_many_args(0, file, linenum, args, &err_code))
5878 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005879 }
5880#endif
5881 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005882 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005883 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005884
Willy Tarreaubaaee002006-06-26 02:48:02 +02005885 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005886 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005887 err_code |= ERR_ALERT | ERR_FATAL;
5888 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005889 }
5890 curproxy->maxconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005891 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5892 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005893 }
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005894 else if (!strcmp(args[0], "backlog")) { /* backlog */
5895 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005896 err_code |= ERR_WARN;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005897
5898 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005899 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005900 err_code |= ERR_ALERT | ERR_FATAL;
5901 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005902 }
5903 curproxy->backlog = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005904 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5905 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005906 }
Willy Tarreau86034312006-12-29 00:10:33 +01005907 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005908 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005909 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005910
Willy Tarreau86034312006-12-29 00:10:33 +01005911 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005912 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005913 err_code |= ERR_ALERT | ERR_FATAL;
5914 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005915 }
5916 curproxy->fullconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005917 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5918 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005919 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005920 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
5921 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005922 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005923 err_code |= ERR_ALERT | ERR_FATAL;
5924 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005925 }
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005926 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
5927 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005928 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
5929 file, linenum, *err);
Willy Tarreau93893792009-07-23 13:19:11 +02005930 err_code |= ERR_ALERT | ERR_FATAL;
5931 goto out;
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005932 }
5933 curproxy->grace = val;
William Lallemanddf1425a2015-04-28 20:17:49 +02005934 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5935 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005936 }
5937 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
David du Colombier6f5ccb12011-03-10 22:26:24 +01005938 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005939 int port1, port2;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005940 struct protocol *proto;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005941
Willy Tarreaubaaee002006-06-26 02:48:02 +02005942 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005943 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005944 err_code |= ERR_ALERT | ERR_FATAL;
5945 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005946 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01005947 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005948 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005949
Willy Tarreau48ef4c92017-01-06 18:32:38 +01005950 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005951 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005952 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005953 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005954 goto out;
5955 }
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005956
5957 proto = protocol_by_family(sk->ss_family);
5958 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005959 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
5960 file, linenum, args[0], args[1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005961 err_code |= ERR_ALERT | ERR_FATAL;
5962 goto out;
5963 }
5964
5965 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005966 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
5967 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005968 err_code |= ERR_ALERT | ERR_FATAL;
5969 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005970 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005971
5972 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005973 ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
5974 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01005975 err_code |= ERR_ALERT | ERR_FATAL;
5976 goto out;
5977 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005978
William Lallemanddf1425a2015-04-28 20:17:49 +02005979 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5980 goto out;
5981
Willy Tarreaud5191e72010-02-09 20:50:45 +01005982 curproxy->dispatch_addr = *sk;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005983 curproxy->options |= PR_O_DISPATCH;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005984 }
5985 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005986 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005987 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005988
Willy Tarreaua93c74b2012-05-08 18:14:39 +02005989 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005990 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02005991 err_code |= ERR_ALERT | ERR_FATAL;
5992 goto out;
Willy Tarreau2fcb5002007-05-08 13:35:26 +02005993 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005994 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005995 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005996 /**
5997 * The syntax for hash-type config element is
5998 * hash-type {map-based|consistent} [[<algo>] avalanche]
5999 *
6000 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
6001 */
6002 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
Bhaskar98634f02013-10-29 23:30:51 -04006003
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006004 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
6005 err_code |= ERR_WARN;
6006
6007 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006008 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
6009 }
6010 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006011 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
6012 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006013 else if (strcmp(args[1], "avalanche") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006014 ha_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]);
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006015 err_code |= ERR_ALERT | ERR_FATAL;
6016 goto out;
Willy Tarreau798a39c2010-11-24 15:04:29 +01006017 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006018 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006019 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006020 err_code |= ERR_ALERT | ERR_FATAL;
6021 goto out;
6022 }
Bhaskar98634f02013-10-29 23:30:51 -04006023
6024 /* set the hash function to use */
6025 if (!*args[2]) {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006026 /* the default algo is sdbm */
Bhaskar98634f02013-10-29 23:30:51 -04006027 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006028
6029 /* if consistent with no argument, then avalanche modifier is also applied */
6030 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
6031 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
Bhaskar98634f02013-10-29 23:30:51 -04006032 } else {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006033 /* set the hash function */
6034 if (!strcmp(args[2], "sdbm")) {
6035 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
6036 }
6037 else if (!strcmp(args[2], "djb2")) {
6038 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
Willy Tarreau324f07f2015-01-20 19:44:50 +01006039 }
6040 else if (!strcmp(args[2], "wt6")) {
Willy Tarreaua0f42712013-11-14 14:30:35 +01006041 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006042 }
Willy Tarreau324f07f2015-01-20 19:44:50 +01006043 else if (!strcmp(args[2], "crc32")) {
6044 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
6045 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006046 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006047 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006048 err_code |= ERR_ALERT | ERR_FATAL;
6049 goto out;
6050 }
6051
6052 /* set the hash modifier */
6053 if (!strcmp(args[3], "avalanche")) {
6054 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
6055 }
6056 else if (*args[3]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006057 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006058 err_code |= ERR_ALERT | ERR_FATAL;
6059 goto out;
6060 }
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01006061 }
William Lallemanda73203e2012-03-12 12:48:57 +01006062 }
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04006063 else if (strcmp(args[0], "hash-balance-factor") == 0) {
6064 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006065 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04006066 err_code |= ERR_ALERT | ERR_FATAL;
6067 goto out;
6068 }
6069 curproxy->lbprm.chash.balance_factor = atol(args[1]);
6070 if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006071 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04006072 err_code |= ERR_ALERT | ERR_FATAL;
6073 goto out;
6074 }
6075 }
William Lallemanda73203e2012-03-12 12:48:57 +01006076 else if (strcmp(args[0], "unique-id-format") == 0) {
6077 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006078 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
William Lallemanda73203e2012-03-12 12:48:57 +01006079 err_code |= ERR_ALERT | ERR_FATAL;
6080 goto out;
6081 }
William Lallemand3203ff42012-11-11 17:30:56 +01006082 if (*(args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006083 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
William Lallemand3203ff42012-11-11 17:30:56 +01006084 err_code |= ERR_ALERT | ERR_FATAL;
6085 goto out;
6086 }
Willy Tarreau62a61232013-04-12 18:13:46 +02006087 free(curproxy->conf.uniqueid_format_string);
6088 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02006089
Willy Tarreau62a61232013-04-12 18:13:46 +02006090 free(curproxy->conf.uif_file);
6091 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
6092 curproxy->conf.uif_line = curproxy->conf.args.line;
William Lallemand723b73a2012-02-08 16:37:49 +01006093 }
William Lallemanda73203e2012-03-12 12:48:57 +01006094
6095 else if (strcmp(args[0], "unique-id-header") == 0) {
6096 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006097 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
William Lallemanda73203e2012-03-12 12:48:57 +01006098 err_code |= ERR_ALERT | ERR_FATAL;
6099 goto out;
6100 }
6101 free(curproxy->header_unique_id);
6102 curproxy->header_unique_id = strdup(args[1]);
6103 }
6104
William Lallemand723b73a2012-02-08 16:37:49 +01006105 else if (strcmp(args[0], "log-format") == 0) {
6106 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006107 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
William Lallemand723b73a2012-02-08 16:37:49 +01006108 err_code |= ERR_ALERT | ERR_FATAL;
6109 goto out;
6110 }
William Lallemand3203ff42012-11-11 17:30:56 +01006111 if (*(args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006112 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
William Lallemand3203ff42012-11-11 17:30:56 +01006113 err_code |= ERR_ALERT | ERR_FATAL;
6114 goto out;
6115 }
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02006116 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
6117 char *oldlogformat = "log-format";
Willy Tarreau196729e2012-05-31 19:30:26 +02006118
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02006119 if (curproxy->conf.logformat_string == default_http_log_format)
6120 oldlogformat = "option httplog";
6121 else if (curproxy->conf.logformat_string == default_tcp_log_format)
6122 oldlogformat = "option tcplog";
6123 else if (curproxy->conf.logformat_string == clf_http_log_format)
6124 oldlogformat = "option httplog clf";
Christopher Faulet767a84b2017-11-24 16:50:31 +01006125 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
6126 file, linenum, oldlogformat);
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02006127 }
Willy Tarreau62a61232013-04-12 18:13:46 +02006128 if (curproxy->conf.logformat_string != default_http_log_format &&
6129 curproxy->conf.logformat_string != default_tcp_log_format &&
6130 curproxy->conf.logformat_string != clf_http_log_format)
6131 free(curproxy->conf.logformat_string);
6132 curproxy->conf.logformat_string = strdup(args[1]);
6133
6134 free(curproxy->conf.lfs_file);
6135 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
6136 curproxy->conf.lfs_line = curproxy->conf.args.line;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02006137
6138 /* get a chance to improve log-format error reporting by
6139 * reporting the correct line-number when possible.
6140 */
6141 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006142 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
6143 file, linenum, curproxy->id);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02006144 err_code |= ERR_WARN;
6145 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006146 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02006147 else if (!strcmp(args[0], "log-format-sd")) {
6148 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006149 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
Dragan Dosen0b85ece2015-09-25 19:17:44 +02006150 err_code |= ERR_ALERT | ERR_FATAL;
6151 goto out;
6152 }
6153 if (*(args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006154 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
Dragan Dosen0b85ece2015-09-25 19:17:44 +02006155 err_code |= ERR_ALERT | ERR_FATAL;
6156 goto out;
6157 }
6158
6159 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
6160 free(curproxy->conf.logformat_sd_string);
6161 curproxy->conf.logformat_sd_string = strdup(args[1]);
6162
6163 free(curproxy->conf.lfsd_file);
6164 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
6165 curproxy->conf.lfsd_line = curproxy->conf.args.line;
6166
6167 /* get a chance to improve log-format-sd error reporting by
6168 * reporting the correct line-number when possible.
6169 */
6170 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006171 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
6172 file, linenum, curproxy->id);
Dragan Dosen0b85ece2015-09-25 19:17:44 +02006173 err_code |= ERR_WARN;
6174 }
6175 }
Willy Tarreau094af4e2015-01-07 15:03:42 +01006176 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
6177 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006178 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
Willy Tarreau094af4e2015-01-07 15:03:42 +01006179 err_code |= ERR_ALERT | ERR_FATAL;
6180 goto out;
6181 }
Dragan Dosen43885c72015-10-01 13:18:13 +02006182 chunk_destroy(&curproxy->log_tag);
6183 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
Willy Tarreau094af4e2015-01-07 15:03:42 +01006184 }
Christopher Faulet4b0b79d2018-03-26 15:54:32 +02006185 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
6186 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
6187 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006188 err_code |= ERR_ALERT | ERR_FATAL;
6189 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006190 }
6191 }
6192 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006193 int cur_arg;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006194 int port1, port2;
David du Colombier6f5ccb12011-03-10 22:26:24 +01006195 struct sockaddr_storage *sk;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006196 struct protocol *proto;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006197
Willy Tarreau977b8e42006-12-29 14:19:17 +01006198 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006199 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006200
Willy Tarreaubaaee002006-06-26 02:48:02 +02006201 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006202 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
6203 file, linenum, "source", "usesrc", "interface");
Willy Tarreau93893792009-07-23 13:19:11 +02006204 err_code |= ERR_ALERT | ERR_FATAL;
6205 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006206 }
Willy Tarreau368480c2009-03-01 08:27:21 +01006207
6208 /* we must first clear any optional default setting */
Willy Tarreauef9a3602012-12-08 22:29:20 +01006209 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6210 free(curproxy->conn_src.iface_name);
6211 curproxy->conn_src.iface_name = NULL;
6212 curproxy->conn_src.iface_len = 0;
Willy Tarreau368480c2009-03-01 08:27:21 +01006213
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006214 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006215 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006216 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
6217 file, linenum, args[0], args[1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006218 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006219 goto out;
6220 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006221
6222 proto = protocol_by_family(sk->ss_family);
6223 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006224 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
6225 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006226 err_code |= ERR_ALERT | ERR_FATAL;
6227 goto out;
6228 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006229
6230 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006231 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6232 file, linenum, args[0], args[1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006233 err_code |= ERR_ALERT | ERR_FATAL;
6234 goto out;
6235 }
6236
Willy Tarreauef9a3602012-12-08 22:29:20 +01006237 curproxy->conn_src.source_addr = *sk;
6238 curproxy->conn_src.opts |= CO_SRC_BIND;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006239
6240 cur_arg = 2;
6241 while (*(args[cur_arg])) {
6242 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
Willy Tarreau29fbe512015-08-20 19:35:14 +02006243#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006244 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006245 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
6246 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006247 err_code |= ERR_ALERT | ERR_FATAL;
6248 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006249 }
6250
6251 if (!strcmp(args[cur_arg + 1], "client")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006252 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6253 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006254 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006255 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6256 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
Willy Tarreaubce70882009-09-07 11:51:47 +02006257 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
6258 char *name, *end;
6259
6260 name = args[cur_arg+1] + 7;
6261 while (isspace(*name))
6262 name++;
6263
6264 end = name;
6265 while (*end && !isspace(*end) && *end != ',' && *end != ')')
6266 end++;
6267
Willy Tarreauef9a3602012-12-08 22:29:20 +01006268 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6269 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
6270 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
6271 curproxy->conn_src.bind_hdr_len = end - name;
6272 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
6273 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
6274 curproxy->conn_src.bind_hdr_occ = -1;
Willy Tarreaubce70882009-09-07 11:51:47 +02006275
6276 /* now look for an occurrence number */
6277 while (isspace(*end))
6278 end++;
6279 if (*end == ',') {
6280 end++;
6281 name = end;
6282 if (*end == '-')
6283 end++;
Willy Tarreau83d84cf2012-11-22 01:04:31 +01006284 while (isdigit((int)*end))
Willy Tarreaubce70882009-09-07 11:51:47 +02006285 end++;
Willy Tarreauef9a3602012-12-08 22:29:20 +01006286 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
Willy Tarreaubce70882009-09-07 11:51:47 +02006287 }
6288
Willy Tarreauef9a3602012-12-08 22:29:20 +01006289 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006290 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
6291 " occurrences values smaller than %d.\n",
6292 file, linenum, MAX_HDR_HISTORY);
Willy Tarreaubce70882009-09-07 11:51:47 +02006293 err_code |= ERR_ALERT | ERR_FATAL;
6294 goto out;
6295 }
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006296 } else {
Willy Tarreau902636f2013-03-10 19:44:48 +01006297 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006298
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006299 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006300 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006301 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
6302 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006303 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006304 goto out;
6305 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006306
6307 proto = protocol_by_family(sk->ss_family);
6308 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006309 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
6310 file, linenum, args[cur_arg], args[cur_arg+1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006311 err_code |= ERR_ALERT | ERR_FATAL;
6312 goto out;
6313 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006314
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006315 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006316 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6317 file, linenum, args[cur_arg], args[cur_arg + 1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006318 err_code |= ERR_ALERT | ERR_FATAL;
6319 goto out;
6320 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006321 curproxy->conn_src.tproxy_addr = *sk;
6322 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006323 }
6324 global.last_checks |= LSTCHK_NETADM;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006325#else /* no TPROXY support */
Christopher Faulet767a84b2017-11-24 16:50:31 +01006326 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
6327 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006328 err_code |= ERR_ALERT | ERR_FATAL;
6329 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006330#endif
6331 cur_arg += 2;
6332 continue;
Willy Tarreau77074d52006-11-12 23:57:19 +01006333 }
6334
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006335 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
6336#ifdef SO_BINDTODEVICE
6337 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006338 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
6339 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006340 err_code |= ERR_ALERT | ERR_FATAL;
6341 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006342 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006343 free(curproxy->conn_src.iface_name);
6344 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
6345 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006346 global.last_checks |= LSTCHK_NETADM;
6347#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01006348 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
6349 file, linenum, args[0], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02006350 err_code |= ERR_ALERT | ERR_FATAL;
6351 goto out;
Willy Tarreau5b6995c2008-01-13 16:31:17 +01006352#endif
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006353 cur_arg += 2;
6354 continue;
6355 }
Christopher Faulet767a84b2017-11-24 16:50:31 +01006356 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
6357 file, linenum, args[0], "interface", "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006358 err_code |= ERR_ALERT | ERR_FATAL;
6359 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006360 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006361 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006362 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
Christopher Faulet767a84b2017-11-24 16:50:31 +01006363 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
6364 file, linenum, "usesrc", "source");
Willy Tarreau93893792009-07-23 13:19:11 +02006365 err_code |= ERR_ALERT | ERR_FATAL;
6366 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006367 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006368 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006369 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006370 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6371 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006372 err_code |= ERR_ALERT | ERR_FATAL;
6373 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006374 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006375
6376 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006377 SMP_OPT_DIR_REQ, ACT_REPLACE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006378 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006379 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006380 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006381 }
6382 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006383 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006384 SMP_OPT_DIR_REQ, ACT_REMOVE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006385 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006386 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006387 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006388 }
6389 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006390 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006391 SMP_OPT_DIR_REQ, ACT_DENY, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006392 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006393 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006394 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006395 }
6396 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006397 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006398 SMP_OPT_DIR_REQ, ACT_PASS, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006399 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006400 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006401 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006402 }
6403 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006404 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006405 SMP_OPT_DIR_REQ, ACT_ALLOW, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006406 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006407 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006408 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006409 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006410 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006411 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006412 SMP_OPT_DIR_REQ, ACT_TARPIT, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006413 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006414 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006415 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006416 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006417 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006418 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006419 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6420 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006421 err_code |= ERR_ALERT | ERR_FATAL;
6422 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006423 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006424
6425 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006426 SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006427 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006428 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006429 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006430 }
6431 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006432 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006433 SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006434 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006435 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006436 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006437 }
6438 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006439 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006440 SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006441 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006442 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006443 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006444 }
6445 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006446 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006447 SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006448 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006449 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006450 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006451 }
6452 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006453 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006454 SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006455 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006456 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006457 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006458 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006459 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006460 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006461 SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006462 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006463 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006464 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006465 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006466 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006467 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006468
Willy Tarreaubaaee002006-06-26 02:48:02 +02006469 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006470 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006471 err_code |= ERR_ALERT | ERR_FATAL;
6472 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006473 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006474 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006475 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006476
Willy Tarreaubaaee002006-06-26 02:48:02 +02006477 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006478 ha_alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006479 err_code |= ERR_ALERT | ERR_FATAL;
6480 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006481 }
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006482
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006483 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Christopher Faulet1b421ea2017-09-22 14:38:56 +02006484 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006485 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6486 file, linenum, args[0], errmsg);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006487 err_code |= ERR_ALERT | ERR_FATAL;
6488 goto out;
6489 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006490 err_code |= warnif_cond_conflicts(cond,
6491 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
6492 file, linenum);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006493 }
6494 else if (*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006495 ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6496 file, linenum, args[0], args[2]);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006497 err_code |= ERR_ALERT | ERR_FATAL;
6498 goto out;
6499 }
6500
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006501 wl = calloc(1, sizeof(*wl));
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006502 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006503 wl->s = strdup(args[1]);
6504 LIST_ADDQ(&curproxy->req_add, &wl->list);
Willy Tarreau61d18892009-03-31 10:49:21 +02006505 warnif_misplaced_reqadd(curproxy, file, linenum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006506 }
6507 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006508 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006509 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6510 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006511 err_code |= ERR_ALERT | ERR_FATAL;
6512 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006513 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01006514
Willy Tarreauade5ec42010-01-28 19:33:49 +01006515 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006516 SMP_OPT_DIR_RES, ACT_REPLACE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006517 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006518 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006519 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006520 }
6521 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006522 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006523 SMP_OPT_DIR_RES, ACT_REMOVE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006524 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006525 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006526 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006527 }
6528 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006529 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006530 SMP_OPT_DIR_RES, ACT_DENY, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006531 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006532 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006533 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006534 }
6535 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006536 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006537 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6538 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006539 err_code |= ERR_ALERT | ERR_FATAL;
6540 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006541 }
6542
Willy Tarreauade5ec42010-01-28 19:33:49 +01006543 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006544 SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006545 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006546 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006547 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006548 }
6549 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006550 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006551 SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006552 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006553 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006554 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006555 }
6556 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006557 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006558 SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006559 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006560 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006561 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006562 }
6563 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006564 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006565
Willy Tarreaubaaee002006-06-26 02:48:02 +02006566 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006567 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006568 err_code |= ERR_ALERT | ERR_FATAL;
6569 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006570 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006571 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006572 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006573
Willy Tarreaubaaee002006-06-26 02:48:02 +02006574 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006575 ha_alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006576 err_code |= ERR_ALERT | ERR_FATAL;
6577 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006578 }
6579
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006580 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Christopher Faulet1b421ea2017-09-22 14:38:56 +02006581 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006582 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6583 file, linenum, args[0], errmsg);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006584 err_code |= ERR_ALERT | ERR_FATAL;
6585 goto out;
6586 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006587 err_code |= warnif_cond_conflicts(cond,
6588 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
6589 file, linenum);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006590 }
6591 else if (*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006592 ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6593 file, linenum, args[0], args[2]);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006594 err_code |= ERR_ALERT | ERR_FATAL;
6595 goto out;
6596 }
6597
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006598 wl = calloc(1, sizeof(*wl));
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006599 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006600 wl->s = strdup(args[1]);
6601 LIST_ADDQ(&curproxy->rsp_add, &wl->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006602 }
6603 else if (!strcmp(args[0], "errorloc") ||
6604 !strcmp(args[0], "errorloc302") ||
6605 !strcmp(args[0], "errorloc303")) { /* error location */
6606 int errnum, errlen;
6607 char *err;
6608
Willy Tarreau977b8e42006-12-29 14:19:17 +01006609 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006610 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006611
Willy Tarreaubaaee002006-06-26 02:48:02 +02006612 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006613 ha_alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006614 err_code |= ERR_ALERT | ERR_FATAL;
6615 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006616 }
6617
6618 errnum = atol(args[1]);
6619 if (!strcmp(args[0], "errorloc303")) {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006620 errlen = strlen(HTTP_303) + strlen(args[2]) + 5;
6621 err = malloc(errlen);
6622 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_303, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006623 } else {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006624 errlen = strlen(HTTP_302) + strlen(args[2]) + 5;
6625 err = malloc(errlen);
6626 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_302, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006627 }
6628
Willy Tarreau0f772532006-12-23 20:51:41 +01006629 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6630 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006631 chunk_destroy(&curproxy->errmsg[rc]);
6632 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau0f772532006-12-23 20:51:41 +01006633 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006634 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006635 }
Willy Tarreau0f772532006-12-23 20:51:41 +01006636
6637 if (rc >= HTTP_ERR_SIZE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006638 ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n",
6639 file, linenum, errnum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006640 free(err);
6641 }
6642 }
Willy Tarreau3f49b302007-06-11 00:29:26 +02006643 else if (!strcmp(args[0], "errorfile")) { /* error message from a file */
6644 int errnum, errlen, fd;
6645 char *err;
6646 struct stat stat;
6647
6648 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006649 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006650
6651 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006652 ha_alert("parsing [%s:%d] : <%s> expects <status_code> and <file> as arguments.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006653 err_code |= ERR_ALERT | ERR_FATAL;
6654 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006655 }
6656
6657 fd = open(args[2], O_RDONLY);
6658 if ((fd < 0) || (fstat(fd, &stat) < 0)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006659 ha_alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n",
6660 file, linenum, args[2], args[1]);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006661 if (fd >= 0)
6662 close(fd);
Willy Tarreau93893792009-07-23 13:19:11 +02006663 err_code |= ERR_ALERT | ERR_FATAL;
6664 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006665 }
6666
Willy Tarreau27a674e2009-08-17 07:23:33 +02006667 if (stat.st_size <= global.tune.bufsize) {
Willy Tarreau3f49b302007-06-11 00:29:26 +02006668 errlen = stat.st_size;
6669 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006670 ha_warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n",
6671 file, linenum, args[2], global.tune.bufsize);
Willy Tarreau93893792009-07-23 13:19:11 +02006672 err_code |= ERR_WARN;
Willy Tarreau27a674e2009-08-17 07:23:33 +02006673 errlen = global.tune.bufsize;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006674 }
6675
6676 err = malloc(errlen); /* malloc() must succeed during parsing */
6677 errnum = read(fd, err, errlen);
6678 if (errnum != errlen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006679 ha_alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n",
6680 file, linenum, args[2], args[1]);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006681 close(fd);
6682 free(err);
Willy Tarreau93893792009-07-23 13:19:11 +02006683 err_code |= ERR_ALERT | ERR_FATAL;
6684 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006685 }
6686 close(fd);
6687
6688 errnum = atol(args[1]);
6689 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6690 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006691 chunk_destroy(&curproxy->errmsg[rc]);
6692 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006693 break;
6694 }
6695 }
6696
6697 if (rc >= HTTP_ERR_SIZE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006698 ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n",
6699 file, linenum, errnum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006700 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006701 free(err);
6702 }
6703 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006704 else {
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006705 struct cfg_kw_list *kwl;
6706 int index;
6707
6708 list_for_each_entry(kwl, &cfg_keywords.list, list) {
6709 for (index = 0; kwl->kw[index].kw != NULL; index++) {
6710 if (kwl->kw[index].section != CFG_LISTEN)
6711 continue;
6712 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
6713 /* prepare error message just in case */
Willy Tarreau28a47d62012-09-18 20:02:48 +02006714 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
Willy Tarreau39f23b62008-07-09 20:22:56 +02006715 if (rc < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006716 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006717 err_code |= ERR_ALERT | ERR_FATAL;
6718 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006719 }
Willy Tarreau39f23b62008-07-09 20:22:56 +02006720 else if (rc > 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006721 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006722 err_code |= ERR_WARN;
6723 goto out;
Willy Tarreau39f23b62008-07-09 20:22:56 +02006724 }
Willy Tarreau93893792009-07-23 13:19:11 +02006725 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006726 }
6727 }
6728 }
William Lallemand82fe75c2012-10-23 10:25:10 +02006729
Christopher Faulet767a84b2017-11-24 16:50:31 +01006730 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau93893792009-07-23 13:19:11 +02006731 err_code |= ERR_ALERT | ERR_FATAL;
6732 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006733 }
Willy Tarreau93893792009-07-23 13:19:11 +02006734 out:
Willy Tarreauf4068b62012-05-08 17:37:49 +02006735 free(errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006736 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006737}
6738
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006739int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006740cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
6741{
6742#ifdef CONFIG_HAP_NS
6743 const char *err;
6744 const char *item = args[0];
6745
6746 if (!strcmp(item, "namespace_list")) {
6747 return 0;
6748 }
6749 else if (!strcmp(item, "namespace")) {
6750 size_t idx = 1;
6751 const char *current;
6752 while (*(current = args[idx++])) {
6753 err = invalid_char(current);
6754 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006755 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6756 file, linenum, *err, item, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006757 return ERR_ALERT | ERR_FATAL;
6758 }
6759
6760 if (netns_store_lookup(current, strlen(current))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006761 ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
6762 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006763 return ERR_ALERT | ERR_FATAL;
6764 }
6765 if (!netns_store_insert(current)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006766 ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
6767 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006768 return ERR_ALERT | ERR_FATAL;
6769 }
6770 }
6771 }
6772
6773 return 0;
6774#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01006775 ha_alert("parsing [%s:%d]: namespace support is not compiled in.",
6776 file, linenum);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006777 return ERR_ALERT | ERR_FATAL;
6778#endif
6779}
6780
6781int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006782cfg_parse_users(const char *file, int linenum, char **args, int kwm)
6783{
6784
6785 int err_code = 0;
6786 const char *err;
6787
6788 if (!strcmp(args[0], "userlist")) { /* new userlist */
6789 struct userlist *newul;
6790
6791 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006792 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6793 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006794 err_code |= ERR_ALERT | ERR_FATAL;
6795 goto out;
6796 }
William Lallemand6e62fb62015-04-28 16:55:23 +02006797 if (alertif_too_many_args(1, file, linenum, args, &err_code))
6798 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006799
6800 err = invalid_char(args[1]);
6801 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006802 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6803 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006804 err_code |= ERR_ALERT | ERR_FATAL;
6805 goto out;
6806 }
6807
6808 for (newul = userlist; newul; newul = newul->next)
6809 if (!strcmp(newul->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006810 ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
6811 file, linenum, args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006812 err_code |= ERR_WARN;
6813 goto out;
6814 }
6815
Vincent Bernat02779b62016-04-03 13:48:43 +02006816 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006817 if (!newul) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006818 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006819 err_code |= ERR_ALERT | ERR_ABORT;
6820 goto out;
6821 }
6822
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006823 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006824 if (!newul->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006825 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006826 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01006827 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006828 goto out;
6829 }
6830
6831 newul->next = userlist;
6832 userlist = newul;
6833
6834 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006835 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006836 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006837 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006838
6839 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006840 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6841 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006842 err_code |= ERR_ALERT | ERR_FATAL;
6843 goto out;
6844 }
6845
6846 err = invalid_char(args[1]);
6847 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006848 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6849 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006850 err_code |= ERR_ALERT | ERR_FATAL;
6851 goto out;
6852 }
6853
William Lallemand4ac9f542015-05-28 18:03:51 +02006854 if (!userlist)
6855 goto out;
6856
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006857 for (ag = userlist->groups; ag; ag = ag->next)
6858 if (!strcmp(ag->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006859 ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
6860 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006861 err_code |= ERR_ALERT;
6862 goto out;
6863 }
6864
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006865 ag = calloc(1, sizeof(*ag));
6866 if (!ag) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006867 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006868 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006869 goto out;
6870 }
6871
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006872 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01006873 if (!ag->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006874 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006875 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01006876 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006877 goto out;
6878 }
6879
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006880 cur_arg = 2;
6881
6882 while (*args[cur_arg]) {
6883 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006884 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006885 cur_arg += 2;
6886 continue;
6887 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006888 ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
6889 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006890 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01006891 free(ag->groupusers);
6892 free(ag->name);
6893 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006894 goto out;
6895 }
6896 }
6897
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006898 ag->next = userlist->groups;
6899 userlist->groups = ag;
6900
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006901 } else if (!strcmp(args[0], "user")) { /* new user */
6902 struct auth_users *newuser;
6903 int cur_arg;
6904
6905 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006906 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6907 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006908 err_code |= ERR_ALERT | ERR_FATAL;
6909 goto out;
6910 }
William Lallemand4ac9f542015-05-28 18:03:51 +02006911 if (!userlist)
6912 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006913
6914 for (newuser = userlist->users; newuser; newuser = newuser->next)
6915 if (!strcmp(newuser->user, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006916 ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
6917 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006918 err_code |= ERR_ALERT;
6919 goto out;
6920 }
6921
Vincent Bernat02779b62016-04-03 13:48:43 +02006922 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006923 if (!newuser) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006924 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006925 err_code |= ERR_ALERT | ERR_ABORT;
6926 goto out;
6927 }
6928
6929 newuser->user = strdup(args[1]);
6930
6931 newuser->next = userlist->users;
6932 userlist->users = newuser;
6933
6934 cur_arg = 2;
6935
6936 while (*args[cur_arg]) {
6937 if (!strcmp(args[cur_arg], "password")) {
Cyril Bonté1a0191d2014-08-29 20:20:02 +02006938#ifdef CONFIG_HAP_CRYPT
6939 if (!crypt("", args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006940 ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
6941 file, linenum, newuser->user);
Cyril Bonté1a0191d2014-08-29 20:20:02 +02006942 err_code |= ERR_ALERT | ERR_FATAL;
6943 goto out;
6944 }
6945#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01006946 ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
6947 file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006948 err_code |= ERR_ALERT;
6949#endif
6950 newuser->pass = strdup(args[cur_arg + 1]);
6951 cur_arg += 2;
6952 continue;
6953 } else if (!strcmp(args[cur_arg], "insecure-password")) {
6954 newuser->pass = strdup(args[cur_arg + 1]);
6955 newuser->flags |= AU_O_INSECURE;
6956 cur_arg += 2;
6957 continue;
6958 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006959 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006960 cur_arg += 2;
6961 continue;
6962 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006963 ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
6964 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006965 err_code |= ERR_ALERT | ERR_FATAL;
6966 goto out;
6967 }
6968 }
6969 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006970 ha_alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users");
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006971 err_code |= ERR_ALERT | ERR_FATAL;
6972 }
6973
6974out:
6975 return err_code;
6976}
Willy Tarreaubaaee002006-06-26 02:48:02 +02006977
Christopher Faulet79bdef32016-11-04 22:36:15 +01006978int
6979cfg_parse_scope(const char *file, int linenum, char *line)
6980{
6981 char *beg, *end, *scope = NULL;
6982 int err_code = 0;
6983 const char *err;
6984
6985 beg = line + 1;
6986 end = strchr(beg, ']');
6987
6988 /* Detect end of scope declaration */
6989 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006990 ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n",
6991 file, linenum);
Christopher Faulet79bdef32016-11-04 22:36:15 +01006992 err_code |= ERR_ALERT | ERR_FATAL;
6993 goto out;
6994 }
6995
6996 /* Get scope name and check its validity */
6997 scope = my_strndup(beg, end-beg);
6998 err = invalid_char(scope);
6999 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007000 ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
7001 file, linenum, *err);
Christopher Faulet79bdef32016-11-04 22:36:15 +01007002 err_code |= ERR_ALERT | ERR_ABORT;
7003 goto out;
7004 }
7005
7006 /* Be sure to have a scope declaration alone on its line */
7007 line = end+1;
7008 while (isspace((unsigned char)*line))
7009 line++;
7010 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007011 ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
7012 file, linenum, *line);
Christopher Faulet79bdef32016-11-04 22:36:15 +01007013 err_code |= ERR_ALERT | ERR_ABORT;
7014 goto out;
7015 }
7016
7017 /* We have a valid scope declaration, save it */
7018 free(cfg_scope);
7019 cfg_scope = scope;
7020 scope = NULL;
7021
7022 out:
7023 free(scope);
7024 return err_code;
7025}
7026
Frédéric Lécaillea41d5312018-01-29 12:05:07 +01007027int
7028cfg_parse_track_sc_num(unsigned int *track_sc_num,
7029 const char *arg, const char *end, char **errmsg)
7030{
7031 const char *p;
7032 unsigned int num;
7033
7034 p = arg;
7035 num = read_uint64(&arg, end);
7036
7037 if (arg != end) {
7038 memprintf(errmsg, "Wrong track-sc number '%s'", p);
7039 return -1;
7040 }
7041
7042 if (num >= MAX_SESS_STKCTR) {
7043 memprintf(errmsg, "%u track-sc number exceeding "
7044 "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1);
7045 return -1;
7046 }
7047
7048 *track_sc_num = num;
7049 return 0;
7050}
7051
Willy Tarreaubaaee002006-06-26 02:48:02 +02007052/*
7053 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02007054 * Returns the error code, 0 if OK, or any combination of :
7055 * - ERR_ABORT: must abort ASAP
7056 * - ERR_FATAL: we can continue parsing but not start the service
7057 * - ERR_WARN: a warning has been emitted
7058 * - ERR_ALERT: an alert has been emitted
7059 * Only the two first ones can stop processing, the two others are just
7060 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02007061 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02007062int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02007063{
William Lallemand64e84512015-05-12 14:25:37 +02007064 char *thisline;
7065 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007066 FILE *f;
7067 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02007068 int err_code = 0;
William Lallemandd2ff56d2017-10-16 11:06:50 +02007069 struct cfg_section *cs = NULL, *pcs = NULL;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007070 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02007071 int readbytes = 0;
7072
7073 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007074 ha_alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02007075 return -1;
7076 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007077
David Carlier97880bb2016-04-08 10:35:26 +01007078 if ((f=fopen(file,"r")) == NULL) {
7079 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007080 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01007081 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007082
William Lallemandb2f07452015-05-12 14:27:13 +02007083next_line:
William Lallemand64e84512015-05-12 14:25:37 +02007084 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02007085 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007086 char *end;
7087 char *args[MAX_LINE_ARGS + 1];
7088 char *line = thisline;
William Lallemandf9873ba2015-05-05 17:37:14 +02007089 int dquote = 0; /* double quote */
7090 int squote = 0; /* simple quote */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007091
Willy Tarreaubaaee002006-06-26 02:48:02 +02007092 linenum++;
7093
7094 end = line + strlen(line);
7095
William Lallemand64e84512015-05-12 14:25:37 +02007096 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007097 /* Check if we reached the limit and the last char is not \n.
7098 * Watch out for the last line without the terminating '\n'!
7099 */
William Lallemand64e84512015-05-12 14:25:37 +02007100 char *newline;
7101 int newlinesize = linesize * 2;
7102
7103 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
7104 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007105 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
7106 file, linenum);
William Lallemand64e84512015-05-12 14:25:37 +02007107 err_code |= ERR_ALERT | ERR_FATAL;
7108 continue;
7109 }
7110
7111 readbytes = linesize - 1;
7112 linesize = newlinesize;
7113 thisline = newline;
7114 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007115 }
7116
William Lallemand64e84512015-05-12 14:25:37 +02007117 readbytes = 0;
7118
Willy Tarreaubaaee002006-06-26 02:48:02 +02007119 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02007120 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02007121 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02007122
Christopher Faulet79bdef32016-11-04 22:36:15 +01007123
7124 if (*line == '[') {/* This is the begining if a scope */
7125 err_code |= cfg_parse_scope(file, linenum, line);
7126 goto next_line;
7127 }
7128
Willy Tarreaubaaee002006-06-26 02:48:02 +02007129 arg = 0;
7130 args[arg] = line;
7131
7132 while (*line && arg < MAX_LINE_ARGS) {
William Lallemandf9873ba2015-05-05 17:37:14 +02007133 if (*line == '"' && !squote) { /* double quote outside single quotes */
7134 if (dquote)
7135 dquote = 0;
7136 else
7137 dquote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02007138 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02007139 end--;
7140 }
7141 else if (*line == '\'' && !dquote) { /* single quote outside double quotes */
7142 if (squote)
7143 squote = 0;
7144 else
7145 squote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02007146 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02007147 end--;
7148 }
7149 else if (*line == '\\' && !squote) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007150 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
7151 * C equivalent value. Other combinations left unchanged (eg: \1).
7152 */
Willy Tarreaubaaee002006-06-26 02:48:02 +02007153 int skip = 0;
7154 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
7155 *line = line[1];
7156 skip = 1;
7157 }
7158 else if (line[1] == 'r') {
7159 *line = '\r';
7160 skip = 1;
William Lallemandf9873ba2015-05-05 17:37:14 +02007161 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007162 else if (line[1] == 'n') {
7163 *line = '\n';
7164 skip = 1;
7165 }
7166 else if (line[1] == 't') {
7167 *line = '\t';
7168 skip = 1;
7169 }
7170 else if (line[1] == 'x') {
Emeric Brunb982a3d2010-01-04 15:45:53 +01007171 if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007172 unsigned char hex1, hex2;
7173 hex1 = toupper(line[2]) - '0';
7174 hex2 = toupper(line[3]) - '0';
7175 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
7176 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
7177 *line = (hex1<<4) + hex2;
7178 skip = 3;
7179 }
7180 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007181 ha_alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007182 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007183 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007184 } else if (line[1] == '"') {
7185 *line = '"';
7186 skip = 1;
7187 } else if (line[1] == '\'') {
7188 *line = '\'';
7189 skip = 1;
William Lallemandb2f07452015-05-12 14:27:13 +02007190 } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */
7191 *line = '$';
7192 skip = 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007193 }
7194 if (skip) {
Cyril Bontédd1b01d2009-12-06 13:43:42 +01007195 memmove(line + 1, line + 1 + skip, end - (line + skip));
Willy Tarreaubaaee002006-06-26 02:48:02 +02007196 end -= skip;
7197 }
7198 line++;
7199 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007200 else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007201 /* end of string, end of loop */
7202 *line = 0;
7203 break;
7204 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007205 else if (!squote && !dquote && isspace((unsigned char)*line)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007206 /* a non-escaped space is an argument separator */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007207 *line++ = '\0';
Willy Tarreau8f8e6452007-06-17 21:51:38 +02007208 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02007209 line++;
7210 args[++arg] = line;
7211 }
William Lallemandb2f07452015-05-12 14:27:13 +02007212 else if (dquote && *line == '$') {
7213 /* environment variables are evaluated inside double quotes */
7214 char *var_beg;
7215 char *var_end;
7216 char save_char;
7217 char *value;
7218 int val_len;
7219 int newlinesize;
7220 int braces = 0;
7221
7222 var_beg = line + 1;
7223 var_end = var_beg;
7224
7225 if (*var_beg == '{') {
7226 var_beg++;
7227 var_end++;
7228 braces = 1;
7229 }
7230
7231 if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007232 ha_alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg);
William Lallemandb2f07452015-05-12 14:27:13 +02007233 err_code |= ERR_ALERT | ERR_FATAL;
7234 goto next_line; /* skip current line */
7235 }
7236
7237 while (isalnum((int)(unsigned char)*var_end) || *var_end == '_')
7238 var_end++;
7239
7240 save_char = *var_end;
7241 *var_end = '\0';
7242 value = getenv(var_beg);
7243 *var_end = save_char;
7244 val_len = value ? strlen(value) : 0;
7245
7246 if (braces) {
7247 if (*var_end == '}') {
7248 var_end++;
7249 braces = 0;
7250 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007251 ha_alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02007252 err_code |= ERR_ALERT | ERR_FATAL;
7253 goto next_line; /* skip current line */
7254 }
7255 }
7256
7257 newlinesize = (end - thisline) - (var_end - line) + val_len + 1;
7258
7259 /* if not enough space in thisline */
7260 if (newlinesize > linesize) {
7261 char *newline;
7262
7263 newline = realloc(thisline, newlinesize * sizeof(*thisline));
7264 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007265 ha_alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02007266 err_code |= ERR_ALERT | ERR_FATAL;
7267 goto next_line; /* slip current line */
7268 }
7269 /* recompute pointers if realloc returns a new pointer */
7270 if (newline != thisline) {
7271 int i;
7272 int diff;
7273
7274 for (i = 0; i <= arg; i++) {
7275 diff = args[i] - thisline;
7276 args[i] = newline + diff;
7277 }
7278
7279 diff = var_end - thisline;
7280 var_end = newline + diff;
7281 diff = end - thisline;
7282 end = newline + diff;
7283 diff = line - thisline;
7284 line = newline + diff;
7285 thisline = newline;
7286 }
7287 linesize = newlinesize;
7288 }
7289
7290 /* insert value inside the line */
7291 memmove(line + val_len, var_end, end - var_end + 1);
7292 memcpy(line, value, val_len);
7293 end += val_len - (var_end - line);
7294 line += val_len;
7295 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007296 else {
7297 line++;
7298 }
7299 }
William Lallemandb2f07452015-05-12 14:27:13 +02007300
William Lallemandf9873ba2015-05-05 17:37:14 +02007301 if (dquote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007302 ha_alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02007303 err_code |= ERR_ALERT | ERR_FATAL;
7304 }
7305
7306 if (squote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007307 ha_alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02007308 err_code |= ERR_ALERT | ERR_FATAL;
7309 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007310
7311 /* empty line */
7312 if (!**args)
7313 continue;
7314
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007315 if (*line) {
7316 /* we had to stop due to too many args.
7317 * Let's terminate the string, print the offending part then cut the
7318 * last arg.
7319 */
7320 while (*line && *line != '#' && *line != '\n' && *line != '\r')
7321 line++;
7322 *line = '\0';
7323
Christopher Faulet767a84b2017-11-24 16:50:31 +01007324 ha_alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n",
7325 file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]);
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007326 err_code |= ERR_ALERT | ERR_FATAL;
7327 args[arg] = line;
7328 }
7329
Willy Tarreau540abe42007-05-02 20:50:16 +02007330 /* zero out remaining args and ensure that at least one entry
7331 * is zeroed out.
7332 */
7333 while (++arg <= MAX_LINE_ARGS) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007334 args[arg] = line;
7335 }
7336
Willy Tarreau3842f002009-06-14 11:39:52 +02007337 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007338 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02007339 char *tmp;
7340
Willy Tarreau3842f002009-06-14 11:39:52 +02007341 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02007342 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007343 for (arg=0; *args[arg+1]; arg++)
7344 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02007345 *tmp = '\0'; // fix the next arg to \0
7346 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007347 }
Willy Tarreau3842f002009-06-14 11:39:52 +02007348 else if (!strcmp(args[0], "default")) {
7349 kwm = KWM_DEF;
7350 for (arg=0; *args[arg+1]; arg++)
7351 args[arg] = args[arg+1]; // shift args after inversion
7352 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007353
William Lallemand0f99e342011-10-12 17:50:54 +02007354 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \
7355 strcmp(args[0], "log") != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007356 ha_alert("parsing [%s:%d]: negation/default currently supported only for options and log.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02007357 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007358 }
7359
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007360 /* detect section start */
7361 list_for_each_entry(ics, &sections, list) {
7362 if (strcmp(args[0], ics->section_name) == 0) {
7363 cursection = ics->section_name;
7364 cs = ics;
7365 break;
7366 }
Emeric Brun32da3c42010-09-23 18:39:19 +02007367 }
7368
William Lallemandd2ff56d2017-10-16 11:06:50 +02007369 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007370 ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007371 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemandd2ff56d2017-10-16 11:06:50 +02007372 } else {
7373 /* else it's a section keyword */
Willy Tarreau058e9072009-07-20 09:30:05 +02007374
William Lallemandd2ff56d2017-10-16 11:06:50 +02007375 if (pcs != cs && pcs && pcs->post_section_parser) {
7376 err_code |= pcs->post_section_parser();
7377 if (err_code & ERR_ABORT)
7378 goto err;
7379 }
7380
7381 err_code |= cs->section_parser(file, linenum, args, kwm);
7382 if (err_code & ERR_ABORT)
7383 goto err;
7384 }
7385 pcs = cs;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007386 }
William Lallemandd2ff56d2017-10-16 11:06:50 +02007387
7388 if (pcs == cs && pcs && pcs->post_section_parser)
7389 err_code |= pcs->post_section_parser();
7390
7391err:
Christopher Faulet79bdef32016-11-04 22:36:15 +01007392 free(cfg_scope);
7393 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01007394 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02007395 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007396 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02007397 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007398}
7399
Willy Tarreau64ab6072014-09-16 12:17:36 +02007400/* This function propagates processes from frontend <from> to backend <to> so
7401 * that it is always guaranteed that a backend pointed to by a frontend is
7402 * bound to all of its processes. After that, if the target is a "listen"
7403 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02007404 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02007405 * checked first to ensure that <to> is already bound to all processes of
7406 * <from>, there is no risk of looping and we ensure to follow the shortest
7407 * path to the destination.
7408 *
7409 * It is possible to set <to> to NULL for the first call so that the function
7410 * takes care of visiting the initial frontend in <from>.
7411 *
7412 * It is important to note that the function relies on the fact that all names
7413 * have already been resolved.
7414 */
7415void propagate_processes(struct proxy *from, struct proxy *to)
7416{
7417 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007418
7419 if (to) {
7420 /* check whether we need to go down */
7421 if (from->bind_proc &&
7422 (from->bind_proc & to->bind_proc) == from->bind_proc)
7423 return;
7424
7425 if (!from->bind_proc && !to->bind_proc)
7426 return;
7427
7428 to->bind_proc = from->bind_proc ?
7429 (to->bind_proc | from->bind_proc) : 0;
7430
7431 /* now propagate down */
7432 from = to;
7433 }
7434
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01007435 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02007436 return;
7437
Willy Tarreauf6b70012014-12-18 14:00:43 +01007438 if (from->state == PR_STSTOPPED)
7439 return;
7440
Willy Tarreau64ab6072014-09-16 12:17:36 +02007441 /* default_backend */
7442 if (from->defbe.be)
7443 propagate_processes(from, from->defbe.be);
7444
7445 /* use_backend */
7446 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02007447 if (rule->dynamic)
7448 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007449 to = rule->be.backend;
7450 propagate_processes(from, to);
7451 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02007452}
7453
Willy Tarreaubb925012009-07-23 13:36:36 +02007454/*
7455 * Returns the error code, 0 if OK, or any combination of :
7456 * - ERR_ABORT: must abort ASAP
7457 * - ERR_FATAL: we can continue parsing but not start the service
7458 * - ERR_WARN: a warning has been emitted
7459 * - ERR_ALERT: an alert has been emitted
7460 * Only the two first ones can stop processing, the two others are just
7461 * indicators.
7462 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007463int check_config_validity()
7464{
7465 int cfgerr = 0;
7466 struct proxy *curproxy = NULL;
7467 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02007468 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007469 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007470 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007471 char *err;
William Lallemand48b4bb42017-10-23 14:36:34 +02007472 struct cfg_postparser *postparser;
Ben Draut054fbee2018-04-13 15:43:04 -06007473 struct dns_resolvers *curr_resolvers = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007474
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007475 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007476 /*
7477 * Now, check for the integrity of all that we have collected.
7478 */
7479
7480 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02007481 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007482
Willy Tarreau193b8c62012-11-22 00:17:38 +01007483 if (!global.tune.max_http_hdr)
7484 global.tune.max_http_hdr = MAX_HTTP_HDR;
7485
7486 if (!global.tune.cookie_len)
7487 global.tune.cookie_len = CAPTURE_LEN;
7488
Stéphane Cottin23e9e932017-05-18 08:58:41 +02007489 if (!global.tune.requri_len)
7490 global.tune.requri_len = REQURI_LEN;
7491
Willy Tarreaubafbe012017-11-24 17:34:44 +01007492 pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
Emeric Brun96fd9262017-07-05 13:33:16 +02007493
Willy Tarreaubafbe012017-11-24 17:34:44 +01007494 pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
Willy Tarreau193b8c62012-11-22 00:17:38 +01007495
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01007496 /* Post initialisation of the users and groups lists. */
7497 err_code = userlist_postinit();
7498 if (err_code != ERR_NONE)
7499 goto out;
7500
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007501 /* first, we will invert the proxy list order */
7502 curproxy = NULL;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007503 while (proxies_list) {
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007504 struct proxy *next;
7505
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007506 next = proxies_list->next;
7507 proxies_list->next = curproxy;
7508 curproxy = proxies_list;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007509 if (!next)
7510 break;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007511 proxies_list = next;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007512 }
7513
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007514 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007515 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007516 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01007517 struct sticking_rule *mrule;
Christopher Faulete4e830d2017-09-18 14:51:41 +02007518 struct act_rule *arule;
Dragan Dosen1322d092015-09-22 16:05:32 +02007519 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007520 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01007521 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007522
Willy Tarreau050536d2012-10-04 08:47:34 +02007523 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007524 /* proxy ID not set, use automatic numbering with first
7525 * spare entry starting with next_pxid.
7526 */
7527 next_pxid = get_next_id(&used_proxy_id, next_pxid);
7528 curproxy->conf.id.key = curproxy->uuid = next_pxid;
7529 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007530 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01007531 next_pxid++;
7532
Willy Tarreau55ea7572007-06-17 19:56:27 +02007533
Willy Tarreaubaaee002006-06-26 02:48:02 +02007534 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02007535 /* ensure we don't keep listeners uselessly bound */
7536 stop_proxy(curproxy);
Willy Tarreau02df7742015-05-01 19:59:56 +02007537 free((void *)curproxy->table.peers.name);
7538 curproxy->table.peers.p = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007539 continue;
7540 }
7541
Willy Tarreau102df612014-05-07 23:56:38 +02007542 /* Check multi-process mode compatibility for the current proxy */
7543
7544 if (curproxy->bind_proc) {
7545 /* an explicit bind-process was specified, let's check how many
7546 * processes remain.
7547 */
David Carliere6c39412015-07-02 07:00:17 +00007548 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02007549
7550 curproxy->bind_proc &= nbits(global.nbproc);
7551 if (!curproxy->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007552 ha_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);
Willy Tarreau102df612014-05-07 23:56:38 +02007553 curproxy->bind_proc = 1;
7554 }
7555 else if (!curproxy->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007556 ha_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);
Willy Tarreau102df612014-05-07 23:56:38 +02007557 curproxy->bind_proc = 0;
7558 }
7559 }
7560
Willy Tarreau3d209582014-05-09 17:06:11 +02007561 /* check and reduce the bind-proc of each listener */
7562 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
7563 unsigned long mask;
7564
Willy Tarreau45a66cc2017-11-24 11:28:00 +01007565 /* HTTP frontends with "h2" as ALPN/NPN will work in
7566 * HTTP/2 and absolutely require buffers 16kB or larger.
7567 */
7568#ifdef USE_OPENSSL
7569 if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
7570#ifdef OPENSSL_NPN_NEGOTIATED
7571 /* check NPN */
7572 if (bind_conf->ssl_conf.npn_str && strcmp(bind_conf->ssl_conf.npn_str, "\002h2") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007573 ha_alert("config : HTTP frontend '%s' enables HTTP/2 via NPN at [%s:%d], so global.tune.bufsize must be at least 16384 bytes (%d now).\n",
7574 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01007575 cfgerr++;
7576 }
7577#endif
7578#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
7579 /* check ALPN */
7580 if (bind_conf->ssl_conf.alpn_str && strcmp(bind_conf->ssl_conf.alpn_str, "\002h2") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007581 ha_alert("config : HTTP frontend '%s' enables HTTP/2 via ALPN at [%s:%d], so global.tune.bufsize must be at least 16384 bytes (%d now).\n",
7582 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01007583 cfgerr++;
7584 }
7585#endif
7586 } /* HTTP && bufsize < 16384 */
7587#endif
7588
Willy Tarreauc477b6f2018-07-27 18:07:41 +02007589 /* detect and address thread affinity inconsistencies */
7590 nbproc = 0;
7591 if (bind_conf->bind_proc)
7592 nbproc = my_ffsl(bind_conf->bind_proc);
7593
7594 mask = bind_conf->bind_thread[nbproc - 1];
Willy Tarreau0c026f42018-08-01 19:12:20 +02007595 if (mask && !(mask & all_threads_mask)) {
Willy Tarreauc477b6f2018-07-27 18:07:41 +02007596 unsigned long new_mask = 0;
7597
7598 while (mask) {
Willy Tarreau0c026f42018-08-01 19:12:20 +02007599 new_mask |= mask & all_threads_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02007600 mask >>= global.nbthread;
7601 }
7602
7603 for (nbproc = 0; nbproc < LONGBITS; nbproc++) {
7604 if (!bind_conf->bind_proc || (bind_conf->bind_proc & (1UL << nbproc)))
7605 bind_conf->bind_thread[nbproc] = new_mask;
7606 }
7607 ha_warning("Proxy '%s': the thread range specified on the 'process' directive of 'bind %s' at [%s:%d] only refers to thread numbers out of the range defined by the global 'nbthread' directive. The thread numbers were remapped to existing threads instead (mask 0x%lx).\n",
7608 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
7609 }
7610
7611 /* detect process and nbproc affinity inconsistencies */
Willy Tarreau3d209582014-05-09 17:06:11 +02007612 if (!bind_conf->bind_proc)
7613 continue;
7614
7615 mask = nbits(global.nbproc);
7616 if (curproxy->bind_proc)
7617 mask &= curproxy->bind_proc;
7618 /* mask cannot be null here thanks to the previous checks */
7619
David Carliere6c39412015-07-02 07:00:17 +00007620 nbproc = my_popcountl(bind_conf->bind_proc);
Willy Tarreau3d209582014-05-09 17:06:11 +02007621 bind_conf->bind_proc &= mask;
7622
7623 if (!bind_conf->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007624 ha_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",
7625 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreau3d209582014-05-09 17:06:11 +02007626 bind_conf->bind_proc = mask & ~(mask - 1);
7627 }
7628 else if (!bind_conf->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007629 ha_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",
7630 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreau3d209582014-05-09 17:06:11 +02007631 bind_conf->bind_proc = 0;
7632 }
7633 }
7634
Willy Tarreauff01a212009-03-15 13:46:16 +01007635 switch (curproxy->mode) {
7636 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007637 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007638 if (!(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007639 ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
7640 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007641 cfgerr++;
7642 }
7643
7644 if (curproxy->srv != NULL)
Christopher Faulet767a84b2017-11-24 16:50:31 +01007645 ha_warning("config : servers will be ignored for %s '%s'.\n",
7646 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007647 break;
7648
7649 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007650 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007651 break;
7652
7653 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01007654 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01007655 break;
7656 }
7657
Willy Tarreau58aa5cc2018-02-08 09:55:09 +01007658 if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007659 ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
7660 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauf3934b82015-08-11 11:36:45 +02007661 err_code |= ERR_WARN;
7662 }
7663
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007664 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02007665 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007666 if (curproxy->options & PR_O_TRANSP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007667 ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n",
7668 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007669 cfgerr++;
7670 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007671#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007672 else if (curproxy->srv == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007673 ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n",
7674 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007675 cfgerr++;
7676 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007677#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02007678 else if (curproxy->options & PR_O_DISPATCH) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007679 ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
7680 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02007681 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007682 }
7683 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02007684 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007685 /* If no LB algo is set in a backend, and we're not in
7686 * transparent mode, dispatch mode nor proxy mode, we
7687 * want to use balance roundrobin by default.
7688 */
7689 curproxy->lbprm.algo &= ~BE_LB_ALGO;
7690 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007691 }
7692 }
Willy Tarreau193cf932007-09-17 10:17:23 +02007693
Willy Tarreau1620ec32011-08-06 17:05:02 +02007694 if (curproxy->options & PR_O_DISPATCH)
7695 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
7696 else if (curproxy->options & PR_O_HTTP_PROXY)
7697 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
7698 else if (curproxy->options & PR_O_TRANSP)
7699 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01007700
Willy Tarreau1620ec32011-08-06 17:05:02 +02007701 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) {
7702 if (curproxy->options & PR_O_DISABLE404) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007703 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7704 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02007705 err_code |= ERR_WARN;
7706 curproxy->options &= ~PR_O_DISABLE404;
7707 }
7708 if (curproxy->options2 & PR_O2_CHK_SNDST) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007709 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7710 "send-state", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02007711 err_code |= ERR_WARN;
7712 curproxy->options &= ~PR_O2_CHK_SNDST;
7713 }
Willy Tarreauef781042010-01-27 11:53:01 +01007714 }
7715
Simon Horman98637e52014-06-20 12:30:16 +09007716 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
7717 if (!global.external_check) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007718 ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
7719 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09007720 cfgerr++;
7721 }
7722 if (!curproxy->check_command) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007723 ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
7724 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09007725 cfgerr++;
7726 }
7727 }
7728
Simon Horman64e34162015-02-06 11:11:57 +09007729 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007730 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007731 ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
7732 "'email-alert from', 'email-alert level' 'email-alert mailers', "
7733 "'email-alert myhostname', or 'email-alert to' "
7734 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
7735 "to be present).\n",
7736 proxy_type_str(curproxy), curproxy->id);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007737 err_code |= ERR_WARN;
7738 free_email_alert(curproxy);
7739 }
7740 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01007741 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09007742 }
7743
Simon Horman98637e52014-06-20 12:30:16 +09007744 if (curproxy->check_command) {
7745 int clear = 0;
7746 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007747 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7748 "external-check command", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09007749 err_code |= ERR_WARN;
7750 clear = 1;
7751 }
7752 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007753 ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
7754 curproxy->id, "external-check command");
Simon Horman98637e52014-06-20 12:30:16 +09007755 cfgerr++;
7756 }
7757 if (clear) {
7758 free(curproxy->check_command);
7759 curproxy->check_command = NULL;
7760 }
7761 }
7762
7763 if (curproxy->check_path) {
7764 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007765 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7766 "external-check path", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09007767 err_code |= ERR_WARN;
7768 free(curproxy->check_path);
7769 curproxy->check_path = NULL;
7770 }
7771 }
7772
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007773 /* if a default backend was specified, let's find it */
7774 if (curproxy->defbe.name) {
7775 struct proxy *target;
7776
Willy Tarreauafb39922015-05-26 12:04:09 +02007777 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007778 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007779 ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
7780 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007781 cfgerr++;
7782 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007783 ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
7784 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02007785 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007786 } else if (target->mode != curproxy->mode &&
7787 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7788
Christopher Faulet767a84b2017-11-24 16:50:31 +01007789 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
7790 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7791 curproxy->conf.file, curproxy->conf.line,
7792 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7793 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02007794 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007795 } else {
7796 free(curproxy->defbe.name);
7797 curproxy->defbe.be = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007798 /* Update tot_fe_maxconn for a further fullconn's computation */
7799 target->tot_fe_maxconn += curproxy->maxconn;
Willy Tarreauff678132012-02-13 14:32:34 +01007800 /* Emit a warning if this proxy also has some servers */
7801 if (curproxy->srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007802 ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
7803 curproxy->id);
Willy Tarreauff678132012-02-13 14:32:34 +01007804 err_code |= ERR_WARN;
7805 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007806 }
7807 }
7808
Emeric Brun3f783572017-01-12 11:21:28 +01007809 if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
7810 /* Case of listen without default backend
7811 * The curproxy will be its own default backend
7812 * so we update tot_fe_maxconn for a further
7813 * fullconn's computation */
7814 curproxy->tot_fe_maxconn += curproxy->maxconn;
7815 }
7816
Willy Tarreau55ea7572007-06-17 19:56:27 +02007817 /* find the target proxy for 'use_backend' rules */
7818 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007819 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007820 struct logformat_node *node;
7821 char *pxname;
7822
7823 /* Try to parse the string as a log format expression. If the result
7824 * of the parsing is only one entry containing a simple string, then
7825 * it's a standard string corresponding to a static rule, thus the
7826 * parsing is cancelled and be.name is restored to be resolved.
7827 */
7828 pxname = rule->be.name;
7829 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01007830 curproxy->conf.args.ctx = ARGC_UBK;
7831 curproxy->conf.args.file = rule->file;
7832 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007833 err = NULL;
7834 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007835 ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
7836 rule->file, rule->line, pxname, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007837 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01007838 cfgerr++;
7839 continue;
7840 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007841 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
7842
7843 if (!LIST_ISEMPTY(&rule->be.expr)) {
7844 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
7845 rule->dynamic = 1;
7846 free(pxname);
7847 continue;
7848 }
7849 /* simple string: free the expression and fall back to static rule */
7850 free(node->arg);
7851 free(node);
7852 }
7853
7854 rule->dynamic = 0;
7855 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007856
Willy Tarreauafb39922015-05-26 12:04:09 +02007857 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007858 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007859 ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
7860 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007861 cfgerr++;
7862 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007863 ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
7864 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007865 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007866 } else if (target->mode != curproxy->mode &&
7867 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7868
Christopher Faulet767a84b2017-11-24 16:50:31 +01007869 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
7870 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7871 curproxy->conf.file, curproxy->conf.line,
7872 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7873 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02007874 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007875 } else {
7876 free((void *)rule->be.name);
7877 rule->be.backend = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007878 /* For each target of switching rules, we update
7879 * their tot_fe_maxconn, except if a previous rule point
7880 * on the same backend or on the default backend */
7881 if (rule->be.backend != curproxy->defbe.be) {
7882 struct switching_rule *swrule;
7883
7884 list_for_each_entry(swrule, &curproxy->switching_rules, list) {
7885 if (rule == swrule) {
7886 target->tot_fe_maxconn += curproxy->maxconn;
7887 break;
7888 }
7889 else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) {
7890 /* there is multiple ref of this backend */
7891 break;
7892 }
7893 }
7894 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02007895 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007896 }
7897
Willy Tarreau64ab6072014-09-16 12:17:36 +02007898 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007899 list_for_each_entry(srule, &curproxy->server_rules, list) {
7900 struct server *target = findserver(curproxy, srule->srv.name);
7901
7902 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007903 ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
7904 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007905 cfgerr++;
7906 continue;
7907 }
7908 free((void *)srule->srv.name);
7909 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007910 }
7911
Emeric Brunb982a3d2010-01-04 15:45:53 +01007912 /* find the target table for 'stick' rules */
7913 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
7914 struct proxy *target;
7915
Emeric Brun1d33b292010-01-04 15:47:17 +01007916 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
7917 if (mrule->flags & STK_IS_STORE)
7918 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7919
Emeric Brunb982a3d2010-01-04 15:45:53 +01007920 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007921 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007922 else
7923 target = curproxy;
7924
7925 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007926 ha_alert("Proxy '%s': unable to find stick-table '%s'.\n",
7927 curproxy->id, mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007928 cfgerr++;
7929 }
7930 else if (target->table.size == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007931 ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7932 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007933 cfgerr++;
7934 }
Willy Tarreau12785782012-04-27 21:37:17 +02007935 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007936 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
7937 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007938 cfgerr++;
7939 }
7940 else {
7941 free((void *)mrule->table.name);
7942 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007943 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007944 }
7945 }
7946
7947 /* find the target table for 'store response' rules */
7948 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
7949 struct proxy *target;
7950
Emeric Brun1d33b292010-01-04 15:47:17 +01007951 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7952
Emeric Brunb982a3d2010-01-04 15:45:53 +01007953 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007954 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007955 else
7956 target = curproxy;
7957
7958 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007959 ha_alert("Proxy '%s': unable to find store table '%s'.\n",
7960 curproxy->id, mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007961 cfgerr++;
7962 }
7963 else if (target->table.size == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007964 ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7965 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007966 cfgerr++;
7967 }
Willy Tarreau12785782012-04-27 21:37:17 +02007968 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007969 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
7970 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007971 cfgerr++;
7972 }
7973 else {
7974 free((void *)mrule->table.name);
7975 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007976 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007977 }
7978 }
7979
Christopher Faulete4e830d2017-09-18 14:51:41 +02007980 /* check validity for 'tcp-request' layer 4 rules */
7981 list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) {
7982 err = NULL;
7983 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007984 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02007985 free(err);
Willy Tarreau5f53de72012-12-12 00:25:44 +01007986 cfgerr++;
7987 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02007988 }
7989
Christopher Faulete4e830d2017-09-18 14:51:41 +02007990 /* check validity for 'tcp-request' layer 5 rules */
7991 list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) {
7992 err = NULL;
7993 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007994 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02007995 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01007996 cfgerr++;
7997 }
7998 }
7999
Christopher Faulete4e830d2017-09-18 14:51:41 +02008000 /* check validity for 'tcp-request' layer 6 rules */
8001 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
8002 err = NULL;
8003 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008004 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02008005 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01008006 cfgerr++;
8007 }
8008 }
8009
Christopher Faulete4e830d2017-09-18 14:51:41 +02008010 /* check validity for 'http-request' layer 7 rules */
8011 list_for_each_entry(arule, &curproxy->http_req_rules, list) {
8012 err = NULL;
8013 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008014 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02008015 free(err);
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08008016 cfgerr++;
8017 }
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08008018 }
8019
Christopher Faulete4e830d2017-09-18 14:51:41 +02008020 /* check validity for 'http-response' layer 7 rules */
8021 list_for_each_entry(arule, &curproxy->http_res_rules, list) {
8022 err = NULL;
8023 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008024 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02008025 free(err);
Willy Tarreau09448f72014-06-25 18:12:15 +02008026 cfgerr++;
8027 }
Willy Tarreau09448f72014-06-25 18:12:15 +02008028 }
8029
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02008030 /* move any "block" rules at the beginning of the http-request rules */
8031 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
8032 /* insert block_rules into http_req_rules at the beginning */
8033 curproxy->block_rules.p->n = curproxy->http_req_rules.n;
8034 curproxy->http_req_rules.n->p = curproxy->block_rules.p;
8035 curproxy->block_rules.n->p = &curproxy->http_req_rules;
8036 curproxy->http_req_rules.n = curproxy->block_rules.n;
8037 LIST_INIT(&curproxy->block_rules);
8038 }
8039
Emeric Brun32da3c42010-09-23 18:39:19 +02008040 if (curproxy->table.peers.name) {
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02008041 struct peers *curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02008042
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02008043 for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +02008044 if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) {
8045 free((void *)curproxy->table.peers.name);
Willy Tarreau973ca492013-01-17 21:34:52 +01008046 curproxy->table.peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02008047 break;
8048 }
8049 }
8050
8051 if (!curpeers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008052 ha_alert("Proxy '%s': unable to find sync peers '%s'.\n",
8053 curproxy->id, curproxy->table.peers.name);
Willy Tarreaud66bf962011-10-28 14:16:49 +02008054 free((void *)curproxy->table.peers.name);
8055 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02008056 cfgerr++;
8057 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02008058 else if (curpeers->state == PR_STSTOPPED) {
8059 /* silently disable this peers section */
8060 curproxy->table.peers.p = NULL;
8061 }
Emeric Brun32da3c42010-09-23 18:39:19 +02008062 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008063 ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
8064 curproxy->id, localpeer, curpeers->id);
Willy Tarreaud66bf962011-10-28 14:16:49 +02008065 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02008066 cfgerr++;
8067 }
8068 }
8069
Simon Horman9dc49962015-01-30 11:22:59 +09008070
8071 if (curproxy->email_alert.mailers.name) {
8072 struct mailers *curmailers = mailers;
8073
8074 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
Christopher Faulet0108bb32017-10-20 21:34:32 +02008075 if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name))
Simon Horman9dc49962015-01-30 11:22:59 +09008076 break;
Simon Horman9dc49962015-01-30 11:22:59 +09008077 }
Simon Horman9dc49962015-01-30 11:22:59 +09008078 if (!curmailers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008079 ha_alert("Proxy '%s': unable to find mailers '%s'.\n",
8080 curproxy->id, curproxy->email_alert.mailers.name);
Simon Horman9dc49962015-01-30 11:22:59 +09008081 free_email_alert(curproxy);
8082 cfgerr++;
8083 }
Christopher Faulet0108bb32017-10-20 21:34:32 +02008084 else {
8085 err = NULL;
8086 if (init_email_alert(curmailers, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008087 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulet0108bb32017-10-20 21:34:32 +02008088 free(err);
8089 cfgerr++;
8090 }
8091 }
Simon Horman9dc49962015-01-30 11:22:59 +09008092 }
8093
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008094 if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) &&
Willy Tarreauff011f22011-01-06 17:51:27 +01008095 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008096 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008097 ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
8098 "proxy", curproxy->id);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008099 cfgerr++;
8100 goto out_uri_auth_compat;
8101 }
8102
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008103 if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008104 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02008105 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01008106 int i = 0;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008107
Willy Tarreau95fa4692010-02-01 13:05:50 +01008108 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
8109 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008110
8111 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008112 uri_auth_compat_req[i++] = "realm";
8113 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
8114 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008115
Willy Tarreau95fa4692010-02-01 13:05:50 +01008116 uri_auth_compat_req[i++] = "unless";
8117 uri_auth_compat_req[i++] = "{";
8118 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
8119 uri_auth_compat_req[i++] = "}";
8120 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008121
Willy Tarreauff011f22011-01-06 17:51:27 +01008122 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
8123 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008124 cfgerr++;
8125 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008126 }
8127
Willy Tarreauff011f22011-01-06 17:51:27 +01008128 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01008129
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008130 if (curproxy->uri_auth->auth_realm) {
8131 free(curproxy->uri_auth->auth_realm);
8132 curproxy->uri_auth->auth_realm = NULL;
8133 }
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008134
8135 curproxy->uri_auth->flags |= ST_CONVDONE;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008136 }
8137out_uri_auth_compat:
8138
Dragan Dosen43885c72015-10-01 13:18:13 +02008139 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02008140 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02008141 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
8142 if (!curproxy->conf.logformat_sd_string) {
8143 /* set the default logformat_sd_string */
8144 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
8145 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008146 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02008147 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008148 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02008149
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008150 /* compile the log format */
8151 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02008152 if (curproxy->conf.logformat_string != default_http_log_format &&
8153 curproxy->conf.logformat_string != default_tcp_log_format &&
8154 curproxy->conf.logformat_string != clf_http_log_format)
8155 free(curproxy->conf.logformat_string);
8156 curproxy->conf.logformat_string = NULL;
8157 free(curproxy->conf.lfs_file);
8158 curproxy->conf.lfs_file = NULL;
8159 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008160
8161 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
8162 free(curproxy->conf.logformat_sd_string);
8163 curproxy->conf.logformat_sd_string = NULL;
8164 free(curproxy->conf.lfsd_file);
8165 curproxy->conf.lfsd_file = NULL;
8166 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008167 }
8168
Willy Tarreau62a61232013-04-12 18:13:46 +02008169 if (curproxy->conf.logformat_string) {
8170 curproxy->conf.args.ctx = ARGC_LOG;
8171 curproxy->conf.args.file = curproxy->conf.lfs_file;
8172 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008173 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008174 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008175 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008176 ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
8177 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008178 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008179 cfgerr++;
8180 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008181 curproxy->conf.args.file = NULL;
8182 curproxy->conf.args.line = 0;
8183 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008184
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008185 if (curproxy->conf.logformat_sd_string) {
8186 curproxy->conf.args.ctx = ARGC_LOGSD;
8187 curproxy->conf.args.file = curproxy->conf.lfsd_file;
8188 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008189 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008190 if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008191 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008192 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8193 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008194 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008195 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008196 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008197 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8198 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008199 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008200 cfgerr++;
8201 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008202 curproxy->conf.args.file = NULL;
8203 curproxy->conf.args.line = 0;
8204 }
8205
Willy Tarreau62a61232013-04-12 18:13:46 +02008206 if (curproxy->conf.uniqueid_format_string) {
8207 curproxy->conf.args.ctx = ARGC_UIF;
8208 curproxy->conf.args.file = curproxy->conf.uif_file;
8209 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008210 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008211 if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008212 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008213 ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
8214 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008215 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008216 cfgerr++;
8217 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008218 curproxy->conf.args.file = NULL;
8219 curproxy->conf.args.line = 0;
8220 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008221
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01008222 /* only now we can check if some args remain unresolved.
8223 * This must be done after the users and groups resolution.
8224 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008225 cfgerr += smp_resolve_args(curproxy);
8226 if (!cfgerr)
8227 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01008228
Willy Tarreau2738a142006-07-08 17:28:09 +02008229 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008230 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02008231 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02008232 (!curproxy->timeout.connect ||
8233 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008234 ha_warning("config : missing timeouts for %s '%s'.\n"
8235 " | While not properly invalid, you will certainly encounter various problems\n"
8236 " | with such a configuration. To fix this, please ensure that all following\n"
8237 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
8238 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008239 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02008240 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02008241
Willy Tarreau1fa31262007-12-03 00:36:16 +01008242 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
8243 * We must still support older configurations, so let's find out whether those
8244 * parameters have been set or must be copied from contimeouts.
8245 */
8246 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008247 if (!curproxy->timeout.tarpit ||
8248 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008249 /* tarpit timeout not set. We search in the following order:
8250 * default.tarpit, curr.connect, default.connect.
8251 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008252 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008253 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008254 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008255 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008256 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008257 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008258 }
8259 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008260 (!curproxy->timeout.queue ||
8261 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008262 /* queue timeout not set. We search in the following order:
8263 * default.queue, curr.connect, default.connect.
8264 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008265 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008266 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008267 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008268 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008269 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008270 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008271 }
8272 }
8273
Willy Tarreau1620ec32011-08-06 17:05:02 +02008274 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) {
Willy Tarreau137325d2010-02-01 16:38:17 +01008275 curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02008276 curproxy->check_req = malloc(curproxy->check_len);
Willy Tarreau137325d2010-02-01 16:38:17 +01008277 memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len);
Willy Tarreauf3c69202006-07-09 16:42:34 +02008278 }
8279
Willy Tarreau215663d2014-06-13 18:30:23 +02008280 if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) &&
8281 (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008282 ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
8283 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau215663d2014-06-13 18:30:23 +02008284 err_code |= ERR_WARN;
8285 }
8286
Willy Tarreau193b8c62012-11-22 00:17:38 +01008287 /* ensure that cookie capture length is not too large */
8288 if (curproxy->capture_len >= global.tune.cookie_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008289 ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n",
8290 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau193b8c62012-11-22 00:17:38 +01008291 err_code |= ERR_WARN;
8292 curproxy->capture_len = global.tune.cookie_len - 1;
8293 }
8294
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008295 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01008296 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008297 curproxy->req_cap_pool = create_pool("ptrcap",
8298 curproxy->nb_req_cap * sizeof(char *),
8299 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008300 }
8301
8302 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008303 curproxy->rsp_cap_pool = create_pool("ptrcap",
8304 curproxy->nb_rsp_cap * sizeof(char *),
8305 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008306 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008307
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02008308 switch (curproxy->load_server_state_from_file) {
8309 case PR_SRV_STATE_FILE_UNSPEC:
8310 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
8311 break;
8312 case PR_SRV_STATE_FILE_GLOBAL:
8313 if (!global.server_state_file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008314 ha_warning("config : backend '%s' configured to load server state file from global section 'server-state-file' directive. Unfortunately, 'server-state-file' is not set!\n",
8315 curproxy->id);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02008316 err_code |= ERR_WARN;
8317 }
8318 break;
8319 }
8320
Willy Tarreaubaaee002006-06-26 02:48:02 +02008321 /* first, we will invert the servers list order */
8322 newsrv = NULL;
8323 while (curproxy->srv) {
8324 struct server *next;
8325
8326 next = curproxy->srv->next;
8327 curproxy->srv->next = newsrv;
8328 newsrv = curproxy->srv;
8329 if (!next)
8330 break;
8331 curproxy->srv = next;
8332 }
8333
Willy Tarreau17edc812014-01-03 12:14:34 +01008334 /* Check that no server name conflicts. This causes trouble in the stats.
8335 * We only emit a warning for the first conflict affecting each server,
8336 * in order to avoid combinatory explosion if all servers have the same
8337 * name. We do that only for servers which do not have an explicit ID,
8338 * because these IDs were made also for distinguishing them and we don't
8339 * want to annoy people who correctly manage them.
8340 */
8341 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
8342 struct server *other_srv;
8343
8344 if (newsrv->puid)
8345 continue;
8346
8347 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
8348 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008349 ha_warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n",
8350 newsrv->conf.file, newsrv->conf.line,
8351 proxy_type_str(curproxy), curproxy->id,
8352 newsrv->id, other_srv->conf.line);
Willy Tarreau17edc812014-01-03 12:14:34 +01008353 break;
8354 }
8355 }
8356 }
8357
Willy Tarreaudd701652010-05-25 23:03:02 +02008358 /* assign automatic UIDs to servers which don't have one yet */
8359 next_id = 1;
8360 newsrv = curproxy->srv;
8361 while (newsrv != NULL) {
8362 if (!newsrv->puid) {
8363 /* server ID not set, use automatic numbering with first
8364 * spare entry starting with next_svid.
8365 */
8366 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
8367 newsrv->conf.id.key = newsrv->puid = next_id;
8368 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
8369 }
8370 next_id++;
8371 newsrv = newsrv->next;
8372 }
8373
Willy Tarreau20697042007-11-15 23:26:18 +01008374 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01008375 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02008376
Willy Tarreau62c3be22012-01-20 13:12:32 +01008377 /*
8378 * If this server supports a maxconn parameter, it needs a dedicated
8379 * tasks to fill the emptied slots when a connection leaves.
8380 * Also, resolve deferred tracking dependency if needed.
8381 */
8382 newsrv = curproxy->srv;
8383 while (newsrv != NULL) {
8384 if (newsrv->minconn > newsrv->maxconn) {
8385 /* Only 'minconn' was specified, or it was higher than or equal
8386 * to 'maxconn'. Let's turn this into maxconn and clean it, as
8387 * this will avoid further useless expensive computations.
8388 */
8389 newsrv->maxconn = newsrv->minconn;
8390 } else if (newsrv->maxconn && !newsrv->minconn) {
8391 /* minconn was not specified, so we set it to maxconn */
8392 newsrv->minconn = newsrv->maxconn;
8393 }
8394
Willy Tarreau17d45382016-12-22 21:16:08 +01008395 /* this will also properly set the transport layer for prod and checks */
8396 if (newsrv->use_ssl || newsrv->check.use_ssl) {
8397 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
8398 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
8399 }
Emeric Brun94324a42012-10-11 14:00:19 +02008400
Willy Tarreau2f075e92013-12-03 11:11:34 +01008401 /* set the check type on the server */
8402 newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY;
8403
Willy Tarreau62c3be22012-01-20 13:12:32 +01008404 if (newsrv->trackit) {
8405 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02008406 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008407 char *pname, *sname;
8408
8409 pname = newsrv->trackit;
8410 sname = strrchr(pname, '/');
8411
8412 if (sname)
8413 *sname++ = '\0';
8414 else {
8415 sname = pname;
8416 pname = NULL;
8417 }
8418
8419 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02008420 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008421 if (!px) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008422 ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
8423 proxy_type_str(curproxy), curproxy->id,
8424 newsrv->id, pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008425 cfgerr++;
8426 goto next_srv;
8427 }
8428 } else
8429 px = curproxy;
8430
8431 srv = findserver(px, sname);
8432 if (!srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008433 ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
8434 proxy_type_str(curproxy), curproxy->id,
8435 newsrv->id, sname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008436 cfgerr++;
8437 goto next_srv;
8438 }
8439
Willy Tarreau32091232014-05-16 13:52:00 +02008440 if (!(srv->check.state & CHK_ST_CONFIGURED) &&
8441 !(srv->agent.state & CHK_ST_CONFIGURED) &&
8442 !srv->track && !srv->trackit) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008443 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for "
8444 "tracking as it does not have any check nor agent enabled.\n",
8445 proxy_type_str(curproxy), curproxy->id,
8446 newsrv->id, px->id, srv->id);
Willy Tarreau32091232014-05-16 13:52:00 +02008447 cfgerr++;
8448 goto next_srv;
8449 }
8450
8451 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
8452
Frédéric Lécaille2efc6492017-03-14 14:32:17 +01008453 if (newsrv == srv || loop) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008454 ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it "
8455 "belongs to a tracking chain looping back to %s/%s.\n",
8456 proxy_type_str(curproxy), curproxy->id,
8457 newsrv->id, px->id, srv->id, px->id,
8458 newsrv == srv ? srv->id : loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008459 cfgerr++;
8460 goto next_srv;
8461 }
8462
8463 if (curproxy != px &&
8464 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008465 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for"
8466 "tracking: disable-on-404 option inconsistency.\n",
8467 proxy_type_str(curproxy), curproxy->id,
8468 newsrv->id, px->id, srv->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008469 cfgerr++;
8470 goto next_srv;
8471 }
8472
Willy Tarreau62c3be22012-01-20 13:12:32 +01008473 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01008474 newsrv->tracknext = srv->trackers;
8475 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008476
8477 free(newsrv->trackit);
8478 newsrv->trackit = NULL;
8479 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02008480
Willy Tarreau62c3be22012-01-20 13:12:32 +01008481 next_srv:
8482 newsrv = newsrv->next;
8483 }
8484
Olivier Houchard4e694042017-03-14 20:01:29 +01008485 /*
8486 * Try to generate dynamic cookies for servers now.
8487 * It couldn't be done earlier, since at the time we parsed
8488 * the server line, we may not have known yet that we
8489 * should use dynamic cookies, or the secret key may not
8490 * have been provided yet.
8491 */
8492 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
8493 newsrv = curproxy->srv;
8494 while (newsrv != NULL) {
8495 srv_set_dyncookie(newsrv);
8496 newsrv = newsrv->next;
8497 }
8498
8499 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008500 /* We have to initialize the server lookup mechanism depending
8501 * on what LB algorithm was choosen.
8502 */
8503
8504 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
8505 switch (curproxy->lbprm.algo & BE_LB_KIND) {
8506 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02008507 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
8508 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8509 init_server_map(curproxy);
Willy Tarreau760e81d2018-05-03 07:20:40 +02008510 } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
8511 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
8512 chash_init_server_tree(curproxy);
Willy Tarreau9757a382009-10-03 12:56:50 +02008513 } else {
8514 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
8515 fwrr_init_server_groups(curproxy);
8516 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008517 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008518
Willy Tarreau3ebb1162012-02-13 16:57:44 +01008519 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01008520 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
8521 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
8522 fwlc_init_server_tree(curproxy);
8523 } else {
8524 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
8525 fas_init_server_tree(curproxy);
8526 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008527 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008528
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008529 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008530 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
8531 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
8532 chash_init_server_tree(curproxy);
8533 } else {
8534 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8535 init_server_map(curproxy);
8536 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008537 break;
8538 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01008539 HA_SPIN_INIT(&curproxy->lbprm.lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +02008540
8541 if (curproxy->options & PR_O_LOGASAP)
8542 curproxy->to_log &= ~LW_BYTES;
8543
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008544 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008545 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
8546 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008547 ha_warning("config : log format ignored for %s '%s' since it has no log address.\n",
8548 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008549 err_code |= ERR_WARN;
8550 }
8551
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008552 if (curproxy->mode != PR_MODE_HTTP) {
8553 int optnum;
8554
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008555 if (curproxy->uri_auth) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008556 ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
8557 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008558 err_code |= ERR_WARN;
8559 curproxy->uri_auth = NULL;
8560 }
8561
Willy Tarreaude7dc882017-03-10 11:49:21 +01008562 if (curproxy->capture_name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008563 ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
8564 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008565 err_code |= ERR_WARN;
8566 }
8567
8568 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008569 ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
8570 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008571 err_code |= ERR_WARN;
8572 }
8573
8574 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008575 ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
8576 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008577 err_code |= ERR_WARN;
8578 }
8579
8580 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008581 ha_warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n",
8582 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008583 err_code |= ERR_WARN;
8584 }
8585
8586 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008587 ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
8588 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008589 err_code |= ERR_WARN;
8590 }
8591
Willy Tarreau87cf5142011-08-19 22:57:24 +02008592 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008593 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8594 "forwardfor", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008595 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02008596 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008597 }
8598
8599 if (curproxy->options & PR_O_ORGTO) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008600 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8601 "originalto", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008602 err_code |= ERR_WARN;
8603 curproxy->options &= ~PR_O_ORGTO;
8604 }
8605
8606 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
8607 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
8608 (curproxy->cap & cfg_opts[optnum].cap) &&
8609 (curproxy->options & cfg_opts[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008610 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8611 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008612 err_code |= ERR_WARN;
8613 curproxy->options &= ~cfg_opts[optnum].val;
8614 }
8615 }
8616
8617 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
8618 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
8619 (curproxy->cap & cfg_opts2[optnum].cap) &&
8620 (curproxy->options2 & cfg_opts2[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008621 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8622 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008623 err_code |= ERR_WARN;
8624 curproxy->options2 &= ~cfg_opts2[optnum].val;
8625 }
8626 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008627
Willy Tarreau29fbe512015-08-20 19:35:14 +02008628#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008629 if (curproxy->conn_src.bind_hdr_occ) {
8630 curproxy->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01008631 ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
8632 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008633 err_code |= ERR_WARN;
8634 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008635#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008636 }
8637
Willy Tarreaubaaee002006-06-26 02:48:02 +02008638 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01008639 * ensure that we're not cross-dressing a TCP server into HTTP.
8640 */
8641 newsrv = curproxy->srv;
8642 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01008643 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008644 ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
8645 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008646 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01008647 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008648
Willy Tarreau0cec3312011-10-31 13:49:26 +01008649 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008650 ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
8651 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau0cec3312011-10-31 13:49:26 +01008652 err_code |= ERR_WARN;
8653 }
8654
Willy Tarreauc93cd162014-05-13 15:54:22 +02008655 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008656 ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
8657 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau82ffa392013-08-13 17:19:08 +02008658 err_code |= ERR_WARN;
8659 }
8660
Willy Tarreau29fbe512015-08-20 19:35:14 +02008661#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008662 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
8663 newsrv->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01008664 ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
8665 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008666 err_code |= ERR_WARN;
8667 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008668#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01008669
Willy Tarreau46deab62018-04-28 07:18:15 +02008670 if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR)
8671 curproxy->options &= ~PR_O_REUSE_MASK;
8672
Willy Tarreau4c183462017-01-06 12:21:38 +01008673 if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) {
8674 if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8675 (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP ||
8676 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8677 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008678 ha_warning("config : %s '%s' : connections to server '%s' use the client's IP address as the source while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'usesrc' and to use the 'forwardfor' option instead.\n",
8679 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau4c183462017-01-06 12:21:38 +01008680 err_code |= ERR_WARN;
8681 }
8682
8683
8684 if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008685 ha_warning("config : %s '%s' : connections to server '%s' will have a PROXY protocol header announcing the first client's IP address while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'send-proxy' and to use the 'forwardfor' option instead.\n",
8686 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau4c183462017-01-06 12:21:38 +01008687 err_code |= ERR_WARN;
8688 }
8689 }
8690
Willy Tarreau21d2af32008-02-14 20:25:24 +01008691 newsrv = newsrv->next;
8692 }
8693
Willy Tarreaue42bd962014-09-16 16:21:19 +02008694 /* check if we have a frontend with "tcp-request content" looking at L7
8695 * with no inspect-delay
8696 */
8697 if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) {
Christopher Faulete4e830d2017-09-18 14:51:41 +02008698 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
8699 if (arule->action == ACT_TCP_CAPTURE &&
8700 !(arule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008701 break;
Christopher Faulete4e830d2017-09-18 14:51:41 +02008702 if ((arule->action >= ACT_ACTION_TRK_SC0 && arule->action <= ACT_ACTION_TRK_SCMAX) &&
8703 !(arule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008704 break;
8705 }
8706
Christopher Faulete4e830d2017-09-18 14:51:41 +02008707 if (&arule->list != &curproxy->tcp_req.inspect_rules) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008708 ha_warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request"
8709 " contents were found in a frontend without any 'tcp-request inspect-delay' setting."
8710 " This means that these rules will randomly find their contents. This can be fixed by"
8711 " setting the tcp-request inspect-delay.\n",
8712 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue42bd962014-09-16 16:21:19 +02008713 err_code |= ERR_WARN;
8714 }
8715 }
8716
Christopher Fauletd7c91962015-04-30 11:48:27 +02008717 /* Check filter configuration, if any */
8718 cfgerr += flt_check(curproxy);
8719
Willy Tarreauc1a21672009-08-16 22:37:44 +02008720 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02008721 if (!curproxy->accept)
8722 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02008723
Willy Tarreauc1a21672009-08-16 22:37:44 +02008724 if (curproxy->tcp_req.inspect_delay ||
8725 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02008726 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008727
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008728 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008729 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008730 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008731 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008732
8733 /* both TCP and HTTP must check switching rules */
8734 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008735
8736 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008737 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008738 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8739 curproxy->fe_rsp_ana |= AN_RES_FLT_START_FE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END;
Christopher Faulet309c6412015-12-02 09:57:32 +01008740 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008741 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8742 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008743 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008744 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008745 }
8746
8747 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02008748 if (curproxy->tcp_req.inspect_delay ||
8749 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
8750 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
8751
Emeric Brun97679e72010-09-23 17:56:44 +02008752 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
8753 curproxy->be_rsp_ana |= AN_RES_INSPECT;
8754
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008755 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008756 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008757 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008758 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008759
8760 /* If the backend does requires RDP cookie persistence, we have to
8761 * enable the corresponding analyser.
8762 */
8763 if (curproxy->options2 & PR_O2_RDPC_PRST)
8764 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008765
8766 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008767 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008768 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8769 curproxy->be_rsp_ana |= AN_RES_FLT_START_BE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END;
Christopher Faulet309c6412015-12-02 09:57:32 +01008770 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008771 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8772 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008773 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008774 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008775 }
Christopher Fauleta717b992018-04-10 14:43:00 +02008776
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02008777 /* Check the mux protocols, if any, for each listener and server
Christopher Fauleta717b992018-04-10 14:43:00 +02008778 * attached to the current proxy */
8779 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
8780 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
8781
8782 if (!bind_conf->mux_proto)
8783 continue;
8784 if (!(bind_conf->mux_proto->mode & mode)) {
8785 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n",
8786 proxy_type_str(curproxy), curproxy->id,
8787 (int)bind_conf->mux_proto->token.len,
8788 bind_conf->mux_proto->token.ptr,
8789 bind_conf->arg, bind_conf->file, bind_conf->line);
8790 cfgerr++;
8791 }
8792 }
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02008793 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
8794 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
8795
8796 if (!newsrv->mux_proto)
8797 continue;
8798 if (!(newsrv->mux_proto->mode & mode)) {
8799 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n",
8800 proxy_type_str(curproxy), curproxy->id,
8801 (int)newsrv->mux_proto->token.len,
8802 newsrv->mux_proto->token.ptr,
8803 newsrv->id, newsrv->conf.file, newsrv->conf.line);
8804 cfgerr++;
8805 }
8806 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008807 }
8808
8809 /***********************************************************/
8810 /* At this point, target names have already been resolved. */
8811 /***********************************************************/
8812
8813 /* Check multi-process mode compatibility */
8814
8815 if (global.nbproc > 1 && global.stats_fe) {
8816 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8817 unsigned long mask;
8818
8819 mask = nbits(global.nbproc);
8820 if (global.stats_fe->bind_proc)
8821 mask &= global.stats_fe->bind_proc;
8822
8823 if (bind_conf->bind_proc)
8824 mask &= bind_conf->bind_proc;
8825
8826 /* stop here if more than one process is used */
Willy Tarreau9504dd62018-10-15 09:37:03 +02008827 if (atleast2(mask))
Willy Tarreau419ead82014-09-16 13:41:21 +02008828 break;
8829 }
8830 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008831 ha_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");
Willy Tarreau419ead82014-09-16 13:41:21 +02008832 }
8833 }
8834
8835 /* Make each frontend inherit bind-process from its listeners when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008836 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02008837 if (curproxy->bind_proc)
8838 continue;
8839
8840 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
8841 unsigned long mask;
8842
Willy Tarreaue428b082015-05-04 21:57:58 +02008843 mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008844 curproxy->bind_proc |= mask;
8845 }
8846
8847 if (!curproxy->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008848 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008849 }
8850
8851 if (global.stats_fe) {
8852 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8853 unsigned long mask;
8854
Cyril Bonté06181952016-02-24 00:14:54 +01008855 mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02008856 global.stats_fe->bind_proc |= mask;
8857 }
8858 if (!global.stats_fe->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008859 global.stats_fe->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008860 }
8861
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02008862 /* propagate bindings from frontends to backends. Don't do it if there
8863 * are any fatal errors as we must not call it with unresolved proxies.
8864 */
8865 if (!cfgerr) {
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008866 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02008867 if (curproxy->cap & PR_CAP_FE)
8868 propagate_processes(curproxy, NULL);
8869 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008870 }
8871
8872 /* Bind each unbound backend to all processes when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008873 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02008874 if (curproxy->bind_proc)
8875 continue;
Willy Tarreaue428b082015-05-04 21:57:58 +02008876 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008877 }
8878
8879 /*******************************************************/
8880 /* At this step, all proxies have a non-null bind_proc */
8881 /*******************************************************/
8882
8883 /* perform the final checks before creating tasks */
8884
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008885 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02008886 struct listener *listener;
8887 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008888
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008889 /* Configure SSL for each bind line.
8890 * Note: if configuration fails at some point, the ->ctx member
8891 * remains NULL so that listeners can later detach.
8892 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008893 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01008894 if (bind_conf->xprt->prepare_bind_conf &&
8895 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008896 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008897 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008898
Willy Tarreaue6b98942007-10-29 01:09:36 +01008899 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008900 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02008901 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008902 int nbproc;
8903
8904 nbproc = my_popcountl(curproxy->bind_proc &
Cyril Bonté4920d702016-04-15 07:58:43 +02008905 (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) &
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008906 nbits(global.nbproc));
8907
8908 if (!nbproc) /* no intersection between listener and frontend */
8909 nbproc = 1;
8910
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008911 if (!listener->luid) {
8912 /* listener ID not set, use automatic numbering with first
8913 * spare entry starting with next_luid.
8914 */
8915 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
8916 listener->conf.id.key = listener->luid = next_id;
8917 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008918 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01008919 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008920
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008921 /* enable separate counters */
8922 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01008923 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01008924 if (!listener->name)
8925 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008926 }
Willy Tarreau81796be2012-09-22 19:11:47 +02008927
Willy Tarreaue6b98942007-10-29 01:09:36 +01008928 if (curproxy->options & PR_O_TCP_NOLING)
8929 listener->options |= LI_O_NOLINGER;
Willy Tarreau32368ce2012-09-06 11:10:55 +02008930 if (!listener->maxconn)
8931 listener->maxconn = curproxy->maxconn;
8932 if (!listener->backlog)
8933 listener->backlog = curproxy->backlog;
Willy Tarreau16a21472012-11-19 12:39:59 +01008934 if (!listener->maxaccept)
8935 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
8936
8937 /* we want to have an optimal behaviour on single process mode to
8938 * maximize the work at once, but in multi-process we want to keep
8939 * some fairness between processes, so we target half of the max
8940 * number of events to be balanced over all the processes the proxy
8941 * is bound to. Rememeber that maxaccept = -1 must be kept as it is
8942 * used to disable the limit.
8943 */
8944 if (listener->maxaccept > 0) {
8945 if (nbproc > 1)
8946 listener->maxaccept = (listener->maxaccept + 1) / 2;
8947 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
8948 }
8949
Willy Tarreau9903f0e2015-04-04 18:50:31 +02008950 listener->accept = session_accept_fd;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008951 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01008952 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01008953
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008954 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02008955 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008956
Willy Tarreau620408f2016-10-21 16:37:51 +02008957 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
8958 listener->options |= LI_O_TCP_L5_RULES;
8959
Willy Tarreaude3041d2010-05-31 10:56:17 +02008960 if (curproxy->mon_mask.s_addr)
8961 listener->options |= LI_O_CHK_MONNET;
8962
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008963 /* smart accept mode is automatic in HTTP mode */
8964 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008965 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008966 !(curproxy->no_options2 & PR_O2_SMARTACC)))
8967 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01008968 }
8969
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008970 /* Release unused SSL configs */
8971 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01008972 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
8973 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008974 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008975
Willy Tarreau9504dd62018-10-15 09:37:03 +02008976 if (atleast2(curproxy->bind_proc & nbits(global.nbproc))) {
Willy Tarreau102df612014-05-07 23:56:38 +02008977 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02008978 int count, maxproc = 0;
8979
8980 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
David Carliere6c39412015-07-02 07:00:17 +00008981 count = my_popcountl(bind_conf->bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02008982 if (count > maxproc)
8983 maxproc = count;
8984 }
8985 /* backends have 0, frontends have 1 or more */
8986 if (maxproc != 1)
Christopher Faulet767a84b2017-11-24 16:50:31 +01008987 ha_warning("Proxy '%s': in multi-process mode, stats will be"
8988 " limited to process assigned to the current request.\n",
8989 curproxy->id);
Willy Tarreaueb791e02014-09-16 15:11:04 +02008990
Willy Tarreau102df612014-05-07 23:56:38 +02008991 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008992 ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
8993 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008994 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008995 }
Willy Tarreau102df612014-05-07 23:56:38 +02008996 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008997 ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
8998 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008999 }
9000 }
Willy Tarreau918ff602011-07-25 16:33:49 +02009001
9002 /* create the task associated with the proxy */
Emeric Brunc60def82017-09-27 14:59:38 +02009003 curproxy->task = task_new(MAX_THREADS_MASK);
Willy Tarreau918ff602011-07-25 16:33:49 +02009004 if (curproxy->task) {
9005 curproxy->task->context = curproxy;
9006 curproxy->task->process = manage_proxy;
Willy Tarreau918ff602011-07-25 16:33:49 +02009007 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009008 ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
9009 curproxy->id);
Willy Tarreau918ff602011-07-25 16:33:49 +02009010 cfgerr++;
9011 }
Willy Tarreaub369a042014-09-16 13:21:03 +02009012 }
9013
Willy Tarreaufbb78422011-06-05 15:38:35 +02009014 /* automatically compute fullconn if not set. We must not do it in the
9015 * loop above because cross-references are not yet fully resolved.
9016 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009017 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02009018 /* If <fullconn> is not set, let's set it to 10% of the sum of
9019 * the possible incoming frontend's maxconns.
9020 */
9021 if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02009022 /* we have the sum of the maxconns in <total>. We only
9023 * keep 10% of that sum to set the default fullconn, with
9024 * a hard minimum of 1 (to avoid a divide by zero).
9025 */
Emeric Brun3f783572017-01-12 11:21:28 +01009026 curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10;
Willy Tarreaufbb78422011-06-05 15:38:35 +02009027 if (!curproxy->fullconn)
9028 curproxy->fullconn = 1;
9029 }
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01009030 }
9031
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009032 /*
9033 * Recount currently required checks.
9034 */
9035
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009036 for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009037 int optnum;
9038
Willy Tarreau66aa61f2009-01-18 21:44:07 +01009039 for (optnum = 0; cfg_opts[optnum].name; optnum++)
9040 if (curproxy->options & cfg_opts[optnum].val)
9041 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009042
Willy Tarreau66aa61f2009-01-18 21:44:07 +01009043 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
9044 if (curproxy->options2 & cfg_opts2[optnum].val)
9045 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009046 }
9047
Willy Tarreau0fca4832015-05-01 19:12:05 +02009048 /* compute the required process bindings for the peers */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009049 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
Willy Tarreau0fca4832015-05-01 19:12:05 +02009050 if (curproxy->table.peers.p)
9051 curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
9052
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02009053 if (cfg_peers) {
9054 struct peers *curpeers = cfg_peers, **last;
Willy Tarreau122541c2011-09-07 21:24:49 +02009055 struct peer *p, *pb;
9056
Willy Tarreau1e273012015-05-01 19:15:17 +02009057 /* Remove all peers sections which don't have a valid listener,
9058 * which are not used by any table, or which are bound to more
9059 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02009060 */
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02009061 last = &cfg_peers;
Willy Tarreau122541c2011-09-07 21:24:49 +02009062 while (*last) {
9063 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009064
9065 if (curpeers->state == PR_STSTOPPED) {
9066 /* the "disabled" keyword was present */
9067 if (curpeers->peers_fe)
9068 stop_proxy(curpeers->peers_fe);
9069 curpeers->peers_fe = NULL;
9070 }
9071 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009072 ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
9073 curpeers->id, localpeer);
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009074 }
Willy Tarreau9504dd62018-10-15 09:37:03 +02009075 else if (atleast2(curpeers->peers_fe->bind_proc)) {
Willy Tarreau1e273012015-05-01 19:15:17 +02009076 /* either it's totally stopped or too much used */
9077 if (curpeers->peers_fe->bind_proc) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009078 ha_alert("Peers section '%s': peers referenced by sections "
9079 "running in different processes (%d different ones). "
9080 "Check global.nbproc and all tables' bind-process "
9081 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02009082 cfgerr++;
9083 }
9084 stop_proxy(curpeers->peers_fe);
9085 curpeers->peers_fe = NULL;
9086 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009087 else {
Willy Tarreaud9443442018-10-15 11:18:03 +02009088 if (!peers_init_sync(curpeers)) {
9089 ha_alert("Peers section '%s': out of memory, giving up on peers.\n",
9090 curpeers->id);
9091 cfgerr++;
9092 break;
9093 }
Willy Tarreau122541c2011-09-07 21:24:49 +02009094 last = &curpeers->next;
9095 continue;
9096 }
9097
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009098 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02009099 p = curpeers->remote;
9100 while (p) {
9101 pb = p->next;
9102 free(p->id);
9103 free(p);
9104 p = pb;
9105 }
9106
9107 /* Destroy and unlink this curpeers section.
9108 * Note: curpeers is backed up into *last.
9109 */
9110 free(curpeers->id);
9111 curpeers = curpeers->next;
9112 free(*last);
9113 *last = curpeers;
9114 }
9115 }
9116
Willy Tarreau6866f3f2015-05-01 19:09:08 +02009117 /* initialize stick-tables on backend capable proxies. This must not
9118 * be done earlier because the data size may be discovered while parsing
9119 * other proxies.
9120 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009121 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau6866f3f2015-05-01 19:09:08 +02009122 if (curproxy->state == PR_STSTOPPED)
9123 continue;
9124
9125 if (!stktable_init(&curproxy->table)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009126 ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
Willy Tarreau6866f3f2015-05-01 19:09:08 +02009127 cfgerr++;
9128 }
9129 }
9130
Simon Horman0d16a402015-01-30 11:22:58 +09009131 if (mailers) {
9132 struct mailers *curmailers = mailers, **last;
9133 struct mailer *m, *mb;
9134
9135 /* Remove all mailers sections which don't have a valid listener.
9136 * This can happen when a mailers section is never referenced.
9137 */
9138 last = &mailers;
9139 while (*last) {
9140 curmailers = *last;
9141 if (curmailers->users) {
9142 last = &curmailers->next;
9143 continue;
9144 }
9145
Christopher Faulet767a84b2017-11-24 16:50:31 +01009146 ha_warning("Removing incomplete section 'mailers %s'.\n",
9147 curmailers->id);
Simon Horman0d16a402015-01-30 11:22:58 +09009148
9149 m = curmailers->mailer_list;
9150 while (m) {
9151 mb = m->next;
9152 free(m->id);
9153 free(m);
9154 m = mb;
9155 }
9156
9157 /* Destroy and unlink this curmailers section.
9158 * Note: curmailers is backed up into *last.
9159 */
9160 free(curmailers->id);
9161 curmailers = curmailers->next;
9162 free(*last);
9163 *last = curmailers;
9164 }
9165 }
9166
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02009167 /* Update server_state_file_name to backend name if backend is supposed to use
9168 * a server-state file locally defined and none has been provided */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009169 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02009170 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
9171 curproxy->server_state_file_name == NULL)
9172 curproxy->server_state_file_name = strdup(curproxy->id);
9173 }
9174
Willy Tarreaubafbe012017-11-24 17:34:44 +01009175 pool_head_hdr_idx = create_pool("hdr_idx",
Willy Tarreauac1932d2011-10-24 19:14:41 +02009176 global.tune.max_http_hdr * sizeof(struct hdr_idx_elem),
Willy Tarreau34eb6712011-10-24 18:15:04 +02009177 MEM_F_SHARED);
9178
Ben Draut054fbee2018-04-13 15:43:04 -06009179 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
9180 if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
9181 ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n",
9182 curr_resolvers->id, curr_resolvers->conf.file,
9183 curr_resolvers->conf.line);
9184 err_code |= ERR_WARN;
9185 }
9186 }
9187
William Lallemand48b4bb42017-10-23 14:36:34 +02009188 list_for_each_entry(postparser, &postparsers, list) {
9189 if (postparser->func)
9190 cfgerr += postparser->func();
9191 }
9192
Willy Tarreaubb925012009-07-23 13:36:36 +02009193 if (cfgerr > 0)
9194 err_code |= ERR_ALERT | ERR_FATAL;
9195 out:
9196 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02009197}
9198
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009199/*
9200 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
9201 * parsing sessions.
9202 */
9203void cfg_register_keywords(struct cfg_kw_list *kwl)
9204{
9205 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
9206}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009207
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009208/*
9209 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
9210 */
9211void cfg_unregister_keywords(struct cfg_kw_list *kwl)
9212{
9213 LIST_DEL(&kwl->list);
9214 LIST_INIT(&kwl->list);
9215}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009216
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009217/* this function register new section in the haproxy configuration file.
9218 * <section_name> is the name of this new section and <section_parser>
9219 * is the called parser. If two section declaration have the same name,
9220 * only the first declared is used.
9221 */
9222int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +02009223 int (*section_parser)(const char *, int, char **, int),
9224 int (*post_section_parser)())
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009225{
9226 struct cfg_section *cs;
9227
Willy Tarreau5e4261b2016-05-17 16:16:09 +02009228 list_for_each_entry(cs, &sections, list) {
9229 if (strcmp(cs->section_name, section_name) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009230 ha_alert("register section '%s': already registered.\n", section_name);
Willy Tarreau5e4261b2016-05-17 16:16:09 +02009231 return 0;
9232 }
9233 }
9234
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009235 cs = calloc(1, sizeof(*cs));
9236 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009237 ha_alert("register section '%s': out of memory.\n", section_name);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009238 return 0;
9239 }
9240
9241 cs->section_name = section_name;
9242 cs->section_parser = section_parser;
William Lallemandd2ff56d2017-10-16 11:06:50 +02009243 cs->post_section_parser = post_section_parser;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009244
9245 LIST_ADDQ(&sections, &cs->list);
9246
9247 return 1;
9248}
9249
William Lallemand48b4bb42017-10-23 14:36:34 +02009250/* this function register a new function which will be called once the haproxy
9251 * configuration file has been parsed. It's useful to check dependencies
9252 * between sections or to resolve items once everything is parsed.
9253 */
9254int cfg_register_postparser(char *name, int (*func)())
9255{
9256 struct cfg_postparser *cp;
9257
9258 cp = calloc(1, sizeof(*cp));
9259 if (!cp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009260 ha_alert("register postparser '%s': out of memory.\n", name);
William Lallemand48b4bb42017-10-23 14:36:34 +02009261 return 0;
9262 }
9263 cp->name = name;
9264 cp->func = func;
9265
9266 LIST_ADDQ(&postparsers, &cp->list);
9267
9268 return 1;
9269}
9270
Willy Tarreaubaaee002006-06-26 02:48:02 +02009271/*
David Carlier845efb52015-09-25 11:49:18 +01009272 * free all config section entries
9273 */
9274void cfg_unregister_sections(void)
9275{
9276 struct cfg_section *cs, *ics;
9277
9278 list_for_each_entry_safe(cs, ics, &sections, list) {
9279 LIST_DEL(&cs->list);
9280 free(cs);
9281 }
9282}
9283
Christopher Faulet7110b402016-10-26 11:09:44 +02009284void cfg_backup_sections(struct list *backup_sections)
9285{
9286 struct cfg_section *cs, *ics;
9287
9288 list_for_each_entry_safe(cs, ics, &sections, list) {
9289 LIST_DEL(&cs->list);
9290 LIST_ADDQ(backup_sections, &cs->list);
9291 }
9292}
9293
9294void cfg_restore_sections(struct list *backup_sections)
9295{
9296 struct cfg_section *cs, *ics;
9297
9298 list_for_each_entry_safe(cs, ics, backup_sections, list) {
9299 LIST_DEL(&cs->list);
9300 LIST_ADDQ(&sections, &cs->list);
9301 }
9302}
9303
Willy Tarreau659fbf02016-05-26 17:55:28 +02009304__attribute__((constructor))
9305static void cfgparse_init(void)
9306{
9307 /* Register internal sections */
William Lallemandd2ff56d2017-10-16 11:06:50 +02009308 cfg_register_section("listen", cfg_parse_listen, NULL);
9309 cfg_register_section("frontend", cfg_parse_listen, NULL);
9310 cfg_register_section("backend", cfg_parse_listen, NULL);
9311 cfg_register_section("defaults", cfg_parse_listen, NULL);
9312 cfg_register_section("global", cfg_parse_global, NULL);
9313 cfg_register_section("userlist", cfg_parse_users, NULL);
9314 cfg_register_section("peers", cfg_parse_peers, NULL);
9315 cfg_register_section("mailers", cfg_parse_mailers, NULL);
9316 cfg_register_section("namespace_list", cfg_parse_netns, NULL);
9317 cfg_register_section("resolvers", cfg_parse_resolvers, NULL);
Willy Tarreau659fbf02016-05-26 17:55:28 +02009318}
9319
David Carlier845efb52015-09-25 11:49:18 +01009320/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02009321 * Local variables:
9322 * c-indent-level: 8
9323 * c-basic-offset: 8
9324 * End:
9325 */