blob: b7c85fa4030034fa2ccb472ede5a210ab9a59a54 [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>
Christopher Fauletd7c91962015-04-30 11:48:27 +020048#include <types/filters.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020049#include <types/global.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010050#include <types/obj_type.h>
Emeric Brun32da3c42010-09-23 18:39:19 +020051#include <types/peers.h>
Simon Horman0d16a402015-01-30 11:22:58 +090052#include <types/mailers.h>
Baptiste Assmann325137d2015-04-13 23:40:55 +020053#include <types/dns.h>
William Lallemand9ed62032016-11-21 17:49:11 +010054#include <types/stats.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020055
Willy Tarreaueb0c6142007-05-07 00:53:22 +020056#include <proto/acl.h>
Christopher Faulet4fce0d82017-09-18 11:57:31 +020057#include <proto/action.h>
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +010058#include <proto/auth.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020059#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020060#include <proto/channel.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020061#include <proto/checks.h>
Baptiste Assmann201c07f2017-05-22 15:17:15 +020062#include <proto/dns.h>
William Lallemand9ed62032016-11-21 17:49:11 +010063#include <proto/stats.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020064#include <proto/filters.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020065#include <proto/frontend.h>
Willy Tarreau34eb6712011-10-24 18:15:04 +020066#include <proto/hdr_idx.h>
Willy Tarreau61c112a2018-10-02 16:43:32 +020067#include <proto/http_rules.h>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020068#include <proto/lb_chash.h>
Willy Tarreauf09c6602012-02-13 17:12:08 +010069#include <proto/lb_fas.h>
Willy Tarreauf89c1872009-10-01 11:19:37 +020070#include <proto/lb_fwlc.h>
71#include <proto/lb_fwrr.h>
72#include <proto/lb_map.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020073#include <proto/listener.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020074#include <proto/log.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020075#include <proto/protocol.h>
Willy Tarreaue6b98942007-10-29 01:09:36 +010076#include <proto/proto_http.h>
Willy Tarreau2b5652f2006-12-31 17:46:05 +010077#include <proto/proxy.h>
Emeric Brun32da3c42010-09-23 18:39:19 +020078#include <proto/peers.h>
Willy Tarreaucd3b0942012-04-27 21:52:18 +020079#include <proto/sample.h>
Willy Tarreau9903f0e2015-04-04 18:50:31 +020080#include <proto/session.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020081#include <proto/server.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020082#include <proto/stream.h>
Emeric Brunb982a3d2010-01-04 15:45:53 +010083#include <proto/stick_table.h>
Willy Tarreau39713102016-11-25 15:49:32 +010084#include <proto/task.h>
85#include <proto/tcp_rules.h>
Olivier Houchard673867c2018-05-25 16:58:52 +020086#include <proto/connection.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020087
88
Willy Tarreauf3c69202006-07-09 16:42:34 +020089/* This is the SSLv3 CLIENT HELLO packet used in conjunction with the
90 * ssl-hello-chk option to ensure that the remote server speaks SSL.
91 *
92 * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details.
93 */
94const char sslv3_client_hello_pkt[] = {
95 "\x16" /* ContentType : 0x16 = Hanshake */
96 "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */
97 "\x00\x79" /* ContentLength : 0x79 bytes after this one */
98 "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */
99 "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */
100 "\x03\x00" /* Hello Version : 0x0300 = v3 */
101 "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */
102 "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */
103 "\x00" /* Session ID length : empty (no session ID) */
104 "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */
105 "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */
106 "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */
107 "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */
108 "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */
109 "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */
110 "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18"
111 "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F"
112 "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33"
113 "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37"
114 "\x00\x38" "\x00\x39" "\x00\x3A"
115 "\x01" /* Compression Length : 0x01 = 1 byte for types */
116 "\x00" /* Compression Type : 0x00 = NULL compression */
117};
118
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +0100119/* Used to chain configuration sections definitions. This list
120 * stores struct cfg_section
121 */
122struct list sections = LIST_HEAD_INIT(sections);
123
William Lallemand48b4bb42017-10-23 14:36:34 +0200124struct list postparsers = LIST_HEAD_INIT(postparsers);
125
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100126char *cursection = NULL;
127struct proxy defproxy = { }; /* fake proxy used to assign default values on all instances */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200128int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */
Willy Tarreau5af24ef2009-03-15 15:23:16 +0100129int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
Christopher Faulet79bdef32016-11-04 22:36:15 +0100130char *cfg_scope = NULL; /* the current scope during the configuration parsing */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200131
Willy Tarreau5b2c3362008-07-09 19:39:06 +0200132/* List head of all known configuration keywords */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100133struct cfg_kw_list cfg_keywords = {
Willy Tarreau5b2c3362008-07-09 19:39:06 +0200134 .list = LIST_HEAD_INIT(cfg_keywords.list)
135};
136
Willy Tarreaubaaee002006-06-26 02:48:02 +0200137/*
138 * converts <str> to a list of listeners which are dynamically allocated.
139 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
140 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
141 * - <port> is a numerical port from 1 to 65535 ;
142 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
143 * This can be repeated as many times as necessary, separated by a coma.
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200144 * Function returns 1 for success or 0 if error. In case of errors, if <err> is
145 * not NULL, it must be a valid pointer to either NULL or a freeable area that
146 * will be replaced with an error message.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200147 */
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200148int 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 +0200149{
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100150 char *next, *dupstr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200151 int port, end;
152
153 next = dupstr = strdup(str);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200154
Willy Tarreaubaaee002006-06-26 02:48:02 +0200155 while (next && *next) {
William Lallemand75ea0a02017-11-15 19:02:58 +0100156 int inherited = 0;
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200157 struct sockaddr_storage *ss2;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100158 int fd = -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200159
160 str = next;
161 /* 1) look for the end of the first address */
Krzysztof Piotr Oledzki52d522b2009-01-27 16:57:08 +0100162 if ((next = strchr(str, ',')) != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200163 *next++ = 0;
164 }
165
Willy Tarreau48ef4c92017-01-06 18:32:38 +0100166 ss2 = str2sa_range(str, NULL, &port, &end, err,
Willy Tarreau72b8c1f2015-09-08 15:50:19 +0200167 curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
Thierry FOURNIER7fe3be72015-09-26 20:03:36 +0200168 NULL, 1);
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100169 if (!ss2)
170 goto fail;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200171
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100172 if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100173 if (!port && !end) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200174 memprintf(err, "missing port number: '%s'\n", str);
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100175 goto fail;
Emeric Bruned760922010-10-22 17:59:25 +0200176 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200177
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100178 if (!port || !end) {
179 memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str);
180 goto fail;
181 }
182
Emeric Bruned760922010-10-22 17:59:25 +0200183 if (port < 1 || port > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200184 memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str);
Emeric Bruned760922010-10-22 17:59:25 +0200185 goto fail;
186 }
187
188 if (end < 1 || end > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200189 memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str);
Emeric Bruned760922010-10-22 17:59:25 +0200190 goto fail;
191 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200192 }
Willy Tarreau40aa0702013-03-10 23:51:38 +0100193 else if (ss2->ss_family == AF_UNSPEC) {
194 socklen_t addr_len;
William Lallemand75ea0a02017-11-15 19:02:58 +0100195 inherited = 1;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100196
197 /* We want to attach to an already bound fd whose number
198 * is in the addr part of ss2 when cast to sockaddr_in.
199 * Note that by definition there is a single listener.
200 * We still have to determine the address family to
201 * register the correct protocol.
202 */
203 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
204 addr_len = sizeof(*ss2);
205 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
206 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
207 goto fail;
208 }
209
210 port = end = get_host_port(ss2);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200211
212 } else if (ss2->ss_family == AF_CUST_SOCKPAIR) {
213 socklen_t addr_len;
214 inherited = 1;
215
216 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
217 addr_len = sizeof(*ss2);
218 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
219 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
220 goto fail;
221 }
222
223 ss2->ss_family = AF_CUST_SOCKPAIR; /* reassign AF_CUST_SOCKPAIR because of getsockname */
224 port = end = 0;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100225 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200226
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100227 /* OK the address looks correct */
William Lallemand75ea0a02017-11-15 19:02:58 +0100228 if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) {
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200229 memprintf(err, "%s for address '%s'.\n", *err, str);
230 goto fail;
231 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200232 } /* end while(next) */
233 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200234 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200235 fail:
236 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200237 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200238}
239
William Lallemand6e62fb62015-04-28 16:55:23 +0200240/*
Willy Tarreauece9b072016-12-21 22:41:44 +0100241 * Report an error in <msg> when there are too many arguments. This version is
242 * intended to be used by keyword parsers so that the message will be included
243 * into the general error message. The index is the current keyword in args.
244 * Return 0 if the number of argument is correct, otherwise build a message and
245 * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The
246 * message may also be null, it will simply not be produced (useful to check only).
247 * <msg> and <err_code> are only affected on error.
248 */
249int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code)
250{
251 int i;
252
253 if (!*args[index + maxarg + 1])
254 return 0;
255
256 if (msg) {
257 *msg = NULL;
258 memprintf(msg, "%s", args[0]);
259 for (i = 1; i <= index; i++)
260 memprintf(msg, "%s %s", *msg, args[i]);
261
262 memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]);
263 }
264 if (err_code)
265 *err_code |= ERR_ALERT | ERR_FATAL;
266
267 return 1;
268}
269
270/*
271 * same as too_many_args_idx with a 0 index
272 */
273int too_many_args(int maxarg, char **args, char **msg, int *err_code)
274{
275 return too_many_args_idx(maxarg, 0, args, msg, err_code);
276}
277
278/*
William Lallemand6e62fb62015-04-28 16:55:23 +0200279 * Report a fatal Alert when there is too much arguments
280 * The index is the current keyword in args
281 * Return 0 if the number of argument is correct, otherwise emit an alert and return 1
282 * Fill err_code with an ERR_ALERT and an ERR_FATAL
283 */
284int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code)
285{
286 char *kw = NULL;
287 int i;
288
289 if (!*args[index + maxarg + 1])
290 return 0;
291
292 memprintf(&kw, "%s", args[0]);
293 for (i = 1; i <= index; i++) {
294 memprintf(&kw, "%s %s", kw, args[i]);
295 }
296
Christopher Faulet767a84b2017-11-24 16:50:31 +0100297 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 +0200298 free(kw);
299 *err_code |= ERR_ALERT | ERR_FATAL;
300 return 1;
301}
302
303/*
304 * same as alertif_too_many_args_idx with a 0 index
305 */
306int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code)
307{
308 return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code);
309}
310
Willy Tarreau61d18892009-03-31 10:49:21 +0200311
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100312/* Report it if a request ACL condition uses some keywords that are incompatible
313 * with the place where the ACL is used. It returns either 0 or ERR_WARN so that
314 * its result can be or'ed with err_code. Note that <cond> may be NULL and then
315 * will be ignored.
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100316 */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100317int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100318{
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100319 const struct acl *acl;
Willy Tarreau93fddf12013-03-31 22:59:32 +0200320 const char *kw;
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100321
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100322 if (!cond)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100323 return 0;
324
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100325 acl = acl_cond_conflicts(cond, where);
326 if (acl) {
327 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100328 ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n",
329 file, line, acl->name, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100330 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100331 ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
332 file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100333 return ERR_WARN;
334 }
335 if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100336 return 0;
337
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100338 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100339 ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
340 file, line, acl->name, kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100341 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100342 ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
343 file, line, kw, sample_ckp_names(where));
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100344 return ERR_WARN;
345}
346
Christopher Faulet62519022017-10-16 15:49:32 +0200347/* Parse a string representing a process number or a set of processes. It must
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100348 * be "all", "odd", "even", a number between 1 and <LONGBITS> or a range with
Christopher Faulet5ab51772017-11-22 11:21:58 +0100349 * two such numbers delimited by a dash ('-'). On success, it returns
350 * 0. otherwise it returns 1 with an error message in <err>.
Christopher Faulet62519022017-10-16 15:49:32 +0200351 *
352 * Note: this function can also be used to parse a thread number or a set of
353 * threads.
354 */
Christopher Faulet26028f62017-11-22 15:01:51 +0100355int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200356{
Christopher Faulet26028f62017-11-22 15:01:51 +0100357 if (autoinc) {
358 *autoinc = 0;
359 if (strncmp(arg, "auto:", 5) == 0) {
360 arg += 5;
361 *autoinc = 1;
362 }
363 }
364
Christopher Faulet62519022017-10-16 15:49:32 +0200365 if (strcmp(arg, "all") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100366 *proc |= ~0UL;
Christopher Faulet62519022017-10-16 15:49:32 +0200367 else if (strcmp(arg, "odd") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100368 *proc |= ~0UL/3UL; /* 0x555....555 */
Christopher Faulet62519022017-10-16 15:49:32 +0200369 else if (strcmp(arg, "even") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100370 *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Christopher Faulet62519022017-10-16 15:49:32 +0200371 else {
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100372 char *dash;
373 unsigned int low, high;
374
Christopher Faulet5ab51772017-11-22 11:21:58 +0100375 if (!isdigit((int)*arg)) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100376 memprintf(err, "'%s' is not a valid number.\n", arg);
Christopher Faulet5ab51772017-11-22 11:21:58 +0100377 return -1;
378 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100379
380 low = high = str2uic(arg);
381 if ((dash = strchr(arg, '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100382 high = ((!*(dash+1)) ? LONGBITS : str2uic(dash + 1));
383
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100384 if (high < low) {
385 unsigned int swap = low;
386 low = high;
387 high = swap;
388 }
389
Christopher Faulet5ab51772017-11-22 11:21:58 +0100390 if (low < 1 || low > LONGBITS || high > LONGBITS) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100391 memprintf(err, "'%s' is not a valid number/range."
392 " It supports numbers from 1 to %d.\n",
Christopher Faulet5ab51772017-11-22 11:21:58 +0100393 arg, LONGBITS);
394 return 1;
395 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100396
397 for (;low <= high; low++)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100398 *proc |= 1UL << (low-1);
Christopher Faulet62519022017-10-16 15:49:32 +0200399 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100400
Christopher Faulet5ab51772017-11-22 11:21:58 +0100401 return 0;
Christopher Faulet62519022017-10-16 15:49:32 +0200402}
403
David Carlier7e351ee2017-12-01 09:14:02 +0000404#ifdef USE_CPU_AFFINITY
Christopher Faulet62519022017-10-16 15:49:32 +0200405/* Parse cpu sets. Each CPU set is either a unique number between 0 and
406 * <LONGBITS> or a range with two such numbers delimited by a dash
407 * ('-'). Multiple CPU numbers or ranges may be specified. On success, it
408 * returns 0. otherwise it returns 1 with an error message in <err>.
409 */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100410unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200411{
412 int cur_arg = 0;
413
414 *cpu_set = 0;
415 while (*args[cur_arg]) {
416 char *dash;
417 unsigned int low, high;
418
419 if (!isdigit((int)*args[cur_arg])) {
420 memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]);
421 return -1;
422 }
423
424 low = high = str2uic(args[cur_arg]);
425 if ((dash = strchr(args[cur_arg], '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100426 high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1));
Christopher Faulet62519022017-10-16 15:49:32 +0200427
428 if (high < low) {
429 unsigned int swap = low;
430 low = high;
431 high = swap;
432 }
433
434 if (high >= LONGBITS) {
435 memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1);
436 return 1;
437 }
438
439 while (low <= high)
440 *cpu_set |= 1UL << low++;
441
442 cur_arg++;
443 }
444 return 0;
445}
David Carlier7e351ee2017-12-01 09:14:02 +0000446#endif
447
Willy Tarreau915e1eb2009-06-22 15:48:36 +0200448void init_default_instance()
Willy Tarreaubaaee002006-06-26 02:48:02 +0200449{
Willy Tarreau97cb7802010-01-03 20:23:58 +0100450 init_new_proxy(&defproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200451 defproxy.mode = PR_MODE_TCP;
452 defproxy.state = PR_STNEW;
453 defproxy.maxconn = cfg_maxpconn;
454 defproxy.conn_retries = CONN_RETRIES;
Joseph Lynch726ab712015-05-11 23:25:34 -0700455 defproxy.redispatch_after = 0;
Olivier Houchard86006a52018-12-14 19:37:49 +0100456 defproxy.options = PR_O_REUSE_SAFE;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100457 defproxy.max_out_conns = MAX_SRV_LIST;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100458
Simon Horman66183002013-02-23 10:16:43 +0900459 defproxy.defsrv.check.inter = DEF_CHKINTR;
460 defproxy.defsrv.check.fastinter = 0;
461 defproxy.defsrv.check.downinter = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900462 defproxy.defsrv.agent.inter = DEF_CHKINTR;
463 defproxy.defsrv.agent.fastinter = 0;
464 defproxy.defsrv.agent.downinter = 0;
Simon Horman58c32972013-11-25 10:46:38 +0900465 defproxy.defsrv.check.rise = DEF_RISETIME;
466 defproxy.defsrv.check.fall = DEF_FALLTIME;
467 defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
468 defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200469 defproxy.defsrv.check.port = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900470 defproxy.defsrv.agent.port = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100471 defproxy.defsrv.maxqueue = 0;
472 defproxy.defsrv.minconn = 0;
473 defproxy.defsrv.maxconn = 0;
Olivier Houchard006e3102018-12-10 18:30:32 +0100474 defproxy.defsrv.max_idle_conns = -1;
Olivier Houchardb7b3faa2018-12-14 18:15:36 +0100475 defproxy.defsrv.pool_purge_delay = 1000;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100476 defproxy.defsrv.slowstart = 0;
477 defproxy.defsrv.onerror = DEF_HANA_ONERR;
478 defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
479 defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
Simon Horman64e34162015-02-06 11:11:57 +0900480
481 defproxy.email_alert.level = LOG_ALERT;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +0200482 defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200483}
484
Frédéric Lécaille18251032019-01-11 11:07:15 +0100485/* Allocate and initialize the frontend of a "peers" section found in
486 * file <file> at line <linenum> with <id> as ID.
487 * Return 0 if succeeded, -1 if not.
488 */
489static int init_peers_frontend(const char *file, int linenum,
490 const char *id, struct peers *peers)
491{
492 struct proxy *p;
493
494 p = calloc(1, sizeof *p);
495 if (!p) {
496 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
497 return -1;
498 }
499
500 init_new_proxy(p);
501 p->parent = peers;
502 p->id = strdup(id);
503 p->conf.args.file = p->conf.file = strdup(file);
504 p->conf.args.line = p->conf.line = linenum;
505 peers_setup_frontend(p);
506 peers->peers_fe = p;
507
508 return 0;
509}
Willy Tarreauade5ec42010-01-28 19:33:49 +0100510
Willy Tarreaubaaee002006-06-26 02:48:02 +0200511/*
William Lallemand51097192015-04-14 16:35:22 +0200512 * Parse a line in a <listen>, <frontend> or <backend> section.
Willy Tarreau93893792009-07-23 13:19:11 +0200513 * Returns the error code, 0 if OK, or any combination of :
514 * - ERR_ABORT: must abort ASAP
515 * - ERR_FATAL: we can continue parsing but not start the service
516 * - ERR_WARN: a warning has been emitted
517 * - ERR_ALERT: an alert has been emitted
518 * Only the two first ones can stop processing, the two others are just
519 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200520 */
Emeric Brun32da3c42010-09-23 18:39:19 +0200521int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
522{
523 static struct peers *curpeers = NULL;
524 struct peer *newpeer = NULL;
525 const char *err;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200526 struct bind_conf *bind_conf;
527 struct listener *l;
Emeric Brun32da3c42010-09-23 18:39:19 +0200528 int err_code = 0;
Willy Tarreau902636f2013-03-10 19:44:48 +0100529 char *errmsg = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +0200530
531 if (strcmp(args[0], "peers") == 0) { /* new peers section */
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100532 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100533 ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum);
Willy Tarreau54984722014-02-16 08:20:13 +0100534 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100535 goto out;
536 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200537
William Lallemand6e62fb62015-04-28 16:55:23 +0200538 if (alertif_too_many_args(1, file, linenum, args, &err_code))
539 goto out;
540
Emeric Brun32da3c42010-09-23 18:39:19 +0200541 err = invalid_char(args[1]);
542 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100543 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
544 file, linenum, *err, args[0], args[1]);
Willy Tarreau54984722014-02-16 08:20:13 +0100545 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100546 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200547 }
548
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200549 for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +0200550 /*
551 * If there are two proxies with the same name only following
552 * combinations are allowed:
553 */
554 if (strcmp(curpeers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100555 ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n",
556 file, linenum, args[1], curpeers->conf.file, curpeers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +0200557 err_code |= ERR_ALERT | ERR_FATAL;
Emeric Brun32da3c42010-09-23 18:39:19 +0200558 }
559 }
560
Vincent Bernat02779b62016-04-03 13:48:43 +0200561 if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100562 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +0200563 err_code |= ERR_ALERT | ERR_ABORT;
564 goto out;
565 }
566
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200567 curpeers->next = cfg_peers;
568 cfg_peers = curpeers;
Willy Tarreau8113a5d2012-10-04 08:01:43 +0200569 curpeers->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +0200570 curpeers->conf.line = linenum;
571 curpeers->last_change = now.tv_sec;
572 curpeers->id = strdup(args[1]);
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200573 curpeers->state = PR_STNEW;
Emeric Brun32da3c42010-09-23 18:39:19 +0200574 }
575 else if (strcmp(args[0], "peer") == 0) { /* peer definition */
David du Colombier6f5ccb12011-03-10 22:26:24 +0100576 struct sockaddr_storage *sk;
Willy Tarreau2aa38802013-02-20 19:20:59 +0100577 int port1, port2;
Willy Tarreaub36487e2013-03-10 18:37:42 +0100578 struct protocol *proto;
Emeric Brun32da3c42010-09-23 18:39:19 +0200579
580 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100581 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
582 file, linenum, args[0]);
Emeric Brun32da3c42010-09-23 18:39:19 +0200583 err_code |= ERR_ALERT | ERR_FATAL;
584 goto out;
585 }
586
587 err = invalid_char(args[1]);
588 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100589 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
590 file, linenum, *err, args[1]);
Emeric Brun32da3c42010-09-23 18:39:19 +0200591 err_code |= ERR_ALERT | ERR_FATAL;
592 goto out;
593 }
594
Vincent Bernat02779b62016-04-03 13:48:43 +0200595 if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100596 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +0200597 err_code |= ERR_ALERT | ERR_ABORT;
598 goto out;
599 }
600
601 /* the peers are linked backwards first */
602 curpeers->count++;
603 newpeer->next = curpeers->remote;
604 curpeers->remote = newpeer;
Willy Tarreau8113a5d2012-10-04 08:01:43 +0200605 newpeer->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +0200606 newpeer->conf.line = linenum;
607
608 newpeer->last_change = now.tv_sec;
609 newpeer->id = strdup(args[1]);
610
Willy Tarreau48ef4c92017-01-06 18:32:38 +0100611 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau2aa38802013-02-20 19:20:59 +0100612 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100613 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Willy Tarreau2aa38802013-02-20 19:20:59 +0100614 err_code |= ERR_ALERT | ERR_FATAL;
615 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200616 }
Willy Tarreaub36487e2013-03-10 18:37:42 +0100617
618 proto = protocol_by_family(sk->ss_family);
619 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100620 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
621 file, linenum, args[0], args[1]);
Willy Tarreaub36487e2013-03-10 18:37:42 +0100622 err_code |= ERR_ALERT | ERR_FATAL;
623 goto out;
624 }
Willy Tarreau2aa38802013-02-20 19:20:59 +0100625
626 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100627 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
628 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +0200629 err_code |= ERR_ALERT | ERR_FATAL;
630 goto out;
631 }
632
Willy Tarreau2aa38802013-02-20 19:20:59 +0100633 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100634 ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
635 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +0200636 err_code |= ERR_ALERT | ERR_FATAL;
637 goto out;
638 }
Willy Tarreau2aa38802013-02-20 19:20:59 +0100639
Emeric Brun32da3c42010-09-23 18:39:19 +0200640 newpeer->addr = *sk;
Willy Tarreaub36487e2013-03-10 18:37:42 +0100641 newpeer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +0100642 newpeer->xprt = xprt_get(XPRT_RAW);
Willy Tarreaud02394b2012-05-11 18:32:18 +0200643 newpeer->sock_init_arg = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100644 HA_SPIN_INIT(&newpeer->lock);
Willy Tarreau26d8c592012-05-07 18:12:14 +0200645
Frédéric Lécaille6617e762018-04-25 15:13:38 +0200646 if (strcmp(newpeer->id, localpeer) != 0)
647 /* We are done. */
648 goto out;
649
Frédéric Lécaille4ba51982018-04-25 15:32:18 +0200650 if (cfg_peers->local) {
651 ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n",
652 file, linenum, args[0], args[1],
653 curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line);
654 err_code |= ERR_FATAL;
655 goto out;
656 }
657
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100658 /* Current is local peer, it define a frontend */
659 newpeer->local = 1;
Emeric Brun32da3c42010-09-23 18:39:19 +0200660
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100661 if (!curpeers->peers_fe) {
662 if (init_peers_frontend(file, linenum, args[1], curpeers) != 0) {
663 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
664 err_code |= ERR_ALERT | ERR_ABORT;
665 goto out;
666 }
Willy Tarreau4348fad2012-09-20 16:48:07 +0200667
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100668 bind_conf = bind_conf_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW));
Willy Tarreau4348fad2012-09-20 16:48:07 +0200669
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100670 if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
671 if (errmsg && *errmsg) {
672 indent_msg(&errmsg, 2);
673 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Willy Tarreau4348fad2012-09-20 16:48:07 +0200674 }
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100675 else
676 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
677 file, linenum, args[0], args[1], args[2]);
Willy Tarreau8b8fd562013-01-18 11:12:27 +0100678 err_code |= ERR_FATAL;
679 goto out;
680 }
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100681
682 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
683 l->maxaccept = 1;
684 l->maxconn = curpeers->peers_fe->maxconn;
685 l->backlog = curpeers->peers_fe->backlog;
686 l->accept = session_accept_fd;
687 l->analysers |= curpeers->peers_fe->fe_req_ana;
688 l->default_target = curpeers->peers_fe->default_target;
689 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
690 global.maxsock += l->maxconn;
691 }
Frédéric Lécaille4ba51982018-04-25 15:32:18 +0200692 cfg_peers->local = newpeer;
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100693 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200694 } /* neither "peer" nor "peers" */
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200695 else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
696 curpeers->state = PR_STSTOPPED;
697 }
698 else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
699 curpeers->state = PR_STNEW;
700 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200701 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100702 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Emeric Brun32da3c42010-09-23 18:39:19 +0200703 err_code |= ERR_ALERT | ERR_FATAL;
704 goto out;
705 }
706
707out:
Willy Tarreau902636f2013-03-10 19:44:48 +0100708 free(errmsg);
Emeric Brun32da3c42010-09-23 18:39:19 +0200709 return err_code;
710}
711
Baptiste Assmann325137d2015-04-13 23:40:55 +0200712/*
713 * Parse a <resolvers> section.
714 * Returns the error code, 0 if OK, or any combination of :
715 * - ERR_ABORT: must abort ASAP
716 * - ERR_FATAL: we can continue parsing but not start the service
717 * - ERR_WARN: a warning has been emitted
718 * - ERR_ALERT: an alert has been emitted
719 * Only the two first ones can stop processing, the two others are just
720 * indicators.
721 */
722int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
723{
724 static struct dns_resolvers *curr_resolvers = NULL;
725 struct dns_nameserver *newnameserver = NULL;
726 const char *err;
727 int err_code = 0;
728 char *errmsg = NULL;
729
730 if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */
731 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100732 ha_alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200733 err_code |= ERR_ALERT | ERR_ABORT;
734 goto out;
735 }
736
737 err = invalid_char(args[1]);
738 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100739 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
740 file, linenum, *err, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200741 err_code |= ERR_ALERT | ERR_ABORT;
742 goto out;
743 }
744
745 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
746 /* Error if two resolvers owns the same name */
747 if (strcmp(curr_resolvers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100748 ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n",
749 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200750 err_code |= ERR_ALERT | ERR_ABORT;
751 }
752 }
753
Vincent Bernat02779b62016-04-03 13:48:43 +0200754 if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100755 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200756 err_code |= ERR_ALERT | ERR_ABORT;
757 goto out;
758 }
759
760 /* default values */
761 LIST_ADDQ(&dns_resolvers, &curr_resolvers->list);
762 curr_resolvers->conf.file = strdup(file);
763 curr_resolvers->conf.line = linenum;
764 curr_resolvers->id = strdup(args[1]);
765 curr_resolvers->query_ids = EB_ROOT;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +0200766 /* default maximum response size */
767 curr_resolvers->accepted_payload_size = 512;
Baptiste Assmann987e16d2016-11-02 22:23:31 +0100768 /* default hold period for nx, other, refuse and timeout is 30s */
769 curr_resolvers->hold.nx = 30000;
770 curr_resolvers->hold.other = 30000;
771 curr_resolvers->hold.refused = 30000;
772 curr_resolvers->hold.timeout = 30000;
Baptiste Assmann686408b2017-08-18 10:15:42 +0200773 curr_resolvers->hold.obsolete = 0;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200774 /* default hold period for valid is 10s */
Baptiste Assmann4c5490a2015-07-14 21:42:49 +0200775 curr_resolvers->hold.valid = 10000;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200776 curr_resolvers->timeout.resolve = 1000;
777 curr_resolvers->timeout.retry = 1000;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200778 curr_resolvers->resolve_retries = 3;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200779 curr_resolvers->nb_nameservers = 0;
780 LIST_INIT(&curr_resolvers->nameservers);
781 LIST_INIT(&curr_resolvers->resolutions.curr);
782 LIST_INIT(&curr_resolvers->resolutions.wait);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100783 HA_SPIN_INIT(&curr_resolvers->lock);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200784 }
785 else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
786 struct sockaddr_storage *sk;
787 int port1, port2;
788 struct protocol *proto;
789
790 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100791 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
792 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200793 err_code |= ERR_ALERT | ERR_FATAL;
794 goto out;
795 }
796
797 err = invalid_char(args[1]);
798 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100799 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
800 file, linenum, *err, args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200801 err_code |= ERR_ALERT | ERR_FATAL;
802 goto out;
803 }
804
Christopher Faulet67957bd2017-09-27 11:00:59 +0200805 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
Baptiste Assmanna315c552015-11-02 22:55:49 +0100806 /* Error if two resolvers owns the same name */
807 if (strcmp(newnameserver->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100808 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 -0600809 file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line);
Baptiste Assmanna315c552015-11-02 22:55:49 +0100810 err_code |= ERR_ALERT | ERR_FATAL;
811 }
812 }
813
Vincent Bernat02779b62016-04-03 13:48:43 +0200814 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100815 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200816 err_code |= ERR_ALERT | ERR_ABORT;
817 goto out;
818 }
819
820 /* the nameservers are linked backward first */
Christopher Faulet67957bd2017-09-27 11:00:59 +0200821 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200822 newnameserver->resolvers = curr_resolvers;
823 newnameserver->conf.file = strdup(file);
824 newnameserver->conf.line = linenum;
825 newnameserver->id = strdup(args[1]);
826
Willy Tarreau48ef4c92017-01-06 18:32:38 +0100827 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200828 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100829 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200830 err_code |= ERR_ALERT | ERR_FATAL;
831 goto out;
832 }
833
834 proto = protocol_by_family(sk->ss_family);
835 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100836 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
Baptiste Assmann325137d2015-04-13 23:40:55 +0200837 file, linenum, args[0], args[1]);
838 err_code |= ERR_ALERT | ERR_FATAL;
839 goto out;
840 }
841
842 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100843 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
844 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200845 err_code |= ERR_ALERT | ERR_FATAL;
846 goto out;
847 }
848
Baptiste Assmann7f43fa92016-01-21 00:59:46 +0100849 if (!port1 && !port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100850 ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n",
851 file, linenum, args[0], args[1]);
Baptiste Assmann7f43fa92016-01-21 00:59:46 +0100852 err_code |= ERR_ALERT | ERR_FATAL;
853 goto out;
854 }
855
Baptiste Assmann325137d2015-04-13 23:40:55 +0200856 newnameserver->addr = *sk;
857 }
Ben Draut44e609b2018-05-29 15:40:08 -0600858 else if (strcmp(args[0], "parse-resolv-conf") == 0) {
859 const char *whitespace = "\r\n\t ";
860 char *resolv_line = NULL;
861 int resolv_linenum = 0;
862 FILE *f = NULL;
863 char *address = NULL;
864 struct sockaddr_storage *sk = NULL;
865 struct protocol *proto;
866 int duplicate_name = 0;
867
868 if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) {
869 ha_alert("parsing [%s:%d] : out of memory.\n",
870 file, linenum);
871 err_code |= ERR_ALERT | ERR_FATAL;
872 goto resolv_out;
873 }
874
875 if ((f = fopen("/etc/resolv.conf", "r")) == NULL) {
876 ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n",
877 file, linenum);
878 err_code |= ERR_ALERT | ERR_FATAL;
879 goto resolv_out;
880 }
881
882 sk = calloc(1, sizeof(*sk));
883 if (sk == NULL) {
884 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n",
885 resolv_linenum);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto resolv_out;
888 }
889
890 while (fgets(resolv_line, LINESIZE, f) != NULL) {
891 resolv_linenum++;
892 if (strncmp(resolv_line, "nameserver", 10) != 0)
893 continue;
894
895 address = strtok(resolv_line + 10, whitespace);
896 if (address == resolv_line + 10)
897 continue;
898
899 if (address == NULL) {
900 ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n",
901 resolv_linenum);
902 err_code |= ERR_WARN;
903 continue;
904 }
905
906 duplicate_name = 0;
907 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
908 if (strcmp(newnameserver->id, address) == 0) {
909 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",
910 resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line);
911 err_code |= ERR_WARN;
912 duplicate_name = 1;
913 }
914 }
915
916 if (duplicate_name)
917 continue;
918
919 memset(sk, 0, sizeof(*sk));
920 sk = str2ip2(address, sk, 1);
921 if (!sk) {
922 ha_warning("parsing [/etc/resolv.conf:%d] : address '%s' could not be recognized, namerserver will be excluded.\n",
923 resolv_linenum, address);
924 err_code |= ERR_WARN;
925 continue;
926 }
927
928 set_host_port(sk, 53);
929
930 proto = protocol_by_family(sk->ss_family);
931 if (!proto || !proto->connect) {
932 ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n",
933 resolv_linenum, address);
934 err_code |= ERR_WARN;
935 continue;
936 }
937
938 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
939 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
940 err_code |= ERR_ALERT | ERR_FATAL;
941 goto resolv_out;
942 }
943
944 newnameserver->conf.file = strdup("/etc/resolv.conf");
945 if (newnameserver->conf.file == NULL) {
946 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
947 err_code |= ERR_ALERT | ERR_FATAL;
948 goto resolv_out;
949 }
950
951 newnameserver->id = strdup(address);
952 if (newnameserver->id == NULL) {
953 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
954 err_code |= ERR_ALERT | ERR_FATAL;
955 goto resolv_out;
956 }
957
958 newnameserver->resolvers = curr_resolvers;
959 newnameserver->conf.line = resolv_linenum;
960 newnameserver->addr = *sk;
961
962 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
963 }
964
965resolv_out:
966 free(sk);
967 free(resolv_line);
968 if (f != NULL)
969 fclose(f);
970 }
Baptiste Assmann325137d2015-04-13 23:40:55 +0200971 else if (strcmp(args[0], "hold") == 0) { /* hold periods */
972 const char *res;
973 unsigned int time;
974
975 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100976 ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n",
977 file, linenum, args[0]);
978 ha_alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n");
Baptiste Assmann325137d2015-04-13 23:40:55 +0200979 err_code |= ERR_ALERT | ERR_FATAL;
980 goto out;
981 }
982 res = parse_time_err(args[2], &time, TIME_UNIT_MS);
983 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100984 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
985 file, linenum, *res, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200986 err_code |= ERR_ALERT | ERR_FATAL;
987 goto out;
988 }
Baptiste Assmann987e16d2016-11-02 22:23:31 +0100989 if (strcmp(args[1], "nx") == 0)
990 curr_resolvers->hold.nx = time;
991 else if (strcmp(args[1], "other") == 0)
992 curr_resolvers->hold.other = time;
993 else if (strcmp(args[1], "refused") == 0)
994 curr_resolvers->hold.refused = time;
995 else if (strcmp(args[1], "timeout") == 0)
996 curr_resolvers->hold.timeout = time;
997 else if (strcmp(args[1], "valid") == 0)
Baptiste Assmann325137d2015-04-13 23:40:55 +0200998 curr_resolvers->hold.valid = time;
Olivier Houcharda8c6db82017-07-06 18:46:47 +0200999 else if (strcmp(args[1], "obsolete") == 0)
1000 curr_resolvers->hold.obsolete = time;
Baptiste Assmann325137d2015-04-13 23:40:55 +02001001 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001002 ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n",
1003 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001004 err_code |= ERR_ALERT | ERR_FATAL;
1005 goto out;
1006 }
1007
1008 }
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001009 else if (strcmp(args[0], "accepted_payload_size") == 0) {
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001010 int i = 0;
1011
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001012 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001013 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1014 file, linenum, args[0]);
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001015 err_code |= ERR_ALERT | ERR_FATAL;
1016 goto out;
1017 }
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001018
1019 i = atoi(args[1]);
Willy Tarreau0c219be2017-08-22 12:01:26 +02001020 if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001021 ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n",
1022 file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]);
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001023 err_code |= ERR_ALERT | ERR_FATAL;
1024 goto out;
1025 }
1026
1027 curr_resolvers->accepted_payload_size = i;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001028 }
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001029 else if (strcmp(args[0], "resolution_pool_size") == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001030 ha_warning("parsing [%s:%d] : '%s' directive is now deprecated and ignored.\n",
1031 file, linenum, args[0]);
Christopher Faulet67957bd2017-09-27 11:00:59 +02001032 err_code |= ERR_WARN;
1033 goto out;
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001034 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001035 else if (strcmp(args[0], "resolve_retries") == 0) {
1036 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001037 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1038 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001039 err_code |= ERR_ALERT | ERR_FATAL;
1040 goto out;
1041 }
1042 curr_resolvers->resolve_retries = atoi(args[1]);
1043 }
1044 else if (strcmp(args[0], "timeout") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001045 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001046 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n",
1047 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001048 err_code |= ERR_ALERT | ERR_FATAL;
1049 goto out;
1050 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001051 else if (strcmp(args[1], "retry") == 0 ||
1052 strcmp(args[1], "resolve") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001053 const char *res;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001054 unsigned int tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001055
1056 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001057 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1058 file, linenum, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001059 err_code |= ERR_ALERT | ERR_FATAL;
1060 goto out;
1061 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001062 res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001063 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001064 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1065 file, linenum, *res, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001066 err_code |= ERR_ALERT | ERR_FATAL;
1067 goto out;
1068 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001069 if (args[1][2] == 't')
1070 curr_resolvers->timeout.retry = tout;
1071 else
1072 curr_resolvers->timeout.resolve = tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001073 }
1074 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001075 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n",
1076 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001077 err_code |= ERR_ALERT | ERR_FATAL;
1078 goto out;
1079 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001080 } /* neither "nameserver" nor "resolvers" */
1081 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001082 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001083 err_code |= ERR_ALERT | ERR_FATAL;
1084 goto out;
1085 }
1086
1087 out:
1088 free(errmsg);
1089 return err_code;
1090}
Simon Horman0d16a402015-01-30 11:22:58 +09001091
1092/*
William Lallemand51097192015-04-14 16:35:22 +02001093 * Parse a line in a <listen>, <frontend> or <backend> section.
Simon Horman0d16a402015-01-30 11:22:58 +09001094 * Returns the error code, 0 if OK, or any combination of :
1095 * - ERR_ABORT: must abort ASAP
1096 * - ERR_FATAL: we can continue parsing but not start the service
1097 * - ERR_WARN: a warning has been emitted
1098 * - ERR_ALERT: an alert has been emitted
1099 * Only the two first ones can stop processing, the two others are just
1100 * indicators.
1101 */
1102int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
1103{
1104 static struct mailers *curmailers = NULL;
1105 struct mailer *newmailer = NULL;
1106 const char *err;
1107 int err_code = 0;
1108 char *errmsg = NULL;
1109
1110 if (strcmp(args[0], "mailers") == 0) { /* new mailers section */
1111 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001112 ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001113 err_code |= ERR_ALERT | ERR_ABORT;
1114 goto out;
1115 }
1116
1117 err = invalid_char(args[1]);
1118 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001119 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1120 file, linenum, *err, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001121 err_code |= ERR_ALERT | ERR_ABORT;
1122 goto out;
1123 }
1124
1125 for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) {
1126 /*
1127 * If there are two proxies with the same name only following
1128 * combinations are allowed:
1129 */
1130 if (strcmp(curmailers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001131 ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n",
1132 file, linenum, args[1], curmailers->conf.file, curmailers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02001133 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman0d16a402015-01-30 11:22:58 +09001134 }
1135 }
1136
Vincent Bernat02779b62016-04-03 13:48:43 +02001137 if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001138 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001139 err_code |= ERR_ALERT | ERR_ABORT;
1140 goto out;
1141 }
1142
1143 curmailers->next = mailers;
1144 mailers = curmailers;
1145 curmailers->conf.file = strdup(file);
1146 curmailers->conf.line = linenum;
1147 curmailers->id = strdup(args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001148 curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
1149 * But need enough time so that timeouts don't occur
1150 * during tcp procssing. For now just us an arbitrary default. */
Simon Horman0d16a402015-01-30 11:22:58 +09001151 }
1152 else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
1153 struct sockaddr_storage *sk;
1154 int port1, port2;
1155 struct protocol *proto;
1156
1157 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001158 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1159 file, linenum, args[0]);
Simon Horman0d16a402015-01-30 11:22:58 +09001160 err_code |= ERR_ALERT | ERR_FATAL;
1161 goto out;
1162 }
1163
1164 err = invalid_char(args[1]);
1165 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001166 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1167 file, linenum, *err, args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001168 err_code |= ERR_ALERT | ERR_FATAL;
1169 goto out;
1170 }
1171
Vincent Bernat02779b62016-04-03 13:48:43 +02001172 if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001173 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001174 err_code |= ERR_ALERT | ERR_ABORT;
1175 goto out;
1176 }
1177
1178 /* the mailers are linked backwards first */
1179 curmailers->count++;
1180 newmailer->next = curmailers->mailer_list;
1181 curmailers->mailer_list = newmailer;
1182 newmailer->mailers = curmailers;
1183 newmailer->conf.file = strdup(file);
1184 newmailer->conf.line = linenum;
1185
1186 newmailer->id = strdup(args[1]);
1187
Willy Tarreau48ef4c92017-01-06 18:32:38 +01001188 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Simon Horman0d16a402015-01-30 11:22:58 +09001189 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001190 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Simon Horman0d16a402015-01-30 11:22:58 +09001191 err_code |= ERR_ALERT | ERR_FATAL;
1192 goto out;
1193 }
1194
1195 proto = protocol_by_family(sk->ss_family);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09001196 if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001197 ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n",
1198 file, linenum, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001199 err_code |= ERR_ALERT | ERR_FATAL;
1200 goto out;
1201 }
1202
1203 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001204 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
1205 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09001206 err_code |= ERR_ALERT | ERR_FATAL;
1207 goto out;
1208 }
1209
1210 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001211 ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
1212 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09001213 err_code |= ERR_ALERT | ERR_FATAL;
1214 goto out;
1215 }
1216
1217 newmailer->addr = *sk;
1218 newmailer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01001219 newmailer->xprt = xprt_get(XPRT_RAW);
Simon Horman0d16a402015-01-30 11:22:58 +09001220 newmailer->sock_init_arg = NULL;
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001221 }
1222 else if (strcmp(args[0], "timeout") == 0) {
1223 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001224 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
1225 file, linenum, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001226 err_code |= ERR_ALERT | ERR_FATAL;
1227 goto out;
1228 }
1229 else if (strcmp(args[1], "mail") == 0) {
1230 const char *res;
1231 unsigned int timeout_mail;
1232 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001233 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1234 file, linenum, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001235 err_code |= ERR_ALERT | ERR_FATAL;
1236 goto out;
1237 }
1238 res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
1239 if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001240 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
1241 file, linenum, *res, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001242 err_code |= ERR_ALERT | ERR_FATAL;
1243 goto out;
1244 }
1245 if (timeout_mail <= 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001246 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 +01001247 err_code |= ERR_ALERT | ERR_FATAL;
1248 goto out;
1249 }
1250 curmailers->timeout.mail = timeout_mail;
1251 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001252 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001253 file, linenum, args[0], args[1]);
1254 err_code |= ERR_ALERT | ERR_FATAL;
1255 goto out;
1256 }
1257 }
Simon Horman0d16a402015-01-30 11:22:58 +09001258 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001259 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Simon Horman0d16a402015-01-30 11:22:58 +09001260 err_code |= ERR_ALERT | ERR_FATAL;
1261 goto out;
1262 }
1263
1264out:
1265 free(errmsg);
1266 return err_code;
1267}
1268
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001269void free_email_alert(struct proxy *p)
Simon Horman9dc49962015-01-30 11:22:59 +09001270{
1271 free(p->email_alert.mailers.name);
1272 p->email_alert.mailers.name = NULL;
1273 free(p->email_alert.from);
1274 p->email_alert.from = NULL;
1275 free(p->email_alert.to);
1276 p->email_alert.to = NULL;
1277 free(p->email_alert.myhostname);
1278 p->email_alert.myhostname = NULL;
1279}
1280
Willy Tarreaubaaee002006-06-26 02:48:02 +02001281
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001282int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001283cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
1284{
1285#ifdef CONFIG_HAP_NS
1286 const char *err;
1287 const char *item = args[0];
1288
1289 if (!strcmp(item, "namespace_list")) {
1290 return 0;
1291 }
1292 else if (!strcmp(item, "namespace")) {
1293 size_t idx = 1;
1294 const char *current;
1295 while (*(current = args[idx++])) {
1296 err = invalid_char(current);
1297 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001298 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1299 file, linenum, *err, item, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001300 return ERR_ALERT | ERR_FATAL;
1301 }
1302
1303 if (netns_store_lookup(current, strlen(current))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001304 ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
1305 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001306 return ERR_ALERT | ERR_FATAL;
1307 }
1308 if (!netns_store_insert(current)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001309 ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
1310 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001311 return ERR_ALERT | ERR_FATAL;
1312 }
1313 }
1314 }
1315
1316 return 0;
1317#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001318 ha_alert("parsing [%s:%d]: namespace support is not compiled in.",
1319 file, linenum);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001320 return ERR_ALERT | ERR_FATAL;
1321#endif
1322}
1323
1324int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001325cfg_parse_users(const char *file, int linenum, char **args, int kwm)
1326{
1327
1328 int err_code = 0;
1329 const char *err;
1330
1331 if (!strcmp(args[0], "userlist")) { /* new userlist */
1332 struct userlist *newul;
1333
1334 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001335 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1336 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001337 err_code |= ERR_ALERT | ERR_FATAL;
1338 goto out;
1339 }
William Lallemand6e62fb62015-04-28 16:55:23 +02001340 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1341 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001342
1343 err = invalid_char(args[1]);
1344 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001345 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1346 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001347 err_code |= ERR_ALERT | ERR_FATAL;
1348 goto out;
1349 }
1350
1351 for (newul = userlist; newul; newul = newul->next)
1352 if (!strcmp(newul->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001353 ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
1354 file, linenum, args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001355 err_code |= ERR_WARN;
1356 goto out;
1357 }
1358
Vincent Bernat02779b62016-04-03 13:48:43 +02001359 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001360 if (!newul) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001361 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001362 err_code |= ERR_ALERT | ERR_ABORT;
1363 goto out;
1364 }
1365
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001366 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001367 if (!newul->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001368 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001369 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01001370 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001371 goto out;
1372 }
1373
1374 newul->next = userlist;
1375 userlist = newul;
1376
1377 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001378 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001379 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001380 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001381
1382 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001383 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1384 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001385 err_code |= ERR_ALERT | ERR_FATAL;
1386 goto out;
1387 }
1388
1389 err = invalid_char(args[1]);
1390 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001391 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1392 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001393 err_code |= ERR_ALERT | ERR_FATAL;
1394 goto out;
1395 }
1396
William Lallemand4ac9f542015-05-28 18:03:51 +02001397 if (!userlist)
1398 goto out;
1399
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001400 for (ag = userlist->groups; ag; ag = ag->next)
1401 if (!strcmp(ag->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001402 ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
1403 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001404 err_code |= ERR_ALERT;
1405 goto out;
1406 }
1407
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001408 ag = calloc(1, sizeof(*ag));
1409 if (!ag) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001410 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001411 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001412 goto out;
1413 }
1414
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001415 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01001416 if (!ag->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001417 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001418 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01001419 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001420 goto out;
1421 }
1422
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001423 cur_arg = 2;
1424
1425 while (*args[cur_arg]) {
1426 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001427 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001428 cur_arg += 2;
1429 continue;
1430 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001431 ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
1432 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001433 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01001434 free(ag->groupusers);
1435 free(ag->name);
1436 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001437 goto out;
1438 }
1439 }
1440
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001441 ag->next = userlist->groups;
1442 userlist->groups = ag;
1443
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001444 } else if (!strcmp(args[0], "user")) { /* new user */
1445 struct auth_users *newuser;
1446 int cur_arg;
1447
1448 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001449 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1450 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001451 err_code |= ERR_ALERT | ERR_FATAL;
1452 goto out;
1453 }
William Lallemand4ac9f542015-05-28 18:03:51 +02001454 if (!userlist)
1455 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001456
1457 for (newuser = userlist->users; newuser; newuser = newuser->next)
1458 if (!strcmp(newuser->user, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001459 ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
1460 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001461 err_code |= ERR_ALERT;
1462 goto out;
1463 }
1464
Vincent Bernat02779b62016-04-03 13:48:43 +02001465 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001466 if (!newuser) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001467 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001468 err_code |= ERR_ALERT | ERR_ABORT;
1469 goto out;
1470 }
1471
1472 newuser->user = strdup(args[1]);
1473
1474 newuser->next = userlist->users;
1475 userlist->users = newuser;
1476
1477 cur_arg = 2;
1478
1479 while (*args[cur_arg]) {
1480 if (!strcmp(args[cur_arg], "password")) {
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001481#ifdef CONFIG_HAP_CRYPT
1482 if (!crypt("", args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001483 ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
1484 file, linenum, newuser->user);
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001485 err_code |= ERR_ALERT | ERR_FATAL;
1486 goto out;
1487 }
1488#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001489 ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
1490 file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001491 err_code |= ERR_ALERT;
1492#endif
1493 newuser->pass = strdup(args[cur_arg + 1]);
1494 cur_arg += 2;
1495 continue;
1496 } else if (!strcmp(args[cur_arg], "insecure-password")) {
1497 newuser->pass = strdup(args[cur_arg + 1]);
1498 newuser->flags |= AU_O_INSECURE;
1499 cur_arg += 2;
1500 continue;
1501 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001502 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001503 cur_arg += 2;
1504 continue;
1505 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001506 ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
1507 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001508 err_code |= ERR_ALERT | ERR_FATAL;
1509 goto out;
1510 }
1511 }
1512 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001513 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 +01001514 err_code |= ERR_ALERT | ERR_FATAL;
1515 }
1516
1517out:
1518 return err_code;
1519}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001520
Christopher Faulet79bdef32016-11-04 22:36:15 +01001521int
1522cfg_parse_scope(const char *file, int linenum, char *line)
1523{
1524 char *beg, *end, *scope = NULL;
1525 int err_code = 0;
1526 const char *err;
1527
1528 beg = line + 1;
1529 end = strchr(beg, ']');
1530
1531 /* Detect end of scope declaration */
1532 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001533 ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n",
1534 file, linenum);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001535 err_code |= ERR_ALERT | ERR_FATAL;
1536 goto out;
1537 }
1538
1539 /* Get scope name and check its validity */
1540 scope = my_strndup(beg, end-beg);
1541 err = invalid_char(scope);
1542 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001543 ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
1544 file, linenum, *err);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001545 err_code |= ERR_ALERT | ERR_ABORT;
1546 goto out;
1547 }
1548
1549 /* Be sure to have a scope declaration alone on its line */
1550 line = end+1;
1551 while (isspace((unsigned char)*line))
1552 line++;
1553 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001554 ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
1555 file, linenum, *line);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001556 err_code |= ERR_ALERT | ERR_ABORT;
1557 goto out;
1558 }
1559
1560 /* We have a valid scope declaration, save it */
1561 free(cfg_scope);
1562 cfg_scope = scope;
1563 scope = NULL;
1564
1565 out:
1566 free(scope);
1567 return err_code;
1568}
1569
Frédéric Lécaillea41d5312018-01-29 12:05:07 +01001570int
1571cfg_parse_track_sc_num(unsigned int *track_sc_num,
1572 const char *arg, const char *end, char **errmsg)
1573{
1574 const char *p;
1575 unsigned int num;
1576
1577 p = arg;
1578 num = read_uint64(&arg, end);
1579
1580 if (arg != end) {
1581 memprintf(errmsg, "Wrong track-sc number '%s'", p);
1582 return -1;
1583 }
1584
1585 if (num >= MAX_SESS_STKCTR) {
1586 memprintf(errmsg, "%u track-sc number exceeding "
1587 "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1);
1588 return -1;
1589 }
1590
1591 *track_sc_num = num;
1592 return 0;
1593}
1594
Willy Tarreaubaaee002006-06-26 02:48:02 +02001595/*
1596 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02001597 * Returns the error code, 0 if OK, or any combination of :
1598 * - ERR_ABORT: must abort ASAP
1599 * - ERR_FATAL: we can continue parsing but not start the service
1600 * - ERR_WARN: a warning has been emitted
1601 * - ERR_ALERT: an alert has been emitted
1602 * Only the two first ones can stop processing, the two others are just
1603 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001604 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02001605int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001606{
William Lallemand64e84512015-05-12 14:25:37 +02001607 char *thisline;
1608 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001609 FILE *f;
1610 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02001611 int err_code = 0;
William Lallemandd2ff56d2017-10-16 11:06:50 +02001612 struct cfg_section *cs = NULL, *pcs = NULL;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001613 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02001614 int readbytes = 0;
1615
1616 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001617 ha_alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02001618 return -1;
1619 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001620
David Carlier97880bb2016-04-08 10:35:26 +01001621 if ((f=fopen(file,"r")) == NULL) {
1622 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001623 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01001624 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001625
William Lallemandb2f07452015-05-12 14:27:13 +02001626next_line:
William Lallemand64e84512015-05-12 14:25:37 +02001627 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02001628 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001629 char *end;
1630 char *args[MAX_LINE_ARGS + 1];
1631 char *line = thisline;
William Lallemandf9873ba2015-05-05 17:37:14 +02001632 int dquote = 0; /* double quote */
1633 int squote = 0; /* simple quote */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001634
Willy Tarreaubaaee002006-06-26 02:48:02 +02001635 linenum++;
1636
1637 end = line + strlen(line);
1638
William Lallemand64e84512015-05-12 14:25:37 +02001639 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001640 /* Check if we reached the limit and the last char is not \n.
1641 * Watch out for the last line without the terminating '\n'!
1642 */
William Lallemand64e84512015-05-12 14:25:37 +02001643 char *newline;
1644 int newlinesize = linesize * 2;
1645
1646 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
1647 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001648 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
1649 file, linenum);
William Lallemand64e84512015-05-12 14:25:37 +02001650 err_code |= ERR_ALERT | ERR_FATAL;
1651 continue;
1652 }
1653
1654 readbytes = linesize - 1;
1655 linesize = newlinesize;
1656 thisline = newline;
1657 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001658 }
1659
William Lallemand64e84512015-05-12 14:25:37 +02001660 readbytes = 0;
1661
Willy Tarreaubaaee002006-06-26 02:48:02 +02001662 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02001663 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02001664 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02001665
Christopher Faulet79bdef32016-11-04 22:36:15 +01001666
Joseph Herlanta14c03e2018-11-15 14:04:19 -08001667 if (*line == '[') {/* This is the beginning if a scope */
Christopher Faulet79bdef32016-11-04 22:36:15 +01001668 err_code |= cfg_parse_scope(file, linenum, line);
1669 goto next_line;
1670 }
1671
Willy Tarreaubaaee002006-06-26 02:48:02 +02001672 arg = 0;
1673 args[arg] = line;
1674
1675 while (*line && arg < MAX_LINE_ARGS) {
William Lallemandf9873ba2015-05-05 17:37:14 +02001676 if (*line == '"' && !squote) { /* double quote outside single quotes */
1677 if (dquote)
1678 dquote = 0;
1679 else
1680 dquote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02001681 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02001682 end--;
1683 }
1684 else if (*line == '\'' && !dquote) { /* single quote outside double quotes */
1685 if (squote)
1686 squote = 0;
1687 else
1688 squote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02001689 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02001690 end--;
1691 }
1692 else if (*line == '\\' && !squote) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001693 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
1694 * C equivalent value. Other combinations left unchanged (eg: \1).
1695 */
Willy Tarreaubaaee002006-06-26 02:48:02 +02001696 int skip = 0;
1697 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
1698 *line = line[1];
1699 skip = 1;
1700 }
1701 else if (line[1] == 'r') {
1702 *line = '\r';
1703 skip = 1;
William Lallemandf9873ba2015-05-05 17:37:14 +02001704 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001705 else if (line[1] == 'n') {
1706 *line = '\n';
1707 skip = 1;
1708 }
1709 else if (line[1] == 't') {
1710 *line = '\t';
1711 skip = 1;
1712 }
1713 else if (line[1] == 'x') {
Emeric Brunb982a3d2010-01-04 15:45:53 +01001714 if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001715 unsigned char hex1, hex2;
1716 hex1 = toupper(line[2]) - '0';
1717 hex2 = toupper(line[3]) - '0';
1718 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
1719 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
1720 *line = (hex1<<4) + hex2;
1721 skip = 3;
1722 }
1723 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001724 ha_alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001725 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001726 }
William Lallemandf9873ba2015-05-05 17:37:14 +02001727 } else if (line[1] == '"') {
1728 *line = '"';
1729 skip = 1;
1730 } else if (line[1] == '\'') {
1731 *line = '\'';
1732 skip = 1;
William Lallemandb2f07452015-05-12 14:27:13 +02001733 } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */
1734 *line = '$';
1735 skip = 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001736 }
1737 if (skip) {
Cyril Bontédd1b01d2009-12-06 13:43:42 +01001738 memmove(line + 1, line + 1 + skip, end - (line + skip));
Willy Tarreaubaaee002006-06-26 02:48:02 +02001739 end -= skip;
1740 }
1741 line++;
1742 }
William Lallemandf9873ba2015-05-05 17:37:14 +02001743 else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001744 /* end of string, end of loop */
1745 *line = 0;
1746 break;
1747 }
William Lallemandf9873ba2015-05-05 17:37:14 +02001748 else if (!squote && !dquote && isspace((unsigned char)*line)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001749 /* a non-escaped space is an argument separator */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001750 *line++ = '\0';
Willy Tarreau8f8e6452007-06-17 21:51:38 +02001751 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02001752 line++;
1753 args[++arg] = line;
1754 }
William Lallemandb2f07452015-05-12 14:27:13 +02001755 else if (dquote && *line == '$') {
1756 /* environment variables are evaluated inside double quotes */
1757 char *var_beg;
1758 char *var_end;
1759 char save_char;
1760 char *value;
1761 int val_len;
1762 int newlinesize;
1763 int braces = 0;
1764
1765 var_beg = line + 1;
1766 var_end = var_beg;
1767
1768 if (*var_beg == '{') {
1769 var_beg++;
1770 var_end++;
1771 braces = 1;
1772 }
1773
1774 if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001775 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 +02001776 err_code |= ERR_ALERT | ERR_FATAL;
1777 goto next_line; /* skip current line */
1778 }
1779
1780 while (isalnum((int)(unsigned char)*var_end) || *var_end == '_')
1781 var_end++;
1782
1783 save_char = *var_end;
1784 *var_end = '\0';
1785 value = getenv(var_beg);
1786 *var_end = save_char;
1787 val_len = value ? strlen(value) : 0;
1788
1789 if (braces) {
1790 if (*var_end == '}') {
1791 var_end++;
1792 braces = 0;
1793 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001794 ha_alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02001795 err_code |= ERR_ALERT | ERR_FATAL;
1796 goto next_line; /* skip current line */
1797 }
1798 }
1799
1800 newlinesize = (end - thisline) - (var_end - line) + val_len + 1;
1801
1802 /* if not enough space in thisline */
1803 if (newlinesize > linesize) {
1804 char *newline;
1805
1806 newline = realloc(thisline, newlinesize * sizeof(*thisline));
1807 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001808 ha_alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02001809 err_code |= ERR_ALERT | ERR_FATAL;
1810 goto next_line; /* slip current line */
1811 }
1812 /* recompute pointers if realloc returns a new pointer */
1813 if (newline != thisline) {
1814 int i;
1815 int diff;
1816
1817 for (i = 0; i <= arg; i++) {
1818 diff = args[i] - thisline;
1819 args[i] = newline + diff;
1820 }
1821
1822 diff = var_end - thisline;
1823 var_end = newline + diff;
1824 diff = end - thisline;
1825 end = newline + diff;
1826 diff = line - thisline;
1827 line = newline + diff;
1828 thisline = newline;
1829 }
1830 linesize = newlinesize;
1831 }
1832
1833 /* insert value inside the line */
1834 memmove(line + val_len, var_end, end - var_end + 1);
1835 memcpy(line, value, val_len);
1836 end += val_len - (var_end - line);
1837 line += val_len;
1838 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001839 else {
1840 line++;
1841 }
1842 }
William Lallemandb2f07452015-05-12 14:27:13 +02001843
William Lallemandf9873ba2015-05-05 17:37:14 +02001844 if (dquote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001845 ha_alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02001846 err_code |= ERR_ALERT | ERR_FATAL;
1847 }
1848
1849 if (squote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001850 ha_alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02001851 err_code |= ERR_ALERT | ERR_FATAL;
1852 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001853
1854 /* empty line */
1855 if (!**args)
1856 continue;
1857
Willy Tarreau7bb651e2009-11-09 21:16:53 +01001858 if (*line) {
1859 /* we had to stop due to too many args.
1860 * Let's terminate the string, print the offending part then cut the
1861 * last arg.
1862 */
1863 while (*line && *line != '#' && *line != '\n' && *line != '\r')
1864 line++;
1865 *line = '\0';
1866
Christopher Faulet767a84b2017-11-24 16:50:31 +01001867 ha_alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n",
1868 file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]);
Willy Tarreau7bb651e2009-11-09 21:16:53 +01001869 err_code |= ERR_ALERT | ERR_FATAL;
1870 args[arg] = line;
1871 }
1872
Willy Tarreau540abe42007-05-02 20:50:16 +02001873 /* zero out remaining args and ensure that at least one entry
1874 * is zeroed out.
1875 */
1876 while (++arg <= MAX_LINE_ARGS) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001877 args[arg] = line;
1878 }
1879
Willy Tarreau3842f002009-06-14 11:39:52 +02001880 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001881 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02001882 char *tmp;
1883
Willy Tarreau3842f002009-06-14 11:39:52 +02001884 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02001885 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001886 for (arg=0; *args[arg+1]; arg++)
1887 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02001888 *tmp = '\0'; // fix the next arg to \0
1889 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001890 }
Willy Tarreau3842f002009-06-14 11:39:52 +02001891 else if (!strcmp(args[0], "default")) {
1892 kwm = KWM_DEF;
1893 for (arg=0; *args[arg+1]; arg++)
1894 args[arg] = args[arg+1]; // shift args after inversion
1895 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001896
William Lallemand0f99e342011-10-12 17:50:54 +02001897 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \
Willy Tarreaubeb859a2018-11-22 18:07:59 +01001898 strcmp(args[0], "log") != 0 && strcmp(args[0], "busy-polling")) {
1899 ha_alert("parsing [%s:%d]: negation/default currently supported only for options, log, and busy-polling.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001900 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001901 }
1902
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001903 /* detect section start */
1904 list_for_each_entry(ics, &sections, list) {
1905 if (strcmp(args[0], ics->section_name) == 0) {
1906 cursection = ics->section_name;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01001907 pcs = cs;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001908 cs = ics;
1909 break;
1910 }
Emeric Brun32da3c42010-09-23 18:39:19 +02001911 }
1912
Christopher Faulet7805e2b2018-11-30 13:50:47 +01001913 if (pcs && pcs->post_section_parser) {
1914 err_code |= pcs->post_section_parser();
1915 if (err_code & ERR_ABORT)
1916 goto err;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01001917 }
Christopher Fauletbf7a9592018-12-02 09:37:38 +01001918 pcs = NULL;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01001919
William Lallemandd2ff56d2017-10-16 11:06:50 +02001920 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001921 ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001922 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemandd2ff56d2017-10-16 11:06:50 +02001923 } else {
William Lallemandd2ff56d2017-10-16 11:06:50 +02001924 err_code |= cs->section_parser(file, linenum, args, kwm);
1925 if (err_code & ERR_ABORT)
1926 goto err;
1927 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001928 }
William Lallemandd2ff56d2017-10-16 11:06:50 +02001929
Christopher Fauletbf7a9592018-12-02 09:37:38 +01001930 if (cs && cs->post_section_parser)
Christopher Faulet7805e2b2018-11-30 13:50:47 +01001931 err_code |= cs->post_section_parser();
William Lallemandd2ff56d2017-10-16 11:06:50 +02001932
1933err:
Christopher Faulet79bdef32016-11-04 22:36:15 +01001934 free(cfg_scope);
1935 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01001936 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02001937 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001938 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02001939 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02001940}
1941
Willy Tarreau64ab6072014-09-16 12:17:36 +02001942/* This function propagates processes from frontend <from> to backend <to> so
1943 * that it is always guaranteed that a backend pointed to by a frontend is
1944 * bound to all of its processes. After that, if the target is a "listen"
1945 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02001946 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02001947 * checked first to ensure that <to> is already bound to all processes of
1948 * <from>, there is no risk of looping and we ensure to follow the shortest
1949 * path to the destination.
1950 *
1951 * It is possible to set <to> to NULL for the first call so that the function
1952 * takes care of visiting the initial frontend in <from>.
1953 *
1954 * It is important to note that the function relies on the fact that all names
1955 * have already been resolved.
1956 */
1957void propagate_processes(struct proxy *from, struct proxy *to)
1958{
1959 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02001960
1961 if (to) {
1962 /* check whether we need to go down */
1963 if (from->bind_proc &&
1964 (from->bind_proc & to->bind_proc) == from->bind_proc)
1965 return;
1966
1967 if (!from->bind_proc && !to->bind_proc)
1968 return;
1969
1970 to->bind_proc = from->bind_proc ?
1971 (to->bind_proc | from->bind_proc) : 0;
1972
1973 /* now propagate down */
1974 from = to;
1975 }
1976
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01001977 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02001978 return;
1979
Willy Tarreauf6b70012014-12-18 14:00:43 +01001980 if (from->state == PR_STSTOPPED)
1981 return;
1982
Willy Tarreau64ab6072014-09-16 12:17:36 +02001983 /* default_backend */
1984 if (from->defbe.be)
1985 propagate_processes(from, from->defbe.be);
1986
1987 /* use_backend */
1988 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02001989 if (rule->dynamic)
1990 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02001991 to = rule->be.backend;
1992 propagate_processes(from, to);
1993 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02001994}
1995
Willy Tarreaubb925012009-07-23 13:36:36 +02001996/*
1997 * Returns the error code, 0 if OK, or any combination of :
1998 * - ERR_ABORT: must abort ASAP
1999 * - ERR_FATAL: we can continue parsing but not start the service
2000 * - ERR_WARN: a warning has been emitted
2001 * - ERR_ALERT: an alert has been emitted
2002 * Only the two first ones can stop processing, the two others are just
2003 * indicators.
2004 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002005int check_config_validity()
2006{
2007 int cfgerr = 0;
2008 struct proxy *curproxy = NULL;
2009 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02002010 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002011 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002012 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002013 char *err;
William Lallemand48b4bb42017-10-23 14:36:34 +02002014 struct cfg_postparser *postparser;
Ben Draut054fbee2018-04-13 15:43:04 -06002015 struct dns_resolvers *curr_resolvers = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002016
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002017 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002018 /*
2019 * Now, check for the integrity of all that we have collected.
2020 */
2021
2022 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02002023 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002024
Willy Tarreau193b8c62012-11-22 00:17:38 +01002025 if (!global.tune.max_http_hdr)
2026 global.tune.max_http_hdr = MAX_HTTP_HDR;
2027
2028 if (!global.tune.cookie_len)
2029 global.tune.cookie_len = CAPTURE_LEN;
2030
Stéphane Cottin23e9e932017-05-18 08:58:41 +02002031 if (!global.tune.requri_len)
2032 global.tune.requri_len = REQURI_LEN;
2033
Willy Tarreaubafbe012017-11-24 17:34:44 +01002034 pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
Emeric Brun96fd9262017-07-05 13:33:16 +02002035
Willy Tarreaubafbe012017-11-24 17:34:44 +01002036 pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
Willy Tarreau193b8c62012-11-22 00:17:38 +01002037
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002038 /* Post initialisation of the users and groups lists. */
2039 err_code = userlist_postinit();
2040 if (err_code != ERR_NONE)
2041 goto out;
2042
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002043 /* first, we will invert the proxy list order */
2044 curproxy = NULL;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002045 while (proxies_list) {
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002046 struct proxy *next;
2047
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002048 next = proxies_list->next;
2049 proxies_list->next = curproxy;
2050 curproxy = proxies_list;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002051 if (!next)
2052 break;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002053 proxies_list = next;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002054 }
2055
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002056 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002057 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002058 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002059 struct sticking_rule *mrule;
Christopher Faulete4e830d2017-09-18 14:51:41 +02002060 struct act_rule *arule;
Dragan Dosen1322d092015-09-22 16:05:32 +02002061 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002062 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01002063 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002064
Willy Tarreau050536d2012-10-04 08:47:34 +02002065 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002066 /* proxy ID not set, use automatic numbering with first
2067 * spare entry starting with next_pxid.
2068 */
2069 next_pxid = get_next_id(&used_proxy_id, next_pxid);
2070 curproxy->conf.id.key = curproxy->uuid = next_pxid;
2071 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002072 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01002073 next_pxid++;
2074
Willy Tarreau55ea7572007-06-17 19:56:27 +02002075
Willy Tarreaubaaee002006-06-26 02:48:02 +02002076 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02002077 /* ensure we don't keep listeners uselessly bound */
2078 stop_proxy(curproxy);
Willy Tarreau02df7742015-05-01 19:59:56 +02002079 free((void *)curproxy->table.peers.name);
2080 curproxy->table.peers.p = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002081 continue;
2082 }
2083
Willy Tarreau102df612014-05-07 23:56:38 +02002084 /* Check multi-process mode compatibility for the current proxy */
2085
2086 if (curproxy->bind_proc) {
2087 /* an explicit bind-process was specified, let's check how many
2088 * processes remain.
2089 */
David Carliere6c39412015-07-02 07:00:17 +00002090 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02002091
2092 curproxy->bind_proc &= nbits(global.nbproc);
2093 if (!curproxy->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002094 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 +02002095 curproxy->bind_proc = 1;
2096 }
2097 else if (!curproxy->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002098 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 +02002099 curproxy->bind_proc = 0;
2100 }
2101 }
2102
Willy Tarreau3d209582014-05-09 17:06:11 +02002103 /* check and reduce the bind-proc of each listener */
2104 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
2105 unsigned long mask;
2106
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002107 /* HTTP frontends with "h2" as ALPN/NPN will work in
2108 * HTTP/2 and absolutely require buffers 16kB or larger.
2109 */
2110#ifdef USE_OPENSSL
2111 if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
2112#ifdef OPENSSL_NPN_NEGOTIATED
2113 /* check NPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002114 if (bind_conf->ssl_conf.npn_str && strstr(bind_conf->ssl_conf.npn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002115 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",
2116 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002117 cfgerr++;
2118 }
2119#endif
2120#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
2121 /* check ALPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002122 if (bind_conf->ssl_conf.alpn_str && strstr(bind_conf->ssl_conf.alpn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002123 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",
2124 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002125 cfgerr++;
2126 }
2127#endif
2128 } /* HTTP && bufsize < 16384 */
2129#endif
2130
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002131 /* detect and address thread affinity inconsistencies */
2132 nbproc = 0;
2133 if (bind_conf->bind_proc)
2134 nbproc = my_ffsl(bind_conf->bind_proc);
2135
2136 mask = bind_conf->bind_thread[nbproc - 1];
Willy Tarreau0c026f42018-08-01 19:12:20 +02002137 if (mask && !(mask & all_threads_mask)) {
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002138 unsigned long new_mask = 0;
2139
2140 while (mask) {
Willy Tarreau0c026f42018-08-01 19:12:20 +02002141 new_mask |= mask & all_threads_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002142 mask >>= global.nbthread;
2143 }
2144
2145 for (nbproc = 0; nbproc < LONGBITS; nbproc++) {
2146 if (!bind_conf->bind_proc || (bind_conf->bind_proc & (1UL << nbproc)))
2147 bind_conf->bind_thread[nbproc] = new_mask;
2148 }
2149 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",
2150 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
2151 }
2152
2153 /* detect process and nbproc affinity inconsistencies */
Willy Tarreau3d209582014-05-09 17:06:11 +02002154 if (!bind_conf->bind_proc)
2155 continue;
2156
2157 mask = nbits(global.nbproc);
2158 if (curproxy->bind_proc)
2159 mask &= curproxy->bind_proc;
2160 /* mask cannot be null here thanks to the previous checks */
2161
David Carliere6c39412015-07-02 07:00:17 +00002162 nbproc = my_popcountl(bind_conf->bind_proc);
Willy Tarreau3d209582014-05-09 17:06:11 +02002163 bind_conf->bind_proc &= mask;
2164
2165 if (!bind_conf->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002166 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",
2167 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreau3d209582014-05-09 17:06:11 +02002168 bind_conf->bind_proc = mask & ~(mask - 1);
2169 }
2170 else if (!bind_conf->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002171 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",
2172 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreau3d209582014-05-09 17:06:11 +02002173 bind_conf->bind_proc = 0;
2174 }
2175 }
2176
Willy Tarreauff01a212009-03-15 13:46:16 +01002177 switch (curproxy->mode) {
2178 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002179 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002180 if (!(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002181 ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
2182 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002183 cfgerr++;
2184 }
2185
2186 if (curproxy->srv != NULL)
Christopher Faulet767a84b2017-11-24 16:50:31 +01002187 ha_warning("config : servers will be ignored for %s '%s'.\n",
2188 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002189 break;
2190
2191 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002192 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002193 break;
2194
2195 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01002196 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01002197 break;
William Lallemandcf62f7e2018-10-26 14:47:40 +02002198
2199 case PR_MODE_CLI:
2200 cfgerr += proxy_cfg_ensure_no_http(curproxy);
2201 break;
Willy Tarreauff01a212009-03-15 13:46:16 +01002202 }
2203
Willy Tarreau58aa5cc2018-02-08 09:55:09 +01002204 if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002205 ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
2206 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauf3934b82015-08-11 11:36:45 +02002207 err_code |= ERR_WARN;
2208 }
2209
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002210 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02002211 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002212 if (curproxy->options & PR_O_TRANSP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002213 ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n",
2214 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002215 cfgerr++;
2216 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002217#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002218 else if (curproxy->srv == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002219 ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n",
2220 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002221 cfgerr++;
2222 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002223#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02002224 else if (curproxy->options & PR_O_DISPATCH) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002225 ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
2226 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002227 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002228 }
2229 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02002230 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002231 /* If no LB algo is set in a backend, and we're not in
2232 * transparent mode, dispatch mode nor proxy mode, we
2233 * want to use balance roundrobin by default.
2234 */
2235 curproxy->lbprm.algo &= ~BE_LB_ALGO;
2236 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002237 }
2238 }
Willy Tarreau193cf932007-09-17 10:17:23 +02002239
Willy Tarreau1620ec32011-08-06 17:05:02 +02002240 if (curproxy->options & PR_O_DISPATCH)
2241 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
2242 else if (curproxy->options & PR_O_HTTP_PROXY)
2243 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
2244 else if (curproxy->options & PR_O_TRANSP)
2245 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01002246
Willy Tarreau1620ec32011-08-06 17:05:02 +02002247 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) {
2248 if (curproxy->options & PR_O_DISABLE404) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002249 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2250 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002251 err_code |= ERR_WARN;
2252 curproxy->options &= ~PR_O_DISABLE404;
2253 }
2254 if (curproxy->options2 & PR_O2_CHK_SNDST) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002255 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2256 "send-state", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002257 err_code |= ERR_WARN;
2258 curproxy->options &= ~PR_O2_CHK_SNDST;
2259 }
Willy Tarreauef781042010-01-27 11:53:01 +01002260 }
2261
Simon Horman98637e52014-06-20 12:30:16 +09002262 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
2263 if (!global.external_check) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002264 ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
2265 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002266 cfgerr++;
2267 }
2268 if (!curproxy->check_command) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002269 ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
2270 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002271 cfgerr++;
2272 }
2273 }
2274
Simon Horman64e34162015-02-06 11:11:57 +09002275 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002276 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002277 ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
2278 "'email-alert from', 'email-alert level' 'email-alert mailers', "
2279 "'email-alert myhostname', or 'email-alert to' "
2280 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
2281 "to be present).\n",
2282 proxy_type_str(curproxy), curproxy->id);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002283 err_code |= ERR_WARN;
2284 free_email_alert(curproxy);
2285 }
2286 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01002287 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09002288 }
2289
Simon Horman98637e52014-06-20 12:30:16 +09002290 if (curproxy->check_command) {
2291 int clear = 0;
2292 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002293 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2294 "external-check command", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002295 err_code |= ERR_WARN;
2296 clear = 1;
2297 }
2298 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002299 ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
2300 curproxy->id, "external-check command");
Simon Horman98637e52014-06-20 12:30:16 +09002301 cfgerr++;
2302 }
2303 if (clear) {
2304 free(curproxy->check_command);
2305 curproxy->check_command = NULL;
2306 }
2307 }
2308
2309 if (curproxy->check_path) {
2310 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002311 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2312 "external-check path", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002313 err_code |= ERR_WARN;
2314 free(curproxy->check_path);
2315 curproxy->check_path = NULL;
2316 }
2317 }
2318
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002319 /* if a default backend was specified, let's find it */
2320 if (curproxy->defbe.name) {
2321 struct proxy *target;
2322
Willy Tarreauafb39922015-05-26 12:04:09 +02002323 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002324 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002325 ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
2326 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002327 cfgerr++;
2328 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002329 ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
2330 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02002331 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002332 } else if (target->mode != curproxy->mode &&
2333 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2334
Christopher Faulet767a84b2017-11-24 16:50:31 +01002335 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
2336 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2337 curproxy->conf.file, curproxy->conf.line,
2338 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2339 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002340 cfgerr++;
Willy Tarreau68ad3a42018-10-22 11:49:15 +02002341 } else if ((curproxy->options2 ^ target->options2) & PR_O2_USE_HTX) {
2342 ha_alert("%s %s '%s' (%s:%d) tries to use %s %s '%s' (%s:%d) as its default backend, both of which disagree on 'option http-use-htx'.\n",
2343 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2344 curproxy->conf.file, curproxy->conf.line,
2345 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2346 target->conf.file, target->conf.line);
2347 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002348 } else {
2349 free(curproxy->defbe.name);
2350 curproxy->defbe.be = target;
Emeric Brun3f783572017-01-12 11:21:28 +01002351 /* Update tot_fe_maxconn for a further fullconn's computation */
2352 target->tot_fe_maxconn += curproxy->maxconn;
Willy Tarreauff678132012-02-13 14:32:34 +01002353 /* Emit a warning if this proxy also has some servers */
2354 if (curproxy->srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002355 ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
2356 curproxy->id);
Willy Tarreauff678132012-02-13 14:32:34 +01002357 err_code |= ERR_WARN;
2358 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002359 }
2360 }
2361
Emeric Brun3f783572017-01-12 11:21:28 +01002362 if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
2363 /* Case of listen without default backend
2364 * The curproxy will be its own default backend
2365 * so we update tot_fe_maxconn for a further
2366 * fullconn's computation */
2367 curproxy->tot_fe_maxconn += curproxy->maxconn;
2368 }
2369
Willy Tarreau55ea7572007-06-17 19:56:27 +02002370 /* find the target proxy for 'use_backend' rules */
2371 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002372 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002373 struct logformat_node *node;
2374 char *pxname;
2375
2376 /* Try to parse the string as a log format expression. If the result
2377 * of the parsing is only one entry containing a simple string, then
2378 * it's a standard string corresponding to a static rule, thus the
2379 * parsing is cancelled and be.name is restored to be resolved.
2380 */
2381 pxname = rule->be.name;
2382 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01002383 curproxy->conf.args.ctx = ARGC_UBK;
2384 curproxy->conf.args.file = rule->file;
2385 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002386 err = NULL;
2387 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002388 ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
2389 rule->file, rule->line, pxname, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002390 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002391 cfgerr++;
2392 continue;
2393 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002394 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
2395
2396 if (!LIST_ISEMPTY(&rule->be.expr)) {
2397 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
2398 rule->dynamic = 1;
2399 free(pxname);
2400 continue;
2401 }
2402 /* simple string: free the expression and fall back to static rule */
2403 free(node->arg);
2404 free(node);
2405 }
2406
2407 rule->dynamic = 0;
2408 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002409
Willy Tarreauafb39922015-05-26 12:04:09 +02002410 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002411 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002412 ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
2413 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002414 cfgerr++;
2415 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002416 ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
2417 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002418 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002419 } else if (target->mode != curproxy->mode &&
2420 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2421
Christopher Faulet767a84b2017-11-24 16:50:31 +01002422 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
2423 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2424 curproxy->conf.file, curproxy->conf.line,
2425 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2426 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002427 cfgerr++;
Willy Tarreau68ad3a42018-10-22 11:49:15 +02002428 } else if ((curproxy->options2 ^ target->options2) & PR_O2_USE_HTX) {
2429 ha_alert("%s %s '%s' (%s:%d) tries to use %s %s '%s' (%s:%d) in a 'use_backend' rule, both of which disagree on 'option http-use-htx'.\n",
2430 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2431 curproxy->conf.file, curproxy->conf.line,
2432 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2433 target->conf.file, target->conf.line);
2434 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002435 } else {
2436 free((void *)rule->be.name);
2437 rule->be.backend = target;
Emeric Brun3f783572017-01-12 11:21:28 +01002438 /* For each target of switching rules, we update
2439 * their tot_fe_maxconn, except if a previous rule point
2440 * on the same backend or on the default backend */
2441 if (rule->be.backend != curproxy->defbe.be) {
2442 struct switching_rule *swrule;
2443
2444 list_for_each_entry(swrule, &curproxy->switching_rules, list) {
2445 if (rule == swrule) {
2446 target->tot_fe_maxconn += curproxy->maxconn;
2447 break;
2448 }
2449 else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) {
2450 /* there is multiple ref of this backend */
2451 break;
2452 }
2453 }
2454 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02002455 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002456 }
2457
Willy Tarreau64ab6072014-09-16 12:17:36 +02002458 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002459 list_for_each_entry(srule, &curproxy->server_rules, list) {
2460 struct server *target = findserver(curproxy, srule->srv.name);
2461
2462 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002463 ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
2464 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002465 cfgerr++;
2466 continue;
2467 }
2468 free((void *)srule->srv.name);
2469 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002470 }
2471
Emeric Brunb982a3d2010-01-04 15:45:53 +01002472 /* find the target table for 'stick' rules */
2473 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
2474 struct proxy *target;
2475
Emeric Brun1d33b292010-01-04 15:47:17 +01002476 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
2477 if (mrule->flags & STK_IS_STORE)
2478 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2479
Emeric Brunb982a3d2010-01-04 15:45:53 +01002480 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02002481 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002482 else
2483 target = curproxy;
2484
2485 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002486 ha_alert("Proxy '%s': unable to find stick-table '%s'.\n",
2487 curproxy->id, mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002488 cfgerr++;
2489 }
2490 else if (target->table.size == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002491 ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n",
2492 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002493 cfgerr++;
2494 }
Willy Tarreau12785782012-04-27 21:37:17 +02002495 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002496 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2497 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002498 cfgerr++;
2499 }
2500 else {
2501 free((void *)mrule->table.name);
2502 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02002503 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002504 }
2505 }
2506
2507 /* find the target table for 'store response' rules */
2508 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
2509 struct proxy *target;
2510
Emeric Brun1d33b292010-01-04 15:47:17 +01002511 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2512
Emeric Brunb982a3d2010-01-04 15:45:53 +01002513 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02002514 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002515 else
2516 target = curproxy;
2517
2518 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002519 ha_alert("Proxy '%s': unable to find store table '%s'.\n",
2520 curproxy->id, mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002521 cfgerr++;
2522 }
2523 else if (target->table.size == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002524 ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n",
2525 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002526 cfgerr++;
2527 }
Willy Tarreau12785782012-04-27 21:37:17 +02002528 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002529 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2530 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002531 cfgerr++;
2532 }
2533 else {
2534 free((void *)mrule->table.name);
2535 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02002536 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002537 }
2538 }
2539
Christopher Faulete4e830d2017-09-18 14:51:41 +02002540 /* check validity for 'tcp-request' layer 4 rules */
2541 list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) {
2542 err = NULL;
2543 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002544 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002545 free(err);
Willy Tarreau5f53de72012-12-12 00:25:44 +01002546 cfgerr++;
2547 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02002548 }
2549
Christopher Faulete4e830d2017-09-18 14:51:41 +02002550 /* check validity for 'tcp-request' layer 5 rules */
2551 list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) {
2552 err = NULL;
2553 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002554 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002555 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002556 cfgerr++;
2557 }
2558 }
2559
Christopher Faulete4e830d2017-09-18 14:51:41 +02002560 /* check validity for 'tcp-request' layer 6 rules */
2561 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
2562 err = NULL;
2563 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002564 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002565 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002566 cfgerr++;
2567 }
2568 }
2569
Christopher Faulete4e830d2017-09-18 14:51:41 +02002570 /* check validity for 'http-request' layer 7 rules */
2571 list_for_each_entry(arule, &curproxy->http_req_rules, list) {
2572 err = NULL;
2573 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002574 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002575 free(err);
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002576 cfgerr++;
2577 }
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002578 }
2579
Christopher Faulete4e830d2017-09-18 14:51:41 +02002580 /* check validity for 'http-response' layer 7 rules */
2581 list_for_each_entry(arule, &curproxy->http_res_rules, list) {
2582 err = NULL;
2583 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002584 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002585 free(err);
Willy Tarreau09448f72014-06-25 18:12:15 +02002586 cfgerr++;
2587 }
Willy Tarreau09448f72014-06-25 18:12:15 +02002588 }
2589
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02002590 /* move any "block" rules at the beginning of the http-request rules */
2591 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
2592 /* insert block_rules into http_req_rules at the beginning */
2593 curproxy->block_rules.p->n = curproxy->http_req_rules.n;
2594 curproxy->http_req_rules.n->p = curproxy->block_rules.p;
2595 curproxy->block_rules.n->p = &curproxy->http_req_rules;
2596 curproxy->http_req_rules.n = curproxy->block_rules.n;
2597 LIST_INIT(&curproxy->block_rules);
2598 }
2599
Emeric Brun32da3c42010-09-23 18:39:19 +02002600 if (curproxy->table.peers.name) {
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002601 struct peers *curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002602
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002603 for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +02002604 if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) {
2605 free((void *)curproxy->table.peers.name);
Willy Tarreau973ca492013-01-17 21:34:52 +01002606 curproxy->table.peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002607 break;
2608 }
2609 }
2610
2611 if (!curpeers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002612 ha_alert("Proxy '%s': unable to find sync peers '%s'.\n",
2613 curproxy->id, curproxy->table.peers.name);
Willy Tarreaud66bf962011-10-28 14:16:49 +02002614 free((void *)curproxy->table.peers.name);
2615 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002616 cfgerr++;
2617 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002618 else if (curpeers->state == PR_STSTOPPED) {
2619 /* silently disable this peers section */
2620 curproxy->table.peers.p = NULL;
2621 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002622 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002623 ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
2624 curproxy->id, localpeer, curpeers->id);
Willy Tarreaud66bf962011-10-28 14:16:49 +02002625 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002626 cfgerr++;
2627 }
2628 }
2629
Simon Horman9dc49962015-01-30 11:22:59 +09002630
2631 if (curproxy->email_alert.mailers.name) {
2632 struct mailers *curmailers = mailers;
2633
2634 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
Christopher Faulet0108bb32017-10-20 21:34:32 +02002635 if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name))
Simon Horman9dc49962015-01-30 11:22:59 +09002636 break;
Simon Horman9dc49962015-01-30 11:22:59 +09002637 }
Simon Horman9dc49962015-01-30 11:22:59 +09002638 if (!curmailers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002639 ha_alert("Proxy '%s': unable to find mailers '%s'.\n",
2640 curproxy->id, curproxy->email_alert.mailers.name);
Simon Horman9dc49962015-01-30 11:22:59 +09002641 free_email_alert(curproxy);
2642 cfgerr++;
2643 }
Christopher Faulet0108bb32017-10-20 21:34:32 +02002644 else {
2645 err = NULL;
2646 if (init_email_alert(curmailers, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002647 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulet0108bb32017-10-20 21:34:32 +02002648 free(err);
2649 cfgerr++;
2650 }
2651 }
Simon Horman9dc49962015-01-30 11:22:59 +09002652 }
2653
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01002654 if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) &&
Willy Tarreauff011f22011-01-06 17:51:27 +01002655 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002656 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002657 ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
2658 "proxy", curproxy->id);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002659 cfgerr++;
2660 goto out_uri_auth_compat;
2661 }
2662
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01002663 if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002664 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02002665 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002666 int i = 0;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002667
Willy Tarreau95fa4692010-02-01 13:05:50 +01002668 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
2669 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002670
2671 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002672 uri_auth_compat_req[i++] = "realm";
2673 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
2674 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002675
Willy Tarreau95fa4692010-02-01 13:05:50 +01002676 uri_auth_compat_req[i++] = "unless";
2677 uri_auth_compat_req[i++] = "{";
2678 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
2679 uri_auth_compat_req[i++] = "}";
2680 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002681
Willy Tarreauff011f22011-01-06 17:51:27 +01002682 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
2683 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002684 cfgerr++;
2685 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002686 }
2687
Willy Tarreauff011f22011-01-06 17:51:27 +01002688 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01002689
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002690 if (curproxy->uri_auth->auth_realm) {
2691 free(curproxy->uri_auth->auth_realm);
2692 curproxy->uri_auth->auth_realm = NULL;
2693 }
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01002694
2695 curproxy->uri_auth->flags |= ST_CONVDONE;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002696 }
2697out_uri_auth_compat:
2698
Dragan Dosen43885c72015-10-01 13:18:13 +02002699 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02002700 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02002701 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
2702 if (!curproxy->conf.logformat_sd_string) {
2703 /* set the default logformat_sd_string */
2704 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
2705 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002706 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02002707 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002708 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02002709
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002710 /* compile the log format */
2711 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02002712 if (curproxy->conf.logformat_string != default_http_log_format &&
2713 curproxy->conf.logformat_string != default_tcp_log_format &&
2714 curproxy->conf.logformat_string != clf_http_log_format)
2715 free(curproxy->conf.logformat_string);
2716 curproxy->conf.logformat_string = NULL;
2717 free(curproxy->conf.lfs_file);
2718 curproxy->conf.lfs_file = NULL;
2719 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002720
2721 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2722 free(curproxy->conf.logformat_sd_string);
2723 curproxy->conf.logformat_sd_string = NULL;
2724 free(curproxy->conf.lfsd_file);
2725 curproxy->conf.lfsd_file = NULL;
2726 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002727 }
2728
Willy Tarreau62a61232013-04-12 18:13:46 +02002729 if (curproxy->conf.logformat_string) {
2730 curproxy->conf.args.ctx = ARGC_LOG;
2731 curproxy->conf.args.file = curproxy->conf.lfs_file;
2732 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002733 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002734 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002735 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002736 ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
2737 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002738 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002739 cfgerr++;
2740 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002741 curproxy->conf.args.file = NULL;
2742 curproxy->conf.args.line = 0;
2743 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002744
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002745 if (curproxy->conf.logformat_sd_string) {
2746 curproxy->conf.args.ctx = ARGC_LOGSD;
2747 curproxy->conf.args.file = curproxy->conf.lfsd_file;
2748 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002749 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002750 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 +01002751 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002752 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2753 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002754 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002755 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002756 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002757 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2758 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002759 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002760 cfgerr++;
2761 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002762 curproxy->conf.args.file = NULL;
2763 curproxy->conf.args.line = 0;
2764 }
2765
Willy Tarreau62a61232013-04-12 18:13:46 +02002766 if (curproxy->conf.uniqueid_format_string) {
2767 curproxy->conf.args.ctx = ARGC_UIF;
2768 curproxy->conf.args.file = curproxy->conf.uif_file;
2769 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002770 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002771 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 +01002772 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002773 ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
2774 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002775 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002776 cfgerr++;
2777 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002778 curproxy->conf.args.file = NULL;
2779 curproxy->conf.args.line = 0;
2780 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002781
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002782 /* only now we can check if some args remain unresolved.
2783 * This must be done after the users and groups resolution.
2784 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002785 cfgerr += smp_resolve_args(curproxy);
2786 if (!cfgerr)
2787 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01002788
Willy Tarreau2738a142006-07-08 17:28:09 +02002789 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002790 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02002791 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02002792 (!curproxy->timeout.connect ||
2793 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002794 ha_warning("config : missing timeouts for %s '%s'.\n"
2795 " | While not properly invalid, you will certainly encounter various problems\n"
2796 " | with such a configuration. To fix this, please ensure that all following\n"
2797 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
2798 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002799 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02002800 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02002801
Willy Tarreau1fa31262007-12-03 00:36:16 +01002802 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
2803 * We must still support older configurations, so let's find out whether those
2804 * parameters have been set or must be copied from contimeouts.
2805 */
2806 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002807 if (!curproxy->timeout.tarpit ||
2808 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01002809 /* tarpit timeout not set. We search in the following order:
2810 * default.tarpit, curr.connect, default.connect.
2811 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002812 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01002813 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002814 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002815 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002816 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002817 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002818 }
2819 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002820 (!curproxy->timeout.queue ||
2821 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01002822 /* queue timeout not set. We search in the following order:
2823 * default.queue, curr.connect, default.connect.
2824 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002825 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01002826 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002827 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002828 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002829 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002830 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002831 }
2832 }
2833
Willy Tarreau1620ec32011-08-06 17:05:02 +02002834 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) {
Willy Tarreau137325d2010-02-01 16:38:17 +01002835 curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02002836 curproxy->check_req = malloc(curproxy->check_len);
Willy Tarreau137325d2010-02-01 16:38:17 +01002837 memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len);
Willy Tarreauf3c69202006-07-09 16:42:34 +02002838 }
2839
Willy Tarreau215663d2014-06-13 18:30:23 +02002840 if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) &&
2841 (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002842 ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
2843 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau215663d2014-06-13 18:30:23 +02002844 err_code |= ERR_WARN;
2845 }
2846
Willy Tarreau193b8c62012-11-22 00:17:38 +01002847 /* ensure that cookie capture length is not too large */
2848 if (curproxy->capture_len >= global.tune.cookie_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002849 ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n",
2850 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau193b8c62012-11-22 00:17:38 +01002851 err_code |= ERR_WARN;
2852 curproxy->capture_len = global.tune.cookie_len - 1;
2853 }
2854
Willy Tarreaucf7f3202007-05-13 22:46:04 +02002855 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01002856 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02002857 curproxy->req_cap_pool = create_pool("ptrcap",
2858 curproxy->nb_req_cap * sizeof(char *),
2859 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01002860 }
2861
2862 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02002863 curproxy->rsp_cap_pool = create_pool("ptrcap",
2864 curproxy->nb_rsp_cap * sizeof(char *),
2865 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01002866 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02002867
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02002868 switch (curproxy->load_server_state_from_file) {
2869 case PR_SRV_STATE_FILE_UNSPEC:
2870 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
2871 break;
2872 case PR_SRV_STATE_FILE_GLOBAL:
2873 if (!global.server_state_file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002874 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",
2875 curproxy->id);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02002876 err_code |= ERR_WARN;
2877 }
2878 break;
2879 }
2880
Willy Tarreaubaaee002006-06-26 02:48:02 +02002881 /* first, we will invert the servers list order */
2882 newsrv = NULL;
2883 while (curproxy->srv) {
2884 struct server *next;
2885
2886 next = curproxy->srv->next;
2887 curproxy->srv->next = newsrv;
2888 newsrv = curproxy->srv;
2889 if (!next)
2890 break;
2891 curproxy->srv = next;
2892 }
2893
Willy Tarreau17edc812014-01-03 12:14:34 +01002894 /* Check that no server name conflicts. This causes trouble in the stats.
2895 * We only emit a warning for the first conflict affecting each server,
2896 * in order to avoid combinatory explosion if all servers have the same
2897 * name. We do that only for servers which do not have an explicit ID,
2898 * because these IDs were made also for distinguishing them and we don't
2899 * want to annoy people who correctly manage them.
2900 */
2901 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
2902 struct server *other_srv;
2903
2904 if (newsrv->puid)
2905 continue;
2906
2907 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
2908 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002909 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",
2910 newsrv->conf.file, newsrv->conf.line,
2911 proxy_type_str(curproxy), curproxy->id,
2912 newsrv->id, other_srv->conf.line);
Willy Tarreau17edc812014-01-03 12:14:34 +01002913 break;
2914 }
2915 }
2916 }
2917
Willy Tarreaudd701652010-05-25 23:03:02 +02002918 /* assign automatic UIDs to servers which don't have one yet */
2919 next_id = 1;
2920 newsrv = curproxy->srv;
2921 while (newsrv != NULL) {
2922 if (!newsrv->puid) {
2923 /* server ID not set, use automatic numbering with first
2924 * spare entry starting with next_svid.
2925 */
2926 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
2927 newsrv->conf.id.key = newsrv->puid = next_id;
2928 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
2929 }
2930 next_id++;
2931 newsrv = newsrv->next;
2932 }
2933
Willy Tarreau20697042007-11-15 23:26:18 +01002934 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01002935 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02002936
Willy Tarreau62c3be22012-01-20 13:12:32 +01002937 /*
2938 * If this server supports a maxconn parameter, it needs a dedicated
2939 * tasks to fill the emptied slots when a connection leaves.
2940 * Also, resolve deferred tracking dependency if needed.
2941 */
2942 newsrv = curproxy->srv;
2943 while (newsrv != NULL) {
2944 if (newsrv->minconn > newsrv->maxconn) {
2945 /* Only 'minconn' was specified, or it was higher than or equal
2946 * to 'maxconn'. Let's turn this into maxconn and clean it, as
2947 * this will avoid further useless expensive computations.
2948 */
2949 newsrv->maxconn = newsrv->minconn;
2950 } else if (newsrv->maxconn && !newsrv->minconn) {
2951 /* minconn was not specified, so we set it to maxconn */
2952 newsrv->minconn = newsrv->maxconn;
2953 }
2954
Willy Tarreau17d45382016-12-22 21:16:08 +01002955 /* this will also properly set the transport layer for prod and checks */
2956 if (newsrv->use_ssl || newsrv->check.use_ssl) {
2957 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
2958 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
2959 }
Emeric Brun94324a42012-10-11 14:00:19 +02002960
Willy Tarreau2f075e92013-12-03 11:11:34 +01002961 /* set the check type on the server */
2962 newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY;
2963
Willy Tarreau62c3be22012-01-20 13:12:32 +01002964 if (newsrv->trackit) {
2965 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02002966 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01002967 char *pname, *sname;
2968
2969 pname = newsrv->trackit;
2970 sname = strrchr(pname, '/');
2971
2972 if (sname)
2973 *sname++ = '\0';
2974 else {
2975 sname = pname;
2976 pname = NULL;
2977 }
2978
2979 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02002980 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01002981 if (!px) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002982 ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
2983 proxy_type_str(curproxy), curproxy->id,
2984 newsrv->id, pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01002985 cfgerr++;
2986 goto next_srv;
2987 }
2988 } else
2989 px = curproxy;
2990
2991 srv = findserver(px, sname);
2992 if (!srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002993 ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
2994 proxy_type_str(curproxy), curproxy->id,
2995 newsrv->id, sname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01002996 cfgerr++;
2997 goto next_srv;
2998 }
2999
Willy Tarreau32091232014-05-16 13:52:00 +02003000 if (!(srv->check.state & CHK_ST_CONFIGURED) &&
3001 !(srv->agent.state & CHK_ST_CONFIGURED) &&
3002 !srv->track && !srv->trackit) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003003 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for "
3004 "tracking as it does not have any check nor agent enabled.\n",
3005 proxy_type_str(curproxy), curproxy->id,
3006 newsrv->id, px->id, srv->id);
Willy Tarreau32091232014-05-16 13:52:00 +02003007 cfgerr++;
3008 goto next_srv;
3009 }
3010
3011 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
3012
Frédéric Lécaille2efc6492017-03-14 14:32:17 +01003013 if (newsrv == srv || loop) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003014 ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it "
3015 "belongs to a tracking chain looping back to %s/%s.\n",
3016 proxy_type_str(curproxy), curproxy->id,
3017 newsrv->id, px->id, srv->id, px->id,
3018 newsrv == srv ? srv->id : loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003019 cfgerr++;
3020 goto next_srv;
3021 }
3022
3023 if (curproxy != px &&
3024 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003025 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for"
3026 "tracking: disable-on-404 option inconsistency.\n",
3027 proxy_type_str(curproxy), curproxy->id,
3028 newsrv->id, px->id, srv->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003029 cfgerr++;
3030 goto next_srv;
3031 }
3032
Willy Tarreau62c3be22012-01-20 13:12:32 +01003033 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01003034 newsrv->tracknext = srv->trackers;
3035 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003036
3037 free(newsrv->trackit);
3038 newsrv->trackit = NULL;
3039 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02003040
Willy Tarreau62c3be22012-01-20 13:12:32 +01003041 next_srv:
3042 newsrv = newsrv->next;
3043 }
3044
Olivier Houchard4e694042017-03-14 20:01:29 +01003045 /*
3046 * Try to generate dynamic cookies for servers now.
3047 * It couldn't be done earlier, since at the time we parsed
3048 * the server line, we may not have known yet that we
3049 * should use dynamic cookies, or the secret key may not
3050 * have been provided yet.
3051 */
3052 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
3053 newsrv = curproxy->srv;
3054 while (newsrv != NULL) {
3055 srv_set_dyncookie(newsrv);
3056 newsrv = newsrv->next;
3057 }
3058
3059 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003060 /* We have to initialize the server lookup mechanism depending
Joseph Herlanta14c03e2018-11-15 14:04:19 -08003061 * on what LB algorithm was chosen.
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003062 */
3063
3064 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
3065 switch (curproxy->lbprm.algo & BE_LB_KIND) {
3066 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02003067 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
3068 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3069 init_server_map(curproxy);
Willy Tarreau760e81d2018-05-03 07:20:40 +02003070 } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
3071 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3072 chash_init_server_tree(curproxy);
Willy Tarreau9757a382009-10-03 12:56:50 +02003073 } else {
3074 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
3075 fwrr_init_server_groups(curproxy);
3076 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003077 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003078
Willy Tarreau3ebb1162012-02-13 16:57:44 +01003079 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01003080 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
3081 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
3082 fwlc_init_server_tree(curproxy);
3083 } else {
3084 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
3085 fas_init_server_tree(curproxy);
3086 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003087 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003088
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003089 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003090 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
3091 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3092 chash_init_server_tree(curproxy);
3093 } else {
3094 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3095 init_server_map(curproxy);
3096 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003097 break;
3098 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003099 HA_SPIN_INIT(&curproxy->lbprm.lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003100
3101 if (curproxy->options & PR_O_LOGASAP)
3102 curproxy->to_log &= ~LW_BYTES;
3103
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003104 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003105 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
3106 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003107 ha_warning("config : log format ignored for %s '%s' since it has no log address.\n",
3108 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003109 err_code |= ERR_WARN;
3110 }
3111
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003112 if (curproxy->mode != PR_MODE_HTTP) {
3113 int optnum;
3114
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003115 if (curproxy->uri_auth) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003116 ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
3117 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003118 err_code |= ERR_WARN;
3119 curproxy->uri_auth = NULL;
3120 }
3121
Willy Tarreaude7dc882017-03-10 11:49:21 +01003122 if (curproxy->capture_name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003123 ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
3124 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003125 err_code |= ERR_WARN;
3126 }
3127
3128 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003129 ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
3130 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003131 err_code |= ERR_WARN;
3132 }
3133
3134 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003135 ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
3136 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003137 err_code |= ERR_WARN;
3138 }
3139
3140 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003141 ha_warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n",
3142 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003143 err_code |= ERR_WARN;
3144 }
3145
3146 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003147 ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
3148 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003149 err_code |= ERR_WARN;
3150 }
3151
Willy Tarreau87cf5142011-08-19 22:57:24 +02003152 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003153 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3154 "forwardfor", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003155 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02003156 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003157 }
3158
3159 if (curproxy->options & PR_O_ORGTO) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003160 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3161 "originalto", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003162 err_code |= ERR_WARN;
3163 curproxy->options &= ~PR_O_ORGTO;
3164 }
3165
3166 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
3167 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
3168 (curproxy->cap & cfg_opts[optnum].cap) &&
3169 (curproxy->options & cfg_opts[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003170 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3171 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003172 err_code |= ERR_WARN;
3173 curproxy->options &= ~cfg_opts[optnum].val;
3174 }
3175 }
3176
3177 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
3178 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
3179 (curproxy->cap & cfg_opts2[optnum].cap) &&
3180 (curproxy->options2 & cfg_opts2[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003181 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3182 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003183 err_code |= ERR_WARN;
3184 curproxy->options2 &= ~cfg_opts2[optnum].val;
3185 }
3186 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003187
Willy Tarreau29fbe512015-08-20 19:35:14 +02003188#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003189 if (curproxy->conn_src.bind_hdr_occ) {
3190 curproxy->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003191 ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
3192 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003193 err_code |= ERR_WARN;
3194 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003195#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003196 }
3197
Willy Tarreaubaaee002006-06-26 02:48:02 +02003198 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01003199 * ensure that we're not cross-dressing a TCP server into HTTP.
3200 */
3201 newsrv = curproxy->srv;
3202 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01003203 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003204 ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
3205 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02003206 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01003207 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003208
Willy Tarreau0cec3312011-10-31 13:49:26 +01003209 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003210 ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
3211 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau0cec3312011-10-31 13:49:26 +01003212 err_code |= ERR_WARN;
3213 }
3214
Willy Tarreauc93cd162014-05-13 15:54:22 +02003215 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003216 ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
3217 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau82ffa392013-08-13 17:19:08 +02003218 err_code |= ERR_WARN;
3219 }
3220
Willy Tarreau29fbe512015-08-20 19:35:14 +02003221#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003222 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
3223 newsrv->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003224 ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
3225 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003226 err_code |= ERR_WARN;
3227 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003228#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01003229
Willy Tarreau46deab62018-04-28 07:18:15 +02003230 if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR)
3231 curproxy->options &= ~PR_O_REUSE_MASK;
3232
Willy Tarreau21d2af32008-02-14 20:25:24 +01003233 newsrv = newsrv->next;
3234 }
3235
Willy Tarreaue42bd962014-09-16 16:21:19 +02003236 /* check if we have a frontend with "tcp-request content" looking at L7
3237 * with no inspect-delay
3238 */
3239 if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) {
Christopher Faulete4e830d2017-09-18 14:51:41 +02003240 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
3241 if (arule->action == ACT_TCP_CAPTURE &&
3242 !(arule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02003243 break;
Christopher Faulete4e830d2017-09-18 14:51:41 +02003244 if ((arule->action >= ACT_ACTION_TRK_SC0 && arule->action <= ACT_ACTION_TRK_SCMAX) &&
3245 !(arule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02003246 break;
3247 }
3248
Christopher Faulete4e830d2017-09-18 14:51:41 +02003249 if (&arule->list != &curproxy->tcp_req.inspect_rules) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003250 ha_warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request"
3251 " contents were found in a frontend without any 'tcp-request inspect-delay' setting."
3252 " This means that these rules will randomly find their contents. This can be fixed by"
3253 " setting the tcp-request inspect-delay.\n",
3254 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue42bd962014-09-16 16:21:19 +02003255 err_code |= ERR_WARN;
3256 }
3257 }
3258
Christopher Fauletd7c91962015-04-30 11:48:27 +02003259 /* Check filter configuration, if any */
3260 cfgerr += flt_check(curproxy);
3261
Willy Tarreauc1a21672009-08-16 22:37:44 +02003262 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02003263 if (!curproxy->accept)
3264 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02003265
Willy Tarreauc1a21672009-08-16 22:37:44 +02003266 if (curproxy->tcp_req.inspect_delay ||
3267 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02003268 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003269
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003270 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003271 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003272 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003273 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003274
William Lallemandcf62f7e2018-10-26 14:47:40 +02003275 if (curproxy->mode == PR_MODE_CLI) {
3276 curproxy->fe_req_ana |= AN_REQ_WAIT_CLI;
3277 curproxy->fe_rsp_ana |= AN_RES_WAIT_CLI;
3278 }
3279
Willy Tarreauc1a21672009-08-16 22:37:44 +02003280 /* both TCP and HTTP must check switching rules */
3281 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003282
3283 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003284 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003285 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3286 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 +01003287 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003288 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3289 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003290 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003291 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003292 }
3293
3294 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02003295 if (curproxy->tcp_req.inspect_delay ||
3296 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
3297 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
3298
Emeric Brun97679e72010-09-23 17:56:44 +02003299 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
3300 curproxy->be_rsp_ana |= AN_RES_INSPECT;
3301
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003302 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003303 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003304 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003305 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003306
3307 /* If the backend does requires RDP cookie persistence, we have to
3308 * enable the corresponding analyser.
3309 */
3310 if (curproxy->options2 & PR_O2_RDPC_PRST)
3311 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003312
3313 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003314 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003315 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3316 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 +01003317 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003318 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3319 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003320 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003321 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003322 }
Christopher Fauleta717b992018-04-10 14:43:00 +02003323
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003324 /* Check the mux protocols, if any, for each listener and server
Christopher Fauleta717b992018-04-10 14:43:00 +02003325 * attached to the current proxy */
3326 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3327 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003328 const struct mux_proto_list *mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003329
Christopher Faulet7ff4f142018-11-20 11:23:52 +01003330 /* Special case for HTX because it is still experimental */
3331 if (curproxy->options2 & PR_O2_USE_HTX)
3332 mode = PROTO_MODE_HTX;
3333
Christopher Fauleta717b992018-04-10 14:43:00 +02003334 if (!bind_conf->mux_proto)
3335 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003336
3337 /* it is possible that an incorrect mux was referenced
3338 * due to the proxy's mode not being taken into account
3339 * on first pass. Let's adjust it now.
3340 */
3341 mux_ent = conn_get_best_mux_entry(bind_conf->mux_proto->token, PROTO_SIDE_FE, mode);
3342
3343 if (!mux_ent || !isteq(mux_ent->token, bind_conf->mux_proto->token)) {
Christopher Fauleta717b992018-04-10 14:43:00 +02003344 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n",
3345 proxy_type_str(curproxy), curproxy->id,
3346 (int)bind_conf->mux_proto->token.len,
3347 bind_conf->mux_proto->token.ptr,
3348 bind_conf->arg, bind_conf->file, bind_conf->line);
3349 cfgerr++;
3350 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003351
3352 /* update the mux */
3353 bind_conf->mux_proto = mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003354 }
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003355 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3356 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003357 const struct mux_proto_list *mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003358
Christopher Faulet7ff4f142018-11-20 11:23:52 +01003359 /* Special case for HTX because it is still experimental */
3360 if (curproxy->options2 & PR_O2_USE_HTX)
3361 mode = PROTO_MODE_HTX;
3362
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003363 if (!newsrv->mux_proto)
3364 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003365
3366 /* it is possible that an incorrect mux was referenced
3367 * due to the proxy's mode not being taken into account
3368 * on first pass. Let's adjust it now.
3369 */
3370 mux_ent = conn_get_best_mux_entry(newsrv->mux_proto->token, PROTO_SIDE_BE, mode);
3371
3372 if (!mux_ent || !isteq(mux_ent->token, newsrv->mux_proto->token)) {
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003373 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n",
3374 proxy_type_str(curproxy), curproxy->id,
3375 (int)newsrv->mux_proto->token.len,
3376 newsrv->mux_proto->token.ptr,
3377 newsrv->id, newsrv->conf.file, newsrv->conf.line);
3378 cfgerr++;
3379 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003380
3381 /* update the mux */
3382 newsrv->mux_proto = mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003383 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003384 }
3385
3386 /***********************************************************/
3387 /* At this point, target names have already been resolved. */
3388 /***********************************************************/
3389
3390 /* Check multi-process mode compatibility */
3391
3392 if (global.nbproc > 1 && global.stats_fe) {
3393 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3394 unsigned long mask;
3395
3396 mask = nbits(global.nbproc);
3397 if (global.stats_fe->bind_proc)
3398 mask &= global.stats_fe->bind_proc;
3399
3400 if (bind_conf->bind_proc)
3401 mask &= bind_conf->bind_proc;
3402
3403 /* stop here if more than one process is used */
Willy Tarreau9504dd62018-10-15 09:37:03 +02003404 if (atleast2(mask))
Willy Tarreau419ead82014-09-16 13:41:21 +02003405 break;
3406 }
3407 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003408 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 +02003409 }
3410 }
3411
3412 /* Make each frontend inherit bind-process from its listeners when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003413 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003414 if (curproxy->bind_proc)
3415 continue;
3416
3417 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3418 unsigned long mask;
3419
Willy Tarreaue428b082015-05-04 21:57:58 +02003420 mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003421 curproxy->bind_proc |= mask;
3422 }
3423
3424 if (!curproxy->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02003425 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003426 }
3427
3428 if (global.stats_fe) {
3429 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3430 unsigned long mask;
3431
Cyril Bonté06181952016-02-24 00:14:54 +01003432 mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02003433 global.stats_fe->bind_proc |= mask;
3434 }
3435 if (!global.stats_fe->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02003436 global.stats_fe->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003437 }
3438
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003439 /* propagate bindings from frontends to backends. Don't do it if there
3440 * are any fatal errors as we must not call it with unresolved proxies.
3441 */
3442 if (!cfgerr) {
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003443 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003444 if (curproxy->cap & PR_CAP_FE)
3445 propagate_processes(curproxy, NULL);
3446 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003447 }
3448
3449 /* Bind each unbound backend to all processes when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003450 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003451 if (curproxy->bind_proc)
3452 continue;
Willy Tarreaue428b082015-05-04 21:57:58 +02003453 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003454 }
3455
3456 /*******************************************************/
3457 /* At this step, all proxies have a non-null bind_proc */
3458 /*******************************************************/
3459
3460 /* perform the final checks before creating tasks */
3461
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003462 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003463 struct listener *listener;
3464 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003465
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003466 /* Configure SSL for each bind line.
3467 * Note: if configuration fails at some point, the ->ctx member
3468 * remains NULL so that listeners can later detach.
3469 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003470 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01003471 if (bind_conf->xprt->prepare_bind_conf &&
3472 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003473 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003474 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003475
Willy Tarreaue6b98942007-10-29 01:09:36 +01003476 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003477 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02003478 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003479 int nbproc;
3480
3481 nbproc = my_popcountl(curproxy->bind_proc &
Cyril Bonté4920d702016-04-15 07:58:43 +02003482 (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) &
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003483 nbits(global.nbproc));
3484
3485 if (!nbproc) /* no intersection between listener and frontend */
3486 nbproc = 1;
3487
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003488 if (!listener->luid) {
3489 /* listener ID not set, use automatic numbering with first
3490 * spare entry starting with next_luid.
3491 */
3492 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
3493 listener->conf.id.key = listener->luid = next_id;
3494 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003495 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01003496 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003497
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003498 /* enable separate counters */
3499 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01003500 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003501 if (!listener->name)
3502 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003503 }
Willy Tarreau81796be2012-09-22 19:11:47 +02003504
Willy Tarreaue6b98942007-10-29 01:09:36 +01003505 if (curproxy->options & PR_O_TCP_NOLING)
3506 listener->options |= LI_O_NOLINGER;
Willy Tarreau32368ce2012-09-06 11:10:55 +02003507 if (!listener->maxconn)
3508 listener->maxconn = curproxy->maxconn;
3509 if (!listener->backlog)
3510 listener->backlog = curproxy->backlog;
Willy Tarreau16a21472012-11-19 12:39:59 +01003511 if (!listener->maxaccept)
3512 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
3513
3514 /* we want to have an optimal behaviour on single process mode to
3515 * maximize the work at once, but in multi-process we want to keep
3516 * some fairness between processes, so we target half of the max
3517 * number of events to be balanced over all the processes the proxy
3518 * is bound to. Rememeber that maxaccept = -1 must be kept as it is
3519 * used to disable the limit.
3520 */
3521 if (listener->maxaccept > 0) {
3522 if (nbproc > 1)
3523 listener->maxaccept = (listener->maxaccept + 1) / 2;
3524 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
3525 }
3526
Willy Tarreau9903f0e2015-04-04 18:50:31 +02003527 listener->accept = session_accept_fd;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003528 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01003529 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01003530
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003531 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02003532 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003533
Willy Tarreau620408f2016-10-21 16:37:51 +02003534 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
3535 listener->options |= LI_O_TCP_L5_RULES;
3536
Willy Tarreaude3041d2010-05-31 10:56:17 +02003537 if (curproxy->mon_mask.s_addr)
3538 listener->options |= LI_O_CHK_MONNET;
3539
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003540 /* smart accept mode is automatic in HTTP mode */
3541 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003542 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003543 !(curproxy->no_options2 & PR_O2_SMARTACC)))
3544 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01003545 }
3546
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003547 /* Release unused SSL configs */
3548 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01003549 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
3550 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003551 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003552
Willy Tarreau9504dd62018-10-15 09:37:03 +02003553 if (atleast2(curproxy->bind_proc & nbits(global.nbproc))) {
Willy Tarreau102df612014-05-07 23:56:38 +02003554 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02003555 int count, maxproc = 0;
3556
3557 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
David Carliere6c39412015-07-02 07:00:17 +00003558 count = my_popcountl(bind_conf->bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003559 if (count > maxproc)
3560 maxproc = count;
3561 }
3562 /* backends have 0, frontends have 1 or more */
3563 if (maxproc != 1)
Christopher Faulet767a84b2017-11-24 16:50:31 +01003564 ha_warning("Proxy '%s': in multi-process mode, stats will be"
3565 " limited to process assigned to the current request.\n",
3566 curproxy->id);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003567
Willy Tarreau102df612014-05-07 23:56:38 +02003568 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003569 ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
3570 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003571 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003572 }
Willy Tarreau102df612014-05-07 23:56:38 +02003573 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003574 ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
3575 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003576 }
3577 }
Willy Tarreau918ff602011-07-25 16:33:49 +02003578
3579 /* create the task associated with the proxy */
Emeric Brunc60def82017-09-27 14:59:38 +02003580 curproxy->task = task_new(MAX_THREADS_MASK);
Willy Tarreau918ff602011-07-25 16:33:49 +02003581 if (curproxy->task) {
3582 curproxy->task->context = curproxy;
3583 curproxy->task->process = manage_proxy;
Willy Tarreau918ff602011-07-25 16:33:49 +02003584 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003585 ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
3586 curproxy->id);
Willy Tarreau918ff602011-07-25 16:33:49 +02003587 cfgerr++;
3588 }
Willy Tarreaub369a042014-09-16 13:21:03 +02003589 }
3590
Willy Tarreaufbb78422011-06-05 15:38:35 +02003591 /* automatically compute fullconn if not set. We must not do it in the
3592 * loop above because cross-references are not yet fully resolved.
3593 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003594 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02003595 /* If <fullconn> is not set, let's set it to 10% of the sum of
3596 * the possible incoming frontend's maxconns.
3597 */
3598 if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02003599 /* we have the sum of the maxconns in <total>. We only
3600 * keep 10% of that sum to set the default fullconn, with
3601 * a hard minimum of 1 (to avoid a divide by zero).
3602 */
Emeric Brun3f783572017-01-12 11:21:28 +01003603 curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10;
Willy Tarreaufbb78422011-06-05 15:38:35 +02003604 if (!curproxy->fullconn)
3605 curproxy->fullconn = 1;
3606 }
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01003607 }
3608
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003609 /*
3610 * Recount currently required checks.
3611 */
3612
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003613 for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003614 int optnum;
3615
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003616 for (optnum = 0; cfg_opts[optnum].name; optnum++)
3617 if (curproxy->options & cfg_opts[optnum].val)
3618 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003619
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003620 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
3621 if (curproxy->options2 & cfg_opts2[optnum].val)
3622 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003623 }
3624
Willy Tarreau0fca4832015-05-01 19:12:05 +02003625 /* compute the required process bindings for the peers */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003626 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
Willy Tarreau0fca4832015-05-01 19:12:05 +02003627 if (curproxy->table.peers.p)
3628 curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
3629
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003630 if (cfg_peers) {
3631 struct peers *curpeers = cfg_peers, **last;
Willy Tarreau122541c2011-09-07 21:24:49 +02003632 struct peer *p, *pb;
3633
Willy Tarreau1e273012015-05-01 19:15:17 +02003634 /* Remove all peers sections which don't have a valid listener,
3635 * which are not used by any table, or which are bound to more
3636 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02003637 */
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003638 last = &cfg_peers;
Willy Tarreau122541c2011-09-07 21:24:49 +02003639 while (*last) {
3640 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003641
3642 if (curpeers->state == PR_STSTOPPED) {
3643 /* the "disabled" keyword was present */
3644 if (curpeers->peers_fe)
3645 stop_proxy(curpeers->peers_fe);
3646 curpeers->peers_fe = NULL;
3647 }
3648 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003649 ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
3650 curpeers->id, localpeer);
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003651 }
Willy Tarreau9504dd62018-10-15 09:37:03 +02003652 else if (atleast2(curpeers->peers_fe->bind_proc)) {
Willy Tarreau1e273012015-05-01 19:15:17 +02003653 /* either it's totally stopped or too much used */
3654 if (curpeers->peers_fe->bind_proc) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003655 ha_alert("Peers section '%s': peers referenced by sections "
3656 "running in different processes (%d different ones). "
3657 "Check global.nbproc and all tables' bind-process "
3658 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02003659 cfgerr++;
3660 }
3661 stop_proxy(curpeers->peers_fe);
3662 curpeers->peers_fe = NULL;
3663 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003664 else {
Willy Tarreaud9443442018-10-15 11:18:03 +02003665 if (!peers_init_sync(curpeers)) {
3666 ha_alert("Peers section '%s': out of memory, giving up on peers.\n",
3667 curpeers->id);
3668 cfgerr++;
3669 break;
3670 }
Willy Tarreau122541c2011-09-07 21:24:49 +02003671 last = &curpeers->next;
3672 continue;
3673 }
3674
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003675 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02003676 p = curpeers->remote;
3677 while (p) {
3678 pb = p->next;
3679 free(p->id);
3680 free(p);
3681 p = pb;
3682 }
3683
3684 /* Destroy and unlink this curpeers section.
3685 * Note: curpeers is backed up into *last.
3686 */
3687 free(curpeers->id);
3688 curpeers = curpeers->next;
3689 free(*last);
3690 *last = curpeers;
3691 }
3692 }
3693
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003694 /* initialize stick-tables on backend capable proxies. This must not
3695 * be done earlier because the data size may be discovered while parsing
3696 * other proxies.
3697 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003698 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003699 if (curproxy->state == PR_STSTOPPED)
3700 continue;
3701
3702 if (!stktable_init(&curproxy->table)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003703 ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003704 cfgerr++;
3705 }
3706 }
3707
Simon Horman0d16a402015-01-30 11:22:58 +09003708 if (mailers) {
3709 struct mailers *curmailers = mailers, **last;
3710 struct mailer *m, *mb;
3711
3712 /* Remove all mailers sections which don't have a valid listener.
3713 * This can happen when a mailers section is never referenced.
3714 */
3715 last = &mailers;
3716 while (*last) {
3717 curmailers = *last;
3718 if (curmailers->users) {
3719 last = &curmailers->next;
3720 continue;
3721 }
3722
Christopher Faulet767a84b2017-11-24 16:50:31 +01003723 ha_warning("Removing incomplete section 'mailers %s'.\n",
3724 curmailers->id);
Simon Horman0d16a402015-01-30 11:22:58 +09003725
3726 m = curmailers->mailer_list;
3727 while (m) {
3728 mb = m->next;
3729 free(m->id);
3730 free(m);
3731 m = mb;
3732 }
3733
3734 /* Destroy and unlink this curmailers section.
3735 * Note: curmailers is backed up into *last.
3736 */
3737 free(curmailers->id);
3738 curmailers = curmailers->next;
3739 free(*last);
3740 *last = curmailers;
3741 }
3742 }
3743
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003744 /* Update server_state_file_name to backend name if backend is supposed to use
3745 * a server-state file locally defined and none has been provided */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003746 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003747 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
3748 curproxy->server_state_file_name == NULL)
3749 curproxy->server_state_file_name = strdup(curproxy->id);
3750 }
3751
Willy Tarreaubafbe012017-11-24 17:34:44 +01003752 pool_head_hdr_idx = create_pool("hdr_idx",
Willy Tarreauac1932d2011-10-24 19:14:41 +02003753 global.tune.max_http_hdr * sizeof(struct hdr_idx_elem),
Willy Tarreau34eb6712011-10-24 18:15:04 +02003754 MEM_F_SHARED);
3755
Ben Draut054fbee2018-04-13 15:43:04 -06003756 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
3757 if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
3758 ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n",
3759 curr_resolvers->id, curr_resolvers->conf.file,
3760 curr_resolvers->conf.line);
3761 err_code |= ERR_WARN;
3762 }
3763 }
3764
William Lallemand48b4bb42017-10-23 14:36:34 +02003765 list_for_each_entry(postparser, &postparsers, list) {
3766 if (postparser->func)
3767 cfgerr += postparser->func();
3768 }
3769
Willy Tarreaubb925012009-07-23 13:36:36 +02003770 if (cfgerr > 0)
3771 err_code |= ERR_ALERT | ERR_FATAL;
3772 out:
3773 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003774}
3775
Willy Tarreau5b2c3362008-07-09 19:39:06 +02003776/*
3777 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
3778 * parsing sessions.
3779 */
3780void cfg_register_keywords(struct cfg_kw_list *kwl)
3781{
3782 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
3783}
Willy Tarreaubaaee002006-06-26 02:48:02 +02003784
Willy Tarreau5b2c3362008-07-09 19:39:06 +02003785/*
3786 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
3787 */
3788void cfg_unregister_keywords(struct cfg_kw_list *kwl)
3789{
3790 LIST_DEL(&kwl->list);
3791 LIST_INIT(&kwl->list);
3792}
Willy Tarreaubaaee002006-06-26 02:48:02 +02003793
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01003794/* this function register new section in the haproxy configuration file.
3795 * <section_name> is the name of this new section and <section_parser>
3796 * is the called parser. If two section declaration have the same name,
3797 * only the first declared is used.
3798 */
3799int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +02003800 int (*section_parser)(const char *, int, char **, int),
3801 int (*post_section_parser)())
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01003802{
3803 struct cfg_section *cs;
3804
Willy Tarreau5e4261b2016-05-17 16:16:09 +02003805 list_for_each_entry(cs, &sections, list) {
3806 if (strcmp(cs->section_name, section_name) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003807 ha_alert("register section '%s': already registered.\n", section_name);
Willy Tarreau5e4261b2016-05-17 16:16:09 +02003808 return 0;
3809 }
3810 }
3811
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01003812 cs = calloc(1, sizeof(*cs));
3813 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003814 ha_alert("register section '%s': out of memory.\n", section_name);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01003815 return 0;
3816 }
3817
3818 cs->section_name = section_name;
3819 cs->section_parser = section_parser;
William Lallemandd2ff56d2017-10-16 11:06:50 +02003820 cs->post_section_parser = post_section_parser;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01003821
3822 LIST_ADDQ(&sections, &cs->list);
3823
3824 return 1;
3825}
3826
William Lallemand48b4bb42017-10-23 14:36:34 +02003827/* this function register a new function which will be called once the haproxy
3828 * configuration file has been parsed. It's useful to check dependencies
3829 * between sections or to resolve items once everything is parsed.
3830 */
3831int cfg_register_postparser(char *name, int (*func)())
3832{
3833 struct cfg_postparser *cp;
3834
3835 cp = calloc(1, sizeof(*cp));
3836 if (!cp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003837 ha_alert("register postparser '%s': out of memory.\n", name);
William Lallemand48b4bb42017-10-23 14:36:34 +02003838 return 0;
3839 }
3840 cp->name = name;
3841 cp->func = func;
3842
3843 LIST_ADDQ(&postparsers, &cp->list);
3844
3845 return 1;
3846}
3847
Willy Tarreaubaaee002006-06-26 02:48:02 +02003848/*
David Carlier845efb52015-09-25 11:49:18 +01003849 * free all config section entries
3850 */
3851void cfg_unregister_sections(void)
3852{
3853 struct cfg_section *cs, *ics;
3854
3855 list_for_each_entry_safe(cs, ics, &sections, list) {
3856 LIST_DEL(&cs->list);
3857 free(cs);
3858 }
3859}
3860
Christopher Faulet7110b402016-10-26 11:09:44 +02003861void cfg_backup_sections(struct list *backup_sections)
3862{
3863 struct cfg_section *cs, *ics;
3864
3865 list_for_each_entry_safe(cs, ics, &sections, list) {
3866 LIST_DEL(&cs->list);
3867 LIST_ADDQ(backup_sections, &cs->list);
3868 }
3869}
3870
3871void cfg_restore_sections(struct list *backup_sections)
3872{
3873 struct cfg_section *cs, *ics;
3874
3875 list_for_each_entry_safe(cs, ics, backup_sections, list) {
3876 LIST_DEL(&cs->list);
3877 LIST_ADDQ(&sections, &cs->list);
3878 }
3879}
3880
Willy Tarreaue6552512018-11-26 11:33:13 +01003881/* these are the config sections handled by default */
3882REGISTER_CONFIG_SECTION("listen", cfg_parse_listen, NULL);
3883REGISTER_CONFIG_SECTION("frontend", cfg_parse_listen, NULL);
3884REGISTER_CONFIG_SECTION("backend", cfg_parse_listen, NULL);
3885REGISTER_CONFIG_SECTION("defaults", cfg_parse_listen, NULL);
3886REGISTER_CONFIG_SECTION("global", cfg_parse_global, NULL);
3887REGISTER_CONFIG_SECTION("userlist", cfg_parse_users, NULL);
3888REGISTER_CONFIG_SECTION("peers", cfg_parse_peers, NULL);
3889REGISTER_CONFIG_SECTION("mailers", cfg_parse_mailers, NULL);
3890REGISTER_CONFIG_SECTION("namespace_list", cfg_parse_netns, NULL);
3891REGISTER_CONFIG_SECTION("resolvers", cfg_parse_resolvers, NULL);
Willy Tarreau659fbf02016-05-26 17:55:28 +02003892
David Carlier845efb52015-09-25 11:49:18 +01003893/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02003894 * Local variables:
3895 * c-indent-level: 8
3896 * c-basic-offset: 8
3897 * End:
3898 */