blob: 429954ca18091b460ba4f35964c039f8102400fb [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
Willy Tarreaue5733232019-05-22 19:24:06 +020013#ifdef USE_LIBCRYPT
Cyril Bonté1a0191d2014-08-29 20:20:02 +020014/* This is to have crypt() defined on Linux */
15#define _GNU_SOURCE
16
Willy Tarreaue5733232019-05-22 19:24:06 +020017#ifdef USE_CRYPT_H
Cyril Bonté1a0191d2014-08-29 20:20:02 +020018/* some platforms such as Solaris need this */
19#include <crypt.h>
20#endif
Willy Tarreaue5733232019-05-22 19:24:06 +020021#endif /* USE_LIBCRYPT */
Cyril Bonté1a0191d2014-08-29 20:20:02 +020022
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 Tarreaudcc048a2020-06-04 19:11:43 +020036#include <haproxy/acl.h>
Willy Tarreau122eba92020-06-04 10:15:32 +020037#include <haproxy/action-t.h>
Willy Tarreauac13aea2020-06-04 10:36:03 +020038#include <haproxy/auth.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020039#include <haproxy/api.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020040#include <haproxy/capture.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020041#include <common/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020042#include <haproxy/check.h>
Willy Tarreauc13ed532020-06-02 10:22:45 +020043#include <haproxy/chunk.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020044#include <haproxy/connection.h>
Willy Tarreaueb92deb2020-06-04 10:53:16 +020045#include <haproxy/dns.h>
Willy Tarreau8d366972020-05-27 16:10:29 +020046#include <haproxy/errors.h>
Willy Tarreau762d7a52020-06-04 11:23:07 +020047#include <haproxy/frontend.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020048#include <haproxy/http_rules.h>
Willy Tarreaufbe8da32020-06-04 14:34:27 +020049#include <haproxy/lb_chash.h>
Willy Tarreaub5fc3bf2020-06-04 14:37:38 +020050#include <haproxy/lb_fas.h>
Willy Tarreau02549412020-06-04 14:41:04 +020051#include <haproxy/lb_fwlc.h>
Willy Tarreau546ba422020-06-04 14:45:03 +020052#include <haproxy/lb_fwrr.h>
Willy Tarreau28671592020-06-04 20:22:59 +020053#include <haproxy/lb_map.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020054#include <haproxy/listener.h>
Willy Tarreaucc9bbfb2020-06-04 11:09:42 +020055#include <haproxy/mailers-t.h>
Willy Tarreau8efbdfb2020-06-04 11:29:21 +020056#include <haproxy/obj_type-t.h>
Willy Tarreau3c2a7c22020-06-04 18:38:21 +020057#include <haproxy/peers-t.h>
Willy Tarreaud0ef4392020-06-02 09:38:52 +020058#include <haproxy/pool.h>
Willy Tarreau48d25b32020-06-04 18:58:52 +020059#include <haproxy/session.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020060#include <haproxy/stats-t.h>
Willy Tarreau48fbcae2020-06-03 18:09:46 +020061#include <haproxy/tools.h>
Willy Tarreau92b4f132020-06-01 11:05:15 +020062#include <haproxy/time.h>
Willy Tarreau8c42b8a2020-06-04 19:27:34 +020063#include <haproxy/uri_auth-t.h>
Willy Tarreau7a00efb2020-06-02 17:02:59 +020064#include <haproxy/namespace.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020065#include <haproxy/task.h>
Willy Tarreau3f567e42020-05-28 15:29:19 +020066#include <haproxy/thread.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020067
Christopher Fauletd7c91962015-04-30 11:48:27 +020068#include <types/filters.h>
Willy Tarreauf268ee82020-06-04 17:05:57 +020069#include <haproxy/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020070
71#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020072#include <proto/channel.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020073#include <proto/filters.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020074#include <proto/log.h>
Willy Tarreau2dd7c352020-06-03 15:26:55 +020075#include <haproxy/protocol.h>
Christopher Fauletfc9cfe42019-07-16 14:54:53 +020076#include <proto/http_ana.h>
Willy Tarreau2b5652f2006-12-31 17:46:05 +010077#include <proto/proxy.h>
Willy Tarreau3c2a7c22020-06-04 18:38:21 +020078#include <haproxy/peers.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020079#include <haproxy/sample.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020080#include <proto/server.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020081#include <proto/stream.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020082#include <haproxy/stick_table.h>
Willy Tarreau8b550af2020-06-04 17:42:48 +020083#include <haproxy/tcp_rules.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020084
85
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +010086/* Used to chain configuration sections definitions. This list
87 * stores struct cfg_section
88 */
89struct list sections = LIST_HEAD_INIT(sections);
90
William Lallemand48b4bb42017-10-23 14:36:34 +020091struct list postparsers = LIST_HEAD_INIT(postparsers);
92
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010093char *cursection = NULL;
94struct proxy defproxy = { }; /* fake proxy used to assign default values on all instances */
Willy Tarreauc8d5b952019-02-27 17:25:52 +010095int cfg_maxpconn = 0; /* # of simultaneous connections per proxy (-N) */
Willy Tarreau5af24ef2009-03-15 15:23:16 +010096int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
Christopher Faulet79bdef32016-11-04 22:36:15 +010097char *cfg_scope = NULL; /* the current scope during the configuration parsing */
Willy Tarreaubaaee002006-06-26 02:48:02 +020098
Willy Tarreau5b2c3362008-07-09 19:39:06 +020099/* List head of all known configuration keywords */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100100struct cfg_kw_list cfg_keywords = {
Willy Tarreau5b2c3362008-07-09 19:39:06 +0200101 .list = LIST_HEAD_INIT(cfg_keywords.list)
102};
103
Willy Tarreaubaaee002006-06-26 02:48:02 +0200104/*
105 * converts <str> to a list of listeners which are dynamically allocated.
106 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
107 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
108 * - <port> is a numerical port from 1 to 65535 ;
109 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
110 * This can be repeated as many times as necessary, separated by a coma.
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200111 * Function returns 1 for success or 0 if error. In case of errors, if <err> is
112 * not NULL, it must be a valid pointer to either NULL or a freeable area that
113 * will be replaced with an error message.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200114 */
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200115int 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 +0200116{
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100117 char *next, *dupstr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200118 int port, end;
119
120 next = dupstr = strdup(str);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200121
Willy Tarreaubaaee002006-06-26 02:48:02 +0200122 while (next && *next) {
William Lallemand75ea0a02017-11-15 19:02:58 +0100123 int inherited = 0;
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200124 struct sockaddr_storage *ss2;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100125 int fd = -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200126
127 str = next;
128 /* 1) look for the end of the first address */
Krzysztof Piotr Oledzki52d522b2009-01-27 16:57:08 +0100129 if ((next = strchr(str, ',')) != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200130 *next++ = 0;
131 }
132
Willy Tarreau48ef4c92017-01-06 18:32:38 +0100133 ss2 = str2sa_range(str, NULL, &port, &end, err,
Willy Tarreau72b8c1f2015-09-08 15:50:19 +0200134 curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
Thierry FOURNIER7fe3be72015-09-26 20:03:36 +0200135 NULL, 1);
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100136 if (!ss2)
137 goto fail;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200138
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100139 if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100140 if (!port && !end) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200141 memprintf(err, "missing port number: '%s'\n", str);
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100142 goto fail;
Emeric Bruned760922010-10-22 17:59:25 +0200143 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200144
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100145 if (!port || !end) {
146 memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str);
147 goto fail;
148 }
149
Emeric Bruned760922010-10-22 17:59:25 +0200150 if (port < 1 || port > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200151 memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str);
Emeric Bruned760922010-10-22 17:59:25 +0200152 goto fail;
153 }
154
155 if (end < 1 || end > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200156 memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str);
Emeric Bruned760922010-10-22 17:59:25 +0200157 goto fail;
158 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200159 }
Willy Tarreau40aa0702013-03-10 23:51:38 +0100160 else if (ss2->ss_family == AF_UNSPEC) {
161 socklen_t addr_len;
William Lallemand75ea0a02017-11-15 19:02:58 +0100162 inherited = 1;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100163
164 /* We want to attach to an already bound fd whose number
165 * is in the addr part of ss2 when cast to sockaddr_in.
166 * Note that by definition there is a single listener.
167 * We still have to determine the address family to
168 * register the correct protocol.
169 */
170 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
171 addr_len = sizeof(*ss2);
172 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
173 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
174 goto fail;
175 }
176
177 port = end = get_host_port(ss2);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200178
179 } else if (ss2->ss_family == AF_CUST_SOCKPAIR) {
180 socklen_t addr_len;
181 inherited = 1;
182
183 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
184 addr_len = sizeof(*ss2);
185 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
186 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
187 goto fail;
188 }
189
190 ss2->ss_family = AF_CUST_SOCKPAIR; /* reassign AF_CUST_SOCKPAIR because of getsockname */
191 port = end = 0;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100192 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200193
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100194 /* OK the address looks correct */
William Lallemand75ea0a02017-11-15 19:02:58 +0100195 if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) {
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200196 memprintf(err, "%s for address '%s'.\n", *err, str);
197 goto fail;
198 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200199 } /* end while(next) */
200 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200201 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200202 fail:
203 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200204 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200205}
206
William Lallemand6e62fb62015-04-28 16:55:23 +0200207/*
Willy Tarreauece9b072016-12-21 22:41:44 +0100208 * Report an error in <msg> when there are too many arguments. This version is
209 * intended to be used by keyword parsers so that the message will be included
210 * into the general error message. The index is the current keyword in args.
211 * Return 0 if the number of argument is correct, otherwise build a message and
212 * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The
213 * message may also be null, it will simply not be produced (useful to check only).
214 * <msg> and <err_code> are only affected on error.
215 */
216int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code)
217{
218 int i;
219
220 if (!*args[index + maxarg + 1])
221 return 0;
222
223 if (msg) {
224 *msg = NULL;
225 memprintf(msg, "%s", args[0]);
226 for (i = 1; i <= index; i++)
227 memprintf(msg, "%s %s", *msg, args[i]);
228
229 memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]);
230 }
231 if (err_code)
232 *err_code |= ERR_ALERT | ERR_FATAL;
233
234 return 1;
235}
236
237/*
238 * same as too_many_args_idx with a 0 index
239 */
240int too_many_args(int maxarg, char **args, char **msg, int *err_code)
241{
242 return too_many_args_idx(maxarg, 0, args, msg, err_code);
243}
244
245/*
William Lallemand6e62fb62015-04-28 16:55:23 +0200246 * Report a fatal Alert when there is too much arguments
247 * The index is the current keyword in args
248 * Return 0 if the number of argument is correct, otherwise emit an alert and return 1
249 * Fill err_code with an ERR_ALERT and an ERR_FATAL
250 */
251int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code)
252{
253 char *kw = NULL;
254 int i;
255
256 if (!*args[index + maxarg + 1])
257 return 0;
258
259 memprintf(&kw, "%s", args[0]);
260 for (i = 1; i <= index; i++) {
261 memprintf(&kw, "%s %s", kw, args[i]);
262 }
263
Christopher Faulet767a84b2017-11-24 16:50:31 +0100264 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 +0200265 free(kw);
266 *err_code |= ERR_ALERT | ERR_FATAL;
267 return 1;
268}
269
270/*
271 * same as alertif_too_many_args_idx with a 0 index
272 */
273int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code)
274{
275 return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code);
276}
277
Willy Tarreau61d18892009-03-31 10:49:21 +0200278
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100279/* Report it if a request ACL condition uses some keywords that are incompatible
280 * with the place where the ACL is used. It returns either 0 or ERR_WARN so that
281 * its result can be or'ed with err_code. Note that <cond> may be NULL and then
282 * will be ignored.
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100283 */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100284int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100285{
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100286 const struct acl *acl;
Willy Tarreau93fddf12013-03-31 22:59:32 +0200287 const char *kw;
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100288
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100289 if (!cond)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100290 return 0;
291
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100292 acl = acl_cond_conflicts(cond, where);
293 if (acl) {
294 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100295 ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n",
296 file, line, acl->name, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100297 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100298 ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
299 file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100300 return ERR_WARN;
301 }
302 if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100303 return 0;
304
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100305 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100306 ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
307 file, line, acl->name, kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100308 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100309 ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
310 file, line, kw, sample_ckp_names(where));
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100311 return ERR_WARN;
312}
313
Christopher Faulet62519022017-10-16 15:49:32 +0200314/* Parse a string representing a process number or a set of processes. It must
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100315 * be "all", "odd", "even", a number between 1 and <max> or a range with
Christopher Faulet5ab51772017-11-22 11:21:58 +0100316 * two such numbers delimited by a dash ('-'). On success, it returns
317 * 0. otherwise it returns 1 with an error message in <err>.
Christopher Faulet62519022017-10-16 15:49:32 +0200318 *
319 * Note: this function can also be used to parse a thread number or a set of
320 * threads.
321 */
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100322int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200323{
Christopher Faulet26028f62017-11-22 15:01:51 +0100324 if (autoinc) {
325 *autoinc = 0;
326 if (strncmp(arg, "auto:", 5) == 0) {
327 arg += 5;
328 *autoinc = 1;
329 }
330 }
331
Christopher Faulet62519022017-10-16 15:49:32 +0200332 if (strcmp(arg, "all") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100333 *proc |= ~0UL;
Christopher Faulet62519022017-10-16 15:49:32 +0200334 else if (strcmp(arg, "odd") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100335 *proc |= ~0UL/3UL; /* 0x555....555 */
Christopher Faulet62519022017-10-16 15:49:32 +0200336 else if (strcmp(arg, "even") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100337 *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Christopher Faulet62519022017-10-16 15:49:32 +0200338 else {
Christopher Faulet18cca782019-02-07 16:29:41 +0100339 const char *p, *dash = NULL;
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100340 unsigned int low, high;
341
Christopher Faulet18cca782019-02-07 16:29:41 +0100342 for (p = arg; *p; p++) {
343 if (*p == '-' && !dash)
344 dash = p;
Willy Tarreau90807112020-02-25 08:16:33 +0100345 else if (!isdigit((unsigned char)*p)) {
Christopher Faulet18cca782019-02-07 16:29:41 +0100346 memprintf(err, "'%s' is not a valid number/range.", arg);
347 return -1;
348 }
Christopher Faulet5ab51772017-11-22 11:21:58 +0100349 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100350
351 low = high = str2uic(arg);
Christopher Faulet18cca782019-02-07 16:29:41 +0100352 if (dash)
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100353 high = ((!*(dash+1)) ? max : str2uic(dash + 1));
Christopher Fauletff4121f2017-11-22 16:38:49 +0100354
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100355 if (high < low) {
356 unsigned int swap = low;
357 low = high;
358 high = swap;
359 }
360
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100361 if (low < 1 || low > max || high > max) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100362 memprintf(err, "'%s' is not a valid number/range."
363 " It supports numbers from 1 to %d.\n",
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100364 arg, max);
Christopher Faulet5ab51772017-11-22 11:21:58 +0100365 return 1;
366 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100367
368 for (;low <= high; low++)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100369 *proc |= 1UL << (low-1);
Christopher Faulet62519022017-10-16 15:49:32 +0200370 }
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100371 *proc &= ~0UL >> (LONGBITS - max);
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100372
Christopher Faulet5ab51772017-11-22 11:21:58 +0100373 return 0;
Christopher Faulet62519022017-10-16 15:49:32 +0200374}
375
David Carlier7e351ee2017-12-01 09:14:02 +0000376#ifdef USE_CPU_AFFINITY
Christopher Faulet62519022017-10-16 15:49:32 +0200377/* Parse cpu sets. Each CPU set is either a unique number between 0 and
378 * <LONGBITS> or a range with two such numbers delimited by a dash
379 * ('-'). Multiple CPU numbers or ranges may be specified. On success, it
380 * returns 0. otherwise it returns 1 with an error message in <err>.
381 */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100382unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200383{
384 int cur_arg = 0;
385
386 *cpu_set = 0;
387 while (*args[cur_arg]) {
388 char *dash;
389 unsigned int low, high;
390
Willy Tarreau90807112020-02-25 08:16:33 +0100391 if (!isdigit((unsigned char)*args[cur_arg])) {
Christopher Faulet62519022017-10-16 15:49:32 +0200392 memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]);
393 return -1;
394 }
395
396 low = high = str2uic(args[cur_arg]);
397 if ((dash = strchr(args[cur_arg], '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100398 high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1));
Christopher Faulet62519022017-10-16 15:49:32 +0200399
400 if (high < low) {
401 unsigned int swap = low;
402 low = high;
403 high = swap;
404 }
405
406 if (high >= LONGBITS) {
407 memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1);
408 return 1;
409 }
410
411 while (low <= high)
412 *cpu_set |= 1UL << low++;
413
414 cur_arg++;
415 }
416 return 0;
417}
David Carlier7e351ee2017-12-01 09:14:02 +0000418#endif
419
Willy Tarreau915e1eb2009-06-22 15:48:36 +0200420void init_default_instance()
Willy Tarreaubaaee002006-06-26 02:48:02 +0200421{
Willy Tarreau97cb7802010-01-03 20:23:58 +0100422 init_new_proxy(&defproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200423 defproxy.mode = PR_MODE_TCP;
424 defproxy.state = PR_STNEW;
425 defproxy.maxconn = cfg_maxpconn;
426 defproxy.conn_retries = CONN_RETRIES;
Joseph Lynch726ab712015-05-11 23:25:34 -0700427 defproxy.redispatch_after = 0;
Olivier Houchard86006a52018-12-14 19:37:49 +0100428 defproxy.options = PR_O_REUSE_SAFE;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100429 defproxy.max_out_conns = MAX_SRV_LIST;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100430
Simon Horman66183002013-02-23 10:16:43 +0900431 defproxy.defsrv.check.inter = DEF_CHKINTR;
432 defproxy.defsrv.check.fastinter = 0;
433 defproxy.defsrv.check.downinter = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900434 defproxy.defsrv.agent.inter = DEF_CHKINTR;
435 defproxy.defsrv.agent.fastinter = 0;
436 defproxy.defsrv.agent.downinter = 0;
Simon Horman58c32972013-11-25 10:46:38 +0900437 defproxy.defsrv.check.rise = DEF_RISETIME;
438 defproxy.defsrv.check.fall = DEF_FALLTIME;
439 defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
440 defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200441 defproxy.defsrv.check.port = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900442 defproxy.defsrv.agent.port = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100443 defproxy.defsrv.maxqueue = 0;
444 defproxy.defsrv.minconn = 0;
445 defproxy.defsrv.maxconn = 0;
Willy Tarreau9c538e02019-01-23 10:21:49 +0100446 defproxy.defsrv.max_reuse = -1;
Olivier Houchard006e3102018-12-10 18:30:32 +0100447 defproxy.defsrv.max_idle_conns = -1;
Willy Tarreau975b1552019-06-06 16:25:55 +0200448 defproxy.defsrv.pool_purge_delay = 5000;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100449 defproxy.defsrv.slowstart = 0;
450 defproxy.defsrv.onerror = DEF_HANA_ONERR;
451 defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
452 defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
Simon Horman64e34162015-02-06 11:11:57 +0900453
454 defproxy.email_alert.level = LOG_ALERT;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +0200455 defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200456}
457
Frédéric Lécaille18251032019-01-11 11:07:15 +0100458/* Allocate and initialize the frontend of a "peers" section found in
459 * file <file> at line <linenum> with <id> as ID.
460 * Return 0 if succeeded, -1 if not.
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200461 * Note that this function may be called from "default-server"
462 * or "peer" lines.
Frédéric Lécaille18251032019-01-11 11:07:15 +0100463 */
464static int init_peers_frontend(const char *file, int linenum,
465 const char *id, struct peers *peers)
466{
467 struct proxy *p;
468
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200469 if (peers->peers_fe) {
470 p = peers->peers_fe;
471 goto out;
472 }
Frédéric Lécaille9492c4e2019-01-11 11:47:12 +0100473
Frédéric Lécaille18251032019-01-11 11:07:15 +0100474 p = calloc(1, sizeof *p);
475 if (!p) {
476 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
477 return -1;
478 }
479
480 init_new_proxy(p);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200481 peers_setup_frontend(p);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100482 p->parent = peers;
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200483 /* Finally store this frontend. */
484 peers->peers_fe = p;
485
486 out:
487 if (id && !p->id)
488 p->id = strdup(id);
Frédéric Lécaille1055e682018-04-26 14:35:21 +0200489 free(p->conf.file);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100490 p->conf.args.file = p->conf.file = strdup(file);
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100491 if (linenum != -1)
492 p->conf.args.line = p->conf.line = linenum;
Frédéric Lécaille18251032019-01-11 11:07:15 +0100493
494 return 0;
495}
Willy Tarreauade5ec42010-01-28 19:33:49 +0100496
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100497/* Only change ->file, ->line and ->arg struct bind_conf member values
498 * if already present.
499 */
500static struct bind_conf *bind_conf_uniq_alloc(struct proxy *p,
501 const char *file, int line,
502 const char *arg, struct xprt_ops *xprt)
503{
504 struct bind_conf *bind_conf;
505
506 if (!LIST_ISEMPTY(&p->conf.bind)) {
507 bind_conf = LIST_ELEM((&p->conf.bind)->n, typeof(bind_conf), by_fe);
508 free(bind_conf->file);
509 bind_conf->file = strdup(file);
510 bind_conf->line = line;
511 if (arg) {
512 free(bind_conf->arg);
513 bind_conf->arg = strdup(arg);
514 }
515 }
516 else {
517 bind_conf = bind_conf_alloc(p, file, line, arg, xprt);
518 }
519
520 return bind_conf;
521}
522
523/*
524 * Allocate a new struct peer parsed at line <linenum> in file <file>
525 * to be added to <peers>.
526 * Returns the new allocated structure if succeeded, NULL if not.
527 */
528static struct peer *cfg_peers_add_peer(struct peers *peers,
529 const char *file, int linenum,
530 const char *id, int local)
531{
532 struct peer *p;
533
534 p = calloc(1, sizeof *p);
535 if (!p) {
536 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
537 return NULL;
538 }
539
540 /* the peers are linked backwards first */
541 peers->count++;
542 p->next = peers->remote;
543 peers->remote = p;
544 p->conf.file = strdup(file);
545 p->conf.line = linenum;
546 p->last_change = now.tv_sec;
547 p->xprt = xprt_get(XPRT_RAW);
548 p->sock_init_arg = NULL;
549 HA_SPIN_INIT(&p->lock);
550 if (id)
551 p->id = strdup(id);
552 if (local) {
553 p->local = 1;
554 peers->local = p;
555 }
556
557 return p;
558}
559
Willy Tarreaubaaee002006-06-26 02:48:02 +0200560/*
William Lallemand51097192015-04-14 16:35:22 +0200561 * Parse a line in a <listen>, <frontend> or <backend> section.
Willy Tarreau93893792009-07-23 13:19:11 +0200562 * Returns the error code, 0 if OK, or any combination of :
563 * - ERR_ABORT: must abort ASAP
564 * - ERR_FATAL: we can continue parsing but not start the service
565 * - ERR_WARN: a warning has been emitted
566 * - ERR_ALERT: an alert has been emitted
567 * Only the two first ones can stop processing, the two others are just
568 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200569 */
Emeric Brun32da3c42010-09-23 18:39:19 +0200570int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
571{
572 static struct peers *curpeers = NULL;
573 struct peer *newpeer = NULL;
574 const char *err;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200575 struct bind_conf *bind_conf;
576 struct listener *l;
Emeric Brun32da3c42010-09-23 18:39:19 +0200577 int err_code = 0;
Willy Tarreau902636f2013-03-10 19:44:48 +0100578 char *errmsg = NULL;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100579 static int bind_line, peer_line;
580
581 if (strcmp(args[0], "bind") == 0 || strcmp(args[0], "default-bind") == 0) {
582 int cur_arg;
583 static int kws_dumped;
584 struct bind_conf *bind_conf;
585 struct bind_kw *kw;
Emeric Brun32da3c42010-09-23 18:39:19 +0200586
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100587 cur_arg = 1;
588
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200589 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
590 err_code |= ERR_ALERT | ERR_ABORT;
591 goto out;
592 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100593
594 bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum,
595 NULL, xprt_get(XPRT_RAW));
596 if (*args[0] == 'b') {
597 struct listener *l;
598
599 if (peer_line) {
600 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
601 err_code |= ERR_ALERT | ERR_FATAL;
602 goto out;
603 }
604
605 if (!str2listener(args[1], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
606 if (errmsg && *errmsg) {
607 indent_msg(&errmsg, 2);
608 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
609 }
610 else
611 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
612 file, linenum, args[0], args[1], args[2]);
613 err_code |= ERR_FATAL;
614 goto out;
615 }
616 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
617 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100618 l->accept = session_accept_fd;
619 l->analysers |= curpeers->peers_fe->fe_req_ana;
620 l->default_target = curpeers->peers_fe->default_target;
621 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100622 global.maxsock++; /* for the listening socket */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100623
624 bind_line = 1;
625 if (cfg_peers->local) {
626 newpeer = cfg_peers->local;
627 }
628 else {
629 /* This peer is local.
630 * Note that we do not set the peer ID. This latter is initialized
631 * when parsing "peer" or "server" line.
632 */
633 newpeer = cfg_peers_add_peer(curpeers, file, linenum, NULL, 1);
634 if (!newpeer) {
635 err_code |= ERR_ALERT | ERR_ABORT;
636 goto out;
637 }
638 }
639 newpeer->addr = l->addr;
640 newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
641 cur_arg++;
642 }
643
644 while (*args[cur_arg] && (kw = bind_find_kw(args[cur_arg]))) {
645 int ret;
646
647 ret = kw->parse(args, cur_arg, curpeers->peers_fe, bind_conf, &errmsg);
648 err_code |= ret;
649 if (ret) {
650 if (errmsg && *errmsg) {
651 indent_msg(&errmsg, 2);
652 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
653 }
654 else
655 ha_alert("parsing [%s:%d]: error encountered while processing '%s'\n",
656 file, linenum, args[cur_arg]);
657 if (ret & ERR_FATAL)
658 goto out;
659 }
660 cur_arg += 1 + kw->skip;
661 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100662 if (*args[cur_arg] != 0) {
Tim Duesterhus04bcaa12019-05-12 22:54:50 +0200663 char *kws = NULL;
664
665 if (!kws_dumped) {
666 kws_dumped = 1;
667 bind_dump_kws(&kws);
668 indent_msg(&kws, 4);
669 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100670 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section.%s%s\n",
671 file, linenum, args[cur_arg], cursection,
672 kws ? " Registered keywords :" : "", kws ? kws: "");
673 free(kws);
674 err_code |= ERR_ALERT | ERR_FATAL;
675 goto out;
676 }
677 }
678 else if (strcmp(args[0], "default-server") == 0) {
679 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
680 err_code |= ERR_ALERT | ERR_ABORT;
681 goto out;
682 }
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200683 err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, 0, 1);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200684 }
Frédéric Lécailleb6f759b2019-11-05 09:57:45 +0100685 else if (strcmp(args[0], "log") == 0) {
686 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
687 err_code |= ERR_ALERT | ERR_ABORT;
688 goto out;
689 }
690 if (!parse_logsrv(args, &curpeers->peers_fe->logsrvs, (kwm == KWM_NO), &errmsg)) {
691 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
692 err_code |= ERR_ALERT | ERR_FATAL;
693 goto out;
694 }
695 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200696 else if (strcmp(args[0], "peers") == 0) { /* new peers section */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100697 /* Initialize these static variables when entering a new "peers" section*/
698 bind_line = peer_line = 0;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100699 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100700 ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum);
Willy Tarreau54984722014-02-16 08:20:13 +0100701 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100702 goto out;
703 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200704
William Lallemand6e62fb62015-04-28 16:55:23 +0200705 if (alertif_too_many_args(1, file, linenum, args, &err_code))
706 goto out;
707
Emeric Brun32da3c42010-09-23 18:39:19 +0200708 err = invalid_char(args[1]);
709 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100710 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
711 file, linenum, *err, args[0], args[1]);
Willy Tarreau54984722014-02-16 08:20:13 +0100712 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100713 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200714 }
715
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200716 for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +0200717 /*
718 * If there are two proxies with the same name only following
719 * combinations are allowed:
720 */
721 if (strcmp(curpeers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100722 ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n",
723 file, linenum, args[1], curpeers->conf.file, curpeers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +0200724 err_code |= ERR_ALERT | ERR_FATAL;
Emeric Brun32da3c42010-09-23 18:39:19 +0200725 }
726 }
727
Vincent Bernat02779b62016-04-03 13:48:43 +0200728 if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100729 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +0200730 err_code |= ERR_ALERT | ERR_ABORT;
731 goto out;
732 }
733
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200734 curpeers->next = cfg_peers;
735 cfg_peers = curpeers;
Willy Tarreau8113a5d2012-10-04 08:01:43 +0200736 curpeers->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +0200737 curpeers->conf.line = linenum;
738 curpeers->last_change = now.tv_sec;
739 curpeers->id = strdup(args[1]);
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200740 curpeers->state = PR_STNEW;
Emeric Brun32da3c42010-09-23 18:39:19 +0200741 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200742 else if (strcmp(args[0], "peer") == 0 ||
743 strcmp(args[0], "server") == 0) { /* peer or server definition */
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100744 int local_peer, peer;
Emeric Brun32da3c42010-09-23 18:39:19 +0200745
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100746 peer = *args[0] == 'p';
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100747 local_peer = !strcmp(args[1], localpeer);
748 /* The local peer may have already partially been parsed on a "bind" line. */
749 if (*args[0] == 'p') {
750 if (bind_line) {
751 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
752 err_code |= ERR_ALERT | ERR_FATAL;
753 goto out;
754 }
755 peer_line = 1;
756 }
757 if (cfg_peers->local && !cfg_peers->local->id && local_peer) {
758 /* The local peer has already been initialized on a "bind" line.
759 * Let's use it and store its ID.
760 */
761 newpeer = cfg_peers->local;
762 newpeer->id = strdup(localpeer);
763 }
764 else {
765 if (local_peer && cfg_peers->local) {
766 ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d. %s\n",
767 file, linenum, args[0], args[1],
768 curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line, cfg_peers->local->id);
769 err_code |= ERR_FATAL;
770 goto out;
771 }
772 newpeer = cfg_peers_add_peer(curpeers, file, linenum, args[1], local_peer);
773 if (!newpeer) {
774 err_code |= ERR_ALERT | ERR_ABORT;
775 goto out;
776 }
777 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200778
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100779 /* Line number and peer ID are updated only if this peer is the local one. */
780 if (init_peers_frontend(file,
781 newpeer->local ? linenum: -1,
782 newpeer->local ? newpeer->id : NULL,
783 curpeers) != 0) {
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200784 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreaub36487e2013-03-10 18:37:42 +0100785 goto out;
786 }
Willy Tarreau2aa38802013-02-20 19:20:59 +0100787
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100788 /* This initializes curpeer->peers->peers_fe->srv.
789 * The server address is parsed only if we are parsing a "peer" line,
790 * or if we are parsing a "server" line and the current peer is not the local one.
791 */
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200792 err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, peer || !local_peer, 1);
793 if (!curpeers->peers_fe->srv) {
794 /* Remove the newly allocated peer. */
795 if (newpeer != curpeers->local) {
796 struct peer *p;
797
798 p = curpeers->remote;
799 curpeers->remote = curpeers->remote->next;
800 free(p->id);
801 free(p);
802 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200803 goto out;
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200804 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200805
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100806 /* If the peer address has just been parsed, let's copy it to <newpeer>
807 * and initializes ->proto.
808 */
809 if (peer || !local_peer) {
810 newpeer->addr = curpeers->peers_fe->srv->addr;
811 newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
812 }
813
Willy Tarreaua261e9b2016-12-22 20:44:00 +0100814 newpeer->xprt = xprt_get(XPRT_RAW);
Willy Tarreaud02394b2012-05-11 18:32:18 +0200815 newpeer->sock_init_arg = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100816 HA_SPIN_INIT(&newpeer->lock);
Willy Tarreau26d8c592012-05-07 18:12:14 +0200817
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100818 newpeer->srv = curpeers->peers_fe->srv;
819 if (!newpeer->local)
Frédéric Lécaille6617e762018-04-25 15:13:38 +0200820 goto out;
821
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100822 /* The lines above are reserved to "peer" lines. */
823 if (*args[0] == 's')
Frédéric Lécaille4ba51982018-04-25 15:32:18 +0200824 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200825
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100826 bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW));
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100827
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100828 if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
829 if (errmsg && *errmsg) {
830 indent_msg(&errmsg, 2);
831 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Frédéric Lécaille16e49102019-01-11 11:27:16 +0100832 }
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100833 else
834 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
835 file, linenum, args[0], args[1], args[2]);
836 err_code |= ERR_FATAL;
837 goto out;
838 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100839
840 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
841 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100842 l->accept = session_accept_fd;
843 l->analysers |= curpeers->peers_fe->fe_req_ana;
844 l->default_target = curpeers->peers_fe->default_target;
845 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100846 global.maxsock++; /* for the listening socket */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100847 }
848 else if (!strcmp(args[0], "table")) {
849 struct stktable *t, *other;
850 char *id;
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100851 size_t prefix_len;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100852
853 /* Line number and peer ID are updated only if this peer is the local one. */
854 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
855 err_code |= ERR_ALERT | ERR_ABORT;
856 goto out;
857 }
858
859 other = stktable_find_by_name(args[1]);
860 if (other) {
861 ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
862 file, linenum, args[1],
863 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
864 other->proxy ? other->id : other->peers.p->id,
865 other->conf.file, other->conf.line);
866 err_code |= ERR_ALERT | ERR_FATAL;
867 goto out;
868 }
869
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100870 /* Build the stick-table name, concatenating the "peers" section name
871 * followed by a '/' character and the table name argument.
872 */
873 chunk_reset(&trash);
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100874 if (!chunk_strcpy(&trash, curpeers->id)) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100875 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
876 file, linenum, args[0], args[1]);
877 err_code |= ERR_ALERT | ERR_FATAL;
878 goto out;
879 }
880
881 prefix_len = trash.data;
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100882 if (!chunk_memcat(&trash, "/", 1) || !chunk_strcat(&trash, args[1])) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100883 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
884 file, linenum, args[0], args[1]);
885 err_code |= ERR_ALERT | ERR_FATAL;
886 goto out;
887 }
888
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100889 t = calloc(1, sizeof *t);
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100890 id = strdup(trash.area);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100891 if (!t || !id) {
892 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
893 file, linenum, args[0], args[1]);
894 err_code |= ERR_ALERT | ERR_FATAL;
895 goto out;
896 }
897
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100898 err_code |= parse_stick_table(file, linenum, args, t, id, id + prefix_len, curpeers);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100899 if (err_code & ERR_FATAL)
900 goto out;
901
902 stktable_store_name(t);
903 t->next = stktables_list;
904 stktables_list = t;
905 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200906 else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
907 curpeers->state = PR_STSTOPPED;
908 }
909 else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
910 curpeers->state = PR_STNEW;
911 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200912 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100913 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Emeric Brun32da3c42010-09-23 18:39:19 +0200914 err_code |= ERR_ALERT | ERR_FATAL;
915 goto out;
916 }
917
918out:
Willy Tarreau902636f2013-03-10 19:44:48 +0100919 free(errmsg);
Emeric Brun32da3c42010-09-23 18:39:19 +0200920 return err_code;
921}
922
Baptiste Assmann325137d2015-04-13 23:40:55 +0200923/*
924 * Parse a <resolvers> section.
925 * Returns the error code, 0 if OK, or any combination of :
926 * - ERR_ABORT: must abort ASAP
927 * - ERR_FATAL: we can continue parsing but not start the service
928 * - ERR_WARN: a warning has been emitted
929 * - ERR_ALERT: an alert has been emitted
930 * Only the two first ones can stop processing, the two others are just
931 * indicators.
932 */
933int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
934{
935 static struct dns_resolvers *curr_resolvers = NULL;
936 struct dns_nameserver *newnameserver = NULL;
937 const char *err;
938 int err_code = 0;
939 char *errmsg = NULL;
940
941 if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */
942 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100943 ha_alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200944 err_code |= ERR_ALERT | ERR_ABORT;
945 goto out;
946 }
947
948 err = invalid_char(args[1]);
949 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100950 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
951 file, linenum, *err, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200952 err_code |= ERR_ALERT | ERR_ABORT;
953 goto out;
954 }
955
956 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
957 /* Error if two resolvers owns the same name */
958 if (strcmp(curr_resolvers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100959 ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n",
960 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200961 err_code |= ERR_ALERT | ERR_ABORT;
962 }
963 }
964
Vincent Bernat02779b62016-04-03 13:48:43 +0200965 if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100966 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200967 err_code |= ERR_ALERT | ERR_ABORT;
968 goto out;
969 }
970
971 /* default values */
972 LIST_ADDQ(&dns_resolvers, &curr_resolvers->list);
973 curr_resolvers->conf.file = strdup(file);
974 curr_resolvers->conf.line = linenum;
975 curr_resolvers->id = strdup(args[1]);
976 curr_resolvers->query_ids = EB_ROOT;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +0200977 /* default maximum response size */
978 curr_resolvers->accepted_payload_size = 512;
Baptiste Assmann987e16d2016-11-02 22:23:31 +0100979 /* default hold period for nx, other, refuse and timeout is 30s */
980 curr_resolvers->hold.nx = 30000;
981 curr_resolvers->hold.other = 30000;
982 curr_resolvers->hold.refused = 30000;
983 curr_resolvers->hold.timeout = 30000;
Baptiste Assmann686408b2017-08-18 10:15:42 +0200984 curr_resolvers->hold.obsolete = 0;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200985 /* default hold period for valid is 10s */
Baptiste Assmann4c5490a2015-07-14 21:42:49 +0200986 curr_resolvers->hold.valid = 10000;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200987 curr_resolvers->timeout.resolve = 1000;
988 curr_resolvers->timeout.retry = 1000;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200989 curr_resolvers->resolve_retries = 3;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200990 curr_resolvers->nb_nameservers = 0;
991 LIST_INIT(&curr_resolvers->nameservers);
992 LIST_INIT(&curr_resolvers->resolutions.curr);
993 LIST_INIT(&curr_resolvers->resolutions.wait);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100994 HA_SPIN_INIT(&curr_resolvers->lock);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200995 }
996 else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
997 struct sockaddr_storage *sk;
998 int port1, port2;
999 struct protocol *proto;
1000
1001 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001002 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1003 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001004 err_code |= ERR_ALERT | ERR_FATAL;
1005 goto out;
1006 }
1007
1008 err = invalid_char(args[1]);
1009 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001010 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1011 file, linenum, *err, args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001012 err_code |= ERR_ALERT | ERR_FATAL;
1013 goto out;
1014 }
1015
Christopher Faulet67957bd2017-09-27 11:00:59 +02001016 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
Baptiste Assmanna315c552015-11-02 22:55:49 +01001017 /* Error if two resolvers owns the same name */
1018 if (strcmp(newnameserver->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001019 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 -06001020 file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line);
Baptiste Assmanna315c552015-11-02 22:55:49 +01001021 err_code |= ERR_ALERT | ERR_FATAL;
1022 }
1023 }
1024
Vincent Bernat02779b62016-04-03 13:48:43 +02001025 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001026 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001027 err_code |= ERR_ALERT | ERR_ABORT;
1028 goto out;
1029 }
1030
1031 /* the nameservers are linked backward first */
Christopher Faulet67957bd2017-09-27 11:00:59 +02001032 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001033 newnameserver->resolvers = curr_resolvers;
1034 newnameserver->conf.file = strdup(file);
1035 newnameserver->conf.line = linenum;
1036 newnameserver->id = strdup(args[1]);
1037
Willy Tarreau48ef4c92017-01-06 18:32:38 +01001038 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001039 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001040 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001041 err_code |= ERR_ALERT | ERR_FATAL;
1042 goto out;
1043 }
1044
1045 proto = protocol_by_family(sk->ss_family);
1046 if (!proto || !proto->connect) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001047 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
Baptiste Assmann325137d2015-04-13 23:40:55 +02001048 file, linenum, args[0], args[1]);
1049 err_code |= ERR_ALERT | ERR_FATAL;
1050 goto out;
1051 }
1052
1053 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001054 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
1055 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001056 err_code |= ERR_ALERT | ERR_FATAL;
1057 goto out;
1058 }
1059
Baptiste Assmann7f43fa92016-01-21 00:59:46 +01001060 if (!port1 && !port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001061 ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n",
1062 file, linenum, args[0], args[1]);
Baptiste Assmann7f43fa92016-01-21 00:59:46 +01001063 err_code |= ERR_ALERT | ERR_FATAL;
1064 goto out;
1065 }
1066
Baptiste Assmann325137d2015-04-13 23:40:55 +02001067 newnameserver->addr = *sk;
1068 }
Ben Draut44e609b2018-05-29 15:40:08 -06001069 else if (strcmp(args[0], "parse-resolv-conf") == 0) {
1070 const char *whitespace = "\r\n\t ";
1071 char *resolv_line = NULL;
1072 int resolv_linenum = 0;
1073 FILE *f = NULL;
1074 char *address = NULL;
1075 struct sockaddr_storage *sk = NULL;
1076 struct protocol *proto;
1077 int duplicate_name = 0;
1078
1079 if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) {
1080 ha_alert("parsing [%s:%d] : out of memory.\n",
1081 file, linenum);
1082 err_code |= ERR_ALERT | ERR_FATAL;
1083 goto resolv_out;
1084 }
1085
1086 if ((f = fopen("/etc/resolv.conf", "r")) == NULL) {
1087 ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n",
1088 file, linenum);
1089 err_code |= ERR_ALERT | ERR_FATAL;
1090 goto resolv_out;
1091 }
1092
1093 sk = calloc(1, sizeof(*sk));
1094 if (sk == NULL) {
1095 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n",
1096 resolv_linenum);
1097 err_code |= ERR_ALERT | ERR_FATAL;
1098 goto resolv_out;
1099 }
1100
1101 while (fgets(resolv_line, LINESIZE, f) != NULL) {
1102 resolv_linenum++;
1103 if (strncmp(resolv_line, "nameserver", 10) != 0)
1104 continue;
1105
1106 address = strtok(resolv_line + 10, whitespace);
1107 if (address == resolv_line + 10)
1108 continue;
1109
1110 if (address == NULL) {
1111 ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n",
1112 resolv_linenum);
1113 err_code |= ERR_WARN;
1114 continue;
1115 }
1116
1117 duplicate_name = 0;
1118 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
1119 if (strcmp(newnameserver->id, address) == 0) {
1120 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",
1121 resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line);
1122 err_code |= ERR_WARN;
1123 duplicate_name = 1;
1124 }
1125 }
1126
1127 if (duplicate_name)
1128 continue;
1129
1130 memset(sk, 0, sizeof(*sk));
Willy Tarreau78675252020-05-28 18:07:10 +02001131 if (!str2ip2(address, sk, 1)) {
1132 ha_warning("parsing [/etc/resolv.conf:%d] : address '%s' could not be recognized, nameserver will be excluded.\n",
Ben Draut44e609b2018-05-29 15:40:08 -06001133 resolv_linenum, address);
1134 err_code |= ERR_WARN;
1135 continue;
1136 }
1137
1138 set_host_port(sk, 53);
1139
1140 proto = protocol_by_family(sk->ss_family);
1141 if (!proto || !proto->connect) {
1142 ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n",
1143 resolv_linenum, address);
1144 err_code |= ERR_WARN;
1145 continue;
1146 }
1147
1148 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
1149 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1150 err_code |= ERR_ALERT | ERR_FATAL;
1151 goto resolv_out;
1152 }
1153
1154 newnameserver->conf.file = strdup("/etc/resolv.conf");
1155 if (newnameserver->conf.file == NULL) {
1156 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1157 err_code |= ERR_ALERT | ERR_FATAL;
1158 goto resolv_out;
1159 }
1160
1161 newnameserver->id = strdup(address);
1162 if (newnameserver->id == NULL) {
1163 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1164 err_code |= ERR_ALERT | ERR_FATAL;
1165 goto resolv_out;
1166 }
1167
1168 newnameserver->resolvers = curr_resolvers;
1169 newnameserver->conf.line = resolv_linenum;
1170 newnameserver->addr = *sk;
1171
1172 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
1173 }
1174
1175resolv_out:
1176 free(sk);
1177 free(resolv_line);
1178 if (f != NULL)
1179 fclose(f);
1180 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001181 else if (strcmp(args[0], "hold") == 0) { /* hold periods */
1182 const char *res;
1183 unsigned int time;
1184
1185 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001186 ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n",
1187 file, linenum, args[0]);
1188 ha_alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n");
Baptiste Assmann325137d2015-04-13 23:40:55 +02001189 err_code |= ERR_ALERT | ERR_FATAL;
1190 goto out;
1191 }
1192 res = parse_time_err(args[2], &time, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001193 if (res == PARSE_TIME_OVER) {
1194 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1195 file, linenum, args[1], args[0]);
1196 err_code |= ERR_ALERT | ERR_FATAL;
1197 goto out;
1198 }
1199 else if (res == PARSE_TIME_UNDER) {
1200 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1201 file, linenum, args[1], args[0]);
1202 err_code |= ERR_ALERT | ERR_FATAL;
1203 goto out;
1204 }
1205 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001206 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
1207 file, linenum, *res, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001208 err_code |= ERR_ALERT | ERR_FATAL;
1209 goto out;
1210 }
Baptiste Assmann987e16d2016-11-02 22:23:31 +01001211 if (strcmp(args[1], "nx") == 0)
1212 curr_resolvers->hold.nx = time;
1213 else if (strcmp(args[1], "other") == 0)
1214 curr_resolvers->hold.other = time;
1215 else if (strcmp(args[1], "refused") == 0)
1216 curr_resolvers->hold.refused = time;
1217 else if (strcmp(args[1], "timeout") == 0)
1218 curr_resolvers->hold.timeout = time;
1219 else if (strcmp(args[1], "valid") == 0)
Baptiste Assmann325137d2015-04-13 23:40:55 +02001220 curr_resolvers->hold.valid = time;
Olivier Houcharda8c6db82017-07-06 18:46:47 +02001221 else if (strcmp(args[1], "obsolete") == 0)
1222 curr_resolvers->hold.obsolete = time;
Baptiste Assmann325137d2015-04-13 23:40:55 +02001223 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001224 ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n",
1225 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001226 err_code |= ERR_ALERT | ERR_FATAL;
1227 goto out;
1228 }
1229
1230 }
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001231 else if (strcmp(args[0], "accepted_payload_size") == 0) {
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001232 int i = 0;
1233
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001234 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001235 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1236 file, linenum, args[0]);
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001237 err_code |= ERR_ALERT | ERR_FATAL;
1238 goto out;
1239 }
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001240
1241 i = atoi(args[1]);
Willy Tarreau0c219be2017-08-22 12:01:26 +02001242 if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001243 ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n",
1244 file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]);
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001245 err_code |= ERR_ALERT | ERR_FATAL;
1246 goto out;
1247 }
1248
1249 curr_resolvers->accepted_payload_size = i;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001250 }
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001251 else if (strcmp(args[0], "resolution_pool_size") == 0) {
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001252 ha_alert("parsing [%s:%d] : '%s' directive is not supported anymore (it never appeared in a stable release).\n",
Christopher Faulet767a84b2017-11-24 16:50:31 +01001253 file, linenum, args[0]);
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001254 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001255 goto out;
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001256 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001257 else if (strcmp(args[0], "resolve_retries") == 0) {
1258 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001259 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1260 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001261 err_code |= ERR_ALERT | ERR_FATAL;
1262 goto out;
1263 }
1264 curr_resolvers->resolve_retries = atoi(args[1]);
1265 }
1266 else if (strcmp(args[0], "timeout") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001267 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001268 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n",
1269 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001270 err_code |= ERR_ALERT | ERR_FATAL;
1271 goto out;
1272 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001273 else if (strcmp(args[1], "retry") == 0 ||
1274 strcmp(args[1], "resolve") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001275 const char *res;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001276 unsigned int tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001277
1278 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001279 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1280 file, linenum, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001281 err_code |= ERR_ALERT | ERR_FATAL;
1282 goto out;
1283 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001284 res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001285 if (res == PARSE_TIME_OVER) {
1286 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1287 file, linenum, args[2], args[0], args[1]);
1288 err_code |= ERR_ALERT | ERR_FATAL;
1289 goto out;
1290 }
1291 else if (res == PARSE_TIME_UNDER) {
1292 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1293 file, linenum, args[2], args[0], args[1]);
1294 err_code |= ERR_ALERT | ERR_FATAL;
1295 goto out;
1296 }
1297 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001298 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1299 file, linenum, *res, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001300 err_code |= ERR_ALERT | ERR_FATAL;
1301 goto out;
1302 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001303 if (args[1][2] == 't')
1304 curr_resolvers->timeout.retry = tout;
1305 else
1306 curr_resolvers->timeout.resolve = tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001307 }
1308 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001309 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n",
1310 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001311 err_code |= ERR_ALERT | ERR_FATAL;
1312 goto out;
1313 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001314 } /* neither "nameserver" nor "resolvers" */
1315 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001316 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001317 err_code |= ERR_ALERT | ERR_FATAL;
1318 goto out;
1319 }
1320
1321 out:
1322 free(errmsg);
1323 return err_code;
1324}
Simon Horman0d16a402015-01-30 11:22:58 +09001325
1326/*
William Lallemand51097192015-04-14 16:35:22 +02001327 * Parse a line in a <listen>, <frontend> or <backend> section.
Simon Horman0d16a402015-01-30 11:22:58 +09001328 * Returns the error code, 0 if OK, or any combination of :
1329 * - ERR_ABORT: must abort ASAP
1330 * - ERR_FATAL: we can continue parsing but not start the service
1331 * - ERR_WARN: a warning has been emitted
1332 * - ERR_ALERT: an alert has been emitted
1333 * Only the two first ones can stop processing, the two others are just
1334 * indicators.
1335 */
1336int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
1337{
1338 static struct mailers *curmailers = NULL;
1339 struct mailer *newmailer = NULL;
1340 const char *err;
1341 int err_code = 0;
1342 char *errmsg = NULL;
1343
1344 if (strcmp(args[0], "mailers") == 0) { /* new mailers section */
1345 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001346 ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001347 err_code |= ERR_ALERT | ERR_ABORT;
1348 goto out;
1349 }
1350
1351 err = invalid_char(args[1]);
1352 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001353 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1354 file, linenum, *err, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001355 err_code |= ERR_ALERT | ERR_ABORT;
1356 goto out;
1357 }
1358
1359 for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) {
1360 /*
1361 * If there are two proxies with the same name only following
1362 * combinations are allowed:
1363 */
1364 if (strcmp(curmailers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001365 ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n",
1366 file, linenum, args[1], curmailers->conf.file, curmailers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02001367 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman0d16a402015-01-30 11:22:58 +09001368 }
1369 }
1370
Vincent Bernat02779b62016-04-03 13:48:43 +02001371 if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001372 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001373 err_code |= ERR_ALERT | ERR_ABORT;
1374 goto out;
1375 }
1376
1377 curmailers->next = mailers;
1378 mailers = curmailers;
1379 curmailers->conf.file = strdup(file);
1380 curmailers->conf.line = linenum;
1381 curmailers->id = strdup(args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001382 curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
1383 * But need enough time so that timeouts don't occur
1384 * during tcp procssing. For now just us an arbitrary default. */
Simon Horman0d16a402015-01-30 11:22:58 +09001385 }
1386 else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
1387 struct sockaddr_storage *sk;
1388 int port1, port2;
1389 struct protocol *proto;
1390
1391 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001392 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1393 file, linenum, args[0]);
Simon Horman0d16a402015-01-30 11:22:58 +09001394 err_code |= ERR_ALERT | ERR_FATAL;
1395 goto out;
1396 }
1397
1398 err = invalid_char(args[1]);
1399 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001400 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1401 file, linenum, *err, args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001402 err_code |= ERR_ALERT | ERR_FATAL;
1403 goto out;
1404 }
1405
Vincent Bernat02779b62016-04-03 13:48:43 +02001406 if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001407 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001408 err_code |= ERR_ALERT | ERR_ABORT;
1409 goto out;
1410 }
1411
1412 /* the mailers are linked backwards first */
1413 curmailers->count++;
1414 newmailer->next = curmailers->mailer_list;
1415 curmailers->mailer_list = newmailer;
1416 newmailer->mailers = curmailers;
1417 newmailer->conf.file = strdup(file);
1418 newmailer->conf.line = linenum;
1419
1420 newmailer->id = strdup(args[1]);
1421
Willy Tarreau48ef4c92017-01-06 18:32:38 +01001422 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Simon Horman0d16a402015-01-30 11:22:58 +09001423 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001424 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Simon Horman0d16a402015-01-30 11:22:58 +09001425 err_code |= ERR_ALERT | ERR_FATAL;
1426 goto out;
1427 }
1428
1429 proto = protocol_by_family(sk->ss_family);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09001430 if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001431 ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n",
1432 file, linenum, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001433 err_code |= ERR_ALERT | ERR_FATAL;
1434 goto out;
1435 }
1436
1437 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001438 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
1439 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09001440 err_code |= ERR_ALERT | ERR_FATAL;
1441 goto out;
1442 }
1443
1444 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001445 ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
1446 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09001447 err_code |= ERR_ALERT | ERR_FATAL;
1448 goto out;
1449 }
1450
1451 newmailer->addr = *sk;
1452 newmailer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01001453 newmailer->xprt = xprt_get(XPRT_RAW);
Simon Horman0d16a402015-01-30 11:22:58 +09001454 newmailer->sock_init_arg = NULL;
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001455 }
1456 else if (strcmp(args[0], "timeout") == 0) {
1457 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001458 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
1459 file, linenum, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001460 err_code |= ERR_ALERT | ERR_FATAL;
1461 goto out;
1462 }
1463 else if (strcmp(args[1], "mail") == 0) {
1464 const char *res;
1465 unsigned int timeout_mail;
1466 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001467 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1468 file, linenum, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001469 err_code |= ERR_ALERT | ERR_FATAL;
1470 goto out;
1471 }
1472 res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001473 if (res == PARSE_TIME_OVER) {
1474 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1475 file, linenum, args[2], args[0], args[1]);
1476 err_code |= ERR_ALERT | ERR_FATAL;
1477 goto out;
1478 }
1479 else if (res == PARSE_TIME_UNDER) {
1480 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1481 file, linenum, args[2], args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001482 err_code |= ERR_ALERT | ERR_FATAL;
1483 goto out;
1484 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001485 else if (res) {
1486 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1487 file, linenum, *res, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001488 err_code |= ERR_ALERT | ERR_FATAL;
1489 goto out;
1490 }
1491 curmailers->timeout.mail = timeout_mail;
1492 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001493 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001494 file, linenum, args[0], args[1]);
1495 err_code |= ERR_ALERT | ERR_FATAL;
1496 goto out;
1497 }
1498 }
Simon Horman0d16a402015-01-30 11:22:58 +09001499 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001500 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Simon Horman0d16a402015-01-30 11:22:58 +09001501 err_code |= ERR_ALERT | ERR_FATAL;
1502 goto out;
1503 }
1504
1505out:
1506 free(errmsg);
1507 return err_code;
1508}
1509
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001510void free_email_alert(struct proxy *p)
Simon Horman9dc49962015-01-30 11:22:59 +09001511{
1512 free(p->email_alert.mailers.name);
1513 p->email_alert.mailers.name = NULL;
1514 free(p->email_alert.from);
1515 p->email_alert.from = NULL;
1516 free(p->email_alert.to);
1517 p->email_alert.to = NULL;
1518 free(p->email_alert.myhostname);
1519 p->email_alert.myhostname = NULL;
1520}
1521
Willy Tarreaubaaee002006-06-26 02:48:02 +02001522
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001523int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001524cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
1525{
Willy Tarreaue5733232019-05-22 19:24:06 +02001526#ifdef USE_NS
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001527 const char *err;
1528 const char *item = args[0];
1529
1530 if (!strcmp(item, "namespace_list")) {
1531 return 0;
1532 }
1533 else if (!strcmp(item, "namespace")) {
1534 size_t idx = 1;
1535 const char *current;
1536 while (*(current = args[idx++])) {
1537 err = invalid_char(current);
1538 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001539 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1540 file, linenum, *err, item, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001541 return ERR_ALERT | ERR_FATAL;
1542 }
1543
1544 if (netns_store_lookup(current, strlen(current))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001545 ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
1546 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001547 return ERR_ALERT | ERR_FATAL;
1548 }
1549 if (!netns_store_insert(current)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001550 ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
1551 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001552 return ERR_ALERT | ERR_FATAL;
1553 }
1554 }
1555 }
1556
1557 return 0;
1558#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001559 ha_alert("parsing [%s:%d]: namespace support is not compiled in.",
1560 file, linenum);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001561 return ERR_ALERT | ERR_FATAL;
1562#endif
1563}
1564
1565int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001566cfg_parse_users(const char *file, int linenum, char **args, int kwm)
1567{
1568
1569 int err_code = 0;
1570 const char *err;
1571
1572 if (!strcmp(args[0], "userlist")) { /* new userlist */
1573 struct userlist *newul;
1574
1575 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001576 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1577 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001578 err_code |= ERR_ALERT | ERR_FATAL;
1579 goto out;
1580 }
William Lallemand6e62fb62015-04-28 16:55:23 +02001581 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1582 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001583
1584 err = invalid_char(args[1]);
1585 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001586 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1587 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001588 err_code |= ERR_ALERT | ERR_FATAL;
1589 goto out;
1590 }
1591
1592 for (newul = userlist; newul; newul = newul->next)
1593 if (!strcmp(newul->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001594 ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
1595 file, linenum, args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001596 err_code |= ERR_WARN;
1597 goto out;
1598 }
1599
Vincent Bernat02779b62016-04-03 13:48:43 +02001600 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001601 if (!newul) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001602 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001603 err_code |= ERR_ALERT | ERR_ABORT;
1604 goto out;
1605 }
1606
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001607 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001608 if (!newul->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001609 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001610 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01001611 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001612 goto out;
1613 }
1614
1615 newul->next = userlist;
1616 userlist = newul;
1617
1618 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001619 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001620 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001621 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001622
1623 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001624 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1625 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001626 err_code |= ERR_ALERT | ERR_FATAL;
1627 goto out;
1628 }
1629
1630 err = invalid_char(args[1]);
1631 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001632 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1633 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001634 err_code |= ERR_ALERT | ERR_FATAL;
1635 goto out;
1636 }
1637
William Lallemand4ac9f542015-05-28 18:03:51 +02001638 if (!userlist)
1639 goto out;
1640
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001641 for (ag = userlist->groups; ag; ag = ag->next)
1642 if (!strcmp(ag->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001643 ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
1644 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001645 err_code |= ERR_ALERT;
1646 goto out;
1647 }
1648
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001649 ag = calloc(1, sizeof(*ag));
1650 if (!ag) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001651 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001652 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001653 goto out;
1654 }
1655
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001656 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01001657 if (!ag->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001658 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001659 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01001660 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001661 goto out;
1662 }
1663
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001664 cur_arg = 2;
1665
1666 while (*args[cur_arg]) {
1667 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001668 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001669 cur_arg += 2;
1670 continue;
1671 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001672 ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
1673 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001674 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01001675 free(ag->groupusers);
1676 free(ag->name);
1677 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001678 goto out;
1679 }
1680 }
1681
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001682 ag->next = userlist->groups;
1683 userlist->groups = ag;
1684
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001685 } else if (!strcmp(args[0], "user")) { /* new user */
1686 struct auth_users *newuser;
1687 int cur_arg;
1688
1689 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001690 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1691 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001692 err_code |= ERR_ALERT | ERR_FATAL;
1693 goto out;
1694 }
William Lallemand4ac9f542015-05-28 18:03:51 +02001695 if (!userlist)
1696 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001697
1698 for (newuser = userlist->users; newuser; newuser = newuser->next)
1699 if (!strcmp(newuser->user, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001700 ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
1701 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001702 err_code |= ERR_ALERT;
1703 goto out;
1704 }
1705
Vincent Bernat02779b62016-04-03 13:48:43 +02001706 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001707 if (!newuser) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001708 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001709 err_code |= ERR_ALERT | ERR_ABORT;
1710 goto out;
1711 }
1712
1713 newuser->user = strdup(args[1]);
1714
1715 newuser->next = userlist->users;
1716 userlist->users = newuser;
1717
1718 cur_arg = 2;
1719
1720 while (*args[cur_arg]) {
1721 if (!strcmp(args[cur_arg], "password")) {
Willy Tarreaue5733232019-05-22 19:24:06 +02001722#ifdef USE_LIBCRYPT
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001723 if (!crypt("", args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001724 ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
1725 file, linenum, newuser->user);
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001726 err_code |= ERR_ALERT | ERR_FATAL;
1727 goto out;
1728 }
1729#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001730 ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
1731 file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001732 err_code |= ERR_ALERT;
1733#endif
1734 newuser->pass = strdup(args[cur_arg + 1]);
1735 cur_arg += 2;
1736 continue;
1737 } else if (!strcmp(args[cur_arg], "insecure-password")) {
1738 newuser->pass = strdup(args[cur_arg + 1]);
1739 newuser->flags |= AU_O_INSECURE;
1740 cur_arg += 2;
1741 continue;
1742 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001743 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001744 cur_arg += 2;
1745 continue;
1746 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001747 ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
1748 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001749 err_code |= ERR_ALERT | ERR_FATAL;
1750 goto out;
1751 }
1752 }
1753 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001754 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 +01001755 err_code |= ERR_ALERT | ERR_FATAL;
1756 }
1757
1758out:
1759 return err_code;
1760}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001761
Christopher Faulet79bdef32016-11-04 22:36:15 +01001762int
1763cfg_parse_scope(const char *file, int linenum, char *line)
1764{
1765 char *beg, *end, *scope = NULL;
1766 int err_code = 0;
1767 const char *err;
1768
1769 beg = line + 1;
1770 end = strchr(beg, ']');
1771
1772 /* Detect end of scope declaration */
1773 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001774 ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n",
1775 file, linenum);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001776 err_code |= ERR_ALERT | ERR_FATAL;
1777 goto out;
1778 }
1779
1780 /* Get scope name and check its validity */
1781 scope = my_strndup(beg, end-beg);
1782 err = invalid_char(scope);
1783 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001784 ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
1785 file, linenum, *err);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001786 err_code |= ERR_ALERT | ERR_ABORT;
1787 goto out;
1788 }
1789
1790 /* Be sure to have a scope declaration alone on its line */
1791 line = end+1;
1792 while (isspace((unsigned char)*line))
1793 line++;
1794 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001795 ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
1796 file, linenum, *line);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001797 err_code |= ERR_ALERT | ERR_ABORT;
1798 goto out;
1799 }
1800
1801 /* We have a valid scope declaration, save it */
1802 free(cfg_scope);
1803 cfg_scope = scope;
1804 scope = NULL;
1805
1806 out:
1807 free(scope);
1808 return err_code;
1809}
1810
Frédéric Lécaillea41d5312018-01-29 12:05:07 +01001811int
1812cfg_parse_track_sc_num(unsigned int *track_sc_num,
1813 const char *arg, const char *end, char **errmsg)
1814{
1815 const char *p;
1816 unsigned int num;
1817
1818 p = arg;
1819 num = read_uint64(&arg, end);
1820
1821 if (arg != end) {
1822 memprintf(errmsg, "Wrong track-sc number '%s'", p);
1823 return -1;
1824 }
1825
1826 if (num >= MAX_SESS_STKCTR) {
1827 memprintf(errmsg, "%u track-sc number exceeding "
1828 "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1);
1829 return -1;
1830 }
1831
1832 *track_sc_num = num;
1833 return 0;
1834}
1835
Willy Tarreaubaaee002006-06-26 02:48:02 +02001836/*
1837 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02001838 * Returns the error code, 0 if OK, or any combination of :
1839 * - ERR_ABORT: must abort ASAP
1840 * - ERR_FATAL: we can continue parsing but not start the service
1841 * - ERR_WARN: a warning has been emitted
1842 * - ERR_ALERT: an alert has been emitted
1843 * Only the two first ones can stop processing, the two others are just
1844 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001845 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02001846int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001847{
William Lallemand64e84512015-05-12 14:25:37 +02001848 char *thisline;
1849 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001850 FILE *f;
1851 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02001852 int err_code = 0;
William Lallemandd2ff56d2017-10-16 11:06:50 +02001853 struct cfg_section *cs = NULL, *pcs = NULL;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001854 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02001855 int readbytes = 0;
1856
1857 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001858 ha_alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02001859 return -1;
1860 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001861
David Carlier97880bb2016-04-08 10:35:26 +01001862 if ((f=fopen(file,"r")) == NULL) {
1863 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001864 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01001865 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001866
William Lallemandb2f07452015-05-12 14:27:13 +02001867next_line:
William Lallemand64e84512015-05-12 14:25:37 +02001868 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02001869 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001870 char *end;
1871 char *args[MAX_LINE_ARGS + 1];
1872 char *line = thisline;
William Lallemandf9873ba2015-05-05 17:37:14 +02001873 int dquote = 0; /* double quote */
1874 int squote = 0; /* simple quote */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001875
Willy Tarreaubaaee002006-06-26 02:48:02 +02001876 linenum++;
1877
1878 end = line + strlen(line);
1879
William Lallemand64e84512015-05-12 14:25:37 +02001880 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001881 /* Check if we reached the limit and the last char is not \n.
1882 * Watch out for the last line without the terminating '\n'!
1883 */
William Lallemand64e84512015-05-12 14:25:37 +02001884 char *newline;
1885 int newlinesize = linesize * 2;
1886
1887 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
1888 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001889 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
1890 file, linenum);
William Lallemand64e84512015-05-12 14:25:37 +02001891 err_code |= ERR_ALERT | ERR_FATAL;
1892 continue;
1893 }
1894
1895 readbytes = linesize - 1;
1896 linesize = newlinesize;
1897 thisline = newline;
1898 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001899 }
1900
William Lallemand64e84512015-05-12 14:25:37 +02001901 readbytes = 0;
1902
Willy Tarreaubaaee002006-06-26 02:48:02 +02001903 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02001904 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02001905 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02001906
Christopher Faulet79bdef32016-11-04 22:36:15 +01001907
Joseph Herlanta14c03e2018-11-15 14:04:19 -08001908 if (*line == '[') {/* This is the beginning if a scope */
Christopher Faulet79bdef32016-11-04 22:36:15 +01001909 err_code |= cfg_parse_scope(file, linenum, line);
1910 goto next_line;
1911 }
1912
Willy Tarreaubaaee002006-06-26 02:48:02 +02001913 arg = 0;
1914 args[arg] = line;
1915
1916 while (*line && arg < MAX_LINE_ARGS) {
William Lallemandf9873ba2015-05-05 17:37:14 +02001917 if (*line == '"' && !squote) { /* double quote outside single quotes */
1918 if (dquote)
1919 dquote = 0;
1920 else
1921 dquote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02001922 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02001923 end--;
1924 }
1925 else if (*line == '\'' && !dquote) { /* single quote outside double quotes */
1926 if (squote)
1927 squote = 0;
1928 else
1929 squote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02001930 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02001931 end--;
1932 }
1933 else if (*line == '\\' && !squote) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001934 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
1935 * C equivalent value. Other combinations left unchanged (eg: \1).
1936 */
Willy Tarreaubaaee002006-06-26 02:48:02 +02001937 int skip = 0;
1938 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
1939 *line = line[1];
1940 skip = 1;
1941 }
1942 else if (line[1] == 'r') {
1943 *line = '\r';
1944 skip = 1;
William Lallemandf9873ba2015-05-05 17:37:14 +02001945 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001946 else if (line[1] == 'n') {
1947 *line = '\n';
1948 skip = 1;
1949 }
1950 else if (line[1] == 't') {
1951 *line = '\t';
1952 skip = 1;
1953 }
1954 else if (line[1] == 'x') {
Emeric Brunb982a3d2010-01-04 15:45:53 +01001955 if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001956 unsigned char hex1, hex2;
1957 hex1 = toupper(line[2]) - '0';
1958 hex2 = toupper(line[3]) - '0';
1959 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
1960 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
1961 *line = (hex1<<4) + hex2;
1962 skip = 3;
1963 }
1964 else {
Tim Duesterhusac4930e2020-05-07 19:24:20 +02001965 ha_alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence '%.*s' in '%s'.\n", file, linenum, 4, line, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001966 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhuse6291952020-05-07 19:21:31 +02001967 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001968 }
William Lallemandf9873ba2015-05-05 17:37:14 +02001969 } else if (line[1] == '"') {
1970 *line = '"';
1971 skip = 1;
1972 } else if (line[1] == '\'') {
1973 *line = '\'';
1974 skip = 1;
William Lallemandb2f07452015-05-12 14:27:13 +02001975 } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */
1976 *line = '$';
1977 skip = 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001978 }
1979 if (skip) {
Cyril Bontédd1b01d2009-12-06 13:43:42 +01001980 memmove(line + 1, line + 1 + skip, end - (line + skip));
Willy Tarreaubaaee002006-06-26 02:48:02 +02001981 end -= skip;
1982 }
1983 line++;
1984 }
William Lallemandf9873ba2015-05-05 17:37:14 +02001985 else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001986 /* end of string, end of loop */
1987 *line = 0;
1988 break;
1989 }
William Lallemandf9873ba2015-05-05 17:37:14 +02001990 else if (!squote && !dquote && isspace((unsigned char)*line)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001991 /* a non-escaped space is an argument separator */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001992 *line++ = '\0';
Willy Tarreau8f8e6452007-06-17 21:51:38 +02001993 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02001994 line++;
1995 args[++arg] = line;
1996 }
William Lallemandb2f07452015-05-12 14:27:13 +02001997 else if (dquote && *line == '$') {
1998 /* environment variables are evaluated inside double quotes */
1999 char *var_beg;
2000 char *var_end;
2001 char save_char;
2002 char *value;
2003 int val_len;
2004 int newlinesize;
2005 int braces = 0;
2006
2007 var_beg = line + 1;
2008 var_end = var_beg;
2009
2010 if (*var_beg == '{') {
2011 var_beg++;
2012 var_end++;
2013 braces = 1;
2014 }
2015
Willy Tarreau90807112020-02-25 08:16:33 +01002016 if (!isalpha((unsigned char)*var_beg) && *var_beg != '_') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002017 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 +02002018 err_code |= ERR_ALERT | ERR_FATAL;
2019 goto next_line; /* skip current line */
2020 }
2021
Willy Tarreau90807112020-02-25 08:16:33 +01002022 while (isalnum((unsigned char)*var_end) || *var_end == '_')
William Lallemandb2f07452015-05-12 14:27:13 +02002023 var_end++;
2024
2025 save_char = *var_end;
2026 *var_end = '\0';
2027 value = getenv(var_beg);
2028 *var_end = save_char;
2029 val_len = value ? strlen(value) : 0;
2030
2031 if (braces) {
2032 if (*var_end == '}') {
2033 var_end++;
2034 braces = 0;
2035 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002036 ha_alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02002037 err_code |= ERR_ALERT | ERR_FATAL;
2038 goto next_line; /* skip current line */
2039 }
2040 }
2041
2042 newlinesize = (end - thisline) - (var_end - line) + val_len + 1;
2043
2044 /* if not enough space in thisline */
2045 if (newlinesize > linesize) {
2046 char *newline;
2047
2048 newline = realloc(thisline, newlinesize * sizeof(*thisline));
2049 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002050 ha_alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02002051 err_code |= ERR_ALERT | ERR_FATAL;
2052 goto next_line; /* slip current line */
2053 }
2054 /* recompute pointers if realloc returns a new pointer */
2055 if (newline != thisline) {
2056 int i;
2057 int diff;
2058
2059 for (i = 0; i <= arg; i++) {
2060 diff = args[i] - thisline;
2061 args[i] = newline + diff;
2062 }
2063
2064 diff = var_end - thisline;
2065 var_end = newline + diff;
2066 diff = end - thisline;
2067 end = newline + diff;
2068 diff = line - thisline;
2069 line = newline + diff;
2070 thisline = newline;
2071 }
2072 linesize = newlinesize;
2073 }
2074
2075 /* insert value inside the line */
2076 memmove(line + val_len, var_end, end - var_end + 1);
2077 memcpy(line, value, val_len);
2078 end += val_len - (var_end - line);
2079 line += val_len;
2080 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002081 else {
2082 line++;
2083 }
2084 }
William Lallemandb2f07452015-05-12 14:27:13 +02002085
William Lallemandf9873ba2015-05-05 17:37:14 +02002086 if (dquote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002087 ha_alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02002088 err_code |= ERR_ALERT | ERR_FATAL;
2089 }
2090
2091 if (squote) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002092 ha_alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum);
William Lallemandf9873ba2015-05-05 17:37:14 +02002093 err_code |= ERR_ALERT | ERR_FATAL;
2094 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002095
2096 /* empty line */
2097 if (!**args)
2098 continue;
2099
Willy Tarreau7bb651e2009-11-09 21:16:53 +01002100 if (*line) {
2101 /* we had to stop due to too many args.
2102 * Let's terminate the string, print the offending part then cut the
2103 * last arg.
2104 */
2105 while (*line && *line != '#' && *line != '\n' && *line != '\r')
2106 line++;
2107 *line = '\0';
2108
Christopher Faulet767a84b2017-11-24 16:50:31 +01002109 ha_alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n",
2110 file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]);
Willy Tarreau7bb651e2009-11-09 21:16:53 +01002111 err_code |= ERR_ALERT | ERR_FATAL;
2112 args[arg] = line;
2113 }
2114
Willy Tarreau540abe42007-05-02 20:50:16 +02002115 /* zero out remaining args and ensure that at least one entry
2116 * is zeroed out.
2117 */
2118 while (++arg <= MAX_LINE_ARGS) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02002119 args[arg] = line;
2120 }
2121
Willy Tarreau3842f002009-06-14 11:39:52 +02002122 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002123 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02002124 char *tmp;
2125
Willy Tarreau3842f002009-06-14 11:39:52 +02002126 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02002127 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002128 for (arg=0; *args[arg+1]; arg++)
2129 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02002130 *tmp = '\0'; // fix the next arg to \0
2131 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002132 }
Willy Tarreau3842f002009-06-14 11:39:52 +02002133 else if (!strcmp(args[0], "default")) {
2134 kwm = KWM_DEF;
2135 for (arg=0; *args[arg+1]; arg++)
2136 args[arg] = args[arg+1]; // shift args after inversion
2137 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002138
William Dauchyec730982019-10-27 20:08:10 +01002139 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 &&
2140 strcmp(args[0], "log") != 0 && strcmp(args[0], "busy-polling") != 0 &&
Willy Tarreaud96f1122019-12-03 07:07:36 +01002141 strcmp(args[0], "set-dumpable") != 0 && strcmp(args[0], "strict-limits") != 0 &&
2142 strcmp(args[0], "insecure-fork-wanted") != 0) {
William Dauchyec730982019-10-27 20:08:10 +01002143 ha_alert("parsing [%s:%d]: negation/default currently "
William Dauchy0fec3ab2019-10-27 20:08:11 +01002144 "supported only for options, log, busy-polling, "
Willy Tarreaud96f1122019-12-03 07:07:36 +01002145 "set-dumpable, strict-limits, and insecure-fork-wanted.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02002146 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002147 }
2148
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002149 /* detect section start */
2150 list_for_each_entry(ics, &sections, list) {
2151 if (strcmp(args[0], ics->section_name) == 0) {
2152 cursection = ics->section_name;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002153 pcs = cs;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002154 cs = ics;
2155 break;
2156 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002157 }
2158
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002159 if (pcs && pcs->post_section_parser) {
2160 err_code |= pcs->post_section_parser();
2161 if (err_code & ERR_ABORT)
2162 goto err;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002163 }
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002164 pcs = NULL;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002165
William Lallemandd2ff56d2017-10-16 11:06:50 +02002166 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002167 ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02002168 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemandd2ff56d2017-10-16 11:06:50 +02002169 } else {
William Lallemandd2ff56d2017-10-16 11:06:50 +02002170 err_code |= cs->section_parser(file, linenum, args, kwm);
2171 if (err_code & ERR_ABORT)
2172 goto err;
2173 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002174 }
William Lallemandd2ff56d2017-10-16 11:06:50 +02002175
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002176 if (cs && cs->post_section_parser)
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002177 err_code |= cs->post_section_parser();
William Lallemandd2ff56d2017-10-16 11:06:50 +02002178
2179err:
Christopher Faulet79bdef32016-11-04 22:36:15 +01002180 free(cfg_scope);
2181 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01002182 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02002183 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002184 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02002185 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002186}
2187
Willy Tarreau64ab6072014-09-16 12:17:36 +02002188/* This function propagates processes from frontend <from> to backend <to> so
2189 * that it is always guaranteed that a backend pointed to by a frontend is
2190 * bound to all of its processes. After that, if the target is a "listen"
2191 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02002192 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02002193 * checked first to ensure that <to> is already bound to all processes of
2194 * <from>, there is no risk of looping and we ensure to follow the shortest
2195 * path to the destination.
2196 *
2197 * It is possible to set <to> to NULL for the first call so that the function
2198 * takes care of visiting the initial frontend in <from>.
2199 *
2200 * It is important to note that the function relies on the fact that all names
2201 * have already been resolved.
2202 */
2203void propagate_processes(struct proxy *from, struct proxy *to)
2204{
2205 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002206
2207 if (to) {
2208 /* check whether we need to go down */
2209 if (from->bind_proc &&
2210 (from->bind_proc & to->bind_proc) == from->bind_proc)
2211 return;
2212
2213 if (!from->bind_proc && !to->bind_proc)
2214 return;
2215
2216 to->bind_proc = from->bind_proc ?
2217 (to->bind_proc | from->bind_proc) : 0;
2218
2219 /* now propagate down */
2220 from = to;
2221 }
2222
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01002223 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02002224 return;
2225
Willy Tarreauf6b70012014-12-18 14:00:43 +01002226 if (from->state == PR_STSTOPPED)
2227 return;
2228
Willy Tarreau64ab6072014-09-16 12:17:36 +02002229 /* default_backend */
2230 if (from->defbe.be)
2231 propagate_processes(from, from->defbe.be);
2232
2233 /* use_backend */
2234 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02002235 if (rule->dynamic)
2236 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002237 to = rule->be.backend;
2238 propagate_processes(from, to);
2239 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02002240}
2241
Willy Tarreaubb925012009-07-23 13:36:36 +02002242/*
2243 * Returns the error code, 0 if OK, or any combination of :
2244 * - ERR_ABORT: must abort ASAP
2245 * - ERR_FATAL: we can continue parsing but not start the service
2246 * - ERR_WARN: a warning has been emitted
2247 * - ERR_ALERT: an alert has been emitted
2248 * Only the two first ones can stop processing, the two others are just
2249 * indicators.
2250 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002251int check_config_validity()
2252{
2253 int cfgerr = 0;
2254 struct proxy *curproxy = NULL;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002255 struct stktable *t;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002256 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02002257 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002258 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002259 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002260 char *err;
William Lallemand48b4bb42017-10-23 14:36:34 +02002261 struct cfg_postparser *postparser;
Ben Draut054fbee2018-04-13 15:43:04 -06002262 struct dns_resolvers *curr_resolvers = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002263
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002264 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002265 /*
2266 * Now, check for the integrity of all that we have collected.
2267 */
2268
2269 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02002270 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002271
Willy Tarreau193b8c62012-11-22 00:17:38 +01002272 if (!global.tune.max_http_hdr)
2273 global.tune.max_http_hdr = MAX_HTTP_HDR;
2274
2275 if (!global.tune.cookie_len)
2276 global.tune.cookie_len = CAPTURE_LEN;
2277
Stéphane Cottin23e9e932017-05-18 08:58:41 +02002278 if (!global.tune.requri_len)
2279 global.tune.requri_len = REQURI_LEN;
2280
Willy Tarreau149ab772019-01-26 14:27:06 +01002281 if (!global.nbthread) {
2282 /* nbthread not set, thus automatic. In this case, and only if
2283 * running on a single process, we enable the same number of
2284 * threads as the number of CPUs the process is bound to. This
2285 * allows to easily control the number of threads using taskset.
2286 */
2287 global.nbthread = 1;
2288#if defined(USE_THREAD)
2289 if (global.nbproc == 1)
2290 global.nbthread = thread_cpus_enabled_at_boot;
2291 all_threads_mask = nbits(global.nbthread);
2292#endif
2293 }
2294
Willy Tarreau26f6ae12019-02-02 12:56:15 +01002295 if (global.nbproc > 1 && global.nbthread > 1) {
2296 ha_alert("config : cannot enable multiple processes if multiple threads are configured. Please use either nbproc or nbthread but not both.\n");
2297 err_code |= ERR_ALERT | ERR_FATAL;
2298 goto out;
2299 }
2300
Willy Tarreaubafbe012017-11-24 17:34:44 +01002301 pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
Emeric Brun96fd9262017-07-05 13:33:16 +02002302
Willy Tarreaubafbe012017-11-24 17:34:44 +01002303 pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
Willy Tarreau193b8c62012-11-22 00:17:38 +01002304
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002305 /* Post initialisation of the users and groups lists. */
2306 err_code = userlist_postinit();
2307 if (err_code != ERR_NONE)
2308 goto out;
2309
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002310 /* first, we will invert the proxy list order */
2311 curproxy = NULL;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002312 while (proxies_list) {
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002313 struct proxy *next;
2314
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002315 next = proxies_list->next;
2316 proxies_list->next = curproxy;
2317 curproxy = proxies_list;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002318 if (!next)
2319 break;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002320 proxies_list = next;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002321 }
2322
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002323 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002324 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002325 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002326 struct sticking_rule *mrule;
Christopher Faulete4e830d2017-09-18 14:51:41 +02002327 struct act_rule *arule;
Dragan Dosen1322d092015-09-22 16:05:32 +02002328 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002329 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01002330 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002331
Willy Tarreau050536d2012-10-04 08:47:34 +02002332 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002333 /* proxy ID not set, use automatic numbering with first
2334 * spare entry starting with next_pxid.
2335 */
2336 next_pxid = get_next_id(&used_proxy_id, next_pxid);
2337 curproxy->conf.id.key = curproxy->uuid = next_pxid;
2338 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002339 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01002340 next_pxid++;
2341
Willy Tarreau55ea7572007-06-17 19:56:27 +02002342
Willy Tarreaubaaee002006-06-26 02:48:02 +02002343 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02002344 /* ensure we don't keep listeners uselessly bound */
2345 stop_proxy(curproxy);
Dragan Dosen7d61a332019-05-07 14:16:18 +02002346 if (curproxy->table) {
2347 free((void *)curproxy->table->peers.name);
2348 curproxy->table->peers.p = NULL;
2349 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002350 continue;
2351 }
2352
Willy Tarreau102df612014-05-07 23:56:38 +02002353 /* Check multi-process mode compatibility for the current proxy */
2354
2355 if (curproxy->bind_proc) {
2356 /* an explicit bind-process was specified, let's check how many
2357 * processes remain.
2358 */
David Carliere6c39412015-07-02 07:00:17 +00002359 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02002360
Willy Tarreaua38a7172019-02-02 17:11:28 +01002361 curproxy->bind_proc &= all_proc_mask;
Willy Tarreau102df612014-05-07 23:56:38 +02002362 if (!curproxy->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002363 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 +02002364 curproxy->bind_proc = 1;
2365 }
2366 else if (!curproxy->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002367 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 +02002368 curproxy->bind_proc = 0;
2369 }
2370 }
2371
Willy Tarreau3d209582014-05-09 17:06:11 +02002372 /* check and reduce the bind-proc of each listener */
2373 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
2374 unsigned long mask;
2375
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002376 /* HTTP frontends with "h2" as ALPN/NPN will work in
2377 * HTTP/2 and absolutely require buffers 16kB or larger.
2378 */
2379#ifdef USE_OPENSSL
2380 if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
2381#ifdef OPENSSL_NPN_NEGOTIATED
2382 /* check NPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002383 if (bind_conf->ssl_conf.npn_str && strstr(bind_conf->ssl_conf.npn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002384 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",
2385 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002386 cfgerr++;
2387 }
2388#endif
2389#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
2390 /* check ALPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002391 if (bind_conf->ssl_conf.alpn_str && strstr(bind_conf->ssl_conf.alpn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002392 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",
2393 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002394 cfgerr++;
2395 }
2396#endif
2397 } /* HTTP && bufsize < 16384 */
2398#endif
2399
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002400 /* detect and address thread affinity inconsistencies */
Willy Tarreaua36b3242019-02-02 13:14:34 +01002401 mask = thread_mask(bind_conf->bind_thread);
Willy Tarreau3d957172019-02-02 18:00:17 +01002402 if (!(mask & all_threads_mask)) {
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002403 unsigned long new_mask = 0;
2404
2405 while (mask) {
Willy Tarreau0c026f42018-08-01 19:12:20 +02002406 new_mask |= mask & all_threads_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002407 mask >>= global.nbthread;
2408 }
2409
Willy Tarreaua36b3242019-02-02 13:14:34 +01002410 bind_conf->bind_thread = new_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002411 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",
2412 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
2413 }
2414
2415 /* detect process and nbproc affinity inconsistencies */
Willy Tarreaua36b3242019-02-02 13:14:34 +01002416 mask = proc_mask(bind_conf->bind_proc) & proc_mask(curproxy->bind_proc);
2417 if (!(mask & all_proc_mask)) {
2418 mask = proc_mask(curproxy->bind_proc) & all_proc_mask;
2419 nbproc = my_popcountl(bind_conf->bind_proc);
2420 bind_conf->bind_proc = proc_mask(bind_conf->bind_proc) & mask;
Willy Tarreau3d209582014-05-09 17:06:11 +02002421
Willy Tarreaua36b3242019-02-02 13:14:34 +01002422 if (!bind_conf->bind_proc && nbproc == 1) {
2423 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",
2424 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
2425 bind_conf->bind_proc = mask & ~(mask - 1);
2426 }
2427 else if (!bind_conf->bind_proc && nbproc > 1) {
2428 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",
2429 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
2430 bind_conf->bind_proc = 0;
2431 }
Willy Tarreau3d209582014-05-09 17:06:11 +02002432 }
2433 }
2434
Willy Tarreauff01a212009-03-15 13:46:16 +01002435 switch (curproxy->mode) {
2436 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002437 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002438 if (!(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002439 ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
2440 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002441 cfgerr++;
2442 }
2443
2444 if (curproxy->srv != NULL)
Christopher Faulet767a84b2017-11-24 16:50:31 +01002445 ha_warning("config : servers will be ignored for %s '%s'.\n",
2446 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002447 break;
2448
2449 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002450 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002451 break;
2452
2453 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01002454 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01002455 break;
William Lallemandcf62f7e2018-10-26 14:47:40 +02002456
2457 case PR_MODE_CLI:
2458 cfgerr += proxy_cfg_ensure_no_http(curproxy);
2459 break;
Willy Tarreauff01a212009-03-15 13:46:16 +01002460 }
2461
Willy Tarreau58aa5cc2018-02-08 09:55:09 +01002462 if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002463 ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
2464 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauf3934b82015-08-11 11:36:45 +02002465 err_code |= ERR_WARN;
2466 }
2467
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002468 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02002469 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002470 if (curproxy->options & PR_O_TRANSP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002471 ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n",
2472 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002473 cfgerr++;
2474 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002475#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002476 else if (curproxy->srv == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002477 ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n",
2478 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002479 cfgerr++;
2480 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002481#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02002482 else if (curproxy->options & PR_O_DISPATCH) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002483 ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
2484 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002485 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002486 }
2487 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02002488 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002489 /* If no LB algo is set in a backend, and we're not in
2490 * transparent mode, dispatch mode nor proxy mode, we
2491 * want to use balance roundrobin by default.
2492 */
2493 curproxy->lbprm.algo &= ~BE_LB_ALGO;
2494 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002495 }
2496 }
Willy Tarreau193cf932007-09-17 10:17:23 +02002497
Willy Tarreau1620ec32011-08-06 17:05:02 +02002498 if (curproxy->options & PR_O_DISPATCH)
2499 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
2500 else if (curproxy->options & PR_O_HTTP_PROXY)
2501 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
2502 else if (curproxy->options & PR_O_TRANSP)
2503 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01002504
Christopher Faulete5870d82020-04-15 11:32:03 +02002505 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_HTTP_RS)) {
2506 ha_warning("config : %s '%s' uses http-check rules without 'option httpchk', so the rules are ignored.\n",
2507 proxy_type_str(curproxy), curproxy->id);
2508 err_code |= ERR_WARN;
2509 }
2510
2511 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_TCPCHK_CHK &&
Christopher Fauletc0fcbe42020-06-03 19:00:42 +02002512 (curproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) != TCPCHK_RULES_HTTP_CHK) {
Willy Tarreau1620ec32011-08-06 17:05:02 +02002513 if (curproxy->options & PR_O_DISABLE404) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002514 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2515 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002516 err_code |= ERR_WARN;
2517 curproxy->options &= ~PR_O_DISABLE404;
2518 }
2519 if (curproxy->options2 & PR_O2_CHK_SNDST) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002520 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2521 "send-state", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002522 err_code |= ERR_WARN;
2523 curproxy->options &= ~PR_O2_CHK_SNDST;
2524 }
Willy Tarreauef781042010-01-27 11:53:01 +01002525 }
2526
Simon Horman98637e52014-06-20 12:30:16 +09002527 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
2528 if (!global.external_check) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002529 ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
2530 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002531 cfgerr++;
2532 }
2533 if (!curproxy->check_command) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002534 ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
2535 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002536 cfgerr++;
2537 }
Willy Tarreaud96f1122019-12-03 07:07:36 +01002538 if (!(global.tune.options & GTUNE_INSECURE_FORK)) {
2539 ha_warning("Proxy '%s' : 'insecure-fork-wanted' not enabled in the global section, '%s' will likely fail.\n",
2540 curproxy->id, "option external-check");
2541 err_code |= ERR_WARN;
2542 }
Simon Horman98637e52014-06-20 12:30:16 +09002543 }
2544
Simon Horman64e34162015-02-06 11:11:57 +09002545 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002546 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002547 ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
2548 "'email-alert from', 'email-alert level' 'email-alert mailers', "
2549 "'email-alert myhostname', or 'email-alert to' "
2550 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
2551 "to be present).\n",
2552 proxy_type_str(curproxy), curproxy->id);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002553 err_code |= ERR_WARN;
2554 free_email_alert(curproxy);
2555 }
2556 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01002557 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09002558 }
2559
Simon Horman98637e52014-06-20 12:30:16 +09002560 if (curproxy->check_command) {
2561 int clear = 0;
2562 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002563 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2564 "external-check command", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002565 err_code |= ERR_WARN;
2566 clear = 1;
2567 }
2568 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002569 ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
2570 curproxy->id, "external-check command");
Simon Horman98637e52014-06-20 12:30:16 +09002571 cfgerr++;
2572 }
2573 if (clear) {
2574 free(curproxy->check_command);
2575 curproxy->check_command = NULL;
2576 }
2577 }
2578
2579 if (curproxy->check_path) {
2580 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002581 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2582 "external-check path", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002583 err_code |= ERR_WARN;
2584 free(curproxy->check_path);
2585 curproxy->check_path = NULL;
2586 }
2587 }
2588
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002589 /* if a default backend was specified, let's find it */
2590 if (curproxy->defbe.name) {
2591 struct proxy *target;
2592
Willy Tarreauafb39922015-05-26 12:04:09 +02002593 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002594 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002595 ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
2596 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002597 cfgerr++;
2598 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002599 ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
2600 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02002601 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002602 } else if (target->mode != curproxy->mode &&
2603 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2604
Christopher Faulet767a84b2017-11-24 16:50:31 +01002605 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
2606 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2607 curproxy->conf.file, curproxy->conf.line,
2608 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2609 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002610 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002611 } else {
2612 free(curproxy->defbe.name);
2613 curproxy->defbe.be = target;
Willy Tarreauff678132012-02-13 14:32:34 +01002614 /* Emit a warning if this proxy also has some servers */
2615 if (curproxy->srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002616 ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
2617 curproxy->id);
Willy Tarreauff678132012-02-13 14:32:34 +01002618 err_code |= ERR_WARN;
2619 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002620 }
2621 }
2622
Willy Tarreau55ea7572007-06-17 19:56:27 +02002623 /* find the target proxy for 'use_backend' rules */
2624 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002625 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002626 struct logformat_node *node;
2627 char *pxname;
2628
2629 /* Try to parse the string as a log format expression. If the result
2630 * of the parsing is only one entry containing a simple string, then
2631 * it's a standard string corresponding to a static rule, thus the
2632 * parsing is cancelled and be.name is restored to be resolved.
2633 */
2634 pxname = rule->be.name;
2635 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01002636 curproxy->conf.args.ctx = ARGC_UBK;
2637 curproxy->conf.args.file = rule->file;
2638 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002639 err = NULL;
2640 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002641 ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
2642 rule->file, rule->line, pxname, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002643 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002644 cfgerr++;
2645 continue;
2646 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002647 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
2648
2649 if (!LIST_ISEMPTY(&rule->be.expr)) {
2650 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
2651 rule->dynamic = 1;
2652 free(pxname);
2653 continue;
2654 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002655 /* Only one element in the list, a simple string: free the expression and
2656 * fall back to static rule
2657 */
2658 LIST_DEL(&node->list);
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002659 free(node->arg);
2660 free(node);
2661 }
2662
2663 rule->dynamic = 0;
2664 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002665
Willy Tarreauafb39922015-05-26 12:04:09 +02002666 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002667 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002668 ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
2669 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002670 cfgerr++;
2671 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002672 ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
2673 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002674 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002675 } else if (target->mode != curproxy->mode &&
2676 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2677
Christopher Faulet767a84b2017-11-24 16:50:31 +01002678 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
2679 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2680 curproxy->conf.file, curproxy->conf.line,
2681 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2682 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002683 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002684 } else {
2685 free((void *)rule->be.name);
2686 rule->be.backend = target;
2687 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002688 }
2689
Willy Tarreau64ab6072014-09-16 12:17:36 +02002690 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002691 list_for_each_entry(srule, &curproxy->server_rules, list) {
Jerome Magnin824186b2020-03-29 09:37:12 +02002692 struct server *target;
2693 struct logformat_node *node;
2694 char *server_name;
2695
2696 /* We try to parse the string as a log format expression. If the result of the parsing
2697 * is only one entry containing a single string, then it's a standard string corresponding
2698 * to a static rule, thus the parsing is cancelled and we fall back to setting srv.ptr.
2699 */
2700 server_name = srule->srv.name;
2701 LIST_INIT(&srule->expr);
2702 curproxy->conf.args.ctx = ARGC_USRV;
2703 err = NULL;
2704 if (!parse_logformat_string(server_name, curproxy, &srule->expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
2705 ha_alert("Parsing [%s:%d]; use-server rule failed to parse log-format '%s' : %s.\n",
2706 srule->file, srule->line, server_name, err);
2707 free(err);
2708 cfgerr++;
2709 continue;
2710 }
2711 node = LIST_NEXT(&srule->expr, struct logformat_node *, list);
2712
2713 if (!LIST_ISEMPTY(&srule->expr)) {
2714 if (node->type != LOG_FMT_TEXT || node->list.n != &srule->expr) {
2715 srule->dynamic = 1;
2716 free(server_name);
2717 continue;
2718 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002719 /* Only one element in the list, a simple string: free the expression and
2720 * fall back to static rule
2721 */
2722 LIST_DEL(&node->list);
Jerome Magnin824186b2020-03-29 09:37:12 +02002723 free(node->arg);
2724 free(node);
2725 }
2726
2727 srule->dynamic = 0;
2728 srule->srv.name = server_name;
2729 target = findserver(curproxy, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002730
2731 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002732 ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
2733 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002734 cfgerr++;
2735 continue;
2736 }
2737 free((void *)srule->srv.name);
2738 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002739 }
2740
Emeric Brunb982a3d2010-01-04 15:45:53 +01002741 /* find the target table for 'stick' rules */
2742 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002743 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002744
Emeric Brun1d33b292010-01-04 15:47:17 +01002745 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
2746 if (mrule->flags & STK_IS_STORE)
2747 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2748
Emeric Brunb982a3d2010-01-04 15:45:53 +01002749 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002750 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002751 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002752 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002753
2754 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002755 ha_alert("Proxy '%s': unable to find stick-table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002756 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002757 cfgerr++;
2758 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002759 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002760 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2761 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002762 cfgerr++;
2763 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002764 else if (target->proxy && curproxy->bind_proc & ~target->proxy->bind_proc) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002765 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2766 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002767 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002768 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002769 else {
2770 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002771 mrule->table.t = target;
2772 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002773 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002774 if (!in_proxies_list(target->proxies_list, curproxy)) {
2775 curproxy->next_stkt_ref = target->proxies_list;
2776 target->proxies_list = curproxy;
2777 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002778 }
2779 }
2780
2781 /* find the target table for 'store response' rules */
2782 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002783 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002784
Emeric Brun1d33b292010-01-04 15:47:17 +01002785 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2786
Emeric Brunb982a3d2010-01-04 15:45:53 +01002787 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002788 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002789 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002790 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002791
2792 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002793 ha_alert("Proxy '%s': unable to find store table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002794 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002795 cfgerr++;
2796 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002797 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002798 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2799 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002800 cfgerr++;
2801 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002802 else if (target->proxy && (curproxy->bind_proc & ~target->proxy->bind_proc)) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002803 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2804 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002805 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002806 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002807 else {
2808 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002809 mrule->table.t = target;
2810 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002811 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002812 if (!in_proxies_list(target->proxies_list, curproxy)) {
2813 curproxy->next_stkt_ref = target->proxies_list;
2814 target->proxies_list = curproxy;
2815 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002816 }
2817 }
2818
Christopher Faulete4e830d2017-09-18 14:51:41 +02002819 /* check validity for 'tcp-request' layer 4 rules */
2820 list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) {
2821 err = NULL;
2822 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002823 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002824 free(err);
Willy Tarreau5f53de72012-12-12 00:25:44 +01002825 cfgerr++;
2826 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02002827 }
2828
Christopher Faulete4e830d2017-09-18 14:51:41 +02002829 /* check validity for 'tcp-request' layer 5 rules */
2830 list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) {
2831 err = NULL;
2832 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002833 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002834 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002835 cfgerr++;
2836 }
2837 }
2838
Christopher Faulete4e830d2017-09-18 14:51:41 +02002839 /* check validity for 'tcp-request' layer 6 rules */
2840 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
2841 err = NULL;
2842 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002843 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002844 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002845 cfgerr++;
2846 }
2847 }
2848
Christopher Faulete4e830d2017-09-18 14:51:41 +02002849 /* check validity for 'http-request' layer 7 rules */
2850 list_for_each_entry(arule, &curproxy->http_req_rules, list) {
2851 err = NULL;
2852 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002853 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002854 free(err);
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002855 cfgerr++;
2856 }
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002857 }
2858
Christopher Faulete4e830d2017-09-18 14:51:41 +02002859 /* check validity for 'http-response' layer 7 rules */
2860 list_for_each_entry(arule, &curproxy->http_res_rules, list) {
2861 err = NULL;
2862 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002863 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002864 free(err);
Willy Tarreau09448f72014-06-25 18:12:15 +02002865 cfgerr++;
2866 }
Willy Tarreau09448f72014-06-25 18:12:15 +02002867 }
2868
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01002869 /* check validity for 'http-after-response' layer 7 rules */
2870 list_for_each_entry(arule, &curproxy->http_after_res_rules, list) {
2871 err = NULL;
2872 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
2873 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
2874 free(err);
2875 cfgerr++;
2876 }
2877 }
2878
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002879 if (curproxy->table && curproxy->table->peers.name) {
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002880 struct peers *curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002881
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002882 for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002883 if (strcmp(curpeers->id, curproxy->table->peers.name) == 0) {
2884 free((void *)curproxy->table->peers.name);
2885 curproxy->table->peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002886 break;
2887 }
2888 }
2889
2890 if (!curpeers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002891 ha_alert("Proxy '%s': unable to find sync peers '%s'.\n",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002892 curproxy->id, curproxy->table->peers.name);
2893 free((void *)curproxy->table->peers.name);
2894 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002895 cfgerr++;
2896 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002897 else if (curpeers->state == PR_STSTOPPED) {
2898 /* silently disable this peers section */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002899 curproxy->table->peers.p = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002900 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002901 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002902 ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
2903 curproxy->id, localpeer, curpeers->id);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002904 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002905 cfgerr++;
2906 }
2907 }
2908
Simon Horman9dc49962015-01-30 11:22:59 +09002909
2910 if (curproxy->email_alert.mailers.name) {
2911 struct mailers *curmailers = mailers;
2912
2913 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
Christopher Faulet0108bb32017-10-20 21:34:32 +02002914 if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name))
Simon Horman9dc49962015-01-30 11:22:59 +09002915 break;
Simon Horman9dc49962015-01-30 11:22:59 +09002916 }
Simon Horman9dc49962015-01-30 11:22:59 +09002917 if (!curmailers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002918 ha_alert("Proxy '%s': unable to find mailers '%s'.\n",
2919 curproxy->id, curproxy->email_alert.mailers.name);
Simon Horman9dc49962015-01-30 11:22:59 +09002920 free_email_alert(curproxy);
2921 cfgerr++;
2922 }
Christopher Faulet0108bb32017-10-20 21:34:32 +02002923 else {
2924 err = NULL;
2925 if (init_email_alert(curmailers, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002926 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulet0108bb32017-10-20 21:34:32 +02002927 free(err);
2928 cfgerr++;
2929 }
2930 }
Simon Horman9dc49962015-01-30 11:22:59 +09002931 }
2932
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002933 if (curproxy->uri_auth && curproxy->uri_auth != defproxy.uri_auth &&
Willy Tarreauff011f22011-01-06 17:51:27 +01002934 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002935 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002936 ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
2937 "proxy", curproxy->id);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002938 cfgerr++;
2939 goto out_uri_auth_compat;
2940 }
2941
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002942 if (curproxy->uri_auth && curproxy->uri_auth->userlist &&
2943 (curproxy->uri_auth != defproxy.uri_auth ||
2944 LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules))) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002945 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02002946 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002947 int i = 0;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002948 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
2949 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002950
2951 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002952 uri_auth_compat_req[i++] = "realm";
2953 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
2954 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002955
Willy Tarreau95fa4692010-02-01 13:05:50 +01002956 uri_auth_compat_req[i++] = "unless";
2957 uri_auth_compat_req[i++] = "{";
2958 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
2959 uri_auth_compat_req[i++] = "}";
2960 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002961
Willy Tarreauff011f22011-01-06 17:51:27 +01002962 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
2963 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002964 cfgerr++;
2965 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002966 }
2967
Willy Tarreauff011f22011-01-06 17:51:27 +01002968 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01002969
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002970 if (curproxy->uri_auth->auth_realm) {
2971 free(curproxy->uri_auth->auth_realm);
2972 curproxy->uri_auth->auth_realm = NULL;
2973 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002974 }
2975out_uri_auth_compat:
2976
Dragan Dosen43885c72015-10-01 13:18:13 +02002977 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02002978 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02002979 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
2980 if (!curproxy->conf.logformat_sd_string) {
2981 /* set the default logformat_sd_string */
2982 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
2983 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002984 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02002985 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002986 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02002987
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002988 /* compile the log format */
2989 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02002990 if (curproxy->conf.logformat_string != default_http_log_format &&
2991 curproxy->conf.logformat_string != default_tcp_log_format &&
2992 curproxy->conf.logformat_string != clf_http_log_format)
2993 free(curproxy->conf.logformat_string);
2994 curproxy->conf.logformat_string = NULL;
2995 free(curproxy->conf.lfs_file);
2996 curproxy->conf.lfs_file = NULL;
2997 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002998
2999 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
3000 free(curproxy->conf.logformat_sd_string);
3001 curproxy->conf.logformat_sd_string = NULL;
3002 free(curproxy->conf.lfsd_file);
3003 curproxy->conf.lfsd_file = NULL;
3004 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02003005 }
3006
Willy Tarreau62a61232013-04-12 18:13:46 +02003007 if (curproxy->conf.logformat_string) {
3008 curproxy->conf.args.ctx = ARGC_LOG;
3009 curproxy->conf.args.file = curproxy->conf.lfs_file;
3010 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003011 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01003012 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003013 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003014 ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
3015 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003016 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01003017 cfgerr++;
3018 }
Willy Tarreau62a61232013-04-12 18:13:46 +02003019 curproxy->conf.args.file = NULL;
3020 curproxy->conf.args.line = 0;
3021 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02003022
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003023 if (curproxy->conf.logformat_sd_string) {
3024 curproxy->conf.args.ctx = ARGC_LOGSD;
3025 curproxy->conf.args.file = curproxy->conf.lfsd_file;
3026 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003027 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01003028 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 +01003029 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003030 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
3031 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003032 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01003033 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003034 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003035 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
3036 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003037 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01003038 cfgerr++;
3039 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003040 curproxy->conf.args.file = NULL;
3041 curproxy->conf.args.line = 0;
3042 }
3043
Willy Tarreau62a61232013-04-12 18:13:46 +02003044 if (curproxy->conf.uniqueid_format_string) {
3045 curproxy->conf.args.ctx = ARGC_UIF;
3046 curproxy->conf.args.file = curproxy->conf.uif_file;
3047 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003048 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01003049 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 +01003050 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003051 ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
3052 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01003053 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01003054 cfgerr++;
3055 }
Willy Tarreau62a61232013-04-12 18:13:46 +02003056 curproxy->conf.args.file = NULL;
3057 curproxy->conf.args.line = 0;
3058 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02003059
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01003060 /* only now we can check if some args remain unresolved.
3061 * This must be done after the users and groups resolution.
3062 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02003063 cfgerr += smp_resolve_args(curproxy);
3064 if (!cfgerr)
3065 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01003066
Willy Tarreau2738a142006-07-08 17:28:09 +02003067 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003068 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02003069 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02003070 (!curproxy->timeout.connect ||
3071 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003072 ha_warning("config : missing timeouts for %s '%s'.\n"
3073 " | While not properly invalid, you will certainly encounter various problems\n"
3074 " | with such a configuration. To fix this, please ensure that all following\n"
3075 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
3076 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02003077 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02003078 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02003079
Willy Tarreau1fa31262007-12-03 00:36:16 +01003080 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
3081 * We must still support older configurations, so let's find out whether those
3082 * parameters have been set or must be copied from contimeouts.
3083 */
3084 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003085 if (!curproxy->timeout.tarpit ||
3086 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01003087 /* tarpit timeout not set. We search in the following order:
3088 * default.tarpit, curr.connect, default.connect.
3089 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003090 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01003091 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003092 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003093 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003094 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003095 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01003096 }
3097 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003098 (!curproxy->timeout.queue ||
3099 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01003100 /* queue timeout not set. We search in the following order:
3101 * default.queue, curr.connect, default.connect.
3102 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003103 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01003104 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003105 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003106 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003107 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003108 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01003109 }
3110 }
3111
Christopher Faulete5870d82020-04-15 11:32:03 +02003112 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_TCP_RS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003113 ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
3114 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau215663d2014-06-13 18:30:23 +02003115 err_code |= ERR_WARN;
3116 }
3117
Willy Tarreau193b8c62012-11-22 00:17:38 +01003118 /* ensure that cookie capture length is not too large */
3119 if (curproxy->capture_len >= global.tune.cookie_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003120 ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n",
3121 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau193b8c62012-11-22 00:17:38 +01003122 err_code |= ERR_WARN;
3123 curproxy->capture_len = global.tune.cookie_len - 1;
3124 }
3125
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003126 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01003127 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003128 curproxy->req_cap_pool = create_pool("ptrcap",
3129 curproxy->nb_req_cap * sizeof(char *),
3130 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003131 }
3132
3133 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003134 curproxy->rsp_cap_pool = create_pool("ptrcap",
3135 curproxy->nb_rsp_cap * sizeof(char *),
3136 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003137 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003138
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003139 switch (curproxy->load_server_state_from_file) {
3140 case PR_SRV_STATE_FILE_UNSPEC:
3141 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
3142 break;
3143 case PR_SRV_STATE_FILE_GLOBAL:
3144 if (!global.server_state_file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003145 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",
3146 curproxy->id);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003147 err_code |= ERR_WARN;
3148 }
3149 break;
3150 }
3151
Willy Tarreaubaaee002006-06-26 02:48:02 +02003152 /* first, we will invert the servers list order */
3153 newsrv = NULL;
3154 while (curproxy->srv) {
3155 struct server *next;
3156
3157 next = curproxy->srv->next;
3158 curproxy->srv->next = newsrv;
3159 newsrv = curproxy->srv;
3160 if (!next)
3161 break;
3162 curproxy->srv = next;
3163 }
3164
Willy Tarreau17edc812014-01-03 12:14:34 +01003165 /* Check that no server name conflicts. This causes trouble in the stats.
3166 * We only emit a warning for the first conflict affecting each server,
3167 * in order to avoid combinatory explosion if all servers have the same
3168 * name. We do that only for servers which do not have an explicit ID,
3169 * because these IDs were made also for distinguishing them and we don't
3170 * want to annoy people who correctly manage them.
3171 */
3172 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3173 struct server *other_srv;
3174
3175 if (newsrv->puid)
3176 continue;
3177
3178 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
3179 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
Willy Tarreaub01302f2019-05-27 19:31:06 +02003180 ha_alert("parsing [%s:%d] : %s '%s', another server named '%s' was already defined at line %d, please use distinct names.\n",
Christopher Faulet767a84b2017-11-24 16:50:31 +01003181 newsrv->conf.file, newsrv->conf.line,
3182 proxy_type_str(curproxy), curproxy->id,
3183 newsrv->id, other_srv->conf.line);
Willy Tarreaub01302f2019-05-27 19:31:06 +02003184 cfgerr++;
Willy Tarreau17edc812014-01-03 12:14:34 +01003185 break;
3186 }
3187 }
3188 }
3189
Willy Tarreaudd701652010-05-25 23:03:02 +02003190 /* assign automatic UIDs to servers which don't have one yet */
3191 next_id = 1;
3192 newsrv = curproxy->srv;
3193 while (newsrv != NULL) {
3194 if (!newsrv->puid) {
3195 /* server ID not set, use automatic numbering with first
3196 * spare entry starting with next_svid.
3197 */
3198 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
3199 newsrv->conf.id.key = newsrv->puid = next_id;
3200 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
Frédéric Lécaille84d60462019-05-17 14:29:15 +02003201 newsrv->conf.name.key = newsrv->id;
3202 ebis_insert(&curproxy->conf.used_server_name, &newsrv->conf.name);
Willy Tarreaudd701652010-05-25 23:03:02 +02003203 }
3204 next_id++;
3205 newsrv = newsrv->next;
3206 }
3207
Willy Tarreau20697042007-11-15 23:26:18 +01003208 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01003209 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02003210
Willy Tarreau62c3be22012-01-20 13:12:32 +01003211 /*
3212 * If this server supports a maxconn parameter, it needs a dedicated
3213 * tasks to fill the emptied slots when a connection leaves.
3214 * Also, resolve deferred tracking dependency if needed.
3215 */
3216 newsrv = curproxy->srv;
3217 while (newsrv != NULL) {
3218 if (newsrv->minconn > newsrv->maxconn) {
3219 /* Only 'minconn' was specified, or it was higher than or equal
3220 * to 'maxconn'. Let's turn this into maxconn and clean it, as
3221 * this will avoid further useless expensive computations.
3222 */
3223 newsrv->maxconn = newsrv->minconn;
3224 } else if (newsrv->maxconn && !newsrv->minconn) {
3225 /* minconn was not specified, so we set it to maxconn */
3226 newsrv->minconn = newsrv->maxconn;
3227 }
3228
Willy Tarreau17d45382016-12-22 21:16:08 +01003229 /* this will also properly set the transport layer for prod and checks */
Christopher Fauletf61f33a2020-03-27 18:55:49 +01003230 if (newsrv->use_ssl == 1 || newsrv->check.use_ssl == 1 || (newsrv->proxy->options & PR_O_TCPCHK_SSL)) {
Willy Tarreau17d45382016-12-22 21:16:08 +01003231 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
3232 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
3233 }
Emeric Brun94324a42012-10-11 14:00:19 +02003234
Willy Tarreau034c88c2017-01-23 23:36:45 +01003235 if ((newsrv->flags & SRV_F_FASTOPEN) &&
3236 ((curproxy->retry_type & (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)) !=
3237 (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)))
3238 ha_warning("parsing [%s:%d] : %s '%s': server '%s' has tfo activated, the backend should be configured with at least 'conn-failure', 'empty-response' and 'response-timeout' or we wouldn't be able to retry the connection on failure.\n",
3239 newsrv->conf.file, newsrv->conf.line,
3240 proxy_type_str(curproxy), curproxy->id,
3241 newsrv->id);
3242
Willy Tarreau62c3be22012-01-20 13:12:32 +01003243 if (newsrv->trackit) {
3244 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02003245 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003246 char *pname, *sname;
3247
3248 pname = newsrv->trackit;
3249 sname = strrchr(pname, '/');
3250
3251 if (sname)
3252 *sname++ = '\0';
3253 else {
3254 sname = pname;
3255 pname = NULL;
3256 }
3257
3258 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02003259 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003260 if (!px) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003261 ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
3262 proxy_type_str(curproxy), curproxy->id,
3263 newsrv->id, pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003264 cfgerr++;
3265 goto next_srv;
3266 }
3267 } else
3268 px = curproxy;
3269
3270 srv = findserver(px, sname);
3271 if (!srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003272 ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
3273 proxy_type_str(curproxy), curproxy->id,
3274 newsrv->id, sname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003275 cfgerr++;
3276 goto next_srv;
3277 }
3278
Christopher Faulet8892e5d2020-03-26 19:48:20 +01003279 if (!srv->do_check && !srv->do_agent && !srv->track && !srv->trackit) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003280 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for "
3281 "tracking as it does not have any check nor agent enabled.\n",
3282 proxy_type_str(curproxy), curproxy->id,
3283 newsrv->id, px->id, srv->id);
Willy Tarreau32091232014-05-16 13:52:00 +02003284 cfgerr++;
3285 goto next_srv;
3286 }
3287
3288 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
3289
Frédéric Lécaille2efc6492017-03-14 14:32:17 +01003290 if (newsrv == srv || loop) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003291 ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it "
3292 "belongs to a tracking chain looping back to %s/%s.\n",
3293 proxy_type_str(curproxy), curproxy->id,
3294 newsrv->id, px->id, srv->id, px->id,
3295 newsrv == srv ? srv->id : loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003296 cfgerr++;
3297 goto next_srv;
3298 }
3299
3300 if (curproxy != px &&
3301 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003302 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for"
3303 "tracking: disable-on-404 option inconsistency.\n",
3304 proxy_type_str(curproxy), curproxy->id,
3305 newsrv->id, px->id, srv->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003306 cfgerr++;
3307 goto next_srv;
3308 }
3309
Willy Tarreau62c3be22012-01-20 13:12:32 +01003310 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01003311 newsrv->tracknext = srv->trackers;
3312 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003313
3314 free(newsrv->trackit);
3315 newsrv->trackit = NULL;
3316 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02003317
Willy Tarreau62c3be22012-01-20 13:12:32 +01003318 next_srv:
3319 newsrv = newsrv->next;
3320 }
3321
Olivier Houchard4e694042017-03-14 20:01:29 +01003322 /*
3323 * Try to generate dynamic cookies for servers now.
3324 * It couldn't be done earlier, since at the time we parsed
3325 * the server line, we may not have known yet that we
3326 * should use dynamic cookies, or the secret key may not
3327 * have been provided yet.
3328 */
3329 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
3330 newsrv = curproxy->srv;
3331 while (newsrv != NULL) {
3332 srv_set_dyncookie(newsrv);
3333 newsrv = newsrv->next;
3334 }
3335
3336 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003337 /* We have to initialize the server lookup mechanism depending
Joseph Herlanta14c03e2018-11-15 14:04:19 -08003338 * on what LB algorithm was chosen.
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003339 */
3340
3341 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
3342 switch (curproxy->lbprm.algo & BE_LB_KIND) {
3343 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02003344 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
3345 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3346 init_server_map(curproxy);
Willy Tarreau760e81d2018-05-03 07:20:40 +02003347 } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
3348 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3349 chash_init_server_tree(curproxy);
Willy Tarreau9757a382009-10-03 12:56:50 +02003350 } else {
3351 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
3352 fwrr_init_server_groups(curproxy);
3353 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003354 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003355
Willy Tarreau3ebb1162012-02-13 16:57:44 +01003356 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01003357 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
3358 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
3359 fwlc_init_server_tree(curproxy);
3360 } else {
3361 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
3362 fas_init_server_tree(curproxy);
3363 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003364 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003365
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003366 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003367 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
3368 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3369 chash_init_server_tree(curproxy);
3370 } else {
3371 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3372 init_server_map(curproxy);
3373 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003374 break;
3375 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003376 HA_SPIN_INIT(&curproxy->lbprm.lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003377
3378 if (curproxy->options & PR_O_LOGASAP)
3379 curproxy->to_log &= ~LW_BYTES;
3380
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003381 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003382 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
3383 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003384 ha_warning("config : log format ignored for %s '%s' since it has no log address.\n",
3385 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003386 err_code |= ERR_WARN;
3387 }
3388
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003389 if (curproxy->mode != PR_MODE_HTTP) {
3390 int optnum;
3391
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003392 if (curproxy->uri_auth) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003393 ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
3394 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003395 err_code |= ERR_WARN;
3396 curproxy->uri_auth = NULL;
3397 }
3398
Willy Tarreaude7dc882017-03-10 11:49:21 +01003399 if (curproxy->capture_name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003400 ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
3401 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003402 err_code |= ERR_WARN;
3403 }
3404
3405 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003406 ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
3407 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003408 err_code |= ERR_WARN;
3409 }
3410
3411 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003412 ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
3413 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003414 err_code |= ERR_WARN;
3415 }
3416
Willy Tarreaude7dc882017-03-10 11:49:21 +01003417 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003418 ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
3419 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003420 err_code |= ERR_WARN;
3421 }
3422
Willy Tarreau87cf5142011-08-19 22:57:24 +02003423 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003424 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3425 "forwardfor", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003426 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02003427 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003428 }
3429
3430 if (curproxy->options & PR_O_ORGTO) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003431 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3432 "originalto", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003433 err_code |= ERR_WARN;
3434 curproxy->options &= ~PR_O_ORGTO;
3435 }
3436
3437 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
3438 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
3439 (curproxy->cap & cfg_opts[optnum].cap) &&
3440 (curproxy->options & cfg_opts[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003441 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3442 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003443 err_code |= ERR_WARN;
3444 curproxy->options &= ~cfg_opts[optnum].val;
3445 }
3446 }
3447
3448 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
3449 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
3450 (curproxy->cap & cfg_opts2[optnum].cap) &&
3451 (curproxy->options2 & cfg_opts2[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003452 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3453 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003454 err_code |= ERR_WARN;
3455 curproxy->options2 &= ~cfg_opts2[optnum].val;
3456 }
3457 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003458
Willy Tarreau29fbe512015-08-20 19:35:14 +02003459#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003460 if (curproxy->conn_src.bind_hdr_occ) {
3461 curproxy->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003462 ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
3463 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003464 err_code |= ERR_WARN;
3465 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003466#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003467 }
3468
Willy Tarreaubaaee002006-06-26 02:48:02 +02003469 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01003470 * ensure that we're not cross-dressing a TCP server into HTTP.
3471 */
3472 newsrv = curproxy->srv;
3473 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01003474 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003475 ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
3476 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02003477 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01003478 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003479
Willy Tarreau0cec3312011-10-31 13:49:26 +01003480 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003481 ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
3482 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau0cec3312011-10-31 13:49:26 +01003483 err_code |= ERR_WARN;
3484 }
3485
Willy Tarreauc93cd162014-05-13 15:54:22 +02003486 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003487 ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
3488 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau82ffa392013-08-13 17:19:08 +02003489 err_code |= ERR_WARN;
3490 }
3491
Willy Tarreau29fbe512015-08-20 19:35:14 +02003492#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003493 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
3494 newsrv->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003495 ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
3496 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003497 err_code |= ERR_WARN;
3498 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003499#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01003500
Willy Tarreau46deab62018-04-28 07:18:15 +02003501 if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR)
3502 curproxy->options &= ~PR_O_REUSE_MASK;
3503
Willy Tarreau21d2af32008-02-14 20:25:24 +01003504 newsrv = newsrv->next;
3505 }
3506
Christopher Fauletd7c91962015-04-30 11:48:27 +02003507 /* Check filter configuration, if any */
3508 cfgerr += flt_check(curproxy);
3509
Willy Tarreauc1a21672009-08-16 22:37:44 +02003510 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02003511 if (!curproxy->accept)
3512 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02003513
Willy Tarreauc1a21672009-08-16 22:37:44 +02003514 if (curproxy->tcp_req.inspect_delay ||
3515 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02003516 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003517
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003518 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003519 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003520 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003521 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003522
William Lallemandcf62f7e2018-10-26 14:47:40 +02003523 if (curproxy->mode == PR_MODE_CLI) {
3524 curproxy->fe_req_ana |= AN_REQ_WAIT_CLI;
3525 curproxy->fe_rsp_ana |= AN_RES_WAIT_CLI;
3526 }
3527
Willy Tarreauc1a21672009-08-16 22:37:44 +02003528 /* both TCP and HTTP must check switching rules */
3529 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003530
3531 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003532 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003533 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3534 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 +01003535 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003536 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3537 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003538 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003539 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003540 }
3541
3542 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02003543 if (curproxy->tcp_req.inspect_delay ||
3544 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
3545 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
3546
Emeric Brun97679e72010-09-23 17:56:44 +02003547 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
3548 curproxy->be_rsp_ana |= AN_RES_INSPECT;
3549
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003550 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003551 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003552 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003553 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003554
3555 /* If the backend does requires RDP cookie persistence, we have to
3556 * enable the corresponding analyser.
3557 */
3558 if (curproxy->options2 & PR_O2_RDPC_PRST)
3559 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003560
3561 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003562 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003563 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3564 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 +01003565 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003566 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3567 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003568 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003569 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003570 }
Christopher Fauleta717b992018-04-10 14:43:00 +02003571
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003572 /* Check the mux protocols, if any, for each listener and server
Christopher Fauleta717b992018-04-10 14:43:00 +02003573 * attached to the current proxy */
3574 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3575 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003576 const struct mux_proto_list *mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003577
3578 if (!bind_conf->mux_proto)
3579 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003580
3581 /* it is possible that an incorrect mux was referenced
3582 * due to the proxy's mode not being taken into account
3583 * on first pass. Let's adjust it now.
3584 */
3585 mux_ent = conn_get_best_mux_entry(bind_conf->mux_proto->token, PROTO_SIDE_FE, mode);
3586
3587 if (!mux_ent || !isteq(mux_ent->token, bind_conf->mux_proto->token)) {
Christopher Fauleta717b992018-04-10 14:43:00 +02003588 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n",
3589 proxy_type_str(curproxy), curproxy->id,
3590 (int)bind_conf->mux_proto->token.len,
3591 bind_conf->mux_proto->token.ptr,
3592 bind_conf->arg, bind_conf->file, bind_conf->line);
3593 cfgerr++;
3594 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003595
3596 /* update the mux */
3597 bind_conf->mux_proto = mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003598 }
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003599 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3600 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003601 const struct mux_proto_list *mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003602
3603 if (!newsrv->mux_proto)
3604 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003605
3606 /* it is possible that an incorrect mux was referenced
3607 * due to the proxy's mode not being taken into account
3608 * on first pass. Let's adjust it now.
3609 */
3610 mux_ent = conn_get_best_mux_entry(newsrv->mux_proto->token, PROTO_SIDE_BE, mode);
3611
3612 if (!mux_ent || !isteq(mux_ent->token, newsrv->mux_proto->token)) {
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003613 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n",
3614 proxy_type_str(curproxy), curproxy->id,
3615 (int)newsrv->mux_proto->token.len,
3616 newsrv->mux_proto->token.ptr,
3617 newsrv->id, newsrv->conf.file, newsrv->conf.line);
3618 cfgerr++;
3619 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003620
3621 /* update the mux */
3622 newsrv->mux_proto = mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003623 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003624
3625 /* initialize idle conns lists */
3626 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3627 int i;
3628
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003629 newsrv->available_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->available_conns));
Willy Tarreau835daa12019-02-07 14:46:29 +01003630
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003631 if (!newsrv->available_conns) {
Willy Tarreau835daa12019-02-07 14:46:29 +01003632 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003633 newsrv->conf.file, newsrv->conf.line, newsrv->id);
Willy Tarreau835daa12019-02-07 14:46:29 +01003634 cfgerr++;
3635 continue;
3636 }
3637
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003638 for (i = 0; i < global.nbthread; i++)
3639 LIST_INIT(&newsrv->available_conns[i]);
Willy Tarreau980855b2019-02-07 14:59:29 +01003640
3641 if (newsrv->max_idle_conns != 0) {
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003642 if (idle_conn_task == NULL) {
3643 idle_conn_task = task_new(MAX_THREADS_MASK);
3644 if (!idle_conn_task)
3645 goto err;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003646
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003647 idle_conn_task->process = srv_cleanup_idle_connections;
3648 idle_conn_task->context = NULL;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003649
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003650 for (i = 0; i < global.nbthread; i++) {
Willy Tarreaubbb5f1d2019-10-18 08:50:49 +02003651 idle_conn_cleanup[i] = task_new(1UL << i);
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003652 if (!idle_conn_cleanup[i])
3653 goto err;
3654 idle_conn_cleanup[i]->process = srv_cleanup_toremove_connections;
3655 idle_conn_cleanup[i]->context = NULL;
Olivier Houchard859dc802019-08-08 15:47:21 +02003656 MT_LIST_INIT(&toremove_connections[i]);
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003657 }
3658 }
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003659
3660 newsrv->idle_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->idle_conns));
3661 if (!newsrv->idle_conns) {
3662 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3663 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3664 cfgerr++;
3665 continue;
3666 }
3667
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003668 for (i = 0; i < global.nbthread; i++)
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003669 MT_LIST_INIT(&newsrv->idle_conns[i]);
3670
3671 newsrv->safe_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->safe_conns));
3672 if (!newsrv->safe_conns) {
3673 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3674 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3675 cfgerr++;
3676 continue;
3677 }
3678
3679 for (i = 0; i < global.nbthread; i++)
3680 MT_LIST_INIT(&newsrv->safe_conns[i]);
3681
3682 newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(int));
Olivier Houchardf1314812019-02-18 16:41:17 +01003683 if (!newsrv->curr_idle_thr)
3684 goto err;
Willy Tarreau980855b2019-02-07 14:59:29 +01003685 continue;
3686 err:
3687 ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
3688 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3689 cfgerr++;
3690 continue;
3691 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003692 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003693 }
3694
3695 /***********************************************************/
3696 /* At this point, target names have already been resolved. */
3697 /***********************************************************/
3698
3699 /* Check multi-process mode compatibility */
3700
3701 if (global.nbproc > 1 && global.stats_fe) {
3702 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3703 unsigned long mask;
3704
Willy Tarreau6daac192019-02-02 17:39:53 +01003705 mask = proc_mask(global.stats_fe->bind_proc) && all_proc_mask;
3706 mask &= proc_mask(bind_conf->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003707
3708 /* stop here if more than one process is used */
Willy Tarreau9504dd62018-10-15 09:37:03 +02003709 if (atleast2(mask))
Willy Tarreau419ead82014-09-16 13:41:21 +02003710 break;
3711 }
3712 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003713 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 +02003714 }
3715 }
3716
3717 /* Make each frontend inherit bind-process from its listeners when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003718 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003719 if (curproxy->bind_proc)
3720 continue;
3721
3722 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3723 unsigned long mask;
3724
Willy Tarreau6daac192019-02-02 17:39:53 +01003725 mask = proc_mask(bind_conf->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003726 curproxy->bind_proc |= mask;
3727 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003728 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003729 }
3730
3731 if (global.stats_fe) {
3732 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3733 unsigned long mask;
3734
Cyril Bonté06181952016-02-24 00:14:54 +01003735 mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02003736 global.stats_fe->bind_proc |= mask;
3737 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003738 global.stats_fe->bind_proc = proc_mask(global.stats_fe->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003739 }
3740
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003741 /* propagate bindings from frontends to backends. Don't do it if there
3742 * are any fatal errors as we must not call it with unresolved proxies.
3743 */
3744 if (!cfgerr) {
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003745 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003746 if (curproxy->cap & PR_CAP_FE)
3747 propagate_processes(curproxy, NULL);
3748 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003749 }
3750
3751 /* Bind each unbound backend to all processes when not specified. */
Willy Tarreau6daac192019-02-02 17:39:53 +01003752 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
3753 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003754
3755 /*******************************************************/
3756 /* At this step, all proxies have a non-null bind_proc */
3757 /*******************************************************/
3758
3759 /* perform the final checks before creating tasks */
3760
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003761 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003762 struct listener *listener;
3763 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003764
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003765 /* Configure SSL for each bind line.
3766 * Note: if configuration fails at some point, the ->ctx member
3767 * remains NULL so that listeners can later detach.
3768 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003769 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01003770 if (bind_conf->xprt->prepare_bind_conf &&
3771 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003772 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003773 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003774
Willy Tarreaue6b98942007-10-29 01:09:36 +01003775 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003776 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02003777 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003778 int nbproc;
3779
3780 nbproc = my_popcountl(curproxy->bind_proc &
Cyril Bonté4920d702016-04-15 07:58:43 +02003781 (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) &
Willy Tarreaua38a7172019-02-02 17:11:28 +01003782 all_proc_mask);
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003783
3784 if (!nbproc) /* no intersection between listener and frontend */
3785 nbproc = 1;
3786
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003787 if (!listener->luid) {
3788 /* listener ID not set, use automatic numbering with first
3789 * spare entry starting with next_luid.
3790 */
3791 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
3792 listener->conf.id.key = listener->luid = next_id;
3793 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003794 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01003795 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003796
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003797 /* enable separate counters */
3798 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01003799 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003800 if (!listener->name)
3801 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003802 }
Willy Tarreau81796be2012-09-22 19:11:47 +02003803
Willy Tarreaue6b98942007-10-29 01:09:36 +01003804 if (curproxy->options & PR_O_TCP_NOLING)
3805 listener->options |= LI_O_NOLINGER;
Willy Tarreau16a21472012-11-19 12:39:59 +01003806 if (!listener->maxaccept)
3807 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
3808
3809 /* we want to have an optimal behaviour on single process mode to
3810 * maximize the work at once, but in multi-process we want to keep
3811 * some fairness between processes, so we target half of the max
3812 * number of events to be balanced over all the processes the proxy
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +05003813 * is bound to. Remember that maxaccept = -1 must be kept as it is
Willy Tarreau16a21472012-11-19 12:39:59 +01003814 * used to disable the limit.
3815 */
Christopher Faulet02f3cf12019-04-30 14:08:41 +02003816 if (listener->maxaccept > 0 && nbproc > 1) {
3817 listener->maxaccept = (listener->maxaccept + 1) / 2;
Willy Tarreau16a21472012-11-19 12:39:59 +01003818 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
3819 }
3820
Willy Tarreau9903f0e2015-04-04 18:50:31 +02003821 listener->accept = session_accept_fd;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003822 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01003823 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01003824
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003825 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02003826 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003827
Willy Tarreau620408f2016-10-21 16:37:51 +02003828 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
3829 listener->options |= LI_O_TCP_L5_RULES;
3830
Willy Tarreaude3041d2010-05-31 10:56:17 +02003831 if (curproxy->mon_mask.s_addr)
3832 listener->options |= LI_O_CHK_MONNET;
3833
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003834 /* smart accept mode is automatic in HTTP mode */
3835 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003836 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003837 !(curproxy->no_options2 & PR_O2_SMARTACC)))
3838 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01003839 }
3840
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003841 /* Release unused SSL configs */
3842 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01003843 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
3844 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003845 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003846
Willy Tarreaua38a7172019-02-02 17:11:28 +01003847 if (atleast2(curproxy->bind_proc & all_proc_mask)) {
Willy Tarreau102df612014-05-07 23:56:38 +02003848 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02003849 int count, maxproc = 0;
3850
3851 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
David Carliere6c39412015-07-02 07:00:17 +00003852 count = my_popcountl(bind_conf->bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003853 if (count > maxproc)
3854 maxproc = count;
3855 }
3856 /* backends have 0, frontends have 1 or more */
3857 if (maxproc != 1)
Christopher Faulet767a84b2017-11-24 16:50:31 +01003858 ha_warning("Proxy '%s': in multi-process mode, stats will be"
3859 " limited to process assigned to the current request.\n",
3860 curproxy->id);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003861
Willy Tarreau102df612014-05-07 23:56:38 +02003862 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003863 ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
3864 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003865 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003866 }
Willy Tarreau102df612014-05-07 23:56:38 +02003867 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003868 ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
3869 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003870 }
3871 }
Willy Tarreau918ff602011-07-25 16:33:49 +02003872
3873 /* create the task associated with the proxy */
Emeric Brunc60def82017-09-27 14:59:38 +02003874 curproxy->task = task_new(MAX_THREADS_MASK);
Willy Tarreau918ff602011-07-25 16:33:49 +02003875 if (curproxy->task) {
3876 curproxy->task->context = curproxy;
3877 curproxy->task->process = manage_proxy;
Willy Tarreau918ff602011-07-25 16:33:49 +02003878 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003879 ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
3880 curproxy->id);
Willy Tarreau918ff602011-07-25 16:33:49 +02003881 cfgerr++;
3882 }
Willy Tarreaub369a042014-09-16 13:21:03 +02003883 }
3884
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003885 /*
3886 * Recount currently required checks.
3887 */
3888
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003889 for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003890 int optnum;
3891
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003892 for (optnum = 0; cfg_opts[optnum].name; optnum++)
3893 if (curproxy->options & cfg_opts[optnum].val)
3894 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003895
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003896 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
3897 if (curproxy->options2 & cfg_opts2[optnum].val)
3898 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003899 }
3900
Willy Tarreau0fca4832015-05-01 19:12:05 +02003901 /* compute the required process bindings for the peers */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003902 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003903 if (curproxy->table && curproxy->table->peers.p)
3904 curproxy->table->peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
Willy Tarreau0fca4832015-05-01 19:12:05 +02003905
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01003906 /* compute the required process bindings for the peers from <stktables_list>
3907 * for all the stick-tables, the ones coming with "peers" sections included.
3908 */
3909 for (t = stktables_list; t; t = t->next) {
3910 struct proxy *p;
3911
3912 for (p = t->proxies_list; p; p = p->next_stkt_ref) {
3913 if (t->peers.p && t->peers.p->peers_fe) {
3914 t->peers.p->peers_fe->bind_proc |= p->bind_proc;
3915 }
3916 }
3917 }
3918
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003919 if (cfg_peers) {
3920 struct peers *curpeers = cfg_peers, **last;
Willy Tarreau122541c2011-09-07 21:24:49 +02003921 struct peer *p, *pb;
3922
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003923 /* In the case the peers frontend was not initialized by a
3924 stick-table used in the configuration, set its bind_proc
3925 by default to the first process. */
3926 while (curpeers) {
William Lallemand3ef2d562020-03-24 16:42:15 +01003927 if (curpeers->peers_fe) {
3928 if (curpeers->peers_fe->bind_proc == 0)
3929 curpeers->peers_fe->bind_proc = 1;
3930 }
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003931 curpeers = curpeers->next;
3932 }
3933
3934 curpeers = cfg_peers;
Willy Tarreau1e273012015-05-01 19:15:17 +02003935 /* Remove all peers sections which don't have a valid listener,
3936 * which are not used by any table, or which are bound to more
3937 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02003938 */
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003939 last = &cfg_peers;
Willy Tarreau122541c2011-09-07 21:24:49 +02003940 while (*last) {
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003941 struct stktable *t;
Willy Tarreau122541c2011-09-07 21:24:49 +02003942 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003943
3944 if (curpeers->state == PR_STSTOPPED) {
3945 /* the "disabled" keyword was present */
3946 if (curpeers->peers_fe)
3947 stop_proxy(curpeers->peers_fe);
3948 curpeers->peers_fe = NULL;
3949 }
Frédéric Lécaille5a4fe5a2019-10-04 08:30:04 +02003950 else if (!curpeers->peers_fe || !curpeers->peers_fe->id) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003951 ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
3952 curpeers->id, localpeer);
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003953 if (curpeers->peers_fe)
3954 stop_proxy(curpeers->peers_fe);
3955 curpeers->peers_fe = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003956 }
Willy Tarreau9504dd62018-10-15 09:37:03 +02003957 else if (atleast2(curpeers->peers_fe->bind_proc)) {
Willy Tarreau1e273012015-05-01 19:15:17 +02003958 /* either it's totally stopped or too much used */
3959 if (curpeers->peers_fe->bind_proc) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003960 ha_alert("Peers section '%s': peers referenced by sections "
3961 "running in different processes (%d different ones). "
3962 "Check global.nbproc and all tables' bind-process "
3963 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02003964 cfgerr++;
3965 }
3966 stop_proxy(curpeers->peers_fe);
3967 curpeers->peers_fe = NULL;
3968 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003969 else {
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003970 /* Initializes the transport layer of the server part of all the peers belonging to
3971 * <curpeers> section if required.
3972 * Note that ->srv is used by the local peer of a new process to connect to the local peer
3973 * of an old process.
3974 */
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003975 p = curpeers->remote;
3976 while (p) {
Frédéric Lécaille355b2032019-01-11 14:06:12 +01003977 if (p->srv) {
Christopher Fauletf61f33a2020-03-27 18:55:49 +01003978 if (p->srv->use_ssl == 1 && xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
Frédéric Lécaille355b2032019-01-11 14:06:12 +01003979 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(p->srv);
3980 }
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003981 p = p->next;
3982 }
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003983 /* Configure the SSL bindings of the local peer if required. */
3984 if (!LIST_ISEMPTY(&curpeers->peers_fe->conf.bind)) {
3985 struct list *l;
3986 struct bind_conf *bind_conf;
3987
3988 l = &curpeers->peers_fe->conf.bind;
3989 bind_conf = LIST_ELEM(l->n, typeof(bind_conf), by_fe);
3990 if (bind_conf->xprt->prepare_bind_conf &&
3991 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
3992 cfgerr++;
3993 }
Frédéric Lécaille8d78fa72019-05-20 18:22:52 +02003994 if (!peers_init_sync(curpeers) || !peers_alloc_dcache(curpeers)) {
Willy Tarreaud9443442018-10-15 11:18:03 +02003995 ha_alert("Peers section '%s': out of memory, giving up on peers.\n",
3996 curpeers->id);
3997 cfgerr++;
3998 break;
3999 }
Willy Tarreau122541c2011-09-07 21:24:49 +02004000 last = &curpeers->next;
4001 continue;
4002 }
4003
Willy Tarreau77e4bd12015-05-01 20:02:17 +02004004 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02004005 p = curpeers->remote;
4006 while (p) {
4007 pb = p->next;
4008 free(p->id);
4009 free(p);
4010 p = pb;
4011 }
4012
4013 /* Destroy and unlink this curpeers section.
4014 * Note: curpeers is backed up into *last.
4015 */
4016 free(curpeers->id);
4017 curpeers = curpeers->next;
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01004018 /* Reset any refereance to this peers section in the list of stick-tables */
4019 for (t = stktables_list; t; t = t->next) {
4020 if (t->peers.p && t->peers.p == *last)
4021 t->peers.p = NULL;
4022 }
Willy Tarreau122541c2011-09-07 21:24:49 +02004023 free(*last);
4024 *last = curpeers;
4025 }
4026 }
4027
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004028 for (t = stktables_list; t; t = t->next) {
4029 if (t->proxy)
4030 continue;
4031 if (!stktable_init(t)) {
4032 ha_alert("Proxy '%s': failed to initialize stick-table.\n", t->id);
4033 cfgerr++;
4034 }
4035 }
4036
Willy Tarreau6866f3f2015-05-01 19:09:08 +02004037 /* initialize stick-tables on backend capable proxies. This must not
4038 * be done earlier because the data size may be discovered while parsing
4039 * other proxies.
4040 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01004041 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004042 if (curproxy->state == PR_STSTOPPED || !curproxy->table)
Willy Tarreau6866f3f2015-05-01 19:09:08 +02004043 continue;
4044
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004045 if (!stktable_init(curproxy->table)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004046 ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
Willy Tarreau6866f3f2015-05-01 19:09:08 +02004047 cfgerr++;
4048 }
4049 }
4050
Simon Horman0d16a402015-01-30 11:22:58 +09004051 if (mailers) {
4052 struct mailers *curmailers = mailers, **last;
4053 struct mailer *m, *mb;
4054
4055 /* Remove all mailers sections which don't have a valid listener.
4056 * This can happen when a mailers section is never referenced.
4057 */
4058 last = &mailers;
4059 while (*last) {
4060 curmailers = *last;
4061 if (curmailers->users) {
4062 last = &curmailers->next;
4063 continue;
4064 }
4065
Christopher Faulet767a84b2017-11-24 16:50:31 +01004066 ha_warning("Removing incomplete section 'mailers %s'.\n",
4067 curmailers->id);
Simon Horman0d16a402015-01-30 11:22:58 +09004068
4069 m = curmailers->mailer_list;
4070 while (m) {
4071 mb = m->next;
4072 free(m->id);
4073 free(m);
4074 m = mb;
4075 }
4076
4077 /* Destroy and unlink this curmailers section.
4078 * Note: curmailers is backed up into *last.
4079 */
4080 free(curmailers->id);
4081 curmailers = curmailers->next;
4082 free(*last);
4083 *last = curmailers;
4084 }
4085 }
4086
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02004087 /* Update server_state_file_name to backend name if backend is supposed to use
4088 * a server-state file locally defined and none has been provided */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01004089 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02004090 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
4091 curproxy->server_state_file_name == NULL)
4092 curproxy->server_state_file_name = strdup(curproxy->id);
4093 }
4094
Ben Draut054fbee2018-04-13 15:43:04 -06004095 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
4096 if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
4097 ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n",
4098 curr_resolvers->id, curr_resolvers->conf.file,
4099 curr_resolvers->conf.line);
4100 err_code |= ERR_WARN;
4101 }
4102 }
4103
William Lallemand48b4bb42017-10-23 14:36:34 +02004104 list_for_each_entry(postparser, &postparsers, list) {
4105 if (postparser->func)
4106 cfgerr += postparser->func();
4107 }
4108
Willy Tarreaubb925012009-07-23 13:36:36 +02004109 if (cfgerr > 0)
4110 err_code |= ERR_ALERT | ERR_FATAL;
4111 out:
4112 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004113}
4114
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004115/*
4116 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
4117 * parsing sessions.
4118 */
4119void cfg_register_keywords(struct cfg_kw_list *kwl)
4120{
4121 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
4122}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004123
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004124/*
4125 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
4126 */
4127void cfg_unregister_keywords(struct cfg_kw_list *kwl)
4128{
4129 LIST_DEL(&kwl->list);
4130 LIST_INIT(&kwl->list);
4131}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004132
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004133/* this function register new section in the haproxy configuration file.
4134 * <section_name> is the name of this new section and <section_parser>
4135 * is the called parser. If two section declaration have the same name,
4136 * only the first declared is used.
4137 */
4138int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +02004139 int (*section_parser)(const char *, int, char **, int),
4140 int (*post_section_parser)())
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004141{
4142 struct cfg_section *cs;
4143
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004144 list_for_each_entry(cs, &sections, list) {
4145 if (strcmp(cs->section_name, section_name) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004146 ha_alert("register section '%s': already registered.\n", section_name);
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004147 return 0;
4148 }
4149 }
4150
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004151 cs = calloc(1, sizeof(*cs));
4152 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004153 ha_alert("register section '%s': out of memory.\n", section_name);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004154 return 0;
4155 }
4156
4157 cs->section_name = section_name;
4158 cs->section_parser = section_parser;
William Lallemandd2ff56d2017-10-16 11:06:50 +02004159 cs->post_section_parser = post_section_parser;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004160
4161 LIST_ADDQ(&sections, &cs->list);
4162
4163 return 1;
4164}
4165
William Lallemand48b4bb42017-10-23 14:36:34 +02004166/* this function register a new function which will be called once the haproxy
4167 * configuration file has been parsed. It's useful to check dependencies
4168 * between sections or to resolve items once everything is parsed.
4169 */
4170int cfg_register_postparser(char *name, int (*func)())
4171{
4172 struct cfg_postparser *cp;
4173
4174 cp = calloc(1, sizeof(*cp));
4175 if (!cp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004176 ha_alert("register postparser '%s': out of memory.\n", name);
William Lallemand48b4bb42017-10-23 14:36:34 +02004177 return 0;
4178 }
4179 cp->name = name;
4180 cp->func = func;
4181
4182 LIST_ADDQ(&postparsers, &cp->list);
4183
4184 return 1;
4185}
4186
Willy Tarreaubaaee002006-06-26 02:48:02 +02004187/*
David Carlier845efb52015-09-25 11:49:18 +01004188 * free all config section entries
4189 */
4190void cfg_unregister_sections(void)
4191{
4192 struct cfg_section *cs, *ics;
4193
4194 list_for_each_entry_safe(cs, ics, &sections, list) {
4195 LIST_DEL(&cs->list);
4196 free(cs);
4197 }
4198}
4199
Christopher Faulet7110b402016-10-26 11:09:44 +02004200void cfg_backup_sections(struct list *backup_sections)
4201{
4202 struct cfg_section *cs, *ics;
4203
4204 list_for_each_entry_safe(cs, ics, &sections, list) {
4205 LIST_DEL(&cs->list);
4206 LIST_ADDQ(backup_sections, &cs->list);
4207 }
4208}
4209
4210void cfg_restore_sections(struct list *backup_sections)
4211{
4212 struct cfg_section *cs, *ics;
4213
4214 list_for_each_entry_safe(cs, ics, backup_sections, list) {
4215 LIST_DEL(&cs->list);
4216 LIST_ADDQ(&sections, &cs->list);
4217 }
4218}
4219
Willy Tarreaue6552512018-11-26 11:33:13 +01004220/* these are the config sections handled by default */
4221REGISTER_CONFIG_SECTION("listen", cfg_parse_listen, NULL);
4222REGISTER_CONFIG_SECTION("frontend", cfg_parse_listen, NULL);
4223REGISTER_CONFIG_SECTION("backend", cfg_parse_listen, NULL);
4224REGISTER_CONFIG_SECTION("defaults", cfg_parse_listen, NULL);
4225REGISTER_CONFIG_SECTION("global", cfg_parse_global, NULL);
4226REGISTER_CONFIG_SECTION("userlist", cfg_parse_users, NULL);
4227REGISTER_CONFIG_SECTION("peers", cfg_parse_peers, NULL);
4228REGISTER_CONFIG_SECTION("mailers", cfg_parse_mailers, NULL);
4229REGISTER_CONFIG_SECTION("namespace_list", cfg_parse_netns, NULL);
4230REGISTER_CONFIG_SECTION("resolvers", cfg_parse_resolvers, NULL);
Willy Tarreau659fbf02016-05-26 17:55:28 +02004231
David Carlier845efb52015-09-25 11:49:18 +01004232/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02004233 * Local variables:
4234 * c-indent-level: 8
4235 * c-basic-offset: 8
4236 * End:
4237 */