blob: 2ac22b55e210814edf0d7b726084a337e2ea3992 [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
1667 if (autoinc && my_popcountl(proc) != 1 && my_popcountl(thread) != 1) {
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 */
4707 if (strcmp(args[1], "httpclose") == 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;
4712 curproxy->options |= PR_O_HTTP_PCL;
4713 goto out;
4714 }
4715 else if (kwm == KWM_NO) {
4716 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
4717 curproxy->options &= ~PR_O_HTTP_MODE;
4718 goto out;
4719 }
4720 }
4721 else if (strcmp(args[1], "forceclose") == 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_FCL;
4727 goto out;
4728 }
4729 else if (kwm == KWM_NO) {
4730 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL)
4731 curproxy->options &= ~PR_O_HTTP_MODE;
4732 goto out;
4733 }
4734 }
4735 else if (strcmp(args[1], "http-server-close") == 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_SCL;
4741 goto out;
4742 }
4743 else if (kwm == KWM_NO) {
4744 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
4745 curproxy->options &= ~PR_O_HTTP_MODE;
4746 goto out;
4747 }
4748 }
4749 else if (strcmp(args[1], "http-keep-alive") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004750 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4751 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004752 if (kwm == KWM_STD) {
4753 curproxy->options &= ~PR_O_HTTP_MODE;
4754 curproxy->options |= PR_O_HTTP_KAL;
4755 goto out;
4756 }
4757 else if (kwm == KWM_NO) {
4758 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
4759 curproxy->options &= ~PR_O_HTTP_MODE;
4760 goto out;
4761 }
4762 }
4763 else if (strcmp(args[1], "http-tunnel") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004764 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4765 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004766 if (kwm == KWM_STD) {
4767 curproxy->options &= ~PR_O_HTTP_MODE;
4768 curproxy->options |= PR_O_HTTP_TUN;
4769 goto out;
4770 }
4771 else if (kwm == KWM_NO) {
4772 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
4773 curproxy->options &= ~PR_O_HTTP_MODE;
4774 goto out;
4775 }
4776 }
4777
Joseph Lynch726ab712015-05-11 23:25:34 -07004778 /* Redispatch can take an integer argument that control when the
4779 * resispatch occurs. All values are relative to the retries option.
4780 * This can be cancelled using "no option xxx".
4781 */
4782 if (strcmp(args[1], "redispatch") == 0) {
4783 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
4784 err_code |= ERR_WARN;
4785 goto out;
4786 }
4787
4788 curproxy->no_options &= ~PR_O_REDISP;
4789 curproxy->options &= ~PR_O_REDISP;
4790
4791 switch (kwm) {
4792 case KWM_STD:
4793 curproxy->options |= PR_O_REDISP;
4794 curproxy->redispatch_after = -1;
4795 if(*args[2]) {
4796 curproxy->redispatch_after = atol(args[2]);
4797 }
4798 break;
4799 case KWM_NO:
4800 curproxy->no_options |= PR_O_REDISP;
4801 curproxy->redispatch_after = 0;
4802 break;
4803 case KWM_DEF: /* already cleared */
4804 break;
4805 }
4806 goto out;
4807 }
4808
Willy Tarreau3842f002009-06-14 11:39:52 +02004809 if (kwm != KWM_STD) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004810 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
4811 file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004812 err_code |= ERR_ALERT | ERR_FATAL;
4813 goto out;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004814 }
4815
Emeric Brun3a058f32009-06-30 18:26:00 +02004816 if (!strcmp(args[1], "httplog")) {
William Lallemand723b73a2012-02-08 16:37:49 +01004817 char *logformat;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004818 /* generate a complete HTTP log */
William Lallemand723b73a2012-02-08 16:37:49 +01004819 logformat = default_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004820 if (*(args[2]) != '\0') {
4821 if (!strcmp(args[2], "clf")) {
4822 curproxy->options2 |= PR_O2_CLFLOG;
William Lallemand723b73a2012-02-08 16:37:49 +01004823 logformat = clf_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004824 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004825 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004826 err_code |= ERR_ALERT | ERR_FATAL;
4827 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004828 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004829 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
4830 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004831 }
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004832 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
4833 char *oldlogformat = "log-format";
4834 char *clflogformat = "";
4835
4836 if (curproxy->conf.logformat_string == default_http_log_format)
4837 oldlogformat = "option httplog";
4838 else if (curproxy->conf.logformat_string == default_tcp_log_format)
4839 oldlogformat = "option tcplog";
4840 else if (curproxy->conf.logformat_string == clf_http_log_format)
4841 oldlogformat = "option httplog clf";
4842 if (logformat == clf_http_log_format)
4843 clflogformat = " clf";
Christopher Faulet767a84b2017-11-24 16:50:31 +01004844 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
4845 file, linenum, clflogformat, oldlogformat);
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004846 }
Willy Tarreau62a61232013-04-12 18:13:46 +02004847 if (curproxy->conf.logformat_string != default_http_log_format &&
4848 curproxy->conf.logformat_string != default_tcp_log_format &&
4849 curproxy->conf.logformat_string != clf_http_log_format)
4850 free(curproxy->conf.logformat_string);
4851 curproxy->conf.logformat_string = logformat;
4852
4853 free(curproxy->conf.lfs_file);
4854 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4855 curproxy->conf.lfs_line = curproxy->conf.args.line;
Tim Duesterhus9ad9f352018-02-05 20:52:27 +01004856
4857 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
4858 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
4859 file, linenum, curproxy->id);
4860 err_code |= ERR_WARN;
4861 }
Emeric Brun3a058f32009-06-30 18:26:00 +02004862 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01004863 else if (!strcmp(args[1], "tcplog")) {
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004864 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
4865 char *oldlogformat = "log-format";
4866
4867 if (curproxy->conf.logformat_string == default_http_log_format)
4868 oldlogformat = "option httplog";
4869 else if (curproxy->conf.logformat_string == default_tcp_log_format)
4870 oldlogformat = "option tcplog";
4871 else if (curproxy->conf.logformat_string == clf_http_log_format)
4872 oldlogformat = "option httplog clf";
Christopher Faulet767a84b2017-11-24 16:50:31 +01004873 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
4874 file, linenum, oldlogformat);
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02004875 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004876 /* generate a detailed TCP log */
Willy Tarreau62a61232013-04-12 18:13:46 +02004877 if (curproxy->conf.logformat_string != default_http_log_format &&
4878 curproxy->conf.logformat_string != default_tcp_log_format &&
4879 curproxy->conf.logformat_string != clf_http_log_format)
4880 free(curproxy->conf.logformat_string);
4881 curproxy->conf.logformat_string = default_tcp_log_format;
4882
4883 free(curproxy->conf.lfs_file);
4884 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4885 curproxy->conf.lfs_line = curproxy->conf.args.line;
William Lallemanddf1425a2015-04-28 20:17:49 +02004886
4887 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4888 goto out;
Tim Duesterhus9ad9f352018-02-05 20:52:27 +01004889
4890 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
4891 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
4892 file, linenum, curproxy->id);
4893 err_code |= ERR_WARN;
4894 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01004895 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004896 else if (!strcmp(args[1], "tcpka")) {
Willy Tarreau87b09662015-04-03 00:22:06 +02004897 /* enable TCP keep-alives on client and server streams */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004898 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004899 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004900
William Lallemanddf1425a2015-04-28 20:17:49 +02004901 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4902 goto out;
4903
Willy Tarreau13943ab2006-12-31 00:24:10 +01004904 if (curproxy->cap & PR_CAP_FE)
4905 curproxy->options |= PR_O_TCP_CLI_KA;
4906 if (curproxy->cap & PR_CAP_BE)
4907 curproxy->options |= PR_O_TCP_SRV_KA;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004908 }
4909 else if (!strcmp(args[1], "httpchk")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +01004910 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004911 err_code |= ERR_WARN;
4912
Willy Tarreaubaaee002006-06-26 02:48:02 +02004913 /* use HTTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004914 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004915 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004916 curproxy->options2 &= ~PR_O2_CHK_ANY;
4917 curproxy->options2 |= PR_O2_HTTP_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004918 if (!*args[2]) { /* no argument */
4919 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
4920 curproxy->check_len = strlen(DEF_CHECK_REQ);
4921 } else if (!*args[3]) { /* one argument : URI */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004922 int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1;
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 "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */
Willy Tarreaubaaee002006-06-26 02:48:02 +02004926 } else { /* more arguments : METHOD URI [HTTP_VER] */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004927 int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004928 if (*args[4])
4929 reqlen += strlen(args[4]);
4930 else
4931 reqlen += strlen("HTTP/1.0");
4932
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004933 curproxy->check_req = malloc(reqlen);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004934 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Willy Tarreaue9d87882010-01-27 11:28:42 +01004935 "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004936 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004937 if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code))
4938 goto out;
Willy Tarreauf3c69202006-07-09 16:42:34 +02004939 }
4940 else if (!strcmp(args[1], "ssl-hello-chk")) {
4941 /* use SSLv3 CLIENT HELLO to check servers' health */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004942 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004943 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004944
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;
Willy Tarreau07a54902010-03-29 18:33:29 +02004948 curproxy->options2 |= PR_O2_SSL3_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004949
4950 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4951 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004952 }
Willy Tarreau23677902007-05-08 23:50:35 +02004953 else if (!strcmp(args[1], "smtpchk")) {
4954 /* use SMTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004955 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004956 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004957 curproxy->options2 &= ~PR_O2_CHK_ANY;
4958 curproxy->options2 |= PR_O2_SMTP_CHK;
Willy Tarreau23677902007-05-08 23:50:35 +02004959
4960 if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */
4961 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4962 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4963 } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */
4964 if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) {
4965 int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004966 curproxy->check_req = malloc(reqlen);
Willy Tarreau23677902007-05-08 23:50:35 +02004967 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
4968 "%s %s\r\n", args[2], args[3]); /* HELO hostname */
4969 } else {
4970 /* this just hits the default for now, but you could potentially expand it to allow for other stuff
4971 though, it's unlikely you'd want to send anything other than an EHLO or HELO */
4972 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4973 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4974 }
4975 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004976 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
4977 goto out;
Willy Tarreau23677902007-05-08 23:50:35 +02004978 }
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004979 else if (!strcmp(args[1], "pgsql-check")) {
4980 /* use PostgreSQL request to check servers' health */
4981 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4982 err_code |= ERR_WARN;
4983
4984 free(curproxy->check_req);
4985 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004986 curproxy->options2 &= ~PR_O2_CHK_ANY;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004987 curproxy->options2 |= PR_O2_PGSQL_CHK;
4988
4989 if (*(args[2])) {
4990 int cur_arg = 2;
4991
4992 while (*(args[cur_arg])) {
4993 if (strcmp(args[cur_arg], "user") == 0) {
4994 char * packet;
4995 uint32_t packet_len;
4996 uint32_t pv;
4997
4998 /* suboption header - needs additional argument for it */
4999 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005000 ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
5001 file, linenum, args[0], args[1], args[cur_arg]);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01005002 err_code |= ERR_ALERT | ERR_FATAL;
5003 goto out;
5004 }
5005
5006 /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */
5007 packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1;
5008 pv = htonl(0x30000); /* protocol version 3.0 */
5009
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005010 packet = calloc(1, packet_len);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01005011
5012 memcpy(packet + 4, &pv, 4);
5013
5014 /* copy "user" */
5015 memcpy(packet + 8, "user", 4);
5016
5017 /* copy username */
5018 memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1]));
5019
5020 free(curproxy->check_req);
5021 curproxy->check_req = packet;
5022 curproxy->check_len = packet_len;
5023
5024 packet_len = htonl(packet_len);
5025 memcpy(packet, &packet_len, 4);
5026 cur_arg += 2;
5027 } else {
5028 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005029 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
5030 file, linenum, args[0], args[1]);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01005031 err_code |= ERR_ALERT | ERR_FATAL;
5032 goto out;
5033 }
5034 } /* end while loop */
5035 }
William Lallemanddf1425a2015-04-28 20:17:49 +02005036 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
5037 goto out;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01005038 }
5039
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005040 else if (!strcmp(args[1], "redis-check")) {
5041 /* use REDIS PING request to check servers' health */
5042 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
5043 err_code |= ERR_WARN;
5044
5045 free(curproxy->check_req);
5046 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005047 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005048 curproxy->options2 |= PR_O2_REDIS_CHK;
5049
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005050 curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1);
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005051 memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1);
5052 curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02005053
5054 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5055 goto out;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005056 }
5057
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005058 else if (!strcmp(args[1], "mysql-check")) {
5059 /* use MYSQL request to check servers' health */
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005060 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
5061 err_code |= ERR_WARN;
5062
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005063 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01005064 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005065 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005066 curproxy->options2 |= PR_O2_MYSQL_CHK;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005067
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005068 /* This is an example of a MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte.
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005069 * const char mysql40_client_auth_pkt[] = {
5070 * "\x0e\x00\x00" // packet length
5071 * "\x01" // packet number
5072 * "\x00\x00" // client capabilities
5073 * "\x00\x00\x01" // max packet
5074 * "haproxy\x00" // username (null terminated string)
5075 * "\x00" // filler (always 0x00)
5076 * "\x01\x00\x00" // packet length
5077 * "\x00" // packet number
5078 * "\x01" // COM_QUIT command
5079 * };
5080 */
5081
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005082 /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic.
5083 * const char mysql41_client_auth_pkt[] = {
5084 * "\x0e\x00\x00\" // packet length
5085 * "\x01" // packet number
5086 * "\x00\x00\x00\x00" // client capabilities
5087 * "\x00\x00\x00\x01" // max packet
5088 * "\x21" // character set (UTF-8)
5089 * char[23] // All zeroes
5090 * "haproxy\x00" // username (null terminated string)
5091 * "\x00" // filler (always 0x00)
5092 * "\x01\x00\x00" // packet length
5093 * "\x00" // packet number
5094 * "\x01" // COM_QUIT command
5095 * };
5096 */
5097
5098
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005099 if (*(args[2])) {
5100 int cur_arg = 2;
5101
5102 while (*(args[cur_arg])) {
5103 if (strcmp(args[cur_arg], "user") == 0) {
5104 char *mysqluser;
5105 int packetlen, reqlen, userlen;
5106
5107 /* suboption header - needs additional argument for it */
5108 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005109 ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
5110 file, linenum, args[0], args[1], args[cur_arg]);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005111 err_code |= ERR_ALERT | ERR_FATAL;
5112 goto out;
5113 }
5114 mysqluser = args[cur_arg + 1];
5115 userlen = strlen(mysqluser);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005116
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005117 if (*(args[cur_arg+2])) {
5118 if (!strcmp(args[cur_arg+2], "post-41")) {
5119 packetlen = userlen + 7 + 27;
5120 reqlen = packetlen + 9;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005121
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005122 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005123 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005124 curproxy->check_len = reqlen;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005125
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005126 snprintf(curproxy->check_req, 4, "%c%c%c",
5127 ((unsigned char) packetlen & 0xff),
5128 ((unsigned char) (packetlen >> 8) & 0xff),
5129 ((unsigned char) (packetlen >> 16) & 0xff));
5130
5131 curproxy->check_req[3] = 1;
5132 curproxy->check_req[5] = 130;
5133 curproxy->check_req[11] = 1;
5134 curproxy->check_req[12] = 33;
5135 memcpy(&curproxy->check_req[36], mysqluser, userlen);
5136 curproxy->check_req[36 + userlen + 1 + 1] = 1;
5137 curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1;
5138 cur_arg += 3;
5139 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005140 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 +02005141 err_code |= ERR_ALERT | ERR_FATAL;
5142 goto out;
5143 }
5144 } else {
5145 packetlen = userlen + 7;
5146 reqlen = packetlen + 9;
5147
5148 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005149 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005150 curproxy->check_len = reqlen;
5151
5152 snprintf(curproxy->check_req, 4, "%c%c%c",
5153 ((unsigned char) packetlen & 0xff),
5154 ((unsigned char) (packetlen >> 8) & 0xff),
5155 ((unsigned char) (packetlen >> 16) & 0xff));
5156
5157 curproxy->check_req[3] = 1;
5158 curproxy->check_req[5] = 128;
5159 curproxy->check_req[8] = 1;
5160 memcpy(&curproxy->check_req[9], mysqluser, userlen);
5161 curproxy->check_req[9 + userlen + 1 + 1] = 1;
5162 curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1;
5163 cur_arg += 2;
5164 }
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005165 } else {
5166 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005167 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
5168 file, linenum, args[0], args[1]);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005169 err_code |= ERR_ALERT | ERR_FATAL;
5170 goto out;
5171 }
5172 } /* end while loop */
5173 }
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005174 }
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005175 else if (!strcmp(args[1], "ldap-check")) {
5176 /* use LDAP request to check servers' health */
5177 free(curproxy->check_req);
5178 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005179 curproxy->options2 &= ~PR_O2_CHK_ANY;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005180 curproxy->options2 |= PR_O2_LDAP_CHK;
5181
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005182 curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1);
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005183 memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1);
5184 curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02005185 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5186 goto out;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005187 }
Christopher Fauletba7bc162016-11-07 21:07:38 +01005188 else if (!strcmp(args[1], "spop-check")) {
5189 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005190 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n",
5191 file, linenum, args[0], args[1]);
Christopher Fauletba7bc162016-11-07 21:07:38 +01005192 err_code |= ERR_ALERT | ERR_FATAL;
5193 goto out;
5194 }
5195 if (curproxy->cap & PR_CAP_FE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005196 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n",
5197 file, linenum, args[0], args[1]);
Christopher Fauletba7bc162016-11-07 21:07:38 +01005198 err_code |= ERR_ALERT | ERR_FATAL;
5199 goto out;
5200 }
5201
5202 /* use SPOE request to check servers' health */
5203 free(curproxy->check_req);
5204 curproxy->check_req = NULL;
5205 curproxy->options2 &= ~PR_O2_CHK_ANY;
5206 curproxy->options2 |= PR_O2_SPOP_CHK;
5207
Christopher Faulet8ef75252017-02-20 22:56:03 +01005208 if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005209 ha_alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum);
Christopher Fauletba7bc162016-11-07 21:07:38 +01005210 err_code |= ERR_ALERT | ERR_FATAL;
5211 goto out;
5212 }
5213 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5214 goto out;
5215 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005216 else if (!strcmp(args[1], "tcp-check")) {
5217 /* use raw TCPCHK send/expect to check servers' health */
5218 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
5219 err_code |= ERR_WARN;
5220
5221 free(curproxy->check_req);
5222 curproxy->check_req = NULL;
5223 curproxy->options2 &= ~PR_O2_CHK_ANY;
5224 curproxy->options2 |= PR_O2_TCPCHK_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02005225 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5226 goto out;
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005227 }
Simon Horman98637e52014-06-20 12:30:16 +09005228 else if (!strcmp(args[1], "external-check")) {
5229 /* excute an external command to check servers' health */
5230 free(curproxy->check_req);
5231 curproxy->check_req = NULL;
5232 curproxy->options2 &= ~PR_O2_CHK_ANY;
5233 curproxy->options2 |= PR_O2_EXT_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02005234 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5235 goto out;
Simon Horman98637e52014-06-20 12:30:16 +09005236 }
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005237 else if (!strcmp(args[1], "forwardfor")) {
Ross Westaf72a1d2008-08-03 10:51:45 +02005238 int cur_arg;
5239
5240 /* insert x-forwarded-for field, but not for the IP address listed as an except.
5241 * set default options (ie: bitfield, header name, etc)
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005242 */
Ross Westaf72a1d2008-08-03 10:51:45 +02005243
Willy Tarreau87cf5142011-08-19 22:57:24 +02005244 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
Ross Westaf72a1d2008-08-03 10:51:45 +02005245
5246 free(curproxy->fwdfor_hdr_name);
5247 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
5248 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
5249
5250 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
5251 cur_arg = 2;
5252 while (*(args[cur_arg])) {
5253 if (!strcmp(args[cur_arg], "except")) {
5254 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01005255 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005256 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
5257 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005258 err_code |= ERR_ALERT | ERR_FATAL;
5259 goto out;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005260 }
5261 /* flush useless bits */
5262 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
Ross Westaf72a1d2008-08-03 10:51:45 +02005263 cur_arg += 2;
5264 } else if (!strcmp(args[cur_arg], "header")) {
5265 /* suboption header - needs additional argument for it */
5266 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005267 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
5268 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005269 err_code |= ERR_ALERT | ERR_FATAL;
5270 goto out;
Ross Westaf72a1d2008-08-03 10:51:45 +02005271 }
5272 free(curproxy->fwdfor_hdr_name);
5273 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
5274 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
5275 cur_arg += 2;
Willy Tarreau87cf5142011-08-19 22:57:24 +02005276 } else if (!strcmp(args[cur_arg], "if-none")) {
5277 curproxy->options &= ~PR_O_FF_ALWAYS;
5278 cur_arg += 1;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005279 } else {
Ross Westaf72a1d2008-08-03 10:51:45 +02005280 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005281 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
5282 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005283 err_code |= ERR_ALERT | ERR_FATAL;
5284 goto out;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005285 }
Ross Westaf72a1d2008-08-03 10:51:45 +02005286 } /* end while loop */
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005287 }
Maik Broemme2850cb42009-04-17 18:53:21 +02005288 else if (!strcmp(args[1], "originalto")) {
5289 int cur_arg;
5290
5291 /* insert x-original-to field, but not for the IP address listed as an except.
5292 * set default options (ie: bitfield, header name, etc)
5293 */
5294
5295 curproxy->options |= PR_O_ORGTO;
5296
5297 free(curproxy->orgto_hdr_name);
5298 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
5299 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
5300
Willy Tarreau87cf5142011-08-19 22:57:24 +02005301 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
Maik Broemme2850cb42009-04-17 18:53:21 +02005302 cur_arg = 2;
5303 while (*(args[cur_arg])) {
5304 if (!strcmp(args[cur_arg], "except")) {
5305 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01005306 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 +01005307 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
5308 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005309 err_code |= ERR_ALERT | ERR_FATAL;
5310 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005311 }
5312 /* flush useless bits */
5313 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
5314 cur_arg += 2;
5315 } else if (!strcmp(args[cur_arg], "header")) {
5316 /* suboption header - needs additional argument for it */
5317 if (*(args[cur_arg+1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005318 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
5319 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005320 err_code |= ERR_ALERT | ERR_FATAL;
5321 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005322 }
5323 free(curproxy->orgto_hdr_name);
5324 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
5325 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
5326 cur_arg += 2;
5327 } else {
5328 /* unknown suboption - catchall */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005329 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
5330 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005331 err_code |= ERR_ALERT | ERR_FATAL;
5332 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005333 }
5334 } /* end while loop */
5335 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005336 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005337 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005338 err_code |= ERR_ALERT | ERR_FATAL;
5339 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005340 }
Willy Tarreau93893792009-07-23 13:19:11 +02005341 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005342 }
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005343 else if (!strcmp(args[0], "default_backend")) {
5344 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005345 err_code |= ERR_WARN;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005346
5347 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005348 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005349 err_code |= ERR_ALERT | ERR_FATAL;
5350 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005351 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02005352 free(curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005353 curproxy->defbe.name = strdup(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005354
5355 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5356 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005357 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005358 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01005359 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005360 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005361
Willy Tarreaua3c504c2014-04-28 22:37:32 +02005362 if (!already_warned(WARN_REDISPATCH_DEPRECATED))
Christopher Faulet767a84b2017-11-24 16:50:31 +01005363 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n",
5364 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005365 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005366 /* enable reconnections to dispatch */
5367 curproxy->options |= PR_O_REDISP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005368
5369 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5370 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005371 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005372 else if (!strcmp(args[0], "http-reuse")) {
5373 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5374 err_code |= ERR_WARN;
5375
5376 if (strcmp(args[1], "never") == 0) {
5377 /* enable a graceful server shutdown on an HTTP 404 response */
5378 curproxy->options &= ~PR_O_REUSE_MASK;
5379 curproxy->options |= PR_O_REUSE_NEVR;
5380 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5381 goto out;
5382 }
Willy Tarreau161d45f2015-08-05 16:02:46 +02005383 else if (strcmp(args[1], "safe") == 0) {
5384 /* enable a graceful server shutdown on an HTTP 404 response */
5385 curproxy->options &= ~PR_O_REUSE_MASK;
5386 curproxy->options |= PR_O_REUSE_SAFE;
5387 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5388 goto out;
5389 }
Willy Tarreau449d74a2015-08-05 17:16:33 +02005390 else if (strcmp(args[1], "aggressive") == 0) {
5391 curproxy->options &= ~PR_O_REUSE_MASK;
5392 curproxy->options |= PR_O_REUSE_AGGR;
5393 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5394 goto out;
5395 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005396 else if (strcmp(args[1], "always") == 0) {
5397 /* enable a graceful server shutdown on an HTTP 404 response */
5398 curproxy->options &= ~PR_O_REUSE_MASK;
5399 curproxy->options |= PR_O_REUSE_ALWS;
5400 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5401 goto out;
5402 }
5403 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005404 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005405 err_code |= ERR_ALERT | ERR_FATAL;
5406 goto out;
5407 }
5408 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005409 else if (!strcmp(args[0], "http-check")) {
5410 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005411 err_code |= ERR_WARN;
Willy Tarreau48494c02007-11-30 10:41:39 +01005412
5413 if (strcmp(args[1], "disable-on-404") == 0) {
5414 /* enable a graceful server shutdown on an HTTP 404 response */
5415 curproxy->options |= PR_O_DISABLE404;
William Lallemanddf1425a2015-04-28 20:17:49 +02005416 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5417 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005418 }
Willy Tarreauef781042010-01-27 11:53:01 +01005419 else if (strcmp(args[1], "send-state") == 0) {
5420 /* enable emission of the apparent state of a server in HTTP checks */
5421 curproxy->options2 |= PR_O2_CHK_SNDST;
William Lallemanddf1425a2015-04-28 20:17:49 +02005422 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5423 goto out;
Willy Tarreauef781042010-01-27 11:53:01 +01005424 }
Willy Tarreaubd741542010-03-16 18:46:54 +01005425 else if (strcmp(args[1], "expect") == 0) {
5426 const char *ptr_arg;
5427 int cur_arg;
5428
5429 if (curproxy->options2 & PR_O2_EXP_TYPE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005430 ha_alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
Willy Tarreaubd741542010-03-16 18:46:54 +01005431 err_code |= ERR_ALERT | ERR_FATAL;
5432 goto out;
5433 }
5434
5435 cur_arg = 2;
5436 /* consider exclamation marks, sole or at the beginning of a word */
5437 while (*(ptr_arg = args[cur_arg])) {
5438 while (*ptr_arg == '!') {
5439 curproxy->options2 ^= PR_O2_EXP_INV;
5440 ptr_arg++;
5441 }
5442 if (*ptr_arg)
5443 break;
5444 cur_arg++;
5445 }
5446 /* now ptr_arg points to the beginning of a word past any possible
5447 * exclamation mark, and cur_arg is the argument which holds this word.
5448 */
5449 if (strcmp(ptr_arg, "status") == 0) {
5450 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005451 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5452 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005453 err_code |= ERR_ALERT | ERR_FATAL;
5454 goto out;
5455 }
5456 curproxy->options2 |= PR_O2_EXP_STS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005457 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005458 curproxy->expect_str = strdup(args[cur_arg + 1]);
5459 }
5460 else if (strcmp(ptr_arg, "string") == 0) {
5461 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005462 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5463 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005464 err_code |= ERR_ALERT | ERR_FATAL;
5465 goto out;
5466 }
5467 curproxy->options2 |= PR_O2_EXP_STR;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005468 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005469 curproxy->expect_str = strdup(args[cur_arg + 1]);
5470 }
5471 else if (strcmp(ptr_arg, "rstatus") == 0) {
5472 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005473 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5474 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005475 err_code |= ERR_ALERT | ERR_FATAL;
5476 goto out;
5477 }
5478 curproxy->options2 |= PR_O2_EXP_RSTS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005479 free(curproxy->expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005480 if (curproxy->expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005481 regex_free(curproxy->expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005482 free(curproxy->expect_regex);
5483 curproxy->expect_regex = NULL;
5484 }
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005485 curproxy->expect_str = strdup(args[cur_arg + 1]);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005486 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
5487 error = NULL;
5488 if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005489 ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5490 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005491 free(error);
Willy Tarreaubd741542010-03-16 18:46:54 +01005492 err_code |= ERR_ALERT | ERR_FATAL;
5493 goto out;
5494 }
5495 }
5496 else if (strcmp(ptr_arg, "rstring") == 0) {
5497 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005498 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5499 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005500 err_code |= ERR_ALERT | ERR_FATAL;
5501 goto out;
5502 }
5503 curproxy->options2 |= PR_O2_EXP_RSTR;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005504 free(curproxy->expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005505 if (curproxy->expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005506 regex_free(curproxy->expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005507 free(curproxy->expect_regex);
5508 curproxy->expect_regex = NULL;
5509 }
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005510 curproxy->expect_str = strdup(args[cur_arg + 1]);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005511 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
5512 error = NULL;
5513 if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005514 ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5515 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005516 free(error);
Willy Tarreaubd741542010-03-16 18:46:54 +01005517 err_code |= ERR_ALERT | ERR_FATAL;
5518 goto out;
5519 }
5520 }
5521 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005522 ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n",
5523 file, linenum, args[0], args[1], ptr_arg);
Willy Tarreaubd741542010-03-16 18:46:54 +01005524 err_code |= ERR_ALERT | ERR_FATAL;
5525 goto out;
5526 }
5527 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005528 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005529 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 +02005530 err_code |= ERR_ALERT | ERR_FATAL;
5531 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005532 }
5533 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005534 else if (!strcmp(args[0], "tcp-check")) {
5535 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5536 err_code |= ERR_WARN;
5537
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005538 if (strcmp(args[1], "comment") == 0) {
5539 int cur_arg;
5540 struct tcpcheck_rule *tcpcheck;
5541
5542 cur_arg = 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005543 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005544 tcpcheck->action = TCPCHK_ACT_COMMENT;
5545
5546 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005547 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5548 file, linenum, args[cur_arg]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005549 err_code |= ERR_ALERT | ERR_FATAL;
5550 goto out;
5551 }
5552
5553 tcpcheck->comment = strdup(args[cur_arg + 1]);
5554
5555 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
William Lallemanddf1425a2015-04-28 20:17:49 +02005556 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
5557 goto out;
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005558 }
5559 else if (strcmp(args[1], "connect") == 0) {
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005560 const char *ptr_arg;
5561 int cur_arg;
5562 struct tcpcheck_rule *tcpcheck;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005563
5564 /* check if first rule is also a 'connect' action */
Willy Tarreau5581c272015-05-13 12:24:53 +02005565 tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list);
5566 while (&tcpcheck->list != &curproxy->tcpcheck_rules &&
5567 tcpcheck->action == TCPCHK_ACT_COMMENT) {
5568 tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list);
5569 }
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005570
Willy Tarreau5581c272015-05-13 12:24:53 +02005571 if (&tcpcheck->list != &curproxy->tcpcheck_rules
5572 && tcpcheck->action != TCPCHK_ACT_CONNECT) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005573 ha_alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n",
5574 file, linenum);
Willy Tarreau5581c272015-05-13 12:24:53 +02005575 err_code |= ERR_ALERT | ERR_FATAL;
5576 goto out;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005577 }
5578
5579 cur_arg = 2;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005580 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005581 tcpcheck->action = TCPCHK_ACT_CONNECT;
5582
5583 /* parsing each parameters to fill up the rule */
5584 while (*(ptr_arg = args[cur_arg])) {
5585 /* tcp port */
5586 if (strcmp(args[cur_arg], "port") == 0) {
5587 if ( (atol(args[cur_arg + 1]) > 65535) ||
5588 (atol(args[cur_arg + 1]) < 1) ){
Christopher Faulet767a84b2017-11-24 16:50:31 +01005589 ha_alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n",
5590 file, linenum, args[0], args[1], "port", args[cur_arg + 1]);
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005591 err_code |= ERR_ALERT | ERR_FATAL;
5592 goto out;
5593 }
5594 tcpcheck->port = atol(args[cur_arg + 1]);
5595 cur_arg += 2;
5596 }
5597 /* send proxy protocol */
5598 else if (strcmp(args[cur_arg], "send-proxy") == 0) {
5599 tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY;
5600 cur_arg++;
5601 }
5602#ifdef USE_OPENSSL
5603 else if (strcmp(args[cur_arg], "ssl") == 0) {
5604 curproxy->options |= PR_O_TCPCHK_SSL;
5605 tcpcheck->conn_opts |= TCPCHK_OPT_SSL;
5606 cur_arg++;
5607 }
5608#endif /* USE_OPENSSL */
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005609 /* comment for this tcpcheck line */
5610 else if (strcmp(args[cur_arg], "comment") == 0) {
5611 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005612 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5613 file, linenum, args[cur_arg]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005614 err_code |= ERR_ALERT | ERR_FATAL;
5615 goto out;
5616 }
5617 tcpcheck->comment = strdup(args[cur_arg + 1]);
5618 cur_arg += 2;
5619 }
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005620 else {
5621#ifdef USE_OPENSSL
Christopher Faulet767a84b2017-11-24 16:50:31 +01005622 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 +01005623#else /* USE_OPENSSL */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005624 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 +01005625#endif /* USE_OPENSSL */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005626 file, linenum, args[0], args[1], args[cur_arg]);
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005627 err_code |= ERR_ALERT | ERR_FATAL;
5628 goto out;
5629 }
5630
5631 }
5632
5633 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5634 }
5635 else if (strcmp(args[1], "send") == 0) {
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005636 if (! *(args[2]) ) {
5637 /* SEND string expected */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005638 ha_alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n",
5639 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005640 err_code |= ERR_ALERT | ERR_FATAL;
5641 goto out;
5642 } else {
5643 struct tcpcheck_rule *tcpcheck;
5644
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005645 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005646
5647 tcpcheck->action = TCPCHK_ACT_SEND;
5648 tcpcheck->string_len = strlen(args[2]);
5649 tcpcheck->string = strdup(args[2]);
5650 tcpcheck->expect_regex = NULL;
5651
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005652 /* comment for this tcpcheck line */
5653 if (strcmp(args[3], "comment") == 0) {
5654 if (!*args[4]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005655 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5656 file, linenum, args[3]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005657 err_code |= ERR_ALERT | ERR_FATAL;
5658 goto out;
5659 }
5660 tcpcheck->comment = strdup(args[4]);
5661 }
5662
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005663 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5664 }
5665 }
5666 else if (strcmp(args[1], "send-binary") == 0) {
5667 if (! *(args[2]) ) {
5668 /* SEND binary string expected */
Christopher Faulet767a84b2017-11-24 16:50:31 +01005669 ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n",
5670 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005671 err_code |= ERR_ALERT | ERR_FATAL;
5672 goto out;
5673 } else {
5674 struct tcpcheck_rule *tcpcheck;
5675 char *err = NULL;
5676
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005677 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005678
5679 tcpcheck->action = TCPCHK_ACT_SEND;
5680 if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005681 ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5682 file, linenum, args[0], args[1], args[2], err);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005683 err_code |= ERR_ALERT | ERR_FATAL;
5684 goto out;
5685 }
5686 tcpcheck->expect_regex = NULL;
5687
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005688 /* comment for this tcpcheck line */
5689 if (strcmp(args[3], "comment") == 0) {
5690 if (!*args[4]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005691 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5692 file, linenum, args[3]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005693 err_code |= ERR_ALERT | ERR_FATAL;
5694 goto out;
5695 }
5696 tcpcheck->comment = strdup(args[4]);
5697 }
5698
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005699 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5700 }
5701 }
5702 else if (strcmp(args[1], "expect") == 0) {
5703 const char *ptr_arg;
5704 int cur_arg;
5705 int inverse = 0;
5706
5707 if (curproxy->options2 & PR_O2_EXP_TYPE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005708 ha_alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005709 err_code |= ERR_ALERT | ERR_FATAL;
5710 goto out;
5711 }
5712
5713 cur_arg = 2;
5714 /* consider exclamation marks, sole or at the beginning of a word */
5715 while (*(ptr_arg = args[cur_arg])) {
5716 while (*ptr_arg == '!') {
5717 inverse = !inverse;
5718 ptr_arg++;
5719 }
5720 if (*ptr_arg)
5721 break;
5722 cur_arg++;
5723 }
5724 /* now ptr_arg points to the beginning of a word past any possible
5725 * exclamation mark, and cur_arg is the argument which holds this word.
5726 */
5727 if (strcmp(ptr_arg, "binary") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005728 struct tcpcheck_rule *tcpcheck;
5729 char *err = NULL;
5730
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005731 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005732 ha_alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n",
5733 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005734 err_code |= ERR_ALERT | ERR_FATAL;
5735 goto out;
5736 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005737
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005738 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005739
5740 tcpcheck->action = TCPCHK_ACT_EXPECT;
5741 if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005742 ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5743 file, linenum, args[0], args[1], args[2], err);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005744 err_code |= ERR_ALERT | ERR_FATAL;
5745 goto out;
5746 }
5747 tcpcheck->expect_regex = NULL;
5748 tcpcheck->inverse = inverse;
5749
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005750 /* tcpcheck comment */
5751 cur_arg += 2;
5752 if (strcmp(args[cur_arg], "comment") == 0) {
5753 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005754 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5755 file, linenum, args[cur_arg + 1]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005756 err_code |= ERR_ALERT | ERR_FATAL;
5757 goto out;
5758 }
5759 tcpcheck->comment = strdup(args[cur_arg + 1]);
5760 }
5761
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005762 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5763 }
5764 else if (strcmp(ptr_arg, "string") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005765 struct tcpcheck_rule *tcpcheck;
5766
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005767 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005768 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5769 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005770 err_code |= ERR_ALERT | ERR_FATAL;
5771 goto out;
5772 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005773
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005774 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005775
5776 tcpcheck->action = TCPCHK_ACT_EXPECT;
5777 tcpcheck->string_len = strlen(args[cur_arg + 1]);
5778 tcpcheck->string = strdup(args[cur_arg + 1]);
5779 tcpcheck->expect_regex = NULL;
5780 tcpcheck->inverse = inverse;
5781
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005782 /* tcpcheck comment */
5783 cur_arg += 2;
5784 if (strcmp(args[cur_arg], "comment") == 0) {
5785 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005786 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5787 file, linenum, args[cur_arg + 1]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005788 err_code |= ERR_ALERT | ERR_FATAL;
5789 goto out;
5790 }
5791 tcpcheck->comment = strdup(args[cur_arg + 1]);
5792 }
5793
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005794 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5795 }
5796 else if (strcmp(ptr_arg, "rstring") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005797 struct tcpcheck_rule *tcpcheck;
5798
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005799 if (!*(args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005800 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5801 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005802 err_code |= ERR_ALERT | ERR_FATAL;
5803 goto out;
5804 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005805
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005806 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005807
5808 tcpcheck->action = TCPCHK_ACT_EXPECT;
5809 tcpcheck->string_len = 0;
5810 tcpcheck->string = NULL;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005811 tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex));
5812 error = NULL;
5813 if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005814 ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5815 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005816 free(error);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005817 err_code |= ERR_ALERT | ERR_FATAL;
5818 goto out;
5819 }
5820 tcpcheck->inverse = inverse;
5821
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005822 /* tcpcheck comment */
5823 cur_arg += 2;
5824 if (strcmp(args[cur_arg], "comment") == 0) {
5825 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005826 ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5827 file, linenum, args[cur_arg + 1]);
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005828 err_code |= ERR_ALERT | ERR_FATAL;
5829 goto out;
5830 }
5831 tcpcheck->comment = strdup(args[cur_arg + 1]);
5832 }
5833
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005834 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5835 }
5836 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005837 ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n",
5838 file, linenum, args[0], args[1], ptr_arg);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005839 err_code |= ERR_ALERT | ERR_FATAL;
5840 goto out;
5841 }
5842 }
5843 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005844 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 +02005845 err_code |= ERR_ALERT | ERR_FATAL;
5846 goto out;
5847 }
5848 }
Willy Tarreaub80c2302007-11-30 20:51:32 +01005849 else if (!strcmp(args[0], "monitor")) {
Willy Tarreaub099aca2008-10-12 17:26:37 +02005850 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005851 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005852 err_code |= ERR_ALERT | ERR_FATAL;
5853 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02005854 }
5855
Willy Tarreaub80c2302007-11-30 20:51:32 +01005856 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005857 err_code |= ERR_WARN;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005858
5859 if (strcmp(args[1], "fail") == 0) {
5860 /* add a condition to fail monitor requests */
Willy Tarreauef6494c2010-01-28 17:12:36 +01005861 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005862 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
5863 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005864 err_code |= ERR_ALERT | ERR_FATAL;
5865 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005866 }
5867
Willy Tarreau721d8e02017-12-01 18:25:08 +01005868 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
Christopher Faulet1b421ea2017-09-22 14:38:56 +02005869 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005870 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
5871 file, linenum, args[0], args[1], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02005872 err_code |= ERR_ALERT | ERR_FATAL;
5873 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005874 }
5875 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
5876 }
5877 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005878 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005879 err_code |= ERR_ALERT | ERR_FATAL;
5880 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005881 }
5882 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005883#ifdef TPROXY
5884 else if (!strcmp(args[0], "transparent")) {
5885 /* enable transparent proxy connections */
5886 curproxy->options |= PR_O_TRANSP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005887 if (alertif_too_many_args(0, file, linenum, args, &err_code))
5888 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005889 }
5890#endif
5891 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005892 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005893 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005894
Willy Tarreaubaaee002006-06-26 02:48:02 +02005895 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005896 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005897 err_code |= ERR_ALERT | ERR_FATAL;
5898 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005899 }
5900 curproxy->maxconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005901 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5902 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005903 }
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005904 else if (!strcmp(args[0], "backlog")) { /* backlog */
5905 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005906 err_code |= ERR_WARN;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005907
5908 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005909 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005910 err_code |= ERR_ALERT | ERR_FATAL;
5911 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005912 }
5913 curproxy->backlog = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005914 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5915 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005916 }
Willy Tarreau86034312006-12-29 00:10:33 +01005917 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005918 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005919 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005920
Willy Tarreau86034312006-12-29 00:10:33 +01005921 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005922 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005923 err_code |= ERR_ALERT | ERR_FATAL;
5924 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005925 }
5926 curproxy->fullconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005927 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5928 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005929 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005930 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
5931 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005932 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005933 err_code |= ERR_ALERT | ERR_FATAL;
5934 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005935 }
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005936 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
5937 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005938 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
5939 file, linenum, *err);
Willy Tarreau93893792009-07-23 13:19:11 +02005940 err_code |= ERR_ALERT | ERR_FATAL;
5941 goto out;
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005942 }
5943 curproxy->grace = val;
William Lallemanddf1425a2015-04-28 20:17:49 +02005944 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5945 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005946 }
5947 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
David du Colombier6f5ccb12011-03-10 22:26:24 +01005948 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005949 int port1, port2;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005950 struct protocol *proto;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005951
Willy Tarreaubaaee002006-06-26 02:48:02 +02005952 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005953 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005954 err_code |= ERR_ALERT | ERR_FATAL;
5955 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005956 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01005957 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005958 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005959
Willy Tarreau48ef4c92017-01-06 18:32:38 +01005960 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005961 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005962 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005963 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005964 goto out;
5965 }
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005966
5967 proto = protocol_by_family(sk->ss_family);
5968 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005969 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
5970 file, linenum, args[0], args[1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005971 err_code |= ERR_ALERT | ERR_FATAL;
5972 goto out;
5973 }
5974
5975 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005976 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
5977 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005978 err_code |= ERR_ALERT | ERR_FATAL;
5979 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005980 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005981
5982 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01005983 ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
5984 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01005985 err_code |= ERR_ALERT | ERR_FATAL;
5986 goto out;
5987 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005988
William Lallemanddf1425a2015-04-28 20:17:49 +02005989 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5990 goto out;
5991
Willy Tarreaud5191e72010-02-09 20:50:45 +01005992 curproxy->dispatch_addr = *sk;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005993 curproxy->options |= PR_O_DISPATCH;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005994 }
5995 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005996 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005997 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005998
Willy Tarreaua93c74b2012-05-08 18:14:39 +02005999 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006000 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006001 err_code |= ERR_ALERT | ERR_FATAL;
6002 goto out;
Willy Tarreau2fcb5002007-05-08 13:35:26 +02006003 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006004 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006005 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006006 /**
6007 * The syntax for hash-type config element is
6008 * hash-type {map-based|consistent} [[<algo>] avalanche]
6009 *
6010 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
6011 */
6012 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
Bhaskar98634f02013-10-29 23:30:51 -04006013
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006014 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
6015 err_code |= ERR_WARN;
6016
6017 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006018 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
6019 }
6020 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006021 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
6022 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006023 else if (strcmp(args[1], "avalanche") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006024 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 -05006025 err_code |= ERR_ALERT | ERR_FATAL;
6026 goto out;
Willy Tarreau798a39c2010-11-24 15:04:29 +01006027 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006028 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006029 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02006030 err_code |= ERR_ALERT | ERR_FATAL;
6031 goto out;
6032 }
Bhaskar98634f02013-10-29 23:30:51 -04006033
6034 /* set the hash function to use */
6035 if (!*args[2]) {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006036 /* the default algo is sdbm */
Bhaskar98634f02013-10-29 23:30:51 -04006037 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006038
6039 /* if consistent with no argument, then avalanche modifier is also applied */
6040 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
6041 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
Bhaskar98634f02013-10-29 23:30:51 -04006042 } else {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006043 /* set the hash function */
6044 if (!strcmp(args[2], "sdbm")) {
6045 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
6046 }
6047 else if (!strcmp(args[2], "djb2")) {
6048 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
Willy Tarreau324f07f2015-01-20 19:44:50 +01006049 }
6050 else if (!strcmp(args[2], "wt6")) {
Willy Tarreaua0f42712013-11-14 14:30:35 +01006051 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006052 }
Willy Tarreau324f07f2015-01-20 19:44:50 +01006053 else if (!strcmp(args[2], "crc32")) {
6054 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
6055 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05006056 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006057 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 -05006058 err_code |= ERR_ALERT | ERR_FATAL;
6059 goto out;
6060 }
6061
6062 /* set the hash modifier */
6063 if (!strcmp(args[3], "avalanche")) {
6064 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
6065 }
6066 else if (*args[3]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006067 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 -05006068 err_code |= ERR_ALERT | ERR_FATAL;
6069 goto out;
6070 }
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01006071 }
William Lallemanda73203e2012-03-12 12:48:57 +01006072 }
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04006073 else if (strcmp(args[0], "hash-balance-factor") == 0) {
6074 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006075 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04006076 err_code |= ERR_ALERT | ERR_FATAL;
6077 goto out;
6078 }
6079 curproxy->lbprm.chash.balance_factor = atol(args[1]);
6080 if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006081 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 -04006082 err_code |= ERR_ALERT | ERR_FATAL;
6083 goto out;
6084 }
6085 }
William Lallemanda73203e2012-03-12 12:48:57 +01006086 else if (strcmp(args[0], "unique-id-format") == 0) {
6087 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006088 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
William Lallemanda73203e2012-03-12 12:48:57 +01006089 err_code |= ERR_ALERT | ERR_FATAL;
6090 goto out;
6091 }
William Lallemand3203ff42012-11-11 17:30:56 +01006092 if (*(args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006093 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 +01006094 err_code |= ERR_ALERT | ERR_FATAL;
6095 goto out;
6096 }
Willy Tarreau62a61232013-04-12 18:13:46 +02006097 free(curproxy->conf.uniqueid_format_string);
6098 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02006099
Willy Tarreau62a61232013-04-12 18:13:46 +02006100 free(curproxy->conf.uif_file);
6101 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
6102 curproxy->conf.uif_line = curproxy->conf.args.line;
William Lallemand723b73a2012-02-08 16:37:49 +01006103 }
William Lallemanda73203e2012-03-12 12:48:57 +01006104
6105 else if (strcmp(args[0], "unique-id-header") == 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 Lallemanda73203e2012-03-12 12:48:57 +01006108 err_code |= ERR_ALERT | ERR_FATAL;
6109 goto out;
6110 }
6111 free(curproxy->header_unique_id);
6112 curproxy->header_unique_id = strdup(args[1]);
6113 }
6114
William Lallemand723b73a2012-02-08 16:37:49 +01006115 else if (strcmp(args[0], "log-format") == 0) {
6116 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006117 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
William Lallemand723b73a2012-02-08 16:37:49 +01006118 err_code |= ERR_ALERT | ERR_FATAL;
6119 goto out;
6120 }
William Lallemand3203ff42012-11-11 17:30:56 +01006121 if (*(args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006122 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 +01006123 err_code |= ERR_ALERT | ERR_FATAL;
6124 goto out;
6125 }
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02006126 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
6127 char *oldlogformat = "log-format";
Willy Tarreau196729e2012-05-31 19:30:26 +02006128
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02006129 if (curproxy->conf.logformat_string == default_http_log_format)
6130 oldlogformat = "option httplog";
6131 else if (curproxy->conf.logformat_string == default_tcp_log_format)
6132 oldlogformat = "option tcplog";
6133 else if (curproxy->conf.logformat_string == clf_http_log_format)
6134 oldlogformat = "option httplog clf";
Christopher Faulet767a84b2017-11-24 16:50:31 +01006135 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
6136 file, linenum, oldlogformat);
Guillaume de Lafondea5b0e62017-03-31 19:54:09 +02006137 }
Willy Tarreau62a61232013-04-12 18:13:46 +02006138 if (curproxy->conf.logformat_string != default_http_log_format &&
6139 curproxy->conf.logformat_string != default_tcp_log_format &&
6140 curproxy->conf.logformat_string != clf_http_log_format)
6141 free(curproxy->conf.logformat_string);
6142 curproxy->conf.logformat_string = strdup(args[1]);
6143
6144 free(curproxy->conf.lfs_file);
6145 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
6146 curproxy->conf.lfs_line = curproxy->conf.args.line;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02006147
6148 /* get a chance to improve log-format error reporting by
6149 * reporting the correct line-number when possible.
6150 */
6151 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006152 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
6153 file, linenum, curproxy->id);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02006154 err_code |= ERR_WARN;
6155 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006156 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02006157 else if (!strcmp(args[0], "log-format-sd")) {
6158 if (!*(args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006159 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
Dragan Dosen0b85ece2015-09-25 19:17:44 +02006160 err_code |= ERR_ALERT | ERR_FATAL;
6161 goto out;
6162 }
6163 if (*(args[2])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006164 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 +02006165 err_code |= ERR_ALERT | ERR_FATAL;
6166 goto out;
6167 }
6168
6169 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
6170 free(curproxy->conf.logformat_sd_string);
6171 curproxy->conf.logformat_sd_string = strdup(args[1]);
6172
6173 free(curproxy->conf.lfsd_file);
6174 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
6175 curproxy->conf.lfsd_line = curproxy->conf.args.line;
6176
6177 /* get a chance to improve log-format-sd error reporting by
6178 * reporting the correct line-number when possible.
6179 */
6180 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006181 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
6182 file, linenum, curproxy->id);
Dragan Dosen0b85ece2015-09-25 19:17:44 +02006183 err_code |= ERR_WARN;
6184 }
6185 }
Willy Tarreau094af4e2015-01-07 15:03:42 +01006186 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
6187 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006188 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 +01006189 err_code |= ERR_ALERT | ERR_FATAL;
6190 goto out;
6191 }
Dragan Dosen43885c72015-10-01 13:18:13 +02006192 chunk_destroy(&curproxy->log_tag);
6193 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
Willy Tarreau094af4e2015-01-07 15:03:42 +01006194 }
Christopher Faulet4b0b79d2018-03-26 15:54:32 +02006195 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
6196 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
6197 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006198 err_code |= ERR_ALERT | ERR_FATAL;
6199 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006200 }
6201 }
6202 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006203 int cur_arg;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006204 int port1, port2;
David du Colombier6f5ccb12011-03-10 22:26:24 +01006205 struct sockaddr_storage *sk;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006206 struct protocol *proto;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006207
Willy Tarreau977b8e42006-12-29 14:19:17 +01006208 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006209 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006210
Willy Tarreaubaaee002006-06-26 02:48:02 +02006211 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006212 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
6213 file, linenum, "source", "usesrc", "interface");
Willy Tarreau93893792009-07-23 13:19:11 +02006214 err_code |= ERR_ALERT | ERR_FATAL;
6215 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006216 }
Willy Tarreau368480c2009-03-01 08:27:21 +01006217
6218 /* we must first clear any optional default setting */
Willy Tarreauef9a3602012-12-08 22:29:20 +01006219 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6220 free(curproxy->conn_src.iface_name);
6221 curproxy->conn_src.iface_name = NULL;
6222 curproxy->conn_src.iface_len = 0;
Willy Tarreau368480c2009-03-01 08:27:21 +01006223
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006224 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006225 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006226 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
6227 file, linenum, args[0], args[1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006228 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006229 goto out;
6230 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006231
6232 proto = protocol_by_family(sk->ss_family);
6233 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006234 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
6235 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006236 err_code |= ERR_ALERT | ERR_FATAL;
6237 goto out;
6238 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006239
6240 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006241 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6242 file, linenum, args[0], args[1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006243 err_code |= ERR_ALERT | ERR_FATAL;
6244 goto out;
6245 }
6246
Willy Tarreauef9a3602012-12-08 22:29:20 +01006247 curproxy->conn_src.source_addr = *sk;
6248 curproxy->conn_src.opts |= CO_SRC_BIND;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006249
6250 cur_arg = 2;
6251 while (*(args[cur_arg])) {
6252 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
Willy Tarreau29fbe512015-08-20 19:35:14 +02006253#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006254 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006255 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
6256 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006257 err_code |= ERR_ALERT | ERR_FATAL;
6258 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006259 }
6260
6261 if (!strcmp(args[cur_arg + 1], "client")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006262 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6263 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006264 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006265 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6266 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
Willy Tarreaubce70882009-09-07 11:51:47 +02006267 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
6268 char *name, *end;
6269
6270 name = args[cur_arg+1] + 7;
6271 while (isspace(*name))
6272 name++;
6273
6274 end = name;
6275 while (*end && !isspace(*end) && *end != ',' && *end != ')')
6276 end++;
6277
Willy Tarreauef9a3602012-12-08 22:29:20 +01006278 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6279 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
6280 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
6281 curproxy->conn_src.bind_hdr_len = end - name;
6282 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
6283 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
6284 curproxy->conn_src.bind_hdr_occ = -1;
Willy Tarreaubce70882009-09-07 11:51:47 +02006285
6286 /* now look for an occurrence number */
6287 while (isspace(*end))
6288 end++;
6289 if (*end == ',') {
6290 end++;
6291 name = end;
6292 if (*end == '-')
6293 end++;
Willy Tarreau83d84cf2012-11-22 01:04:31 +01006294 while (isdigit((int)*end))
Willy Tarreaubce70882009-09-07 11:51:47 +02006295 end++;
Willy Tarreauef9a3602012-12-08 22:29:20 +01006296 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
Willy Tarreaubce70882009-09-07 11:51:47 +02006297 }
6298
Willy Tarreauef9a3602012-12-08 22:29:20 +01006299 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006300 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
6301 " occurrences values smaller than %d.\n",
6302 file, linenum, MAX_HDR_HISTORY);
Willy Tarreaubce70882009-09-07 11:51:47 +02006303 err_code |= ERR_ALERT | ERR_FATAL;
6304 goto out;
6305 }
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006306 } else {
Willy Tarreau902636f2013-03-10 19:44:48 +01006307 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006308
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006309 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006310 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006311 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
6312 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006313 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006314 goto out;
6315 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006316
6317 proto = protocol_by_family(sk->ss_family);
6318 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006319 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
6320 file, linenum, args[cur_arg], args[cur_arg+1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006321 err_code |= ERR_ALERT | ERR_FATAL;
6322 goto out;
6323 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006324
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006325 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006326 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6327 file, linenum, args[cur_arg], args[cur_arg + 1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006328 err_code |= ERR_ALERT | ERR_FATAL;
6329 goto out;
6330 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006331 curproxy->conn_src.tproxy_addr = *sk;
6332 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006333 }
6334 global.last_checks |= LSTCHK_NETADM;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006335#else /* no TPROXY support */
Christopher Faulet767a84b2017-11-24 16:50:31 +01006336 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
6337 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006338 err_code |= ERR_ALERT | ERR_FATAL;
6339 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006340#endif
6341 cur_arg += 2;
6342 continue;
Willy Tarreau77074d52006-11-12 23:57:19 +01006343 }
6344
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006345 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
6346#ifdef SO_BINDTODEVICE
6347 if (!*args[cur_arg + 1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006348 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
6349 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006350 err_code |= ERR_ALERT | ERR_FATAL;
6351 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006352 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006353 free(curproxy->conn_src.iface_name);
6354 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
6355 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006356 global.last_checks |= LSTCHK_NETADM;
6357#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01006358 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
6359 file, linenum, args[0], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02006360 err_code |= ERR_ALERT | ERR_FATAL;
6361 goto out;
Willy Tarreau5b6995c2008-01-13 16:31:17 +01006362#endif
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006363 cur_arg += 2;
6364 continue;
6365 }
Christopher Faulet767a84b2017-11-24 16:50:31 +01006366 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
6367 file, linenum, args[0], "interface", "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006368 err_code |= ERR_ALERT | ERR_FATAL;
6369 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006370 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006371 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006372 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
Christopher Faulet767a84b2017-11-24 16:50:31 +01006373 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
6374 file, linenum, "usesrc", "source");
Willy Tarreau93893792009-07-23 13:19:11 +02006375 err_code |= ERR_ALERT | ERR_FATAL;
6376 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006377 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006378 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006379 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006380 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6381 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006382 err_code |= ERR_ALERT | ERR_FATAL;
6383 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006384 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006385
6386 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006387 SMP_OPT_DIR_REQ, ACT_REPLACE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006388 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006389 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006390 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006391 }
6392 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006393 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006394 SMP_OPT_DIR_REQ, ACT_REMOVE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006395 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006396 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006397 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006398 }
6399 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006400 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006401 SMP_OPT_DIR_REQ, ACT_DENY, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006402 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006403 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006404 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006405 }
6406 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006407 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006408 SMP_OPT_DIR_REQ, ACT_PASS, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006409 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006410 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006411 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006412 }
6413 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006414 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006415 SMP_OPT_DIR_REQ, ACT_ALLOW, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006416 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006417 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006418 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006419 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006420 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006421 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006422 SMP_OPT_DIR_REQ, ACT_TARPIT, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006423 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006424 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006425 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006426 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006427 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006428 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006429 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6430 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006431 err_code |= ERR_ALERT | ERR_FATAL;
6432 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006433 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006434
6435 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006436 SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006437 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006438 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006439 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006440 }
6441 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006442 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006443 SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006444 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006445 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006446 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006447 }
6448 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006449 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006450 SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006451 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006452 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006453 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006454 }
6455 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006456 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006457 SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006458 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006459 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006460 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006461 }
6462 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006463 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006464 SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006465 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006466 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006467 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006468 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006469 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006470 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006471 SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006472 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006473 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006474 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006475 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006476 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006477 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006478
Willy Tarreaubaaee002006-06-26 02:48:02 +02006479 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006480 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006481 err_code |= ERR_ALERT | ERR_FATAL;
6482 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006483 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006484 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006485 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006486
Willy Tarreaubaaee002006-06-26 02:48:02 +02006487 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006488 ha_alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006489 err_code |= ERR_ALERT | ERR_FATAL;
6490 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006491 }
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006492
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006493 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Christopher Faulet1b421ea2017-09-22 14:38:56 +02006494 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006495 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6496 file, linenum, args[0], errmsg);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006497 err_code |= ERR_ALERT | ERR_FATAL;
6498 goto out;
6499 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006500 err_code |= warnif_cond_conflicts(cond,
6501 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
6502 file, linenum);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006503 }
6504 else if (*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006505 ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6506 file, linenum, args[0], args[2]);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006507 err_code |= ERR_ALERT | ERR_FATAL;
6508 goto out;
6509 }
6510
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006511 wl = calloc(1, sizeof(*wl));
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006512 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006513 wl->s = strdup(args[1]);
6514 LIST_ADDQ(&curproxy->req_add, &wl->list);
Willy Tarreau61d18892009-03-31 10:49:21 +02006515 warnif_misplaced_reqadd(curproxy, file, linenum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006516 }
6517 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006518 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006519 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6520 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006521 err_code |= ERR_ALERT | ERR_FATAL;
6522 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006523 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01006524
Willy Tarreauade5ec42010-01-28 19:33:49 +01006525 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006526 SMP_OPT_DIR_RES, ACT_REPLACE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006527 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006528 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006529 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006530 }
6531 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006532 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006533 SMP_OPT_DIR_RES, ACT_REMOVE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006534 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006535 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006536 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006537 }
6538 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006539 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006540 SMP_OPT_DIR_RES, ACT_DENY, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006541 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006542 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006543 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006544 }
6545 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006546 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006547 ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6548 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006549 err_code |= ERR_ALERT | ERR_FATAL;
6550 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006551 }
6552
Willy Tarreauade5ec42010-01-28 19:33:49 +01006553 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006554 SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006555 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006556 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006557 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006558 }
6559 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006560 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006561 SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006562 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006563 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006564 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006565 }
6566 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006567 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006568 SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006569 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006570 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006571 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006572 }
6573 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006574 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006575
Willy Tarreaubaaee002006-06-26 02:48:02 +02006576 if (curproxy == &defproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006577 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006578 err_code |= ERR_ALERT | ERR_FATAL;
6579 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006580 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006581 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006582 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006583
Willy Tarreaubaaee002006-06-26 02:48:02 +02006584 if (*(args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006585 ha_alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006586 err_code |= ERR_ALERT | ERR_FATAL;
6587 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006588 }
6589
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006590 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Christopher Faulet1b421ea2017-09-22 14:38:56 +02006591 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006592 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6593 file, linenum, args[0], errmsg);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006594 err_code |= ERR_ALERT | ERR_FATAL;
6595 goto out;
6596 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006597 err_code |= warnif_cond_conflicts(cond,
6598 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
6599 file, linenum);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006600 }
6601 else if (*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006602 ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6603 file, linenum, args[0], args[2]);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006604 err_code |= ERR_ALERT | ERR_FATAL;
6605 goto out;
6606 }
6607
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006608 wl = calloc(1, sizeof(*wl));
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006609 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006610 wl->s = strdup(args[1]);
6611 LIST_ADDQ(&curproxy->rsp_add, &wl->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006612 }
6613 else if (!strcmp(args[0], "errorloc") ||
6614 !strcmp(args[0], "errorloc302") ||
6615 !strcmp(args[0], "errorloc303")) { /* error location */
6616 int errnum, errlen;
6617 char *err;
6618
Willy Tarreau977b8e42006-12-29 14:19:17 +01006619 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006620 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006621
Willy Tarreaubaaee002006-06-26 02:48:02 +02006622 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006623 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 +02006624 err_code |= ERR_ALERT | ERR_FATAL;
6625 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006626 }
6627
6628 errnum = atol(args[1]);
6629 if (!strcmp(args[0], "errorloc303")) {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006630 errlen = strlen(HTTP_303) + strlen(args[2]) + 5;
6631 err = malloc(errlen);
6632 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_303, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006633 } else {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006634 errlen = strlen(HTTP_302) + strlen(args[2]) + 5;
6635 err = malloc(errlen);
6636 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_302, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006637 }
6638
Willy Tarreau0f772532006-12-23 20:51:41 +01006639 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6640 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006641 chunk_destroy(&curproxy->errmsg[rc]);
6642 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau0f772532006-12-23 20:51:41 +01006643 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006644 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006645 }
Willy Tarreau0f772532006-12-23 20:51:41 +01006646
6647 if (rc >= HTTP_ERR_SIZE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006648 ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n",
6649 file, linenum, errnum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006650 free(err);
6651 }
6652 }
Willy Tarreau3f49b302007-06-11 00:29:26 +02006653 else if (!strcmp(args[0], "errorfile")) { /* error message from a file */
6654 int errnum, errlen, fd;
6655 char *err;
6656 struct stat stat;
6657
6658 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006659 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006660
6661 if (*(args[2]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006662 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 +02006663 err_code |= ERR_ALERT | ERR_FATAL;
6664 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006665 }
6666
6667 fd = open(args[2], O_RDONLY);
6668 if ((fd < 0) || (fstat(fd, &stat) < 0)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006669 ha_alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n",
6670 file, linenum, args[2], args[1]);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006671 if (fd >= 0)
6672 close(fd);
Willy Tarreau93893792009-07-23 13:19:11 +02006673 err_code |= ERR_ALERT | ERR_FATAL;
6674 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006675 }
6676
Willy Tarreau27a674e2009-08-17 07:23:33 +02006677 if (stat.st_size <= global.tune.bufsize) {
Willy Tarreau3f49b302007-06-11 00:29:26 +02006678 errlen = stat.st_size;
6679 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006680 ha_warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n",
6681 file, linenum, args[2], global.tune.bufsize);
Willy Tarreau93893792009-07-23 13:19:11 +02006682 err_code |= ERR_WARN;
Willy Tarreau27a674e2009-08-17 07:23:33 +02006683 errlen = global.tune.bufsize;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006684 }
6685
6686 err = malloc(errlen); /* malloc() must succeed during parsing */
6687 errnum = read(fd, err, errlen);
6688 if (errnum != errlen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006689 ha_alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n",
6690 file, linenum, args[2], args[1]);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006691 close(fd);
6692 free(err);
Willy Tarreau93893792009-07-23 13:19:11 +02006693 err_code |= ERR_ALERT | ERR_FATAL;
6694 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006695 }
6696 close(fd);
6697
6698 errnum = atol(args[1]);
6699 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6700 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006701 chunk_destroy(&curproxy->errmsg[rc]);
6702 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006703 break;
6704 }
6705 }
6706
6707 if (rc >= HTTP_ERR_SIZE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006708 ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n",
6709 file, linenum, errnum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006710 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006711 free(err);
6712 }
6713 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006714 else {
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006715 struct cfg_kw_list *kwl;
6716 int index;
6717
6718 list_for_each_entry(kwl, &cfg_keywords.list, list) {
6719 for (index = 0; kwl->kw[index].kw != NULL; index++) {
6720 if (kwl->kw[index].section != CFG_LISTEN)
6721 continue;
6722 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
6723 /* prepare error message just in case */
Willy Tarreau28a47d62012-09-18 20:02:48 +02006724 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
Willy Tarreau39f23b62008-07-09 20:22:56 +02006725 if (rc < 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006726 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006727 err_code |= ERR_ALERT | ERR_FATAL;
6728 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006729 }
Willy Tarreau39f23b62008-07-09 20:22:56 +02006730 else if (rc > 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006731 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006732 err_code |= ERR_WARN;
6733 goto out;
Willy Tarreau39f23b62008-07-09 20:22:56 +02006734 }
Willy Tarreau93893792009-07-23 13:19:11 +02006735 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006736 }
6737 }
6738 }
William Lallemand82fe75c2012-10-23 10:25:10 +02006739
Christopher Faulet767a84b2017-11-24 16:50:31 +01006740 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau93893792009-07-23 13:19:11 +02006741 err_code |= ERR_ALERT | ERR_FATAL;
6742 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006743 }
Willy Tarreau93893792009-07-23 13:19:11 +02006744 out:
Willy Tarreauf4068b62012-05-08 17:37:49 +02006745 free(errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006746 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006747}
6748
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006749int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006750cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
6751{
6752#ifdef CONFIG_HAP_NS
6753 const char *err;
6754 const char *item = args[0];
6755
6756 if (!strcmp(item, "namespace_list")) {
6757 return 0;
6758 }
6759 else if (!strcmp(item, "namespace")) {
6760 size_t idx = 1;
6761 const char *current;
6762 while (*(current = args[idx++])) {
6763 err = invalid_char(current);
6764 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006765 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6766 file, linenum, *err, item, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006767 return ERR_ALERT | ERR_FATAL;
6768 }
6769
6770 if (netns_store_lookup(current, strlen(current))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006771 ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
6772 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006773 return ERR_ALERT | ERR_FATAL;
6774 }
6775 if (!netns_store_insert(current)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006776 ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
6777 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006778 return ERR_ALERT | ERR_FATAL;
6779 }
6780 }
6781 }
6782
6783 return 0;
6784#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01006785 ha_alert("parsing [%s:%d]: namespace support is not compiled in.",
6786 file, linenum);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006787 return ERR_ALERT | ERR_FATAL;
6788#endif
6789}
6790
6791int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006792cfg_parse_users(const char *file, int linenum, char **args, int kwm)
6793{
6794
6795 int err_code = 0;
6796 const char *err;
6797
6798 if (!strcmp(args[0], "userlist")) { /* new userlist */
6799 struct userlist *newul;
6800
6801 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006802 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6803 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006804 err_code |= ERR_ALERT | ERR_FATAL;
6805 goto out;
6806 }
William Lallemand6e62fb62015-04-28 16:55:23 +02006807 if (alertif_too_many_args(1, file, linenum, args, &err_code))
6808 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006809
6810 err = invalid_char(args[1]);
6811 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006812 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6813 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006814 err_code |= ERR_ALERT | ERR_FATAL;
6815 goto out;
6816 }
6817
6818 for (newul = userlist; newul; newul = newul->next)
6819 if (!strcmp(newul->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006820 ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
6821 file, linenum, args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006822 err_code |= ERR_WARN;
6823 goto out;
6824 }
6825
Vincent Bernat02779b62016-04-03 13:48:43 +02006826 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006827 if (!newul) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006828 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006829 err_code |= ERR_ALERT | ERR_ABORT;
6830 goto out;
6831 }
6832
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006833 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006834 if (!newul->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006835 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006836 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01006837 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006838 goto out;
6839 }
6840
6841 newul->next = userlist;
6842 userlist = newul;
6843
6844 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006845 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006846 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006847 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006848
6849 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006850 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6851 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006852 err_code |= ERR_ALERT | ERR_FATAL;
6853 goto out;
6854 }
6855
6856 err = invalid_char(args[1]);
6857 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006858 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6859 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006860 err_code |= ERR_ALERT | ERR_FATAL;
6861 goto out;
6862 }
6863
William Lallemand4ac9f542015-05-28 18:03:51 +02006864 if (!userlist)
6865 goto out;
6866
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006867 for (ag = userlist->groups; ag; ag = ag->next)
6868 if (!strcmp(ag->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006869 ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
6870 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006871 err_code |= ERR_ALERT;
6872 goto out;
6873 }
6874
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006875 ag = calloc(1, sizeof(*ag));
6876 if (!ag) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006877 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006878 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006879 goto out;
6880 }
6881
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006882 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01006883 if (!ag->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006884 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006885 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01006886 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006887 goto out;
6888 }
6889
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006890 cur_arg = 2;
6891
6892 while (*args[cur_arg]) {
6893 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006894 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006895 cur_arg += 2;
6896 continue;
6897 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006898 ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
6899 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006900 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01006901 free(ag->groupusers);
6902 free(ag->name);
6903 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006904 goto out;
6905 }
6906 }
6907
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006908 ag->next = userlist->groups;
6909 userlist->groups = ag;
6910
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006911 } else if (!strcmp(args[0], "user")) { /* new user */
6912 struct auth_users *newuser;
6913 int cur_arg;
6914
6915 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006916 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6917 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006918 err_code |= ERR_ALERT | ERR_FATAL;
6919 goto out;
6920 }
William Lallemand4ac9f542015-05-28 18:03:51 +02006921 if (!userlist)
6922 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006923
6924 for (newuser = userlist->users; newuser; newuser = newuser->next)
6925 if (!strcmp(newuser->user, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006926 ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
6927 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006928 err_code |= ERR_ALERT;
6929 goto out;
6930 }
6931
Vincent Bernat02779b62016-04-03 13:48:43 +02006932 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006933 if (!newuser) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006934 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006935 err_code |= ERR_ALERT | ERR_ABORT;
6936 goto out;
6937 }
6938
6939 newuser->user = strdup(args[1]);
6940
6941 newuser->next = userlist->users;
6942 userlist->users = newuser;
6943
6944 cur_arg = 2;
6945
6946 while (*args[cur_arg]) {
6947 if (!strcmp(args[cur_arg], "password")) {
Cyril Bonté1a0191d2014-08-29 20:20:02 +02006948#ifdef CONFIG_HAP_CRYPT
6949 if (!crypt("", args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006950 ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
6951 file, linenum, newuser->user);
Cyril Bonté1a0191d2014-08-29 20:20:02 +02006952 err_code |= ERR_ALERT | ERR_FATAL;
6953 goto out;
6954 }
6955#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01006956 ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
6957 file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006958 err_code |= ERR_ALERT;
6959#endif
6960 newuser->pass = strdup(args[cur_arg + 1]);
6961 cur_arg += 2;
6962 continue;
6963 } else if (!strcmp(args[cur_arg], "insecure-password")) {
6964 newuser->pass = strdup(args[cur_arg + 1]);
6965 newuser->flags |= AU_O_INSECURE;
6966 cur_arg += 2;
6967 continue;
6968 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006969 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006970 cur_arg += 2;
6971 continue;
6972 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006973 ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
6974 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006975 err_code |= ERR_ALERT | ERR_FATAL;
6976 goto out;
6977 }
6978 }
6979 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01006980 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 +01006981 err_code |= ERR_ALERT | ERR_FATAL;
6982 }
6983
6984out:
6985 return err_code;
6986}
Willy Tarreaubaaee002006-06-26 02:48:02 +02006987
Christopher Faulet79bdef32016-11-04 22:36:15 +01006988int
6989cfg_parse_scope(const char *file, int linenum, char *line)
6990{
6991 char *beg, *end, *scope = NULL;
6992 int err_code = 0;
6993 const char *err;
6994
6995 beg = line + 1;
6996 end = strchr(beg, ']');
6997
6998 /* Detect end of scope declaration */
6999 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007000 ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n",
7001 file, linenum);
Christopher Faulet79bdef32016-11-04 22:36:15 +01007002 err_code |= ERR_ALERT | ERR_FATAL;
7003 goto out;
7004 }
7005
7006 /* Get scope name and check its validity */
7007 scope = my_strndup(beg, end-beg);
7008 err = invalid_char(scope);
7009 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007010 ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
7011 file, linenum, *err);
Christopher Faulet79bdef32016-11-04 22:36:15 +01007012 err_code |= ERR_ALERT | ERR_ABORT;
7013 goto out;
7014 }
7015
7016 /* Be sure to have a scope declaration alone on its line */
7017 line = end+1;
7018 while (isspace((unsigned char)*line))
7019 line++;
7020 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007021 ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
7022 file, linenum, *line);
Christopher Faulet79bdef32016-11-04 22:36:15 +01007023 err_code |= ERR_ALERT | ERR_ABORT;
7024 goto out;
7025 }
7026
7027 /* We have a valid scope declaration, save it */
7028 free(cfg_scope);
7029 cfg_scope = scope;
7030 scope = NULL;
7031
7032 out:
7033 free(scope);
7034 return err_code;
7035}
7036
Frédéric Lécaillea41d5312018-01-29 12:05:07 +01007037int
7038cfg_parse_track_sc_num(unsigned int *track_sc_num,
7039 const char *arg, const char *end, char **errmsg)
7040{
7041 const char *p;
7042 unsigned int num;
7043
7044 p = arg;
7045 num = read_uint64(&arg, end);
7046
7047 if (arg != end) {
7048 memprintf(errmsg, "Wrong track-sc number '%s'", p);
7049 return -1;
7050 }
7051
7052 if (num >= MAX_SESS_STKCTR) {
7053 memprintf(errmsg, "%u track-sc number exceeding "
7054 "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1);
7055 return -1;
7056 }
7057
7058 *track_sc_num = num;
7059 return 0;
7060}
7061
Willy Tarreaubaaee002006-06-26 02:48:02 +02007062/*
7063 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02007064 * Returns the error code, 0 if OK, or any combination of :
7065 * - ERR_ABORT: must abort ASAP
7066 * - ERR_FATAL: we can continue parsing but not start the service
7067 * - ERR_WARN: a warning has been emitted
7068 * - ERR_ALERT: an alert has been emitted
7069 * Only the two first ones can stop processing, the two others are just
7070 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02007071 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02007072int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02007073{
William Lallemand64e84512015-05-12 14:25:37 +02007074 char *thisline;
7075 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007076 FILE *f;
7077 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02007078 int err_code = 0;
William Lallemandd2ff56d2017-10-16 11:06:50 +02007079 struct cfg_section *cs = NULL, *pcs = NULL;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007080 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02007081 int readbytes = 0;
7082
7083 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007084 ha_alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02007085 return -1;
7086 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007087
David Carlier97880bb2016-04-08 10:35:26 +01007088 if ((f=fopen(file,"r")) == NULL) {
7089 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007090 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01007091 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007092
William Lallemandb2f07452015-05-12 14:27:13 +02007093next_line:
William Lallemand64e84512015-05-12 14:25:37 +02007094 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02007095 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007096 char *end;
7097 char *args[MAX_LINE_ARGS + 1];
7098 char *line = thisline;
William Lallemandf9873ba2015-05-05 17:37:14 +02007099 int dquote = 0; /* double quote */
7100 int squote = 0; /* simple quote */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007101
Willy Tarreaubaaee002006-06-26 02:48:02 +02007102 linenum++;
7103
7104 end = line + strlen(line);
7105
William Lallemand64e84512015-05-12 14:25:37 +02007106 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007107 /* Check if we reached the limit and the last char is not \n.
7108 * Watch out for the last line without the terminating '\n'!
7109 */
William Lallemand64e84512015-05-12 14:25:37 +02007110 char *newline;
7111 int newlinesize = linesize * 2;
7112
7113 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
7114 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007115 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
7116 file, linenum);
William Lallemand64e84512015-05-12 14:25:37 +02007117 err_code |= ERR_ALERT | ERR_FATAL;
7118 continue;
7119 }
7120
7121 readbytes = linesize - 1;
7122 linesize = newlinesize;
7123 thisline = newline;
7124 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007125 }
7126
William Lallemand64e84512015-05-12 14:25:37 +02007127 readbytes = 0;
7128
Willy Tarreaubaaee002006-06-26 02:48:02 +02007129 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02007130 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02007131 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02007132
Christopher Faulet79bdef32016-11-04 22:36:15 +01007133
7134 if (*line == '[') {/* This is the begining if a scope */
7135 err_code |= cfg_parse_scope(file, linenum, line);
7136 goto next_line;
7137 }
7138
Willy Tarreaubaaee002006-06-26 02:48:02 +02007139 arg = 0;
7140 args[arg] = line;
7141
7142 while (*line && arg < MAX_LINE_ARGS) {
William Lallemandf9873ba2015-05-05 17:37:14 +02007143 if (*line == '"' && !squote) { /* double quote outside single quotes */
7144 if (dquote)
7145 dquote = 0;
7146 else
7147 dquote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02007148 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02007149 end--;
7150 }
7151 else if (*line == '\'' && !dquote) { /* single quote outside double quotes */
7152 if (squote)
7153 squote = 0;
7154 else
7155 squote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02007156 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02007157 end--;
7158 }
7159 else if (*line == '\\' && !squote) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007160 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
7161 * C equivalent value. Other combinations left unchanged (eg: \1).
7162 */
Willy Tarreaubaaee002006-06-26 02:48:02 +02007163 int skip = 0;
7164 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
7165 *line = line[1];
7166 skip = 1;
7167 }
7168 else if (line[1] == 'r') {
7169 *line = '\r';
7170 skip = 1;
William Lallemandf9873ba2015-05-05 17:37:14 +02007171 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007172 else if (line[1] == 'n') {
7173 *line = '\n';
7174 skip = 1;
7175 }
7176 else if (line[1] == 't') {
7177 *line = '\t';
7178 skip = 1;
7179 }
7180 else if (line[1] == 'x') {
Emeric Brunb982a3d2010-01-04 15:45:53 +01007181 if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007182 unsigned char hex1, hex2;
7183 hex1 = toupper(line[2]) - '0';
7184 hex2 = toupper(line[3]) - '0';
7185 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
7186 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
7187 *line = (hex1<<4) + hex2;
7188 skip = 3;
7189 }
7190 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007191 ha_alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007192 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007193 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007194 } else if (line[1] == '"') {
7195 *line = '"';
7196 skip = 1;
7197 } else if (line[1] == '\'') {
7198 *line = '\'';
7199 skip = 1;
William Lallemandb2f07452015-05-12 14:27:13 +02007200 } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */
7201 *line = '$';
7202 skip = 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007203 }
7204 if (skip) {
Cyril Bontédd1b01d2009-12-06 13:43:42 +01007205 memmove(line + 1, line + 1 + skip, end - (line + skip));
Willy Tarreaubaaee002006-06-26 02:48:02 +02007206 end -= skip;
7207 }
7208 line++;
7209 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007210 else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007211 /* end of string, end of loop */
7212 *line = 0;
7213 break;
7214 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007215 else if (!squote && !dquote && isspace((unsigned char)*line)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007216 /* a non-escaped space is an argument separator */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007217 *line++ = '\0';
Willy Tarreau8f8e6452007-06-17 21:51:38 +02007218 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02007219 line++;
7220 args[++arg] = line;
7221 }
William Lallemandb2f07452015-05-12 14:27:13 +02007222 else if (dquote && *line == '$') {
7223 /* environment variables are evaluated inside double quotes */
7224 char *var_beg;
7225 char *var_end;
7226 char save_char;
7227 char *value;
7228 int val_len;
7229 int newlinesize;
7230 int braces = 0;
7231
7232 var_beg = line + 1;
7233 var_end = var_beg;
7234
7235 if (*var_beg == '{') {
7236 var_beg++;
7237 var_end++;
7238 braces = 1;
7239 }
7240
7241 if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007242 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 +02007243 err_code |= ERR_ALERT | ERR_FATAL;
7244 goto next_line; /* skip current line */
7245 }
7246
7247 while (isalnum((int)(unsigned char)*var_end) || *var_end == '_')
7248 var_end++;
7249
7250 save_char = *var_end;
7251 *var_end = '\0';
7252 value = getenv(var_beg);
7253 *var_end = save_char;
7254 val_len = value ? strlen(value) : 0;
7255
7256 if (braces) {
7257 if (*var_end == '}') {
7258 var_end++;
7259 braces = 0;
7260 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007261 ha_alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02007262 err_code |= ERR_ALERT | ERR_FATAL;
7263 goto next_line; /* skip current line */
7264 }
7265 }
7266
7267 newlinesize = (end - thisline) - (var_end - line) + val_len + 1;
7268
7269 /* if not enough space in thisline */
7270 if (newlinesize > linesize) {
7271 char *newline;
7272
7273 newline = realloc(thisline, newlinesize * sizeof(*thisline));
7274 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007275 ha_alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02007276 err_code |= ERR_ALERT | ERR_FATAL;
7277 goto next_line; /* slip current line */
7278 }
7279 /* recompute pointers if realloc returns a new pointer */
7280 if (newline != thisline) {
7281 int i;
7282 int diff;
7283
7284 for (i = 0; i <= arg; i++) {
7285 diff = args[i] - thisline;
7286 args[i] = newline + diff;
7287 }
7288
7289 diff = var_end - thisline;
7290 var_end = newline + diff;
7291 diff = end - thisline;
7292 end = newline + diff;
7293 diff = line - thisline;
7294 line = newline + diff;
7295 thisline = newline;
7296 }
7297 linesize = newlinesize;
7298 }
7299
7300 /* insert value inside the line */
7301 memmove(line + val_len, var_end, end - var_end + 1);
7302 memcpy(line, value, val_len);
7303 end += val_len - (var_end - line);
7304 line += val_len;
7305 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007306 else {
7307 line++;
7308 }
7309 }
William Lallemandb2f07452015-05-12 14:27:13 +02007310
William Lallemandf9873ba2015-05-05 17:37:14 +02007311 if (dquote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007312 ha_alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02007313 err_code |= ERR_ALERT | ERR_FATAL;
7314 }
7315
7316 if (squote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007317 ha_alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02007318 err_code |= ERR_ALERT | ERR_FATAL;
7319 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007320
7321 /* empty line */
7322 if (!**args)
7323 continue;
7324
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007325 if (*line) {
7326 /* we had to stop due to too many args.
7327 * Let's terminate the string, print the offending part then cut the
7328 * last arg.
7329 */
7330 while (*line && *line != '#' && *line != '\n' && *line != '\r')
7331 line++;
7332 *line = '\0';
7333
Christopher Faulet767a84b2017-11-24 16:50:31 +01007334 ha_alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n",
7335 file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]);
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007336 err_code |= ERR_ALERT | ERR_FATAL;
7337 args[arg] = line;
7338 }
7339
Willy Tarreau540abe42007-05-02 20:50:16 +02007340 /* zero out remaining args and ensure that at least one entry
7341 * is zeroed out.
7342 */
7343 while (++arg <= MAX_LINE_ARGS) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007344 args[arg] = line;
7345 }
7346
Willy Tarreau3842f002009-06-14 11:39:52 +02007347 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007348 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02007349 char *tmp;
7350
Willy Tarreau3842f002009-06-14 11:39:52 +02007351 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02007352 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007353 for (arg=0; *args[arg+1]; arg++)
7354 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02007355 *tmp = '\0'; // fix the next arg to \0
7356 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007357 }
Willy Tarreau3842f002009-06-14 11:39:52 +02007358 else if (!strcmp(args[0], "default")) {
7359 kwm = KWM_DEF;
7360 for (arg=0; *args[arg+1]; arg++)
7361 args[arg] = args[arg+1]; // shift args after inversion
7362 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007363
William Lallemand0f99e342011-10-12 17:50:54 +02007364 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \
7365 strcmp(args[0], "log") != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007366 ha_alert("parsing [%s:%d]: negation/default currently supported only for options and log.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02007367 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007368 }
7369
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007370 /* detect section start */
7371 list_for_each_entry(ics, &sections, list) {
7372 if (strcmp(args[0], ics->section_name) == 0) {
7373 cursection = ics->section_name;
7374 cs = ics;
7375 break;
7376 }
Emeric Brun32da3c42010-09-23 18:39:19 +02007377 }
7378
William Lallemandd2ff56d2017-10-16 11:06:50 +02007379 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007380 ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007381 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemandd2ff56d2017-10-16 11:06:50 +02007382 } else {
7383 /* else it's a section keyword */
Willy Tarreau058e9072009-07-20 09:30:05 +02007384
William Lallemandd2ff56d2017-10-16 11:06:50 +02007385 if (pcs != cs && pcs && pcs->post_section_parser) {
7386 err_code |= pcs->post_section_parser();
7387 if (err_code & ERR_ABORT)
7388 goto err;
7389 }
7390
7391 err_code |= cs->section_parser(file, linenum, args, kwm);
7392 if (err_code & ERR_ABORT)
7393 goto err;
7394 }
7395 pcs = cs;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007396 }
William Lallemandd2ff56d2017-10-16 11:06:50 +02007397
7398 if (pcs == cs && pcs && pcs->post_section_parser)
7399 err_code |= pcs->post_section_parser();
7400
7401err:
Christopher Faulet79bdef32016-11-04 22:36:15 +01007402 free(cfg_scope);
7403 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01007404 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02007405 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007406 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02007407 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007408}
7409
Willy Tarreau64ab6072014-09-16 12:17:36 +02007410/* This function propagates processes from frontend <from> to backend <to> so
7411 * that it is always guaranteed that a backend pointed to by a frontend is
7412 * bound to all of its processes. After that, if the target is a "listen"
7413 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02007414 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02007415 * checked first to ensure that <to> is already bound to all processes of
7416 * <from>, there is no risk of looping and we ensure to follow the shortest
7417 * path to the destination.
7418 *
7419 * It is possible to set <to> to NULL for the first call so that the function
7420 * takes care of visiting the initial frontend in <from>.
7421 *
7422 * It is important to note that the function relies on the fact that all names
7423 * have already been resolved.
7424 */
7425void propagate_processes(struct proxy *from, struct proxy *to)
7426{
7427 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007428
7429 if (to) {
7430 /* check whether we need to go down */
7431 if (from->bind_proc &&
7432 (from->bind_proc & to->bind_proc) == from->bind_proc)
7433 return;
7434
7435 if (!from->bind_proc && !to->bind_proc)
7436 return;
7437
7438 to->bind_proc = from->bind_proc ?
7439 (to->bind_proc | from->bind_proc) : 0;
7440
7441 /* now propagate down */
7442 from = to;
7443 }
7444
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01007445 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02007446 return;
7447
Willy Tarreauf6b70012014-12-18 14:00:43 +01007448 if (from->state == PR_STSTOPPED)
7449 return;
7450
Willy Tarreau64ab6072014-09-16 12:17:36 +02007451 /* default_backend */
7452 if (from->defbe.be)
7453 propagate_processes(from, from->defbe.be);
7454
7455 /* use_backend */
7456 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02007457 if (rule->dynamic)
7458 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007459 to = rule->be.backend;
7460 propagate_processes(from, to);
7461 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02007462}
7463
Willy Tarreaubb925012009-07-23 13:36:36 +02007464/*
7465 * Returns the error code, 0 if OK, or any combination of :
7466 * - ERR_ABORT: must abort ASAP
7467 * - ERR_FATAL: we can continue parsing but not start the service
7468 * - ERR_WARN: a warning has been emitted
7469 * - ERR_ALERT: an alert has been emitted
7470 * Only the two first ones can stop processing, the two others are just
7471 * indicators.
7472 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007473int check_config_validity()
7474{
7475 int cfgerr = 0;
7476 struct proxy *curproxy = NULL;
7477 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02007478 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007479 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007480 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007481 char *err;
William Lallemand48b4bb42017-10-23 14:36:34 +02007482 struct cfg_postparser *postparser;
Ben Draut054fbee2018-04-13 15:43:04 -06007483 struct dns_resolvers *curr_resolvers = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007484
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007485 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007486 /*
7487 * Now, check for the integrity of all that we have collected.
7488 */
7489
7490 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02007491 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007492
Willy Tarreau193b8c62012-11-22 00:17:38 +01007493 if (!global.tune.max_http_hdr)
7494 global.tune.max_http_hdr = MAX_HTTP_HDR;
7495
7496 if (!global.tune.cookie_len)
7497 global.tune.cookie_len = CAPTURE_LEN;
7498
Stéphane Cottin23e9e932017-05-18 08:58:41 +02007499 if (!global.tune.requri_len)
7500 global.tune.requri_len = REQURI_LEN;
7501
Willy Tarreaubafbe012017-11-24 17:34:44 +01007502 pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
Emeric Brun96fd9262017-07-05 13:33:16 +02007503
Willy Tarreaubafbe012017-11-24 17:34:44 +01007504 pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
Willy Tarreau193b8c62012-11-22 00:17:38 +01007505
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01007506 /* Post initialisation of the users and groups lists. */
7507 err_code = userlist_postinit();
7508 if (err_code != ERR_NONE)
7509 goto out;
7510
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007511 /* first, we will invert the proxy list order */
7512 curproxy = NULL;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007513 while (proxies_list) {
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007514 struct proxy *next;
7515
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007516 next = proxies_list->next;
7517 proxies_list->next = curproxy;
7518 curproxy = proxies_list;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007519 if (!next)
7520 break;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007521 proxies_list = next;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007522 }
7523
Olivier Houchardfbc74e82017-11-24 16:54:05 +01007524 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007525 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007526 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01007527 struct sticking_rule *mrule;
Christopher Faulete4e830d2017-09-18 14:51:41 +02007528 struct act_rule *arule;
Dragan Dosen1322d092015-09-22 16:05:32 +02007529 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007530 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01007531 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007532
Willy Tarreau050536d2012-10-04 08:47:34 +02007533 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007534 /* proxy ID not set, use automatic numbering with first
7535 * spare entry starting with next_pxid.
7536 */
7537 next_pxid = get_next_id(&used_proxy_id, next_pxid);
7538 curproxy->conf.id.key = curproxy->uuid = next_pxid;
7539 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007540 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01007541 next_pxid++;
7542
Willy Tarreau55ea7572007-06-17 19:56:27 +02007543
Willy Tarreaubaaee002006-06-26 02:48:02 +02007544 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02007545 /* ensure we don't keep listeners uselessly bound */
7546 stop_proxy(curproxy);
Willy Tarreau02df7742015-05-01 19:59:56 +02007547 free((void *)curproxy->table.peers.name);
7548 curproxy->table.peers.p = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007549 continue;
7550 }
7551
Willy Tarreau102df612014-05-07 23:56:38 +02007552 /* Check multi-process mode compatibility for the current proxy */
7553
7554 if (curproxy->bind_proc) {
7555 /* an explicit bind-process was specified, let's check how many
7556 * processes remain.
7557 */
David Carliere6c39412015-07-02 07:00:17 +00007558 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02007559
7560 curproxy->bind_proc &= nbits(global.nbproc);
7561 if (!curproxy->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007562 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 +02007563 curproxy->bind_proc = 1;
7564 }
7565 else if (!curproxy->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007566 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 +02007567 curproxy->bind_proc = 0;
7568 }
7569 }
7570
Willy Tarreau3d209582014-05-09 17:06:11 +02007571 /* check and reduce the bind-proc of each listener */
7572 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
7573 unsigned long mask;
7574
Willy Tarreau45a66cc2017-11-24 11:28:00 +01007575 /* HTTP frontends with "h2" as ALPN/NPN will work in
7576 * HTTP/2 and absolutely require buffers 16kB or larger.
7577 */
7578#ifdef USE_OPENSSL
7579 if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
7580#ifdef OPENSSL_NPN_NEGOTIATED
7581 /* check NPN */
7582 if (bind_conf->ssl_conf.npn_str && strcmp(bind_conf->ssl_conf.npn_str, "\002h2") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007583 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",
7584 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01007585 cfgerr++;
7586 }
7587#endif
7588#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
7589 /* check ALPN */
7590 if (bind_conf->ssl_conf.alpn_str && strcmp(bind_conf->ssl_conf.alpn_str, "\002h2") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007591 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",
7592 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01007593 cfgerr++;
7594 }
7595#endif
7596 } /* HTTP && bufsize < 16384 */
7597#endif
7598
Willy Tarreauc477b6f2018-07-27 18:07:41 +02007599 /* detect and address thread affinity inconsistencies */
7600 nbproc = 0;
7601 if (bind_conf->bind_proc)
7602 nbproc = my_ffsl(bind_conf->bind_proc);
7603
7604 mask = bind_conf->bind_thread[nbproc - 1];
Willy Tarreau0c026f42018-08-01 19:12:20 +02007605 if (mask && !(mask & all_threads_mask)) {
Willy Tarreauc477b6f2018-07-27 18:07:41 +02007606 unsigned long new_mask = 0;
7607
7608 while (mask) {
Willy Tarreau0c026f42018-08-01 19:12:20 +02007609 new_mask |= mask & all_threads_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02007610 mask >>= global.nbthread;
7611 }
7612
7613 for (nbproc = 0; nbproc < LONGBITS; nbproc++) {
7614 if (!bind_conf->bind_proc || (bind_conf->bind_proc & (1UL << nbproc)))
7615 bind_conf->bind_thread[nbproc] = new_mask;
7616 }
7617 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",
7618 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
7619 }
7620
7621 /* detect process and nbproc affinity inconsistencies */
Willy Tarreau3d209582014-05-09 17:06:11 +02007622 if (!bind_conf->bind_proc)
7623 continue;
7624
7625 mask = nbits(global.nbproc);
7626 if (curproxy->bind_proc)
7627 mask &= curproxy->bind_proc;
7628 /* mask cannot be null here thanks to the previous checks */
7629
David Carliere6c39412015-07-02 07:00:17 +00007630 nbproc = my_popcountl(bind_conf->bind_proc);
Willy Tarreau3d209582014-05-09 17:06:11 +02007631 bind_conf->bind_proc &= mask;
7632
7633 if (!bind_conf->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007634 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",
7635 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreau3d209582014-05-09 17:06:11 +02007636 bind_conf->bind_proc = mask & ~(mask - 1);
7637 }
7638 else if (!bind_conf->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007639 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",
7640 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreau3d209582014-05-09 17:06:11 +02007641 bind_conf->bind_proc = 0;
7642 }
7643 }
7644
Willy Tarreauff01a212009-03-15 13:46:16 +01007645 switch (curproxy->mode) {
7646 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007647 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007648 if (!(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007649 ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
7650 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007651 cfgerr++;
7652 }
7653
7654 if (curproxy->srv != NULL)
Christopher Faulet767a84b2017-11-24 16:50:31 +01007655 ha_warning("config : servers will be ignored for %s '%s'.\n",
7656 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007657 break;
7658
7659 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007660 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007661 break;
7662
7663 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01007664 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01007665 break;
7666 }
7667
Willy Tarreau58aa5cc2018-02-08 09:55:09 +01007668 if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007669 ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
7670 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauf3934b82015-08-11 11:36:45 +02007671 err_code |= ERR_WARN;
7672 }
7673
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007674 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02007675 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007676 if (curproxy->options & PR_O_TRANSP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007677 ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n",
7678 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007679 cfgerr++;
7680 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007681#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007682 else if (curproxy->srv == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007683 ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n",
7684 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007685 cfgerr++;
7686 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007687#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02007688 else if (curproxy->options & PR_O_DISPATCH) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007689 ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
7690 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02007691 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007692 }
7693 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02007694 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007695 /* If no LB algo is set in a backend, and we're not in
7696 * transparent mode, dispatch mode nor proxy mode, we
7697 * want to use balance roundrobin by default.
7698 */
7699 curproxy->lbprm.algo &= ~BE_LB_ALGO;
7700 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007701 }
7702 }
Willy Tarreau193cf932007-09-17 10:17:23 +02007703
Willy Tarreau1620ec32011-08-06 17:05:02 +02007704 if (curproxy->options & PR_O_DISPATCH)
7705 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
7706 else if (curproxy->options & PR_O_HTTP_PROXY)
7707 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
7708 else if (curproxy->options & PR_O_TRANSP)
7709 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01007710
Willy Tarreau1620ec32011-08-06 17:05:02 +02007711 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) {
7712 if (curproxy->options & PR_O_DISABLE404) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007713 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7714 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02007715 err_code |= ERR_WARN;
7716 curproxy->options &= ~PR_O_DISABLE404;
7717 }
7718 if (curproxy->options2 & PR_O2_CHK_SNDST) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007719 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7720 "send-state", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02007721 err_code |= ERR_WARN;
7722 curproxy->options &= ~PR_O2_CHK_SNDST;
7723 }
Willy Tarreauef781042010-01-27 11:53:01 +01007724 }
7725
Simon Horman98637e52014-06-20 12:30:16 +09007726 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
7727 if (!global.external_check) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007728 ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
7729 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09007730 cfgerr++;
7731 }
7732 if (!curproxy->check_command) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007733 ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
7734 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09007735 cfgerr++;
7736 }
7737 }
7738
Simon Horman64e34162015-02-06 11:11:57 +09007739 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007740 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007741 ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
7742 "'email-alert from', 'email-alert level' 'email-alert mailers', "
7743 "'email-alert myhostname', or 'email-alert to' "
7744 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
7745 "to be present).\n",
7746 proxy_type_str(curproxy), curproxy->id);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007747 err_code |= ERR_WARN;
7748 free_email_alert(curproxy);
7749 }
7750 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01007751 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09007752 }
7753
Simon Horman98637e52014-06-20 12:30:16 +09007754 if (curproxy->check_command) {
7755 int clear = 0;
7756 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007757 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7758 "external-check command", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09007759 err_code |= ERR_WARN;
7760 clear = 1;
7761 }
7762 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007763 ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
7764 curproxy->id, "external-check command");
Simon Horman98637e52014-06-20 12:30:16 +09007765 cfgerr++;
7766 }
7767 if (clear) {
7768 free(curproxy->check_command);
7769 curproxy->check_command = NULL;
7770 }
7771 }
7772
7773 if (curproxy->check_path) {
7774 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007775 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7776 "external-check path", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09007777 err_code |= ERR_WARN;
7778 free(curproxy->check_path);
7779 curproxy->check_path = NULL;
7780 }
7781 }
7782
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007783 /* if a default backend was specified, let's find it */
7784 if (curproxy->defbe.name) {
7785 struct proxy *target;
7786
Willy Tarreauafb39922015-05-26 12:04:09 +02007787 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007788 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007789 ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
7790 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007791 cfgerr++;
7792 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007793 ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
7794 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02007795 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007796 } else if (target->mode != curproxy->mode &&
7797 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7798
Christopher Faulet767a84b2017-11-24 16:50:31 +01007799 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
7800 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7801 curproxy->conf.file, curproxy->conf.line,
7802 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7803 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02007804 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007805 } else {
7806 free(curproxy->defbe.name);
7807 curproxy->defbe.be = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007808 /* Update tot_fe_maxconn for a further fullconn's computation */
7809 target->tot_fe_maxconn += curproxy->maxconn;
Willy Tarreauff678132012-02-13 14:32:34 +01007810 /* Emit a warning if this proxy also has some servers */
7811 if (curproxy->srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007812 ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
7813 curproxy->id);
Willy Tarreauff678132012-02-13 14:32:34 +01007814 err_code |= ERR_WARN;
7815 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007816 }
7817 }
7818
Emeric Brun3f783572017-01-12 11:21:28 +01007819 if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
7820 /* Case of listen without default backend
7821 * The curproxy will be its own default backend
7822 * so we update tot_fe_maxconn for a further
7823 * fullconn's computation */
7824 curproxy->tot_fe_maxconn += curproxy->maxconn;
7825 }
7826
Willy Tarreau55ea7572007-06-17 19:56:27 +02007827 /* find the target proxy for 'use_backend' rules */
7828 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007829 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007830 struct logformat_node *node;
7831 char *pxname;
7832
7833 /* Try to parse the string as a log format expression. If the result
7834 * of the parsing is only one entry containing a simple string, then
7835 * it's a standard string corresponding to a static rule, thus the
7836 * parsing is cancelled and be.name is restored to be resolved.
7837 */
7838 pxname = rule->be.name;
7839 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01007840 curproxy->conf.args.ctx = ARGC_UBK;
7841 curproxy->conf.args.file = rule->file;
7842 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007843 err = NULL;
7844 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007845 ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
7846 rule->file, rule->line, pxname, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007847 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01007848 cfgerr++;
7849 continue;
7850 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007851 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
7852
7853 if (!LIST_ISEMPTY(&rule->be.expr)) {
7854 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
7855 rule->dynamic = 1;
7856 free(pxname);
7857 continue;
7858 }
7859 /* simple string: free the expression and fall back to static rule */
7860 free(node->arg);
7861 free(node);
7862 }
7863
7864 rule->dynamic = 0;
7865 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007866
Willy Tarreauafb39922015-05-26 12:04:09 +02007867 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007868 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007869 ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
7870 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007871 cfgerr++;
7872 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007873 ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
7874 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007875 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007876 } else if (target->mode != curproxy->mode &&
7877 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7878
Christopher Faulet767a84b2017-11-24 16:50:31 +01007879 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
7880 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7881 curproxy->conf.file, curproxy->conf.line,
7882 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7883 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02007884 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007885 } else {
7886 free((void *)rule->be.name);
7887 rule->be.backend = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007888 /* For each target of switching rules, we update
7889 * their tot_fe_maxconn, except if a previous rule point
7890 * on the same backend or on the default backend */
7891 if (rule->be.backend != curproxy->defbe.be) {
7892 struct switching_rule *swrule;
7893
7894 list_for_each_entry(swrule, &curproxy->switching_rules, list) {
7895 if (rule == swrule) {
7896 target->tot_fe_maxconn += curproxy->maxconn;
7897 break;
7898 }
7899 else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) {
7900 /* there is multiple ref of this backend */
7901 break;
7902 }
7903 }
7904 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02007905 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007906 }
7907
Willy Tarreau64ab6072014-09-16 12:17:36 +02007908 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007909 list_for_each_entry(srule, &curproxy->server_rules, list) {
7910 struct server *target = findserver(curproxy, srule->srv.name);
7911
7912 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007913 ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
7914 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007915 cfgerr++;
7916 continue;
7917 }
7918 free((void *)srule->srv.name);
7919 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007920 }
7921
Emeric Brunb982a3d2010-01-04 15:45:53 +01007922 /* find the target table for 'stick' rules */
7923 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
7924 struct proxy *target;
7925
Emeric Brun1d33b292010-01-04 15:47:17 +01007926 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
7927 if (mrule->flags & STK_IS_STORE)
7928 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7929
Emeric Brunb982a3d2010-01-04 15:45:53 +01007930 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007931 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007932 else
7933 target = curproxy;
7934
7935 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007936 ha_alert("Proxy '%s': unable to find stick-table '%s'.\n",
7937 curproxy->id, mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007938 cfgerr++;
7939 }
7940 else if (target->table.size == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007941 ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7942 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007943 cfgerr++;
7944 }
Willy Tarreau12785782012-04-27 21:37:17 +02007945 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007946 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
7947 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007948 cfgerr++;
7949 }
7950 else {
7951 free((void *)mrule->table.name);
7952 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007953 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007954 }
7955 }
7956
7957 /* find the target table for 'store response' rules */
7958 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
7959 struct proxy *target;
7960
Emeric Brun1d33b292010-01-04 15:47:17 +01007961 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7962
Emeric Brunb982a3d2010-01-04 15:45:53 +01007963 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007964 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007965 else
7966 target = curproxy;
7967
7968 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007969 ha_alert("Proxy '%s': unable to find store table '%s'.\n",
7970 curproxy->id, mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007971 cfgerr++;
7972 }
7973 else if (target->table.size == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007974 ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7975 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007976 cfgerr++;
7977 }
Willy Tarreau12785782012-04-27 21:37:17 +02007978 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01007979 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
7980 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007981 cfgerr++;
7982 }
7983 else {
7984 free((void *)mrule->table.name);
7985 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007986 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007987 }
7988 }
7989
Christopher Faulete4e830d2017-09-18 14:51:41 +02007990 /* check validity for 'tcp-request' layer 4 rules */
7991 list_for_each_entry(arule, &curproxy->tcp_req.l4_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);
Willy Tarreau5f53de72012-12-12 00:25:44 +01007996 cfgerr++;
7997 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02007998 }
7999
Christopher Faulete4e830d2017-09-18 14:51:41 +02008000 /* check validity for 'tcp-request' layer 5 rules */
8001 list_for_each_entry(arule, &curproxy->tcp_req.l5_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 'tcp-request' layer 6 rules */
8011 list_for_each_entry(arule, &curproxy->tcp_req.inspect_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);
Baptiste Assmanne9544932015-11-03 23:31:35 +01008016 cfgerr++;
8017 }
8018 }
8019
Christopher Faulete4e830d2017-09-18 14:51:41 +02008020 /* check validity for 'http-request' layer 7 rules */
8021 list_for_each_entry(arule, &curproxy->http_req_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);
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08008026 cfgerr++;
8027 }
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08008028 }
8029
Christopher Faulete4e830d2017-09-18 14:51:41 +02008030 /* check validity for 'http-response' layer 7 rules */
8031 list_for_each_entry(arule, &curproxy->http_res_rules, list) {
8032 err = NULL;
8033 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008034 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02008035 free(err);
Willy Tarreau09448f72014-06-25 18:12:15 +02008036 cfgerr++;
8037 }
Willy Tarreau09448f72014-06-25 18:12:15 +02008038 }
8039
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02008040 /* move any "block" rules at the beginning of the http-request rules */
8041 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
8042 /* insert block_rules into http_req_rules at the beginning */
8043 curproxy->block_rules.p->n = curproxy->http_req_rules.n;
8044 curproxy->http_req_rules.n->p = curproxy->block_rules.p;
8045 curproxy->block_rules.n->p = &curproxy->http_req_rules;
8046 curproxy->http_req_rules.n = curproxy->block_rules.n;
8047 LIST_INIT(&curproxy->block_rules);
8048 }
8049
Emeric Brun32da3c42010-09-23 18:39:19 +02008050 if (curproxy->table.peers.name) {
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02008051 struct peers *curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02008052
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02008053 for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +02008054 if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) {
8055 free((void *)curproxy->table.peers.name);
Willy Tarreau973ca492013-01-17 21:34:52 +01008056 curproxy->table.peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02008057 break;
8058 }
8059 }
8060
8061 if (!curpeers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008062 ha_alert("Proxy '%s': unable to find sync peers '%s'.\n",
8063 curproxy->id, curproxy->table.peers.name);
Willy Tarreaud66bf962011-10-28 14:16:49 +02008064 free((void *)curproxy->table.peers.name);
8065 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02008066 cfgerr++;
8067 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02008068 else if (curpeers->state == PR_STSTOPPED) {
8069 /* silently disable this peers section */
8070 curproxy->table.peers.p = NULL;
8071 }
Emeric Brun32da3c42010-09-23 18:39:19 +02008072 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008073 ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
8074 curproxy->id, localpeer, curpeers->id);
Willy Tarreaud66bf962011-10-28 14:16:49 +02008075 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02008076 cfgerr++;
8077 }
8078 }
8079
Simon Horman9dc49962015-01-30 11:22:59 +09008080
8081 if (curproxy->email_alert.mailers.name) {
8082 struct mailers *curmailers = mailers;
8083
8084 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
Christopher Faulet0108bb32017-10-20 21:34:32 +02008085 if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name))
Simon Horman9dc49962015-01-30 11:22:59 +09008086 break;
Simon Horman9dc49962015-01-30 11:22:59 +09008087 }
Simon Horman9dc49962015-01-30 11:22:59 +09008088 if (!curmailers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008089 ha_alert("Proxy '%s': unable to find mailers '%s'.\n",
8090 curproxy->id, curproxy->email_alert.mailers.name);
Simon Horman9dc49962015-01-30 11:22:59 +09008091 free_email_alert(curproxy);
8092 cfgerr++;
8093 }
Christopher Faulet0108bb32017-10-20 21:34:32 +02008094 else {
8095 err = NULL;
8096 if (init_email_alert(curmailers, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008097 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulet0108bb32017-10-20 21:34:32 +02008098 free(err);
8099 cfgerr++;
8100 }
8101 }
Simon Horman9dc49962015-01-30 11:22:59 +09008102 }
8103
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008104 if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) &&
Willy Tarreauff011f22011-01-06 17:51:27 +01008105 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008106 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008107 ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
8108 "proxy", curproxy->id);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008109 cfgerr++;
8110 goto out_uri_auth_compat;
8111 }
8112
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008113 if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008114 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02008115 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01008116 int i = 0;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008117
Willy Tarreau95fa4692010-02-01 13:05:50 +01008118 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
8119 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008120
8121 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008122 uri_auth_compat_req[i++] = "realm";
8123 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
8124 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008125
Willy Tarreau95fa4692010-02-01 13:05:50 +01008126 uri_auth_compat_req[i++] = "unless";
8127 uri_auth_compat_req[i++] = "{";
8128 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
8129 uri_auth_compat_req[i++] = "}";
8130 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008131
Willy Tarreauff011f22011-01-06 17:51:27 +01008132 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
8133 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008134 cfgerr++;
8135 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008136 }
8137
Willy Tarreauff011f22011-01-06 17:51:27 +01008138 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01008139
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008140 if (curproxy->uri_auth->auth_realm) {
8141 free(curproxy->uri_auth->auth_realm);
8142 curproxy->uri_auth->auth_realm = NULL;
8143 }
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008144
8145 curproxy->uri_auth->flags |= ST_CONVDONE;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008146 }
8147out_uri_auth_compat:
8148
Dragan Dosen43885c72015-10-01 13:18:13 +02008149 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02008150 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02008151 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
8152 if (!curproxy->conf.logformat_sd_string) {
8153 /* set the default logformat_sd_string */
8154 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
8155 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008156 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02008157 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008158 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02008159
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008160 /* compile the log format */
8161 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02008162 if (curproxy->conf.logformat_string != default_http_log_format &&
8163 curproxy->conf.logformat_string != default_tcp_log_format &&
8164 curproxy->conf.logformat_string != clf_http_log_format)
8165 free(curproxy->conf.logformat_string);
8166 curproxy->conf.logformat_string = NULL;
8167 free(curproxy->conf.lfs_file);
8168 curproxy->conf.lfs_file = NULL;
8169 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008170
8171 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
8172 free(curproxy->conf.logformat_sd_string);
8173 curproxy->conf.logformat_sd_string = NULL;
8174 free(curproxy->conf.lfsd_file);
8175 curproxy->conf.lfsd_file = NULL;
8176 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008177 }
8178
Willy Tarreau62a61232013-04-12 18:13:46 +02008179 if (curproxy->conf.logformat_string) {
8180 curproxy->conf.args.ctx = ARGC_LOG;
8181 curproxy->conf.args.file = curproxy->conf.lfs_file;
8182 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008183 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008184 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008185 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008186 ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
8187 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008188 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008189 cfgerr++;
8190 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008191 curproxy->conf.args.file = NULL;
8192 curproxy->conf.args.line = 0;
8193 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008194
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008195 if (curproxy->conf.logformat_sd_string) {
8196 curproxy->conf.args.ctx = ARGC_LOGSD;
8197 curproxy->conf.args.file = curproxy->conf.lfsd_file;
8198 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008199 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008200 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 +01008201 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008202 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8203 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008204 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008205 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008206 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008207 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8208 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008209 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008210 cfgerr++;
8211 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008212 curproxy->conf.args.file = NULL;
8213 curproxy->conf.args.line = 0;
8214 }
8215
Willy Tarreau62a61232013-04-12 18:13:46 +02008216 if (curproxy->conf.uniqueid_format_string) {
8217 curproxy->conf.args.ctx = ARGC_UIF;
8218 curproxy->conf.args.file = curproxy->conf.uif_file;
8219 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008220 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008221 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 +01008222 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008223 ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
8224 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008225 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008226 cfgerr++;
8227 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008228 curproxy->conf.args.file = NULL;
8229 curproxy->conf.args.line = 0;
8230 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008231
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01008232 /* only now we can check if some args remain unresolved.
8233 * This must be done after the users and groups resolution.
8234 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008235 cfgerr += smp_resolve_args(curproxy);
8236 if (!cfgerr)
8237 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01008238
Willy Tarreau2738a142006-07-08 17:28:09 +02008239 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008240 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02008241 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02008242 (!curproxy->timeout.connect ||
8243 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008244 ha_warning("config : missing timeouts for %s '%s'.\n"
8245 " | While not properly invalid, you will certainly encounter various problems\n"
8246 " | with such a configuration. To fix this, please ensure that all following\n"
8247 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
8248 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008249 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02008250 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02008251
Willy Tarreau1fa31262007-12-03 00:36:16 +01008252 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
8253 * We must still support older configurations, so let's find out whether those
8254 * parameters have been set or must be copied from contimeouts.
8255 */
8256 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008257 if (!curproxy->timeout.tarpit ||
8258 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008259 /* tarpit timeout not set. We search in the following order:
8260 * default.tarpit, curr.connect, default.connect.
8261 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008262 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008263 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008264 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008265 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008266 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008267 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008268 }
8269 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008270 (!curproxy->timeout.queue ||
8271 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008272 /* queue timeout not set. We search in the following order:
8273 * default.queue, curr.connect, default.connect.
8274 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008275 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008276 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008277 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008278 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008279 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008280 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008281 }
8282 }
8283
Willy Tarreau1620ec32011-08-06 17:05:02 +02008284 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) {
Willy Tarreau137325d2010-02-01 16:38:17 +01008285 curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02008286 curproxy->check_req = malloc(curproxy->check_len);
Willy Tarreau137325d2010-02-01 16:38:17 +01008287 memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len);
Willy Tarreauf3c69202006-07-09 16:42:34 +02008288 }
8289
Willy Tarreau215663d2014-06-13 18:30:23 +02008290 if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) &&
8291 (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008292 ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
8293 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau215663d2014-06-13 18:30:23 +02008294 err_code |= ERR_WARN;
8295 }
8296
Willy Tarreau193b8c62012-11-22 00:17:38 +01008297 /* ensure that cookie capture length is not too large */
8298 if (curproxy->capture_len >= global.tune.cookie_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008299 ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n",
8300 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau193b8c62012-11-22 00:17:38 +01008301 err_code |= ERR_WARN;
8302 curproxy->capture_len = global.tune.cookie_len - 1;
8303 }
8304
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008305 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01008306 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008307 curproxy->req_cap_pool = create_pool("ptrcap",
8308 curproxy->nb_req_cap * sizeof(char *),
8309 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008310 }
8311
8312 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008313 curproxy->rsp_cap_pool = create_pool("ptrcap",
8314 curproxy->nb_rsp_cap * sizeof(char *),
8315 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008316 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008317
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02008318 switch (curproxy->load_server_state_from_file) {
8319 case PR_SRV_STATE_FILE_UNSPEC:
8320 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
8321 break;
8322 case PR_SRV_STATE_FILE_GLOBAL:
8323 if (!global.server_state_file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008324 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",
8325 curproxy->id);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02008326 err_code |= ERR_WARN;
8327 }
8328 break;
8329 }
8330
Willy Tarreaubaaee002006-06-26 02:48:02 +02008331 /* first, we will invert the servers list order */
8332 newsrv = NULL;
8333 while (curproxy->srv) {
8334 struct server *next;
8335
8336 next = curproxy->srv->next;
8337 curproxy->srv->next = newsrv;
8338 newsrv = curproxy->srv;
8339 if (!next)
8340 break;
8341 curproxy->srv = next;
8342 }
8343
Willy Tarreau17edc812014-01-03 12:14:34 +01008344 /* Check that no server name conflicts. This causes trouble in the stats.
8345 * We only emit a warning for the first conflict affecting each server,
8346 * in order to avoid combinatory explosion if all servers have the same
8347 * name. We do that only for servers which do not have an explicit ID,
8348 * because these IDs were made also for distinguishing them and we don't
8349 * want to annoy people who correctly manage them.
8350 */
8351 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
8352 struct server *other_srv;
8353
8354 if (newsrv->puid)
8355 continue;
8356
8357 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
8358 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008359 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",
8360 newsrv->conf.file, newsrv->conf.line,
8361 proxy_type_str(curproxy), curproxy->id,
8362 newsrv->id, other_srv->conf.line);
Willy Tarreau17edc812014-01-03 12:14:34 +01008363 break;
8364 }
8365 }
8366 }
8367
Willy Tarreaudd701652010-05-25 23:03:02 +02008368 /* assign automatic UIDs to servers which don't have one yet */
8369 next_id = 1;
8370 newsrv = curproxy->srv;
8371 while (newsrv != NULL) {
8372 if (!newsrv->puid) {
8373 /* server ID not set, use automatic numbering with first
8374 * spare entry starting with next_svid.
8375 */
8376 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
8377 newsrv->conf.id.key = newsrv->puid = next_id;
8378 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
8379 }
8380 next_id++;
8381 newsrv = newsrv->next;
8382 }
8383
Willy Tarreau20697042007-11-15 23:26:18 +01008384 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01008385 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02008386
Willy Tarreau62c3be22012-01-20 13:12:32 +01008387 /*
8388 * If this server supports a maxconn parameter, it needs a dedicated
8389 * tasks to fill the emptied slots when a connection leaves.
8390 * Also, resolve deferred tracking dependency if needed.
8391 */
8392 newsrv = curproxy->srv;
8393 while (newsrv != NULL) {
8394 if (newsrv->minconn > newsrv->maxconn) {
8395 /* Only 'minconn' was specified, or it was higher than or equal
8396 * to 'maxconn'. Let's turn this into maxconn and clean it, as
8397 * this will avoid further useless expensive computations.
8398 */
8399 newsrv->maxconn = newsrv->minconn;
8400 } else if (newsrv->maxconn && !newsrv->minconn) {
8401 /* minconn was not specified, so we set it to maxconn */
8402 newsrv->minconn = newsrv->maxconn;
8403 }
8404
Willy Tarreau17d45382016-12-22 21:16:08 +01008405 /* this will also properly set the transport layer for prod and checks */
8406 if (newsrv->use_ssl || newsrv->check.use_ssl) {
8407 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
8408 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
8409 }
Emeric Brun94324a42012-10-11 14:00:19 +02008410
Willy Tarreau2f075e92013-12-03 11:11:34 +01008411 /* set the check type on the server */
8412 newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY;
8413
Willy Tarreau62c3be22012-01-20 13:12:32 +01008414 if (newsrv->trackit) {
8415 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02008416 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008417 char *pname, *sname;
8418
8419 pname = newsrv->trackit;
8420 sname = strrchr(pname, '/');
8421
8422 if (sname)
8423 *sname++ = '\0';
8424 else {
8425 sname = pname;
8426 pname = NULL;
8427 }
8428
8429 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02008430 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008431 if (!px) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008432 ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
8433 proxy_type_str(curproxy), curproxy->id,
8434 newsrv->id, pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008435 cfgerr++;
8436 goto next_srv;
8437 }
8438 } else
8439 px = curproxy;
8440
8441 srv = findserver(px, sname);
8442 if (!srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008443 ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
8444 proxy_type_str(curproxy), curproxy->id,
8445 newsrv->id, sname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008446 cfgerr++;
8447 goto next_srv;
8448 }
8449
Willy Tarreau32091232014-05-16 13:52:00 +02008450 if (!(srv->check.state & CHK_ST_CONFIGURED) &&
8451 !(srv->agent.state & CHK_ST_CONFIGURED) &&
8452 !srv->track && !srv->trackit) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008453 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for "
8454 "tracking as it does not have any check nor agent enabled.\n",
8455 proxy_type_str(curproxy), curproxy->id,
8456 newsrv->id, px->id, srv->id);
Willy Tarreau32091232014-05-16 13:52:00 +02008457 cfgerr++;
8458 goto next_srv;
8459 }
8460
8461 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
8462
Frédéric Lécaille2efc6492017-03-14 14:32:17 +01008463 if (newsrv == srv || loop) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008464 ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it "
8465 "belongs to a tracking chain looping back to %s/%s.\n",
8466 proxy_type_str(curproxy), curproxy->id,
8467 newsrv->id, px->id, srv->id, px->id,
8468 newsrv == srv ? srv->id : loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008469 cfgerr++;
8470 goto next_srv;
8471 }
8472
8473 if (curproxy != px &&
8474 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008475 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for"
8476 "tracking: disable-on-404 option inconsistency.\n",
8477 proxy_type_str(curproxy), curproxy->id,
8478 newsrv->id, px->id, srv->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008479 cfgerr++;
8480 goto next_srv;
8481 }
8482
Willy Tarreau62c3be22012-01-20 13:12:32 +01008483 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01008484 newsrv->tracknext = srv->trackers;
8485 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008486
8487 free(newsrv->trackit);
8488 newsrv->trackit = NULL;
8489 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02008490
Willy Tarreau62c3be22012-01-20 13:12:32 +01008491 next_srv:
8492 newsrv = newsrv->next;
8493 }
8494
Olivier Houchard4e694042017-03-14 20:01:29 +01008495 /*
8496 * Try to generate dynamic cookies for servers now.
8497 * It couldn't be done earlier, since at the time we parsed
8498 * the server line, we may not have known yet that we
8499 * should use dynamic cookies, or the secret key may not
8500 * have been provided yet.
8501 */
8502 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
8503 newsrv = curproxy->srv;
8504 while (newsrv != NULL) {
8505 srv_set_dyncookie(newsrv);
8506 newsrv = newsrv->next;
8507 }
8508
8509 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008510 /* We have to initialize the server lookup mechanism depending
8511 * on what LB algorithm was choosen.
8512 */
8513
8514 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
8515 switch (curproxy->lbprm.algo & BE_LB_KIND) {
8516 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02008517 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
8518 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8519 init_server_map(curproxy);
Willy Tarreau760e81d2018-05-03 07:20:40 +02008520 } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
8521 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
8522 chash_init_server_tree(curproxy);
Willy Tarreau9757a382009-10-03 12:56:50 +02008523 } else {
8524 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
8525 fwrr_init_server_groups(curproxy);
8526 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008527 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008528
Willy Tarreau3ebb1162012-02-13 16:57:44 +01008529 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01008530 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
8531 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
8532 fwlc_init_server_tree(curproxy);
8533 } else {
8534 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
8535 fas_init_server_tree(curproxy);
8536 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008537 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008538
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008539 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008540 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
8541 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
8542 chash_init_server_tree(curproxy);
8543 } else {
8544 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8545 init_server_map(curproxy);
8546 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008547 break;
8548 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01008549 HA_SPIN_INIT(&curproxy->lbprm.lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +02008550
8551 if (curproxy->options & PR_O_LOGASAP)
8552 curproxy->to_log &= ~LW_BYTES;
8553
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008554 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008555 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
8556 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008557 ha_warning("config : log format ignored for %s '%s' since it has no log address.\n",
8558 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008559 err_code |= ERR_WARN;
8560 }
8561
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008562 if (curproxy->mode != PR_MODE_HTTP) {
8563 int optnum;
8564
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008565 if (curproxy->uri_auth) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008566 ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
8567 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008568 err_code |= ERR_WARN;
8569 curproxy->uri_auth = NULL;
8570 }
8571
Willy Tarreaude7dc882017-03-10 11:49:21 +01008572 if (curproxy->capture_name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008573 ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
8574 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008575 err_code |= ERR_WARN;
8576 }
8577
8578 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008579 ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
8580 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008581 err_code |= ERR_WARN;
8582 }
8583
8584 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008585 ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
8586 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008587 err_code |= ERR_WARN;
8588 }
8589
8590 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008591 ha_warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n",
8592 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008593 err_code |= ERR_WARN;
8594 }
8595
8596 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008597 ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
8598 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01008599 err_code |= ERR_WARN;
8600 }
8601
Willy Tarreau87cf5142011-08-19 22:57:24 +02008602 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008603 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8604 "forwardfor", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008605 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02008606 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008607 }
8608
8609 if (curproxy->options & PR_O_ORGTO) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008610 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8611 "originalto", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008612 err_code |= ERR_WARN;
8613 curproxy->options &= ~PR_O_ORGTO;
8614 }
8615
8616 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
8617 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
8618 (curproxy->cap & cfg_opts[optnum].cap) &&
8619 (curproxy->options & cfg_opts[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008620 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8621 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008622 err_code |= ERR_WARN;
8623 curproxy->options &= ~cfg_opts[optnum].val;
8624 }
8625 }
8626
8627 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
8628 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
8629 (curproxy->cap & cfg_opts2[optnum].cap) &&
8630 (curproxy->options2 & cfg_opts2[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008631 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8632 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008633 err_code |= ERR_WARN;
8634 curproxy->options2 &= ~cfg_opts2[optnum].val;
8635 }
8636 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008637
Willy Tarreau29fbe512015-08-20 19:35:14 +02008638#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008639 if (curproxy->conn_src.bind_hdr_occ) {
8640 curproxy->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01008641 ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
8642 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008643 err_code |= ERR_WARN;
8644 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008645#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008646 }
8647
Willy Tarreaubaaee002006-06-26 02:48:02 +02008648 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01008649 * ensure that we're not cross-dressing a TCP server into HTTP.
8650 */
8651 newsrv = curproxy->srv;
8652 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01008653 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008654 ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
8655 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008656 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01008657 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008658
Willy Tarreau0cec3312011-10-31 13:49:26 +01008659 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008660 ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
8661 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau0cec3312011-10-31 13:49:26 +01008662 err_code |= ERR_WARN;
8663 }
8664
Willy Tarreauc93cd162014-05-13 15:54:22 +02008665 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008666 ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
8667 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau82ffa392013-08-13 17:19:08 +02008668 err_code |= ERR_WARN;
8669 }
8670
Willy Tarreau29fbe512015-08-20 19:35:14 +02008671#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008672 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
8673 newsrv->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01008674 ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
8675 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008676 err_code |= ERR_WARN;
8677 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008678#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01008679
Willy Tarreau46deab62018-04-28 07:18:15 +02008680 if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR)
8681 curproxy->options &= ~PR_O_REUSE_MASK;
8682
Willy Tarreau4c183462017-01-06 12:21:38 +01008683 if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) {
8684 if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8685 (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP ||
8686 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8687 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008688 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",
8689 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau4c183462017-01-06 12:21:38 +01008690 err_code |= ERR_WARN;
8691 }
8692
8693
8694 if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008695 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",
8696 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau4c183462017-01-06 12:21:38 +01008697 err_code |= ERR_WARN;
8698 }
8699 }
8700
Willy Tarreau21d2af32008-02-14 20:25:24 +01008701 newsrv = newsrv->next;
8702 }
8703
Willy Tarreaue42bd962014-09-16 16:21:19 +02008704 /* check if we have a frontend with "tcp-request content" looking at L7
8705 * with no inspect-delay
8706 */
8707 if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) {
Christopher Faulete4e830d2017-09-18 14:51:41 +02008708 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
8709 if (arule->action == ACT_TCP_CAPTURE &&
8710 !(arule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008711 break;
Christopher Faulete4e830d2017-09-18 14:51:41 +02008712 if ((arule->action >= ACT_ACTION_TRK_SC0 && arule->action <= ACT_ACTION_TRK_SCMAX) &&
8713 !(arule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008714 break;
8715 }
8716
Christopher Faulete4e830d2017-09-18 14:51:41 +02008717 if (&arule->list != &curproxy->tcp_req.inspect_rules) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008718 ha_warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request"
8719 " contents were found in a frontend without any 'tcp-request inspect-delay' setting."
8720 " This means that these rules will randomly find their contents. This can be fixed by"
8721 " setting the tcp-request inspect-delay.\n",
8722 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue42bd962014-09-16 16:21:19 +02008723 err_code |= ERR_WARN;
8724 }
8725 }
8726
Christopher Fauletd7c91962015-04-30 11:48:27 +02008727 /* Check filter configuration, if any */
8728 cfgerr += flt_check(curproxy);
8729
Willy Tarreauc1a21672009-08-16 22:37:44 +02008730 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02008731 if (!curproxy->accept)
8732 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02008733
Willy Tarreauc1a21672009-08-16 22:37:44 +02008734 if (curproxy->tcp_req.inspect_delay ||
8735 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02008736 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008737
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008738 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008739 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008740 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008741 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008742
8743 /* both TCP and HTTP must check switching rules */
8744 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008745
8746 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008747 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008748 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8749 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 +01008750 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008751 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8752 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008753 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008754 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008755 }
8756
8757 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02008758 if (curproxy->tcp_req.inspect_delay ||
8759 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
8760 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
8761
Emeric Brun97679e72010-09-23 17:56:44 +02008762 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
8763 curproxy->be_rsp_ana |= AN_RES_INSPECT;
8764
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008765 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008766 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008767 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008768 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008769
8770 /* If the backend does requires RDP cookie persistence, we have to
8771 * enable the corresponding analyser.
8772 */
8773 if (curproxy->options2 & PR_O2_RDPC_PRST)
8774 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008775
8776 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008777 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008778 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8779 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 +01008780 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008781 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8782 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008783 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008784 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008785 }
Christopher Fauleta717b992018-04-10 14:43:00 +02008786
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02008787 /* Check the mux protocols, if any, for each listener and server
Christopher Fauleta717b992018-04-10 14:43:00 +02008788 * attached to the current proxy */
8789 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
8790 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
8791
8792 if (!bind_conf->mux_proto)
8793 continue;
8794 if (!(bind_conf->mux_proto->mode & mode)) {
8795 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n",
8796 proxy_type_str(curproxy), curproxy->id,
8797 (int)bind_conf->mux_proto->token.len,
8798 bind_conf->mux_proto->token.ptr,
8799 bind_conf->arg, bind_conf->file, bind_conf->line);
8800 cfgerr++;
8801 }
8802 }
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02008803 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
8804 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
8805
8806 if (!newsrv->mux_proto)
8807 continue;
8808 if (!(newsrv->mux_proto->mode & mode)) {
8809 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n",
8810 proxy_type_str(curproxy), curproxy->id,
8811 (int)newsrv->mux_proto->token.len,
8812 newsrv->mux_proto->token.ptr,
8813 newsrv->id, newsrv->conf.file, newsrv->conf.line);
8814 cfgerr++;
8815 }
8816 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008817 }
8818
8819 /***********************************************************/
8820 /* At this point, target names have already been resolved. */
8821 /***********************************************************/
8822
8823 /* Check multi-process mode compatibility */
8824
8825 if (global.nbproc > 1 && global.stats_fe) {
8826 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8827 unsigned long mask;
8828
8829 mask = nbits(global.nbproc);
8830 if (global.stats_fe->bind_proc)
8831 mask &= global.stats_fe->bind_proc;
8832
8833 if (bind_conf->bind_proc)
8834 mask &= bind_conf->bind_proc;
8835
8836 /* stop here if more than one process is used */
David Carliere6c39412015-07-02 07:00:17 +00008837 if (my_popcountl(mask) > 1)
Willy Tarreau419ead82014-09-16 13:41:21 +02008838 break;
8839 }
8840 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01008841 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 +02008842 }
8843 }
8844
8845 /* Make each frontend inherit bind-process from its listeners when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008846 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02008847 if (curproxy->bind_proc)
8848 continue;
8849
8850 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
8851 unsigned long mask;
8852
Willy Tarreaue428b082015-05-04 21:57:58 +02008853 mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008854 curproxy->bind_proc |= mask;
8855 }
8856
8857 if (!curproxy->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008858 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008859 }
8860
8861 if (global.stats_fe) {
8862 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8863 unsigned long mask;
8864
Cyril Bonté06181952016-02-24 00:14:54 +01008865 mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02008866 global.stats_fe->bind_proc |= mask;
8867 }
8868 if (!global.stats_fe->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008869 global.stats_fe->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008870 }
8871
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02008872 /* propagate bindings from frontends to backends. Don't do it if there
8873 * are any fatal errors as we must not call it with unresolved proxies.
8874 */
8875 if (!cfgerr) {
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008876 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02008877 if (curproxy->cap & PR_CAP_FE)
8878 propagate_processes(curproxy, NULL);
8879 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008880 }
8881
8882 /* Bind each unbound backend to all processes when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008883 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02008884 if (curproxy->bind_proc)
8885 continue;
Willy Tarreaue428b082015-05-04 21:57:58 +02008886 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008887 }
8888
8889 /*******************************************************/
8890 /* At this step, all proxies have a non-null bind_proc */
8891 /*******************************************************/
8892
8893 /* perform the final checks before creating tasks */
8894
Olivier Houchardfbc74e82017-11-24 16:54:05 +01008895 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02008896 struct listener *listener;
8897 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008898
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008899 /* Configure SSL for each bind line.
8900 * Note: if configuration fails at some point, the ->ctx member
8901 * remains NULL so that listeners can later detach.
8902 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008903 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01008904 if (bind_conf->xprt->prepare_bind_conf &&
8905 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008906 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008907 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008908
Willy Tarreaue6b98942007-10-29 01:09:36 +01008909 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008910 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02008911 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008912 int nbproc;
8913
8914 nbproc = my_popcountl(curproxy->bind_proc &
Cyril Bonté4920d702016-04-15 07:58:43 +02008915 (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) &
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008916 nbits(global.nbproc));
8917
8918 if (!nbproc) /* no intersection between listener and frontend */
8919 nbproc = 1;
8920
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008921 if (!listener->luid) {
8922 /* listener ID not set, use automatic numbering with first
8923 * spare entry starting with next_luid.
8924 */
8925 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
8926 listener->conf.id.key = listener->luid = next_id;
8927 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008928 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01008929 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008930
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008931 /* enable separate counters */
8932 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01008933 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01008934 if (!listener->name)
8935 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008936 }
Willy Tarreau81796be2012-09-22 19:11:47 +02008937
Willy Tarreaue6b98942007-10-29 01:09:36 +01008938 if (curproxy->options & PR_O_TCP_NOLING)
8939 listener->options |= LI_O_NOLINGER;
Willy Tarreau32368ce2012-09-06 11:10:55 +02008940 if (!listener->maxconn)
8941 listener->maxconn = curproxy->maxconn;
8942 if (!listener->backlog)
8943 listener->backlog = curproxy->backlog;
Willy Tarreau16a21472012-11-19 12:39:59 +01008944 if (!listener->maxaccept)
8945 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
8946
8947 /* we want to have an optimal behaviour on single process mode to
8948 * maximize the work at once, but in multi-process we want to keep
8949 * some fairness between processes, so we target half of the max
8950 * number of events to be balanced over all the processes the proxy
8951 * is bound to. Rememeber that maxaccept = -1 must be kept as it is
8952 * used to disable the limit.
8953 */
8954 if (listener->maxaccept > 0) {
8955 if (nbproc > 1)
8956 listener->maxaccept = (listener->maxaccept + 1) / 2;
8957 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
8958 }
8959
Willy Tarreau9903f0e2015-04-04 18:50:31 +02008960 listener->accept = session_accept_fd;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008961 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01008962 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01008963
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008964 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02008965 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008966
Willy Tarreau620408f2016-10-21 16:37:51 +02008967 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
8968 listener->options |= LI_O_TCP_L5_RULES;
8969
Willy Tarreaude3041d2010-05-31 10:56:17 +02008970 if (curproxy->mon_mask.s_addr)
8971 listener->options |= LI_O_CHK_MONNET;
8972
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008973 /* smart accept mode is automatic in HTTP mode */
8974 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008975 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008976 !(curproxy->no_options2 & PR_O2_SMARTACC)))
8977 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01008978 }
8979
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008980 /* Release unused SSL configs */
8981 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01008982 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
8983 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008984 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008985
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008986 if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) {
Willy Tarreau102df612014-05-07 23:56:38 +02008987 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02008988 int count, maxproc = 0;
8989
8990 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
David Carliere6c39412015-07-02 07:00:17 +00008991 count = my_popcountl(bind_conf->bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02008992 if (count > maxproc)
8993 maxproc = count;
8994 }
8995 /* backends have 0, frontends have 1 or more */
8996 if (maxproc != 1)
Christopher Faulet767a84b2017-11-24 16:50:31 +01008997 ha_warning("Proxy '%s': in multi-process mode, stats will be"
8998 " limited to process assigned to the current request.\n",
8999 curproxy->id);
Willy Tarreaueb791e02014-09-16 15:11:04 +02009000
Willy Tarreau102df612014-05-07 23:56:38 +02009001 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009002 ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
9003 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01009004 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01009005 }
Willy Tarreau102df612014-05-07 23:56:38 +02009006 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009007 ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
9008 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01009009 }
9010 }
Willy Tarreau918ff602011-07-25 16:33:49 +02009011
9012 /* create the task associated with the proxy */
Emeric Brunc60def82017-09-27 14:59:38 +02009013 curproxy->task = task_new(MAX_THREADS_MASK);
Willy Tarreau918ff602011-07-25 16:33:49 +02009014 if (curproxy->task) {
9015 curproxy->task->context = curproxy;
9016 curproxy->task->process = manage_proxy;
Willy Tarreau918ff602011-07-25 16:33:49 +02009017 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009018 ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
9019 curproxy->id);
Willy Tarreau918ff602011-07-25 16:33:49 +02009020 cfgerr++;
9021 }
Willy Tarreaub369a042014-09-16 13:21:03 +02009022 }
9023
Willy Tarreaufbb78422011-06-05 15:38:35 +02009024 /* automatically compute fullconn if not set. We must not do it in the
9025 * loop above because cross-references are not yet fully resolved.
9026 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009027 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02009028 /* If <fullconn> is not set, let's set it to 10% of the sum of
9029 * the possible incoming frontend's maxconns.
9030 */
9031 if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02009032 /* we have the sum of the maxconns in <total>. We only
9033 * keep 10% of that sum to set the default fullconn, with
9034 * a hard minimum of 1 (to avoid a divide by zero).
9035 */
Emeric Brun3f783572017-01-12 11:21:28 +01009036 curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10;
Willy Tarreaufbb78422011-06-05 15:38:35 +02009037 if (!curproxy->fullconn)
9038 curproxy->fullconn = 1;
9039 }
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01009040 }
9041
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009042 /*
9043 * Recount currently required checks.
9044 */
9045
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009046 for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009047 int optnum;
9048
Willy Tarreau66aa61f2009-01-18 21:44:07 +01009049 for (optnum = 0; cfg_opts[optnum].name; optnum++)
9050 if (curproxy->options & cfg_opts[optnum].val)
9051 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009052
Willy Tarreau66aa61f2009-01-18 21:44:07 +01009053 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
9054 if (curproxy->options2 & cfg_opts2[optnum].val)
9055 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01009056 }
9057
Willy Tarreau0fca4832015-05-01 19:12:05 +02009058 /* compute the required process bindings for the peers */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009059 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
Willy Tarreau0fca4832015-05-01 19:12:05 +02009060 if (curproxy->table.peers.p)
9061 curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
9062
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02009063 if (cfg_peers) {
9064 struct peers *curpeers = cfg_peers, **last;
Willy Tarreau122541c2011-09-07 21:24:49 +02009065 struct peer *p, *pb;
9066
Willy Tarreau1e273012015-05-01 19:15:17 +02009067 /* Remove all peers sections which don't have a valid listener,
9068 * which are not used by any table, or which are bound to more
9069 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02009070 */
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02009071 last = &cfg_peers;
Willy Tarreau122541c2011-09-07 21:24:49 +02009072 while (*last) {
9073 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009074
9075 if (curpeers->state == PR_STSTOPPED) {
9076 /* the "disabled" keyword was present */
9077 if (curpeers->peers_fe)
9078 stop_proxy(curpeers->peers_fe);
9079 curpeers->peers_fe = NULL;
9080 }
9081 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009082 ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
9083 curpeers->id, localpeer);
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009084 }
David Carliere6c39412015-07-02 07:00:17 +00009085 else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) {
Willy Tarreau1e273012015-05-01 19:15:17 +02009086 /* either it's totally stopped or too much used */
9087 if (curpeers->peers_fe->bind_proc) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009088 ha_alert("Peers section '%s': peers referenced by sections "
9089 "running in different processes (%d different ones). "
9090 "Check global.nbproc and all tables' bind-process "
9091 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02009092 cfgerr++;
9093 }
9094 stop_proxy(curpeers->peers_fe);
9095 curpeers->peers_fe = NULL;
9096 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009097 else {
Emeric Brunb3971ab2015-05-12 18:49:09 +02009098 peers_init_sync(curpeers);
Willy Tarreau122541c2011-09-07 21:24:49 +02009099 last = &curpeers->next;
9100 continue;
9101 }
9102
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009103 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02009104 p = curpeers->remote;
9105 while (p) {
9106 pb = p->next;
9107 free(p->id);
9108 free(p);
9109 p = pb;
9110 }
9111
9112 /* Destroy and unlink this curpeers section.
9113 * Note: curpeers is backed up into *last.
9114 */
9115 free(curpeers->id);
9116 curpeers = curpeers->next;
9117 free(*last);
9118 *last = curpeers;
9119 }
9120 }
9121
Willy Tarreau6866f3f2015-05-01 19:09:08 +02009122 /* initialize stick-tables on backend capable proxies. This must not
9123 * be done earlier because the data size may be discovered while parsing
9124 * other proxies.
9125 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009126 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau6866f3f2015-05-01 19:09:08 +02009127 if (curproxy->state == PR_STSTOPPED)
9128 continue;
9129
9130 if (!stktable_init(&curproxy->table)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009131 ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
Willy Tarreau6866f3f2015-05-01 19:09:08 +02009132 cfgerr++;
9133 }
9134 }
9135
Simon Horman0d16a402015-01-30 11:22:58 +09009136 if (mailers) {
9137 struct mailers *curmailers = mailers, **last;
9138 struct mailer *m, *mb;
9139
9140 /* Remove all mailers sections which don't have a valid listener.
9141 * This can happen when a mailers section is never referenced.
9142 */
9143 last = &mailers;
9144 while (*last) {
9145 curmailers = *last;
9146 if (curmailers->users) {
9147 last = &curmailers->next;
9148 continue;
9149 }
9150
Christopher Faulet767a84b2017-11-24 16:50:31 +01009151 ha_warning("Removing incomplete section 'mailers %s'.\n",
9152 curmailers->id);
Simon Horman0d16a402015-01-30 11:22:58 +09009153
9154 m = curmailers->mailer_list;
9155 while (m) {
9156 mb = m->next;
9157 free(m->id);
9158 free(m);
9159 m = mb;
9160 }
9161
9162 /* Destroy and unlink this curmailers section.
9163 * Note: curmailers is backed up into *last.
9164 */
9165 free(curmailers->id);
9166 curmailers = curmailers->next;
9167 free(*last);
9168 *last = curmailers;
9169 }
9170 }
9171
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02009172 /* Update server_state_file_name to backend name if backend is supposed to use
9173 * a server-state file locally defined and none has been provided */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01009174 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02009175 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
9176 curproxy->server_state_file_name == NULL)
9177 curproxy->server_state_file_name = strdup(curproxy->id);
9178 }
9179
Willy Tarreaubafbe012017-11-24 17:34:44 +01009180 pool_head_hdr_idx = create_pool("hdr_idx",
Willy Tarreauac1932d2011-10-24 19:14:41 +02009181 global.tune.max_http_hdr * sizeof(struct hdr_idx_elem),
Willy Tarreau34eb6712011-10-24 18:15:04 +02009182 MEM_F_SHARED);
9183
Ben Draut054fbee2018-04-13 15:43:04 -06009184 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
9185 if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
9186 ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n",
9187 curr_resolvers->id, curr_resolvers->conf.file,
9188 curr_resolvers->conf.line);
9189 err_code |= ERR_WARN;
9190 }
9191 }
9192
William Lallemand48b4bb42017-10-23 14:36:34 +02009193 list_for_each_entry(postparser, &postparsers, list) {
9194 if (postparser->func)
9195 cfgerr += postparser->func();
9196 }
9197
Willy Tarreaubb925012009-07-23 13:36:36 +02009198 if (cfgerr > 0)
9199 err_code |= ERR_ALERT | ERR_FATAL;
9200 out:
9201 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02009202}
9203
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009204/*
9205 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
9206 * parsing sessions.
9207 */
9208void cfg_register_keywords(struct cfg_kw_list *kwl)
9209{
9210 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
9211}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009212
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009213/*
9214 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
9215 */
9216void cfg_unregister_keywords(struct cfg_kw_list *kwl)
9217{
9218 LIST_DEL(&kwl->list);
9219 LIST_INIT(&kwl->list);
9220}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009221
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009222/* this function register new section in the haproxy configuration file.
9223 * <section_name> is the name of this new section and <section_parser>
9224 * is the called parser. If two section declaration have the same name,
9225 * only the first declared is used.
9226 */
9227int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +02009228 int (*section_parser)(const char *, int, char **, int),
9229 int (*post_section_parser)())
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009230{
9231 struct cfg_section *cs;
9232
Willy Tarreau5e4261b2016-05-17 16:16:09 +02009233 list_for_each_entry(cs, &sections, list) {
9234 if (strcmp(cs->section_name, section_name) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009235 ha_alert("register section '%s': already registered.\n", section_name);
Willy Tarreau5e4261b2016-05-17 16:16:09 +02009236 return 0;
9237 }
9238 }
9239
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009240 cs = calloc(1, sizeof(*cs));
9241 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009242 ha_alert("register section '%s': out of memory.\n", section_name);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009243 return 0;
9244 }
9245
9246 cs->section_name = section_name;
9247 cs->section_parser = section_parser;
William Lallemandd2ff56d2017-10-16 11:06:50 +02009248 cs->post_section_parser = post_section_parser;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009249
9250 LIST_ADDQ(&sections, &cs->list);
9251
9252 return 1;
9253}
9254
William Lallemand48b4bb42017-10-23 14:36:34 +02009255/* this function register a new function which will be called once the haproxy
9256 * configuration file has been parsed. It's useful to check dependencies
9257 * between sections or to resolve items once everything is parsed.
9258 */
9259int cfg_register_postparser(char *name, int (*func)())
9260{
9261 struct cfg_postparser *cp;
9262
9263 cp = calloc(1, sizeof(*cp));
9264 if (!cp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01009265 ha_alert("register postparser '%s': out of memory.\n", name);
William Lallemand48b4bb42017-10-23 14:36:34 +02009266 return 0;
9267 }
9268 cp->name = name;
9269 cp->func = func;
9270
9271 LIST_ADDQ(&postparsers, &cp->list);
9272
9273 return 1;
9274}
9275
Willy Tarreaubaaee002006-06-26 02:48:02 +02009276/*
David Carlier845efb52015-09-25 11:49:18 +01009277 * free all config section entries
9278 */
9279void cfg_unregister_sections(void)
9280{
9281 struct cfg_section *cs, *ics;
9282
9283 list_for_each_entry_safe(cs, ics, &sections, list) {
9284 LIST_DEL(&cs->list);
9285 free(cs);
9286 }
9287}
9288
Christopher Faulet7110b402016-10-26 11:09:44 +02009289void cfg_backup_sections(struct list *backup_sections)
9290{
9291 struct cfg_section *cs, *ics;
9292
9293 list_for_each_entry_safe(cs, ics, &sections, list) {
9294 LIST_DEL(&cs->list);
9295 LIST_ADDQ(backup_sections, &cs->list);
9296 }
9297}
9298
9299void cfg_restore_sections(struct list *backup_sections)
9300{
9301 struct cfg_section *cs, *ics;
9302
9303 list_for_each_entry_safe(cs, ics, backup_sections, list) {
9304 LIST_DEL(&cs->list);
9305 LIST_ADDQ(&sections, &cs->list);
9306 }
9307}
9308
Willy Tarreau659fbf02016-05-26 17:55:28 +02009309__attribute__((constructor))
9310static void cfgparse_init(void)
9311{
9312 /* Register internal sections */
William Lallemandd2ff56d2017-10-16 11:06:50 +02009313 cfg_register_section("listen", cfg_parse_listen, NULL);
9314 cfg_register_section("frontend", cfg_parse_listen, NULL);
9315 cfg_register_section("backend", cfg_parse_listen, NULL);
9316 cfg_register_section("defaults", cfg_parse_listen, NULL);
9317 cfg_register_section("global", cfg_parse_global, NULL);
9318 cfg_register_section("userlist", cfg_parse_users, NULL);
9319 cfg_register_section("peers", cfg_parse_peers, NULL);
9320 cfg_register_section("mailers", cfg_parse_mailers, NULL);
9321 cfg_register_section("namespace_list", cfg_parse_netns, NULL);
9322 cfg_register_section("resolvers", cfg_parse_resolvers, NULL);
Willy Tarreau659fbf02016-05-26 17:55:28 +02009323}
9324
David Carlier845efb52015-09-25 11:49:18 +01009325/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02009326 * Local variables:
9327 * c-indent-level: 8
9328 * c-basic-offset: 8
9329 * End:
9330 */