blob: 660c308c616a732d1f30739106ab8bd29d0f3047 [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 Tarreaub2551052020-06-09 09:07:15 +020038#include <haproxy/api.h>
Willy Tarreauac13aea2020-06-04 10:36:03 +020039#include <haproxy/auth.h>
Willy Tarreau49801602020-06-04 22:50:02 +020040#include <haproxy/backend.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020041#include <haproxy/capture.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020042#include <haproxy/cfgparse.h>
Willy Tarreauf1d32c42020-06-04 21:07:02 +020043#include <haproxy/channel.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020044#include <haproxy/check.h>
Willy Tarreauc13ed532020-06-02 10:22:45 +020045#include <haproxy/chunk.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020046#include <haproxy/connection.h>
Willy Tarreaueb92deb2020-06-04 10:53:16 +020047#include <haproxy/dns.h>
Willy Tarreau8d366972020-05-27 16:10:29 +020048#include <haproxy/errors.h>
Willy Tarreauc7babd82020-06-04 21:29:29 +020049#include <haproxy/filters.h>
Willy Tarreau762d7a52020-06-04 11:23:07 +020050#include <haproxy/frontend.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020051#include <haproxy/global.h>
Willy Tarreauc2b1ff02020-06-04 21:21:03 +020052#include <haproxy/http_ana.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020053#include <haproxy/http_rules.h>
Willy Tarreaufbe8da32020-06-04 14:34:27 +020054#include <haproxy/lb_chash.h>
Willy Tarreaub5fc3bf2020-06-04 14:37:38 +020055#include <haproxy/lb_fas.h>
Willy Tarreau02549412020-06-04 14:41:04 +020056#include <haproxy/lb_fwlc.h>
Willy Tarreau546ba422020-06-04 14:45:03 +020057#include <haproxy/lb_fwrr.h>
Willy Tarreau28671592020-06-04 20:22:59 +020058#include <haproxy/lb_map.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020059#include <haproxy/listener.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020060#include <haproxy/log.h>
Willy Tarreaucee013e2020-06-05 11:40:38 +020061#include <haproxy/mailers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020062#include <haproxy/namespace.h>
Willy Tarreau8efbdfb2020-06-04 11:29:21 +020063#include <haproxy/obj_type-t.h>
Willy Tarreau3c2a7c22020-06-04 18:38:21 +020064#include <haproxy/peers-t.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020065#include <haproxy/peers.h>
Willy Tarreaud0ef4392020-06-02 09:38:52 +020066#include <haproxy/pool.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020067#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020068#include <haproxy/proxy.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020069#include <haproxy/sample.h>
70#include <haproxy/server.h>
Willy Tarreau48d25b32020-06-04 18:58:52 +020071#include <haproxy/session.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020072#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020073#include <haproxy/stick_table.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020074#include <haproxy/stream.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020075#include <haproxy/task.h>
Willy Tarreau8b550af2020-06-04 17:42:48 +020076#include <haproxy/tcp_rules.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020077#include <haproxy/thread.h>
78#include <haproxy/time.h>
79#include <haproxy/tools.h>
80#include <haproxy/uri_auth-t.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020081
82
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +010083/* Used to chain configuration sections definitions. This list
84 * stores struct cfg_section
85 */
86struct list sections = LIST_HEAD_INIT(sections);
87
William Lallemand48b4bb42017-10-23 14:36:34 +020088struct list postparsers = LIST_HEAD_INIT(postparsers);
89
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010090char *cursection = NULL;
91struct proxy defproxy = { }; /* fake proxy used to assign default values on all instances */
Willy Tarreauc8d5b952019-02-27 17:25:52 +010092int cfg_maxpconn = 0; /* # of simultaneous connections per proxy (-N) */
Willy Tarreau5af24ef2009-03-15 15:23:16 +010093int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
Christopher Faulet79bdef32016-11-04 22:36:15 +010094char *cfg_scope = NULL; /* the current scope during the configuration parsing */
Willy Tarreaubaaee002006-06-26 02:48:02 +020095
Willy Tarreau5b2c3362008-07-09 19:39:06 +020096/* List head of all known configuration keywords */
Willy Tarreau36b9e222018-11-11 15:19:52 +010097struct cfg_kw_list cfg_keywords = {
Willy Tarreau5b2c3362008-07-09 19:39:06 +020098 .list = LIST_HEAD_INIT(cfg_keywords.list)
99};
100
Willy Tarreaubaaee002006-06-26 02:48:02 +0200101/*
102 * converts <str> to a list of listeners which are dynamically allocated.
103 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
104 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
105 * - <port> is a numerical port from 1 to 65535 ;
106 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
107 * This can be repeated as many times as necessary, separated by a coma.
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200108 * Function returns 1 for success or 0 if error. In case of errors, if <err> is
109 * not NULL, it must be a valid pointer to either NULL or a freeable area that
110 * will be replaced with an error message.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200111 */
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200112int 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 +0200113{
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100114 char *next, *dupstr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200115 int port, end;
116
117 next = dupstr = strdup(str);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200118
Willy Tarreaubaaee002006-06-26 02:48:02 +0200119 while (next && *next) {
William Lallemand75ea0a02017-11-15 19:02:58 +0100120 int inherited = 0;
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200121 struct sockaddr_storage *ss2;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100122 int fd = -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200123
124 str = next;
125 /* 1) look for the end of the first address */
Krzysztof Piotr Oledzki52d522b2009-01-27 16:57:08 +0100126 if ((next = strchr(str, ',')) != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200127 *next++ = 0;
128 }
129
Willy Tarreau48ef4c92017-01-06 18:32:38 +0100130 ss2 = str2sa_range(str, NULL, &port, &end, err,
Willy Tarreau72b8c1f2015-09-08 15:50:19 +0200131 curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
Willy Tarreau80958762020-09-15 10:30:39 +0200132 NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE);
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100133 if (!ss2)
134 goto fail;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200135
Willy Tarreau8b0fa8f2020-09-15 11:52:23 +0200136 if (ss2->ss_family == AF_CUST_EXISTING_FD) {
Willy Tarreau40aa0702013-03-10 23:51:38 +0100137 socklen_t addr_len;
William Lallemand75ea0a02017-11-15 19:02:58 +0100138 inherited = 1;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100139
140 /* We want to attach to an already bound fd whose number
141 * is in the addr part of ss2 when cast to sockaddr_in.
142 * Note that by definition there is a single listener.
143 * We still have to determine the address family to
144 * register the correct protocol.
145 */
146 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
147 addr_len = sizeof(*ss2);
148 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
149 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
150 goto fail;
151 }
152
153 port = end = get_host_port(ss2);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200154
155 } else if (ss2->ss_family == AF_CUST_SOCKPAIR) {
156 socklen_t addr_len;
157 inherited = 1;
158
159 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
160 addr_len = sizeof(*ss2);
161 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
162 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
163 goto fail;
164 }
165
166 ss2->ss_family = AF_CUST_SOCKPAIR; /* reassign AF_CUST_SOCKPAIR because of getsockname */
167 port = end = 0;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100168 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200169
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100170 /* OK the address looks correct */
William Lallemand75ea0a02017-11-15 19:02:58 +0100171 if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) {
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200172 memprintf(err, "%s for address '%s'.\n", *err, str);
173 goto fail;
174 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200175 } /* end while(next) */
176 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200177 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200178 fail:
179 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200180 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200181}
182
William Lallemand6e62fb62015-04-28 16:55:23 +0200183/*
Willy Tarreauece9b072016-12-21 22:41:44 +0100184 * Report an error in <msg> when there are too many arguments. This version is
185 * intended to be used by keyword parsers so that the message will be included
186 * into the general error message. The index is the current keyword in args.
187 * Return 0 if the number of argument is correct, otherwise build a message and
188 * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The
189 * message may also be null, it will simply not be produced (useful to check only).
190 * <msg> and <err_code> are only affected on error.
191 */
192int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code)
193{
194 int i;
195
196 if (!*args[index + maxarg + 1])
197 return 0;
198
199 if (msg) {
200 *msg = NULL;
201 memprintf(msg, "%s", args[0]);
202 for (i = 1; i <= index; i++)
203 memprintf(msg, "%s %s", *msg, args[i]);
204
205 memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]);
206 }
207 if (err_code)
208 *err_code |= ERR_ALERT | ERR_FATAL;
209
210 return 1;
211}
212
213/*
214 * same as too_many_args_idx with a 0 index
215 */
216int too_many_args(int maxarg, char **args, char **msg, int *err_code)
217{
218 return too_many_args_idx(maxarg, 0, args, msg, err_code);
219}
220
221/*
William Lallemand6e62fb62015-04-28 16:55:23 +0200222 * Report a fatal Alert when there is too much arguments
223 * The index is the current keyword in args
224 * Return 0 if the number of argument is correct, otherwise emit an alert and return 1
225 * Fill err_code with an ERR_ALERT and an ERR_FATAL
226 */
227int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code)
228{
229 char *kw = NULL;
230 int i;
231
232 if (!*args[index + maxarg + 1])
233 return 0;
234
235 memprintf(&kw, "%s", args[0]);
236 for (i = 1; i <= index; i++) {
237 memprintf(&kw, "%s %s", kw, args[i]);
238 }
239
Christopher Faulet767a84b2017-11-24 16:50:31 +0100240 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 +0200241 free(kw);
242 *err_code |= ERR_ALERT | ERR_FATAL;
243 return 1;
244}
245
246/*
247 * same as alertif_too_many_args_idx with a 0 index
248 */
249int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code)
250{
251 return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code);
252}
253
Willy Tarreau61d18892009-03-31 10:49:21 +0200254
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100255/* Report it if a request ACL condition uses some keywords that are incompatible
256 * with the place where the ACL is used. It returns either 0 or ERR_WARN so that
257 * its result can be or'ed with err_code. Note that <cond> may be NULL and then
258 * will be ignored.
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100259 */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100260int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100261{
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100262 const struct acl *acl;
Willy Tarreau93fddf12013-03-31 22:59:32 +0200263 const char *kw;
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100264
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100265 if (!cond)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100266 return 0;
267
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100268 acl = acl_cond_conflicts(cond, where);
269 if (acl) {
270 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100271 ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n",
272 file, line, acl->name, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100273 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100274 ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
275 file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100276 return ERR_WARN;
277 }
278 if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100279 return 0;
280
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100281 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100282 ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
283 file, line, acl->name, kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100284 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100285 ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
286 file, line, kw, sample_ckp_names(where));
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100287 return ERR_WARN;
288}
289
Christopher Faulet62519022017-10-16 15:49:32 +0200290/* Parse a string representing a process number or a set of processes. It must
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100291 * be "all", "odd", "even", a number between 1 and <max> or a range with
Christopher Faulet5ab51772017-11-22 11:21:58 +0100292 * two such numbers delimited by a dash ('-'). On success, it returns
293 * 0. otherwise it returns 1 with an error message in <err>.
Christopher Faulet62519022017-10-16 15:49:32 +0200294 *
295 * Note: this function can also be used to parse a thread number or a set of
296 * threads.
297 */
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100298int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200299{
Christopher Faulet26028f62017-11-22 15:01:51 +0100300 if (autoinc) {
301 *autoinc = 0;
302 if (strncmp(arg, "auto:", 5) == 0) {
303 arg += 5;
304 *autoinc = 1;
305 }
306 }
307
Christopher Faulet62519022017-10-16 15:49:32 +0200308 if (strcmp(arg, "all") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100309 *proc |= ~0UL;
Christopher Faulet62519022017-10-16 15:49:32 +0200310 else if (strcmp(arg, "odd") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100311 *proc |= ~0UL/3UL; /* 0x555....555 */
Christopher Faulet62519022017-10-16 15:49:32 +0200312 else if (strcmp(arg, "even") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100313 *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Christopher Faulet62519022017-10-16 15:49:32 +0200314 else {
Christopher Faulet18cca782019-02-07 16:29:41 +0100315 const char *p, *dash = NULL;
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100316 unsigned int low, high;
317
Christopher Faulet18cca782019-02-07 16:29:41 +0100318 for (p = arg; *p; p++) {
319 if (*p == '-' && !dash)
320 dash = p;
Willy Tarreau90807112020-02-25 08:16:33 +0100321 else if (!isdigit((unsigned char)*p)) {
Christopher Faulet18cca782019-02-07 16:29:41 +0100322 memprintf(err, "'%s' is not a valid number/range.", arg);
323 return -1;
324 }
Christopher Faulet5ab51772017-11-22 11:21:58 +0100325 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100326
327 low = high = str2uic(arg);
Christopher Faulet18cca782019-02-07 16:29:41 +0100328 if (dash)
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100329 high = ((!*(dash+1)) ? max : str2uic(dash + 1));
Christopher Fauletff4121f2017-11-22 16:38:49 +0100330
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100331 if (high < low) {
332 unsigned int swap = low;
333 low = high;
334 high = swap;
335 }
336
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100337 if (low < 1 || low > max || high > max) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100338 memprintf(err, "'%s' is not a valid number/range."
339 " It supports numbers from 1 to %d.\n",
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100340 arg, max);
Christopher Faulet5ab51772017-11-22 11:21:58 +0100341 return 1;
342 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100343
344 for (;low <= high; low++)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100345 *proc |= 1UL << (low-1);
Christopher Faulet62519022017-10-16 15:49:32 +0200346 }
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100347 *proc &= ~0UL >> (LONGBITS - max);
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100348
Christopher Faulet5ab51772017-11-22 11:21:58 +0100349 return 0;
Christopher Faulet62519022017-10-16 15:49:32 +0200350}
351
David Carlier7e351ee2017-12-01 09:14:02 +0000352#ifdef USE_CPU_AFFINITY
Christopher Faulet62519022017-10-16 15:49:32 +0200353/* Parse cpu sets. Each CPU set is either a unique number between 0 and
354 * <LONGBITS> or a range with two such numbers delimited by a dash
355 * ('-'). Multiple CPU numbers or ranges may be specified. On success, it
356 * returns 0. otherwise it returns 1 with an error message in <err>.
357 */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100358unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200359{
360 int cur_arg = 0;
361
362 *cpu_set = 0;
363 while (*args[cur_arg]) {
364 char *dash;
365 unsigned int low, high;
366
Willy Tarreau90807112020-02-25 08:16:33 +0100367 if (!isdigit((unsigned char)*args[cur_arg])) {
Christopher Faulet62519022017-10-16 15:49:32 +0200368 memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]);
369 return -1;
370 }
371
372 low = high = str2uic(args[cur_arg]);
373 if ((dash = strchr(args[cur_arg], '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100374 high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1));
Christopher Faulet62519022017-10-16 15:49:32 +0200375
376 if (high < low) {
377 unsigned int swap = low;
378 low = high;
379 high = swap;
380 }
381
382 if (high >= LONGBITS) {
383 memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1);
384 return 1;
385 }
386
387 while (low <= high)
388 *cpu_set |= 1UL << low++;
389
390 cur_arg++;
391 }
392 return 0;
393}
David Carlier7e351ee2017-12-01 09:14:02 +0000394#endif
395
Willy Tarreau915e1eb2009-06-22 15:48:36 +0200396void init_default_instance()
Willy Tarreaubaaee002006-06-26 02:48:02 +0200397{
Willy Tarreau97cb7802010-01-03 20:23:58 +0100398 init_new_proxy(&defproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200399 defproxy.mode = PR_MODE_TCP;
400 defproxy.state = PR_STNEW;
401 defproxy.maxconn = cfg_maxpconn;
402 defproxy.conn_retries = CONN_RETRIES;
Joseph Lynch726ab712015-05-11 23:25:34 -0700403 defproxy.redispatch_after = 0;
Olivier Houchard86006a52018-12-14 19:37:49 +0100404 defproxy.options = PR_O_REUSE_SAFE;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100405 defproxy.max_out_conns = MAX_SRV_LIST;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100406
Simon Horman66183002013-02-23 10:16:43 +0900407 defproxy.defsrv.check.inter = DEF_CHKINTR;
408 defproxy.defsrv.check.fastinter = 0;
409 defproxy.defsrv.check.downinter = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900410 defproxy.defsrv.agent.inter = DEF_CHKINTR;
411 defproxy.defsrv.agent.fastinter = 0;
412 defproxy.defsrv.agent.downinter = 0;
Simon Horman58c32972013-11-25 10:46:38 +0900413 defproxy.defsrv.check.rise = DEF_RISETIME;
414 defproxy.defsrv.check.fall = DEF_FALLTIME;
415 defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
416 defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200417 defproxy.defsrv.check.port = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900418 defproxy.defsrv.agent.port = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100419 defproxy.defsrv.maxqueue = 0;
420 defproxy.defsrv.minconn = 0;
421 defproxy.defsrv.maxconn = 0;
Willy Tarreau9c538e02019-01-23 10:21:49 +0100422 defproxy.defsrv.max_reuse = -1;
Olivier Houchard006e3102018-12-10 18:30:32 +0100423 defproxy.defsrv.max_idle_conns = -1;
Willy Tarreau975b1552019-06-06 16:25:55 +0200424 defproxy.defsrv.pool_purge_delay = 5000;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100425 defproxy.defsrv.slowstart = 0;
426 defproxy.defsrv.onerror = DEF_HANA_ONERR;
427 defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
428 defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
Simon Horman64e34162015-02-06 11:11:57 +0900429
430 defproxy.email_alert.level = LOG_ALERT;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +0200431 defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200432}
433
Frédéric Lécaille18251032019-01-11 11:07:15 +0100434/* Allocate and initialize the frontend of a "peers" section found in
435 * file <file> at line <linenum> with <id> as ID.
436 * Return 0 if succeeded, -1 if not.
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200437 * Note that this function may be called from "default-server"
438 * or "peer" lines.
Frédéric Lécaille18251032019-01-11 11:07:15 +0100439 */
440static int init_peers_frontend(const char *file, int linenum,
441 const char *id, struct peers *peers)
442{
443 struct proxy *p;
444
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200445 if (peers->peers_fe) {
446 p = peers->peers_fe;
447 goto out;
448 }
Frédéric Lécaille9492c4e2019-01-11 11:47:12 +0100449
Frédéric Lécaille18251032019-01-11 11:07:15 +0100450 p = calloc(1, sizeof *p);
451 if (!p) {
452 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
453 return -1;
454 }
455
456 init_new_proxy(p);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200457 peers_setup_frontend(p);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100458 p->parent = peers;
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200459 /* Finally store this frontend. */
460 peers->peers_fe = p;
461
462 out:
463 if (id && !p->id)
464 p->id = strdup(id);
Frédéric Lécaille1055e682018-04-26 14:35:21 +0200465 free(p->conf.file);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100466 p->conf.args.file = p->conf.file = strdup(file);
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100467 if (linenum != -1)
468 p->conf.args.line = p->conf.line = linenum;
Frédéric Lécaille18251032019-01-11 11:07:15 +0100469
470 return 0;
471}
Willy Tarreauade5ec42010-01-28 19:33:49 +0100472
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100473/* Only change ->file, ->line and ->arg struct bind_conf member values
474 * if already present.
475 */
476static struct bind_conf *bind_conf_uniq_alloc(struct proxy *p,
477 const char *file, int line,
478 const char *arg, struct xprt_ops *xprt)
479{
480 struct bind_conf *bind_conf;
481
482 if (!LIST_ISEMPTY(&p->conf.bind)) {
483 bind_conf = LIST_ELEM((&p->conf.bind)->n, typeof(bind_conf), by_fe);
484 free(bind_conf->file);
485 bind_conf->file = strdup(file);
486 bind_conf->line = line;
487 if (arg) {
488 free(bind_conf->arg);
489 bind_conf->arg = strdup(arg);
490 }
491 }
492 else {
493 bind_conf = bind_conf_alloc(p, file, line, arg, xprt);
494 }
495
496 return bind_conf;
497}
498
499/*
500 * Allocate a new struct peer parsed at line <linenum> in file <file>
501 * to be added to <peers>.
502 * Returns the new allocated structure if succeeded, NULL if not.
503 */
504static struct peer *cfg_peers_add_peer(struct peers *peers,
505 const char *file, int linenum,
506 const char *id, int local)
507{
508 struct peer *p;
509
510 p = calloc(1, sizeof *p);
511 if (!p) {
512 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
513 return NULL;
514 }
515
516 /* the peers are linked backwards first */
517 peers->count++;
518 p->next = peers->remote;
519 peers->remote = p;
520 p->conf.file = strdup(file);
521 p->conf.line = linenum;
522 p->last_change = now.tv_sec;
523 p->xprt = xprt_get(XPRT_RAW);
524 p->sock_init_arg = NULL;
525 HA_SPIN_INIT(&p->lock);
526 if (id)
527 p->id = strdup(id);
528 if (local) {
529 p->local = 1;
530 peers->local = p;
531 }
532
533 return p;
534}
535
Willy Tarreaubaaee002006-06-26 02:48:02 +0200536/*
William Lallemand51097192015-04-14 16:35:22 +0200537 * Parse a line in a <listen>, <frontend> or <backend> section.
Willy Tarreau93893792009-07-23 13:19:11 +0200538 * Returns the error code, 0 if OK, or any combination of :
539 * - ERR_ABORT: must abort ASAP
540 * - ERR_FATAL: we can continue parsing but not start the service
541 * - ERR_WARN: a warning has been emitted
542 * - ERR_ALERT: an alert has been emitted
543 * Only the two first ones can stop processing, the two others are just
544 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200545 */
Emeric Brun32da3c42010-09-23 18:39:19 +0200546int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
547{
548 static struct peers *curpeers = NULL;
549 struct peer *newpeer = NULL;
550 const char *err;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200551 struct bind_conf *bind_conf;
552 struct listener *l;
Emeric Brun32da3c42010-09-23 18:39:19 +0200553 int err_code = 0;
Willy Tarreau902636f2013-03-10 19:44:48 +0100554 char *errmsg = NULL;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100555 static int bind_line, peer_line;
556
557 if (strcmp(args[0], "bind") == 0 || strcmp(args[0], "default-bind") == 0) {
558 int cur_arg;
559 static int kws_dumped;
560 struct bind_conf *bind_conf;
561 struct bind_kw *kw;
Emeric Brun32da3c42010-09-23 18:39:19 +0200562
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100563 cur_arg = 1;
564
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200565 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
566 err_code |= ERR_ALERT | ERR_ABORT;
567 goto out;
568 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100569
570 bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum,
571 NULL, xprt_get(XPRT_RAW));
572 if (*args[0] == 'b') {
573 struct listener *l;
574
575 if (peer_line) {
576 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
577 err_code |= ERR_ALERT | ERR_FATAL;
578 goto out;
579 }
580
581 if (!str2listener(args[1], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
582 if (errmsg && *errmsg) {
583 indent_msg(&errmsg, 2);
584 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
585 }
586 else
587 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
588 file, linenum, args[0], args[1], args[2]);
589 err_code |= ERR_FATAL;
590 goto out;
591 }
592 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
593 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100594 l->accept = session_accept_fd;
595 l->analysers |= curpeers->peers_fe->fe_req_ana;
596 l->default_target = curpeers->peers_fe->default_target;
597 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100598 global.maxsock++; /* for the listening socket */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100599
600 bind_line = 1;
601 if (cfg_peers->local) {
602 newpeer = cfg_peers->local;
603 }
604 else {
605 /* This peer is local.
606 * Note that we do not set the peer ID. This latter is initialized
607 * when parsing "peer" or "server" line.
608 */
609 newpeer = cfg_peers_add_peer(curpeers, file, linenum, NULL, 1);
610 if (!newpeer) {
611 err_code |= ERR_ALERT | ERR_ABORT;
612 goto out;
613 }
614 }
Willy Tarreau37159062020-08-27 07:48:42 +0200615 newpeer->addr = l->rx.addr;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100616 newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
617 cur_arg++;
618 }
619
620 while (*args[cur_arg] && (kw = bind_find_kw(args[cur_arg]))) {
621 int ret;
622
623 ret = kw->parse(args, cur_arg, curpeers->peers_fe, bind_conf, &errmsg);
624 err_code |= ret;
625 if (ret) {
626 if (errmsg && *errmsg) {
627 indent_msg(&errmsg, 2);
628 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
629 }
630 else
631 ha_alert("parsing [%s:%d]: error encountered while processing '%s'\n",
632 file, linenum, args[cur_arg]);
633 if (ret & ERR_FATAL)
634 goto out;
635 }
636 cur_arg += 1 + kw->skip;
637 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100638 if (*args[cur_arg] != 0) {
Tim Duesterhus04bcaa12019-05-12 22:54:50 +0200639 char *kws = NULL;
640
641 if (!kws_dumped) {
642 kws_dumped = 1;
643 bind_dump_kws(&kws);
644 indent_msg(&kws, 4);
645 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100646 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section.%s%s\n",
647 file, linenum, args[cur_arg], cursection,
648 kws ? " Registered keywords :" : "", kws ? kws: "");
649 free(kws);
650 err_code |= ERR_ALERT | ERR_FATAL;
651 goto out;
652 }
653 }
654 else if (strcmp(args[0], "default-server") == 0) {
655 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
656 err_code |= ERR_ALERT | ERR_ABORT;
657 goto out;
658 }
Emeric Brund3db3842020-07-21 16:54:36 +0200659 err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, 0, 1, 1);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200660 }
Frédéric Lécailleb6f759b2019-11-05 09:57:45 +0100661 else if (strcmp(args[0], "log") == 0) {
662 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
663 err_code |= ERR_ALERT | ERR_ABORT;
664 goto out;
665 }
666 if (!parse_logsrv(args, &curpeers->peers_fe->logsrvs, (kwm == KWM_NO), &errmsg)) {
667 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
668 err_code |= ERR_ALERT | ERR_FATAL;
669 goto out;
670 }
671 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200672 else if (strcmp(args[0], "peers") == 0) { /* new peers section */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100673 /* Initialize these static variables when entering a new "peers" section*/
674 bind_line = peer_line = 0;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100675 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100676 ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum);
Willy Tarreau54984722014-02-16 08:20:13 +0100677 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100678 goto out;
679 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200680
William Lallemand6e62fb62015-04-28 16:55:23 +0200681 if (alertif_too_many_args(1, file, linenum, args, &err_code))
682 goto out;
683
Emeric Brun32da3c42010-09-23 18:39:19 +0200684 err = invalid_char(args[1]);
685 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100686 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
687 file, linenum, *err, args[0], args[1]);
Willy Tarreau54984722014-02-16 08:20:13 +0100688 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100689 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200690 }
691
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200692 for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +0200693 /*
694 * If there are two proxies with the same name only following
695 * combinations are allowed:
696 */
697 if (strcmp(curpeers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100698 ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n",
699 file, linenum, args[1], curpeers->conf.file, curpeers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +0200700 err_code |= ERR_ALERT | ERR_FATAL;
Emeric Brun32da3c42010-09-23 18:39:19 +0200701 }
702 }
703
Vincent Bernat02779b62016-04-03 13:48:43 +0200704 if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100705 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +0200706 err_code |= ERR_ALERT | ERR_ABORT;
707 goto out;
708 }
709
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200710 curpeers->next = cfg_peers;
711 cfg_peers = curpeers;
Willy Tarreau8113a5d2012-10-04 08:01:43 +0200712 curpeers->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +0200713 curpeers->conf.line = linenum;
714 curpeers->last_change = now.tv_sec;
715 curpeers->id = strdup(args[1]);
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200716 curpeers->state = PR_STNEW;
Emeric Brun32da3c42010-09-23 18:39:19 +0200717 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200718 else if (strcmp(args[0], "peer") == 0 ||
719 strcmp(args[0], "server") == 0) { /* peer or server definition */
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100720 int local_peer, peer;
Emeric Brun32da3c42010-09-23 18:39:19 +0200721
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100722 peer = *args[0] == 'p';
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100723 local_peer = !strcmp(args[1], localpeer);
724 /* The local peer may have already partially been parsed on a "bind" line. */
725 if (*args[0] == 'p') {
726 if (bind_line) {
727 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
728 err_code |= ERR_ALERT | ERR_FATAL;
729 goto out;
730 }
731 peer_line = 1;
732 }
733 if (cfg_peers->local && !cfg_peers->local->id && local_peer) {
734 /* The local peer has already been initialized on a "bind" line.
735 * Let's use it and store its ID.
736 */
737 newpeer = cfg_peers->local;
738 newpeer->id = strdup(localpeer);
739 }
740 else {
741 if (local_peer && cfg_peers->local) {
742 ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d. %s\n",
743 file, linenum, args[0], args[1],
744 curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line, cfg_peers->local->id);
745 err_code |= ERR_FATAL;
746 goto out;
747 }
748 newpeer = cfg_peers_add_peer(curpeers, file, linenum, args[1], local_peer);
749 if (!newpeer) {
750 err_code |= ERR_ALERT | ERR_ABORT;
751 goto out;
752 }
753 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200754
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100755 /* Line number and peer ID are updated only if this peer is the local one. */
756 if (init_peers_frontend(file,
757 newpeer->local ? linenum: -1,
758 newpeer->local ? newpeer->id : NULL,
759 curpeers) != 0) {
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200760 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreaub36487e2013-03-10 18:37:42 +0100761 goto out;
762 }
Willy Tarreau2aa38802013-02-20 19:20:59 +0100763
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100764 /* This initializes curpeer->peers->peers_fe->srv.
765 * The server address is parsed only if we are parsing a "peer" line,
766 * or if we are parsing a "server" line and the current peer is not the local one.
767 */
Emeric Brund3db3842020-07-21 16:54:36 +0200768 err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, peer || !local_peer, 1, 1);
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200769 if (!curpeers->peers_fe->srv) {
770 /* Remove the newly allocated peer. */
771 if (newpeer != curpeers->local) {
772 struct peer *p;
773
774 p = curpeers->remote;
775 curpeers->remote = curpeers->remote->next;
776 free(p->id);
777 free(p);
778 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200779 goto out;
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200780 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200781
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100782 /* If the peer address has just been parsed, let's copy it to <newpeer>
783 * and initializes ->proto.
784 */
785 if (peer || !local_peer) {
786 newpeer->addr = curpeers->peers_fe->srv->addr;
787 newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
788 }
789
Willy Tarreaua261e9b2016-12-22 20:44:00 +0100790 newpeer->xprt = xprt_get(XPRT_RAW);
Willy Tarreaud02394b2012-05-11 18:32:18 +0200791 newpeer->sock_init_arg = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100792 HA_SPIN_INIT(&newpeer->lock);
Willy Tarreau26d8c592012-05-07 18:12:14 +0200793
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100794 newpeer->srv = curpeers->peers_fe->srv;
795 if (!newpeer->local)
Frédéric Lécaille6617e762018-04-25 15:13:38 +0200796 goto out;
797
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100798 /* The lines above are reserved to "peer" lines. */
799 if (*args[0] == 's')
Frédéric Lécaille4ba51982018-04-25 15:32:18 +0200800 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200801
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100802 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 +0100803
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100804 if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
805 if (errmsg && *errmsg) {
806 indent_msg(&errmsg, 2);
807 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 +0100808 }
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100809 else
810 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
811 file, linenum, args[0], args[1], args[2]);
812 err_code |= ERR_FATAL;
813 goto out;
814 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100815
816 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
817 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100818 l->accept = session_accept_fd;
819 l->analysers |= curpeers->peers_fe->fe_req_ana;
820 l->default_target = curpeers->peers_fe->default_target;
821 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100822 global.maxsock++; /* for the listening socket */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100823 }
824 else if (!strcmp(args[0], "table")) {
825 struct stktable *t, *other;
826 char *id;
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100827 size_t prefix_len;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100828
829 /* Line number and peer ID are updated only if this peer is the local one. */
830 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
831 err_code |= ERR_ALERT | ERR_ABORT;
832 goto out;
833 }
834
835 other = stktable_find_by_name(args[1]);
836 if (other) {
837 ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
838 file, linenum, args[1],
839 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
840 other->proxy ? other->id : other->peers.p->id,
841 other->conf.file, other->conf.line);
842 err_code |= ERR_ALERT | ERR_FATAL;
843 goto out;
844 }
845
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100846 /* Build the stick-table name, concatenating the "peers" section name
847 * followed by a '/' character and the table name argument.
848 */
849 chunk_reset(&trash);
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100850 if (!chunk_strcpy(&trash, curpeers->id)) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100851 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
852 file, linenum, args[0], args[1]);
853 err_code |= ERR_ALERT | ERR_FATAL;
854 goto out;
855 }
856
857 prefix_len = trash.data;
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100858 if (!chunk_memcat(&trash, "/", 1) || !chunk_strcat(&trash, args[1])) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100859 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
860 file, linenum, args[0], args[1]);
861 err_code |= ERR_ALERT | ERR_FATAL;
862 goto out;
863 }
864
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100865 t = calloc(1, sizeof *t);
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100866 id = strdup(trash.area);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100867 if (!t || !id) {
868 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
869 file, linenum, args[0], args[1]);
870 err_code |= ERR_ALERT | ERR_FATAL;
871 goto out;
872 }
873
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100874 err_code |= parse_stick_table(file, linenum, args, t, id, id + prefix_len, curpeers);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100875 if (err_code & ERR_FATAL)
876 goto out;
877
878 stktable_store_name(t);
879 t->next = stktables_list;
880 stktables_list = t;
881 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200882 else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
883 curpeers->state = PR_STSTOPPED;
884 }
885 else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
886 curpeers->state = PR_STNEW;
887 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200888 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100889 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Emeric Brun32da3c42010-09-23 18:39:19 +0200890 err_code |= ERR_ALERT | ERR_FATAL;
891 goto out;
892 }
893
894out:
Willy Tarreau902636f2013-03-10 19:44:48 +0100895 free(errmsg);
Emeric Brun32da3c42010-09-23 18:39:19 +0200896 return err_code;
897}
898
Baptiste Assmann325137d2015-04-13 23:40:55 +0200899/*
900 * Parse a <resolvers> section.
901 * Returns the error code, 0 if OK, or any combination of :
902 * - ERR_ABORT: must abort ASAP
903 * - ERR_FATAL: we can continue parsing but not start the service
904 * - ERR_WARN: a warning has been emitted
905 * - ERR_ALERT: an alert has been emitted
906 * Only the two first ones can stop processing, the two others are just
907 * indicators.
908 */
909int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
910{
911 static struct dns_resolvers *curr_resolvers = NULL;
912 struct dns_nameserver *newnameserver = NULL;
913 const char *err;
914 int err_code = 0;
915 char *errmsg = NULL;
916
917 if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */
918 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100919 ha_alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200920 err_code |= ERR_ALERT | ERR_ABORT;
921 goto out;
922 }
923
924 err = invalid_char(args[1]);
925 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100926 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
927 file, linenum, *err, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200928 err_code |= ERR_ALERT | ERR_ABORT;
929 goto out;
930 }
931
932 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
933 /* Error if two resolvers owns the same name */
934 if (strcmp(curr_resolvers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100935 ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n",
936 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200937 err_code |= ERR_ALERT | ERR_ABORT;
938 }
939 }
940
Vincent Bernat02779b62016-04-03 13:48:43 +0200941 if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100942 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200943 err_code |= ERR_ALERT | ERR_ABORT;
944 goto out;
945 }
946
947 /* default values */
948 LIST_ADDQ(&dns_resolvers, &curr_resolvers->list);
949 curr_resolvers->conf.file = strdup(file);
950 curr_resolvers->conf.line = linenum;
951 curr_resolvers->id = strdup(args[1]);
952 curr_resolvers->query_ids = EB_ROOT;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +0200953 /* default maximum response size */
954 curr_resolvers->accepted_payload_size = 512;
Baptiste Assmann987e16d2016-11-02 22:23:31 +0100955 /* default hold period for nx, other, refuse and timeout is 30s */
956 curr_resolvers->hold.nx = 30000;
957 curr_resolvers->hold.other = 30000;
958 curr_resolvers->hold.refused = 30000;
959 curr_resolvers->hold.timeout = 30000;
Baptiste Assmann686408b2017-08-18 10:15:42 +0200960 curr_resolvers->hold.obsolete = 0;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200961 /* default hold period for valid is 10s */
Baptiste Assmann4c5490a2015-07-14 21:42:49 +0200962 curr_resolvers->hold.valid = 10000;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200963 curr_resolvers->timeout.resolve = 1000;
964 curr_resolvers->timeout.retry = 1000;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200965 curr_resolvers->resolve_retries = 3;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200966 curr_resolvers->nb_nameservers = 0;
967 LIST_INIT(&curr_resolvers->nameservers);
968 LIST_INIT(&curr_resolvers->resolutions.curr);
969 LIST_INIT(&curr_resolvers->resolutions.wait);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100970 HA_SPIN_INIT(&curr_resolvers->lock);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200971 }
972 else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
973 struct sockaddr_storage *sk;
974 int port1, port2;
975 struct protocol *proto;
976
977 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100978 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
979 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200980 err_code |= ERR_ALERT | ERR_FATAL;
981 goto out;
982 }
983
984 err = invalid_char(args[1]);
985 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100986 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
987 file, linenum, *err, args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200988 err_code |= ERR_ALERT | ERR_FATAL;
989 goto out;
990 }
991
Christopher Faulet67957bd2017-09-27 11:00:59 +0200992 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
Baptiste Assmanna315c552015-11-02 22:55:49 +0100993 /* Error if two resolvers owns the same name */
994 if (strcmp(newnameserver->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100995 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 -0600996 file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line);
Baptiste Assmanna315c552015-11-02 22:55:49 +0100997 err_code |= ERR_ALERT | ERR_FATAL;
998 }
999 }
1000
Vincent Bernat02779b62016-04-03 13:48:43 +02001001 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001002 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001003 err_code |= ERR_ALERT | ERR_ABORT;
1004 goto out;
1005 }
1006
1007 /* the nameservers are linked backward first */
Christopher Faulet67957bd2017-09-27 11:00:59 +02001008 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001009 newnameserver->resolvers = curr_resolvers;
1010 newnameserver->conf.file = strdup(file);
1011 newnameserver->conf.line = linenum;
1012 newnameserver->id = strdup(args[1]);
1013
Willy Tarreau80958762020-09-15 10:30:39 +02001014 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001015 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001016 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001017 err_code |= ERR_ALERT | ERR_FATAL;
1018 goto out;
1019 }
1020
Willy Tarreaue42d87f2020-09-16 20:04:17 +02001021 /* handle nicely the case where "udp@" is forced */
1022 if (sk->ss_family == AF_CUST_UDP4)
1023 sk->ss_family = AF_INET;
1024 else if (sk->ss_family == AF_CUST_UDP6)
1025 sk->ss_family = AF_INET6;
1026
Baptiste Assmann325137d2015-04-13 23:40:55 +02001027 proto = protocol_by_family(sk->ss_family);
Willy Tarreaue42d87f2020-09-16 20:04:17 +02001028 if (!proto) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001029 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
Baptiste Assmann325137d2015-04-13 23:40:55 +02001030 file, linenum, args[0], args[1]);
1031 err_code |= ERR_ALERT | ERR_FATAL;
1032 goto out;
1033 }
1034
Baptiste Assmann325137d2015-04-13 23:40:55 +02001035 newnameserver->addr = *sk;
1036 }
Ben Draut44e609b2018-05-29 15:40:08 -06001037 else if (strcmp(args[0], "parse-resolv-conf") == 0) {
1038 const char *whitespace = "\r\n\t ";
1039 char *resolv_line = NULL;
1040 int resolv_linenum = 0;
1041 FILE *f = NULL;
1042 char *address = NULL;
1043 struct sockaddr_storage *sk = NULL;
1044 struct protocol *proto;
1045 int duplicate_name = 0;
1046
1047 if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) {
1048 ha_alert("parsing [%s:%d] : out of memory.\n",
1049 file, linenum);
1050 err_code |= ERR_ALERT | ERR_FATAL;
1051 goto resolv_out;
1052 }
1053
1054 if ((f = fopen("/etc/resolv.conf", "r")) == NULL) {
1055 ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n",
1056 file, linenum);
1057 err_code |= ERR_ALERT | ERR_FATAL;
1058 goto resolv_out;
1059 }
1060
1061 sk = calloc(1, sizeof(*sk));
1062 if (sk == NULL) {
1063 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n",
1064 resolv_linenum);
1065 err_code |= ERR_ALERT | ERR_FATAL;
1066 goto resolv_out;
1067 }
1068
1069 while (fgets(resolv_line, LINESIZE, f) != NULL) {
1070 resolv_linenum++;
1071 if (strncmp(resolv_line, "nameserver", 10) != 0)
1072 continue;
1073
1074 address = strtok(resolv_line + 10, whitespace);
1075 if (address == resolv_line + 10)
1076 continue;
1077
1078 if (address == NULL) {
1079 ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n",
1080 resolv_linenum);
1081 err_code |= ERR_WARN;
1082 continue;
1083 }
1084
1085 duplicate_name = 0;
1086 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
1087 if (strcmp(newnameserver->id, address) == 0) {
1088 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",
1089 resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line);
1090 err_code |= ERR_WARN;
1091 duplicate_name = 1;
1092 }
1093 }
1094
1095 if (duplicate_name)
1096 continue;
1097
1098 memset(sk, 0, sizeof(*sk));
Willy Tarreau78675252020-05-28 18:07:10 +02001099 if (!str2ip2(address, sk, 1)) {
1100 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 -06001101 resolv_linenum, address);
1102 err_code |= ERR_WARN;
1103 continue;
1104 }
1105
1106 set_host_port(sk, 53);
1107
1108 proto = protocol_by_family(sk->ss_family);
1109 if (!proto || !proto->connect) {
1110 ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n",
1111 resolv_linenum, address);
1112 err_code |= ERR_WARN;
1113 continue;
1114 }
1115
1116 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
1117 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1118 err_code |= ERR_ALERT | ERR_FATAL;
1119 goto resolv_out;
1120 }
1121
1122 newnameserver->conf.file = strdup("/etc/resolv.conf");
1123 if (newnameserver->conf.file == NULL) {
1124 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1125 err_code |= ERR_ALERT | ERR_FATAL;
1126 goto resolv_out;
1127 }
1128
1129 newnameserver->id = strdup(address);
1130 if (newnameserver->id == NULL) {
1131 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1132 err_code |= ERR_ALERT | ERR_FATAL;
1133 goto resolv_out;
1134 }
1135
1136 newnameserver->resolvers = curr_resolvers;
1137 newnameserver->conf.line = resolv_linenum;
1138 newnameserver->addr = *sk;
1139
1140 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
1141 }
1142
1143resolv_out:
1144 free(sk);
1145 free(resolv_line);
1146 if (f != NULL)
1147 fclose(f);
1148 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001149 else if (strcmp(args[0], "hold") == 0) { /* hold periods */
1150 const char *res;
1151 unsigned int time;
1152
1153 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001154 ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n",
1155 file, linenum, args[0]);
1156 ha_alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n");
Baptiste Assmann325137d2015-04-13 23:40:55 +02001157 err_code |= ERR_ALERT | ERR_FATAL;
1158 goto out;
1159 }
1160 res = parse_time_err(args[2], &time, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001161 if (res == PARSE_TIME_OVER) {
1162 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1163 file, linenum, args[1], args[0]);
1164 err_code |= ERR_ALERT | ERR_FATAL;
1165 goto out;
1166 }
1167 else if (res == PARSE_TIME_UNDER) {
1168 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1169 file, linenum, args[1], args[0]);
1170 err_code |= ERR_ALERT | ERR_FATAL;
1171 goto out;
1172 }
1173 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001174 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
1175 file, linenum, *res, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001176 err_code |= ERR_ALERT | ERR_FATAL;
1177 goto out;
1178 }
Baptiste Assmann987e16d2016-11-02 22:23:31 +01001179 if (strcmp(args[1], "nx") == 0)
1180 curr_resolvers->hold.nx = time;
1181 else if (strcmp(args[1], "other") == 0)
1182 curr_resolvers->hold.other = time;
1183 else if (strcmp(args[1], "refused") == 0)
1184 curr_resolvers->hold.refused = time;
1185 else if (strcmp(args[1], "timeout") == 0)
1186 curr_resolvers->hold.timeout = time;
1187 else if (strcmp(args[1], "valid") == 0)
Baptiste Assmann325137d2015-04-13 23:40:55 +02001188 curr_resolvers->hold.valid = time;
Olivier Houcharda8c6db82017-07-06 18:46:47 +02001189 else if (strcmp(args[1], "obsolete") == 0)
1190 curr_resolvers->hold.obsolete = time;
Baptiste Assmann325137d2015-04-13 23:40:55 +02001191 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001192 ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n",
1193 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001194 err_code |= ERR_ALERT | ERR_FATAL;
1195 goto out;
1196 }
1197
1198 }
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001199 else if (strcmp(args[0], "accepted_payload_size") == 0) {
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001200 int i = 0;
1201
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001202 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001203 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1204 file, linenum, args[0]);
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001205 err_code |= ERR_ALERT | ERR_FATAL;
1206 goto out;
1207 }
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001208
1209 i = atoi(args[1]);
Willy Tarreau0c219be2017-08-22 12:01:26 +02001210 if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001211 ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n",
1212 file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]);
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001213 err_code |= ERR_ALERT | ERR_FATAL;
1214 goto out;
1215 }
1216
1217 curr_resolvers->accepted_payload_size = i;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001218 }
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001219 else if (strcmp(args[0], "resolution_pool_size") == 0) {
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001220 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 +01001221 file, linenum, args[0]);
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001222 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001223 goto out;
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001224 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001225 else if (strcmp(args[0], "resolve_retries") == 0) {
1226 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001227 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1228 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001229 err_code |= ERR_ALERT | ERR_FATAL;
1230 goto out;
1231 }
1232 curr_resolvers->resolve_retries = atoi(args[1]);
1233 }
1234 else if (strcmp(args[0], "timeout") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001235 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001236 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n",
1237 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001238 err_code |= ERR_ALERT | ERR_FATAL;
1239 goto out;
1240 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001241 else if (strcmp(args[1], "retry") == 0 ||
1242 strcmp(args[1], "resolve") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001243 const char *res;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001244 unsigned int tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001245
1246 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001247 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1248 file, linenum, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001249 err_code |= ERR_ALERT | ERR_FATAL;
1250 goto out;
1251 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001252 res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001253 if (res == PARSE_TIME_OVER) {
1254 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1255 file, linenum, args[2], args[0], args[1]);
1256 err_code |= ERR_ALERT | ERR_FATAL;
1257 goto out;
1258 }
1259 else if (res == PARSE_TIME_UNDER) {
1260 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1261 file, linenum, args[2], args[0], args[1]);
1262 err_code |= ERR_ALERT | ERR_FATAL;
1263 goto out;
1264 }
1265 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001266 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1267 file, linenum, *res, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001268 err_code |= ERR_ALERT | ERR_FATAL;
1269 goto out;
1270 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001271 if (args[1][2] == 't')
1272 curr_resolvers->timeout.retry = tout;
1273 else
1274 curr_resolvers->timeout.resolve = tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001275 }
1276 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001277 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n",
1278 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001279 err_code |= ERR_ALERT | ERR_FATAL;
1280 goto out;
1281 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001282 } /* neither "nameserver" nor "resolvers" */
1283 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001284 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001285 err_code |= ERR_ALERT | ERR_FATAL;
1286 goto out;
1287 }
1288
1289 out:
1290 free(errmsg);
1291 return err_code;
1292}
Simon Horman0d16a402015-01-30 11:22:58 +09001293
1294/*
William Lallemand51097192015-04-14 16:35:22 +02001295 * Parse a line in a <listen>, <frontend> or <backend> section.
Simon Horman0d16a402015-01-30 11:22:58 +09001296 * Returns the error code, 0 if OK, or any combination of :
1297 * - ERR_ABORT: must abort ASAP
1298 * - ERR_FATAL: we can continue parsing but not start the service
1299 * - ERR_WARN: a warning has been emitted
1300 * - ERR_ALERT: an alert has been emitted
1301 * Only the two first ones can stop processing, the two others are just
1302 * indicators.
1303 */
1304int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
1305{
1306 static struct mailers *curmailers = NULL;
1307 struct mailer *newmailer = NULL;
1308 const char *err;
1309 int err_code = 0;
1310 char *errmsg = NULL;
1311
1312 if (strcmp(args[0], "mailers") == 0) { /* new mailers section */
1313 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001314 ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001315 err_code |= ERR_ALERT | ERR_ABORT;
1316 goto out;
1317 }
1318
1319 err = invalid_char(args[1]);
1320 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001321 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1322 file, linenum, *err, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001323 err_code |= ERR_ALERT | ERR_ABORT;
1324 goto out;
1325 }
1326
1327 for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) {
1328 /*
1329 * If there are two proxies with the same name only following
1330 * combinations are allowed:
1331 */
1332 if (strcmp(curmailers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001333 ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n",
1334 file, linenum, args[1], curmailers->conf.file, curmailers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02001335 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman0d16a402015-01-30 11:22:58 +09001336 }
1337 }
1338
Vincent Bernat02779b62016-04-03 13:48:43 +02001339 if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001340 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001341 err_code |= ERR_ALERT | ERR_ABORT;
1342 goto out;
1343 }
1344
1345 curmailers->next = mailers;
1346 mailers = curmailers;
1347 curmailers->conf.file = strdup(file);
1348 curmailers->conf.line = linenum;
1349 curmailers->id = strdup(args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001350 curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
1351 * But need enough time so that timeouts don't occur
1352 * during tcp procssing. For now just us an arbitrary default. */
Simon Horman0d16a402015-01-30 11:22:58 +09001353 }
1354 else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
1355 struct sockaddr_storage *sk;
1356 int port1, port2;
1357 struct protocol *proto;
1358
1359 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001360 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1361 file, linenum, args[0]);
Simon Horman0d16a402015-01-30 11:22:58 +09001362 err_code |= ERR_ALERT | ERR_FATAL;
1363 goto out;
1364 }
1365
1366 err = invalid_char(args[1]);
1367 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001368 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1369 file, linenum, *err, args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001370 err_code |= ERR_ALERT | ERR_FATAL;
1371 goto out;
1372 }
1373
Vincent Bernat02779b62016-04-03 13:48:43 +02001374 if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001375 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001376 err_code |= ERR_ALERT | ERR_ABORT;
1377 goto out;
1378 }
1379
1380 /* the mailers are linked backwards first */
1381 curmailers->count++;
1382 newmailer->next = curmailers->mailer_list;
1383 curmailers->mailer_list = newmailer;
1384 newmailer->mailers = curmailers;
1385 newmailer->conf.file = strdup(file);
1386 newmailer->conf.line = linenum;
1387
1388 newmailer->id = strdup(args[1]);
1389
Willy Tarreau80958762020-09-15 10:30:39 +02001390 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND);
Simon Horman0d16a402015-01-30 11:22:58 +09001391 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001392 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Simon Horman0d16a402015-01-30 11:22:58 +09001393 err_code |= ERR_ALERT | ERR_FATAL;
1394 goto out;
1395 }
1396
1397 proto = protocol_by_family(sk->ss_family);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09001398 if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001399 ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n",
1400 file, linenum, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001401 err_code |= ERR_ALERT | ERR_FATAL;
1402 goto out;
1403 }
1404
Simon Horman0d16a402015-01-30 11:22:58 +09001405 newmailer->addr = *sk;
1406 newmailer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01001407 newmailer->xprt = xprt_get(XPRT_RAW);
Simon Horman0d16a402015-01-30 11:22:58 +09001408 newmailer->sock_init_arg = NULL;
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001409 }
1410 else if (strcmp(args[0], "timeout") == 0) {
1411 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001412 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
1413 file, linenum, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001414 err_code |= ERR_ALERT | ERR_FATAL;
1415 goto out;
1416 }
1417 else if (strcmp(args[1], "mail") == 0) {
1418 const char *res;
1419 unsigned int timeout_mail;
1420 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001421 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1422 file, linenum, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001423 err_code |= ERR_ALERT | ERR_FATAL;
1424 goto out;
1425 }
1426 res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001427 if (res == PARSE_TIME_OVER) {
1428 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1429 file, linenum, args[2], args[0], args[1]);
1430 err_code |= ERR_ALERT | ERR_FATAL;
1431 goto out;
1432 }
1433 else if (res == PARSE_TIME_UNDER) {
1434 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1435 file, linenum, args[2], args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001436 err_code |= ERR_ALERT | ERR_FATAL;
1437 goto out;
1438 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001439 else if (res) {
1440 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1441 file, linenum, *res, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001442 err_code |= ERR_ALERT | ERR_FATAL;
1443 goto out;
1444 }
1445 curmailers->timeout.mail = timeout_mail;
1446 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001447 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001448 file, linenum, args[0], args[1]);
1449 err_code |= ERR_ALERT | ERR_FATAL;
1450 goto out;
1451 }
1452 }
Simon Horman0d16a402015-01-30 11:22:58 +09001453 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001454 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Simon Horman0d16a402015-01-30 11:22:58 +09001455 err_code |= ERR_ALERT | ERR_FATAL;
1456 goto out;
1457 }
1458
1459out:
1460 free(errmsg);
1461 return err_code;
1462}
1463
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001464void free_email_alert(struct proxy *p)
Simon Horman9dc49962015-01-30 11:22:59 +09001465{
1466 free(p->email_alert.mailers.name);
1467 p->email_alert.mailers.name = NULL;
1468 free(p->email_alert.from);
1469 p->email_alert.from = NULL;
1470 free(p->email_alert.to);
1471 p->email_alert.to = NULL;
1472 free(p->email_alert.myhostname);
1473 p->email_alert.myhostname = NULL;
1474}
1475
Willy Tarreaubaaee002006-06-26 02:48:02 +02001476
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001477int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001478cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
1479{
Willy Tarreaue5733232019-05-22 19:24:06 +02001480#ifdef USE_NS
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001481 const char *err;
1482 const char *item = args[0];
1483
1484 if (!strcmp(item, "namespace_list")) {
1485 return 0;
1486 }
1487 else if (!strcmp(item, "namespace")) {
1488 size_t idx = 1;
1489 const char *current;
1490 while (*(current = args[idx++])) {
1491 err = invalid_char(current);
1492 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001493 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1494 file, linenum, *err, item, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001495 return ERR_ALERT | ERR_FATAL;
1496 }
1497
1498 if (netns_store_lookup(current, strlen(current))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001499 ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
1500 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001501 return ERR_ALERT | ERR_FATAL;
1502 }
1503 if (!netns_store_insert(current)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001504 ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
1505 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001506 return ERR_ALERT | ERR_FATAL;
1507 }
1508 }
1509 }
1510
1511 return 0;
1512#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001513 ha_alert("parsing [%s:%d]: namespace support is not compiled in.",
1514 file, linenum);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001515 return ERR_ALERT | ERR_FATAL;
1516#endif
1517}
1518
1519int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001520cfg_parse_users(const char *file, int linenum, char **args, int kwm)
1521{
1522
1523 int err_code = 0;
1524 const char *err;
1525
1526 if (!strcmp(args[0], "userlist")) { /* new userlist */
1527 struct userlist *newul;
1528
1529 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001530 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1531 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001532 err_code |= ERR_ALERT | ERR_FATAL;
1533 goto out;
1534 }
William Lallemand6e62fb62015-04-28 16:55:23 +02001535 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1536 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001537
1538 err = invalid_char(args[1]);
1539 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001540 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1541 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001542 err_code |= ERR_ALERT | ERR_FATAL;
1543 goto out;
1544 }
1545
1546 for (newul = userlist; newul; newul = newul->next)
1547 if (!strcmp(newul->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001548 ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
1549 file, linenum, args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001550 err_code |= ERR_WARN;
1551 goto out;
1552 }
1553
Vincent Bernat02779b62016-04-03 13:48:43 +02001554 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001555 if (!newul) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001556 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001557 err_code |= ERR_ALERT | ERR_ABORT;
1558 goto out;
1559 }
1560
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001561 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001562 if (!newul->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001563 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001564 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01001565 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001566 goto out;
1567 }
1568
1569 newul->next = userlist;
1570 userlist = newul;
1571
1572 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001573 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001574 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001575 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001576
1577 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001578 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1579 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001580 err_code |= ERR_ALERT | ERR_FATAL;
1581 goto out;
1582 }
1583
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
William Lallemand4ac9f542015-05-28 18:03:51 +02001592 if (!userlist)
1593 goto out;
1594
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001595 for (ag = userlist->groups; ag; ag = ag->next)
1596 if (!strcmp(ag->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001597 ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
1598 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001599 err_code |= ERR_ALERT;
1600 goto out;
1601 }
1602
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001603 ag = calloc(1, sizeof(*ag));
1604 if (!ag) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001605 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001606 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001607 goto out;
1608 }
1609
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001610 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01001611 if (!ag->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001612 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001613 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01001614 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001615 goto out;
1616 }
1617
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001618 cur_arg = 2;
1619
1620 while (*args[cur_arg]) {
1621 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001622 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001623 cur_arg += 2;
1624 continue;
1625 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001626 ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
1627 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001628 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01001629 free(ag->groupusers);
1630 free(ag->name);
1631 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001632 goto out;
1633 }
1634 }
1635
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001636 ag->next = userlist->groups;
1637 userlist->groups = ag;
1638
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001639 } else if (!strcmp(args[0], "user")) { /* new user */
1640 struct auth_users *newuser;
1641 int cur_arg;
1642
1643 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001644 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1645 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001646 err_code |= ERR_ALERT | ERR_FATAL;
1647 goto out;
1648 }
William Lallemand4ac9f542015-05-28 18:03:51 +02001649 if (!userlist)
1650 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001651
1652 for (newuser = userlist->users; newuser; newuser = newuser->next)
1653 if (!strcmp(newuser->user, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001654 ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
1655 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001656 err_code |= ERR_ALERT;
1657 goto out;
1658 }
1659
Vincent Bernat02779b62016-04-03 13:48:43 +02001660 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001661 if (!newuser) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001662 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001663 err_code |= ERR_ALERT | ERR_ABORT;
1664 goto out;
1665 }
1666
1667 newuser->user = strdup(args[1]);
1668
1669 newuser->next = userlist->users;
1670 userlist->users = newuser;
1671
1672 cur_arg = 2;
1673
1674 while (*args[cur_arg]) {
1675 if (!strcmp(args[cur_arg], "password")) {
Willy Tarreaue5733232019-05-22 19:24:06 +02001676#ifdef USE_LIBCRYPT
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001677 if (!crypt("", args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001678 ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
1679 file, linenum, newuser->user);
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001680 err_code |= ERR_ALERT | ERR_FATAL;
1681 goto out;
1682 }
1683#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001684 ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
1685 file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001686 err_code |= ERR_ALERT;
1687#endif
1688 newuser->pass = strdup(args[cur_arg + 1]);
1689 cur_arg += 2;
1690 continue;
1691 } else if (!strcmp(args[cur_arg], "insecure-password")) {
1692 newuser->pass = strdup(args[cur_arg + 1]);
1693 newuser->flags |= AU_O_INSECURE;
1694 cur_arg += 2;
1695 continue;
1696 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001697 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001698 cur_arg += 2;
1699 continue;
1700 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001701 ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
1702 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001703 err_code |= ERR_ALERT | ERR_FATAL;
1704 goto out;
1705 }
1706 }
1707 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001708 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 +01001709 err_code |= ERR_ALERT | ERR_FATAL;
1710 }
1711
1712out:
1713 return err_code;
1714}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001715
Christopher Faulet79bdef32016-11-04 22:36:15 +01001716int
1717cfg_parse_scope(const char *file, int linenum, char *line)
1718{
1719 char *beg, *end, *scope = NULL;
1720 int err_code = 0;
1721 const char *err;
1722
1723 beg = line + 1;
1724 end = strchr(beg, ']');
1725
1726 /* Detect end of scope declaration */
1727 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001728 ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n",
1729 file, linenum);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001730 err_code |= ERR_ALERT | ERR_FATAL;
1731 goto out;
1732 }
1733
1734 /* Get scope name and check its validity */
1735 scope = my_strndup(beg, end-beg);
1736 err = invalid_char(scope);
1737 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001738 ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
1739 file, linenum, *err);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001740 err_code |= ERR_ALERT | ERR_ABORT;
1741 goto out;
1742 }
1743
1744 /* Be sure to have a scope declaration alone on its line */
1745 line = end+1;
1746 while (isspace((unsigned char)*line))
1747 line++;
1748 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001749 ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
1750 file, linenum, *line);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001751 err_code |= ERR_ALERT | ERR_ABORT;
1752 goto out;
1753 }
1754
1755 /* We have a valid scope declaration, save it */
1756 free(cfg_scope);
1757 cfg_scope = scope;
1758 scope = NULL;
1759
1760 out:
1761 free(scope);
1762 return err_code;
1763}
1764
Frédéric Lécaillea41d5312018-01-29 12:05:07 +01001765int
1766cfg_parse_track_sc_num(unsigned int *track_sc_num,
1767 const char *arg, const char *end, char **errmsg)
1768{
1769 const char *p;
1770 unsigned int num;
1771
1772 p = arg;
1773 num = read_uint64(&arg, end);
1774
1775 if (arg != end) {
1776 memprintf(errmsg, "Wrong track-sc number '%s'", p);
1777 return -1;
1778 }
1779
1780 if (num >= MAX_SESS_STKCTR) {
1781 memprintf(errmsg, "%u track-sc number exceeding "
1782 "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1);
1783 return -1;
1784 }
1785
1786 *track_sc_num = num;
1787 return 0;
1788}
1789
Willy Tarreaubaaee002006-06-26 02:48:02 +02001790/*
1791 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02001792 * Returns the error code, 0 if OK, or any combination of :
1793 * - ERR_ABORT: must abort ASAP
1794 * - ERR_FATAL: we can continue parsing but not start the service
1795 * - ERR_WARN: a warning has been emitted
1796 * - ERR_ALERT: an alert has been emitted
1797 * Only the two first ones can stop processing, the two others are just
1798 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001799 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02001800int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001801{
William Lallemand64e84512015-05-12 14:25:37 +02001802 char *thisline;
1803 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001804 FILE *f;
1805 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02001806 int err_code = 0;
William Lallemandd2ff56d2017-10-16 11:06:50 +02001807 struct cfg_section *cs = NULL, *pcs = NULL;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001808 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02001809 int readbytes = 0;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001810 char *outline = NULL;
1811 size_t outlen = 0;
1812 size_t outlinesize = 0;
Willy Tarreau32234e72020-06-16 17:14:33 +02001813 int fatal = 0;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001814 int missing_lf = -1;
William Lallemand64e84512015-05-12 14:25:37 +02001815
1816 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001817 ha_alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02001818 return -1;
1819 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001820
David Carlier97880bb2016-04-08 10:35:26 +01001821 if ((f=fopen(file,"r")) == NULL) {
1822 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001823 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01001824 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001825
William Lallemandb2f07452015-05-12 14:27:13 +02001826next_line:
William Lallemand64e84512015-05-12 14:25:37 +02001827 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02001828 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001829 char *end;
1830 char *args[MAX_LINE_ARGS + 1];
1831 char *line = thisline;
1832
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001833 if (missing_lf != -1) {
Tim Duesterhusf92afb72020-08-18 22:00:04 +02001834 ha_alert("parsing [%s:%d]: Stray NUL character at position %d.\n",
1835 file, linenum, (missing_lf + 1));
1836 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001837 missing_lf = -1;
Tim Duesterhusf92afb72020-08-18 22:00:04 +02001838 break;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001839 }
1840
Willy Tarreaubaaee002006-06-26 02:48:02 +02001841 linenum++;
1842
Willy Tarreau32234e72020-06-16 17:14:33 +02001843 if (fatal >= 50) {
1844 ha_alert("parsing [%s:%d]: too many fatal errors (%d), stopping now.\n", file, linenum, fatal);
1845 break;
1846 }
1847
Willy Tarreaubaaee002006-06-26 02:48:02 +02001848 end = line + strlen(line);
1849
William Lallemand64e84512015-05-12 14:25:37 +02001850 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001851 /* Check if we reached the limit and the last char is not \n.
1852 * Watch out for the last line without the terminating '\n'!
1853 */
William Lallemand64e84512015-05-12 14:25:37 +02001854 char *newline;
1855 int newlinesize = linesize * 2;
1856
1857 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
1858 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001859 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
1860 file, linenum);
William Lallemand64e84512015-05-12 14:25:37 +02001861 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001862 fatal++;
Willy Tarreau40cb26f2020-06-25 09:37:54 +02001863 linenum--;
William Lallemand64e84512015-05-12 14:25:37 +02001864 continue;
1865 }
1866
1867 readbytes = linesize - 1;
1868 linesize = newlinesize;
1869 thisline = newline;
Willy Tarreau40cb26f2020-06-25 09:37:54 +02001870 linenum--;
William Lallemand64e84512015-05-12 14:25:37 +02001871 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001872 }
1873
William Lallemand64e84512015-05-12 14:25:37 +02001874 readbytes = 0;
1875
Willy Tarreau08488f62020-06-26 17:24:54 +02001876 if (end > line && *(end-1) == '\n') {
Tim Duesterhus70f58992020-06-22 22:57:44 +02001877 /* kill trailing LF */
1878 *(end - 1) = 0;
1879 }
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001880 else {
1881 /* mark this line as truncated */
1882 missing_lf = end - line;
1883 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001884
Willy Tarreaubaaee002006-06-26 02:48:02 +02001885 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02001886 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02001887 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02001888
Joseph Herlanta14c03e2018-11-15 14:04:19 -08001889 if (*line == '[') {/* This is the beginning if a scope */
Christopher Faulet79bdef32016-11-04 22:36:15 +01001890 err_code |= cfg_parse_scope(file, linenum, line);
1891 goto next_line;
1892 }
1893
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001894 while (1) {
1895 uint32_t err;
1896 char *errptr;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001897
Willy Tarreau61dd44b2020-06-25 07:35:42 +02001898 arg = MAX_LINE_ARGS + 1;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001899 outlen = outlinesize;
1900 err = parse_line(line, outline, &outlen, args, &arg,
1901 PARSE_OPT_ENV | PARSE_OPT_DQUOTE | PARSE_OPT_SQUOTE |
1902 PARSE_OPT_BKSLASH | PARSE_OPT_SHARP, &errptr);
1903
1904 if (err & PARSE_ERR_QUOTE) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001905 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1906
1907 ha_alert("parsing [%s:%d]: unmatched quote at position %d:\n"
1908 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001909 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001910 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001911 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001912 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001913
1914 if (err & PARSE_ERR_BRACE) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001915 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1916
1917 ha_alert("parsing [%s:%d]: unmatched brace in environment variable name at position %d:\n"
1918 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001919 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001920 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001921 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001922 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001923
1924 if (err & PARSE_ERR_VARNAME) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001925 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1926
1927 ha_alert("parsing [%s:%d]: forbidden first char in environment variable name at position %d:\n"
1928 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001929 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001930 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001931 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001932 }
William Lallemandb2f07452015-05-12 14:27:13 +02001933
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001934 if (err & PARSE_ERR_HEX) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001935 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1936
1937 ha_alert("parsing [%s:%d]: truncated or invalid hexadecimal sequence at position %d:\n"
1938 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001939 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus9f658a52020-06-16 18:14:21 +02001940 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001941 goto next_line;
1942 }
William Lallemandb2f07452015-05-12 14:27:13 +02001943
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001944 if (err & (PARSE_ERR_TOOLARGE|PARSE_ERR_OVERLAP)) {
1945 outlinesize = (outlen + 1023) & -1024;
1946 outline = realloc(outline, outlinesize);
1947 if (outline == NULL) {
1948 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
1949 file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02001950 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001951 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001952 goto next_line;
William Lallemandb2f07452015-05-12 14:27:13 +02001953 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001954 /* try again */
1955 continue;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001956 }
Willy Tarreau07d47062020-06-25 07:41:22 +02001957
1958 if (err & PARSE_ERR_TOOMANY) {
1959 /* only check this *after* being sure the output is allocated */
1960 ha_alert("parsing [%s:%d]: too many words, truncating after word %d, position %ld: <%s>.\n",
1961 file, linenum, MAX_LINE_ARGS, (long)(args[MAX_LINE_ARGS-1] - outline + 1), args[MAX_LINE_ARGS-1]);
1962 err_code |= ERR_ALERT | ERR_FATAL;
1963 fatal++;
1964 goto next_line;
1965 }
1966
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001967 /* everything's OK */
1968 break;
William Lallemandf9873ba2015-05-05 17:37:14 +02001969 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001970
1971 /* empty line */
1972 if (!**args)
1973 continue;
1974
Willy Tarreau3842f002009-06-14 11:39:52 +02001975 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001976 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02001977 char *tmp;
1978
Willy Tarreau3842f002009-06-14 11:39:52 +02001979 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02001980 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001981 for (arg=0; *args[arg+1]; arg++)
1982 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02001983 *tmp = '\0'; // fix the next arg to \0
1984 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001985 }
Willy Tarreau3842f002009-06-14 11:39:52 +02001986 else if (!strcmp(args[0], "default")) {
1987 kwm = KWM_DEF;
1988 for (arg=0; *args[arg+1]; arg++)
1989 args[arg] = args[arg+1]; // shift args after inversion
1990 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01001991
William Dauchyec730982019-10-27 20:08:10 +01001992 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 &&
1993 strcmp(args[0], "log") != 0 && strcmp(args[0], "busy-polling") != 0 &&
Willy Tarreaud96f1122019-12-03 07:07:36 +01001994 strcmp(args[0], "set-dumpable") != 0 && strcmp(args[0], "strict-limits") != 0 &&
1995 strcmp(args[0], "insecure-fork-wanted") != 0) {
William Dauchyec730982019-10-27 20:08:10 +01001996 ha_alert("parsing [%s:%d]: negation/default currently "
William Dauchy0fec3ab2019-10-27 20:08:11 +01001997 "supported only for options, log, busy-polling, "
Willy Tarreaud96f1122019-12-03 07:07:36 +01001998 "set-dumpable, strict-limits, and insecure-fork-wanted.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001999 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02002000 fatal++;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002001 }
2002
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002003 /* detect section start */
2004 list_for_each_entry(ics, &sections, list) {
2005 if (strcmp(args[0], ics->section_name) == 0) {
2006 cursection = ics->section_name;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002007 pcs = cs;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002008 cs = ics;
2009 break;
2010 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002011 }
2012
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002013 if (pcs && pcs->post_section_parser) {
Willy Tarreau32234e72020-06-16 17:14:33 +02002014 int status;
2015
2016 status = pcs->post_section_parser();
2017 err_code |= status;
2018 if (status & ERR_FATAL)
2019 fatal++;
2020
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002021 if (err_code & ERR_ABORT)
2022 goto err;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002023 }
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002024 pcs = NULL;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002025
William Lallemandd2ff56d2017-10-16 11:06:50 +02002026 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002027 ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02002028 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02002029 fatal++;
William Lallemandd2ff56d2017-10-16 11:06:50 +02002030 } else {
Willy Tarreau32234e72020-06-16 17:14:33 +02002031 int status;
2032
2033 status = cs->section_parser(file, linenum, args, kwm);
2034 err_code |= status;
2035 if (status & ERR_FATAL)
2036 fatal++;
2037
William Lallemandd2ff56d2017-10-16 11:06:50 +02002038 if (err_code & ERR_ABORT)
2039 goto err;
2040 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002041 }
William Lallemandd2ff56d2017-10-16 11:06:50 +02002042
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02002043 if (missing_lf != -1) {
Tim Duesterhusf92afb72020-08-18 22:00:04 +02002044 ha_alert("parsing [%s:%d]: Missing LF on last line, file might have been truncated at position %d.\n",
2045 file, linenum, (missing_lf + 1));
2046 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02002047 }
2048
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002049 if (cs && cs->post_section_parser)
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002050 err_code |= cs->post_section_parser();
William Lallemandd2ff56d2017-10-16 11:06:50 +02002051
2052err:
Christopher Faulet79bdef32016-11-04 22:36:15 +01002053 free(cfg_scope);
2054 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01002055 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02002056 free(thisline);
Willy Tarreau9e1758e2020-06-16 16:32:59 +02002057 free(outline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002058 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02002059 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002060}
2061
Willy Tarreau64ab6072014-09-16 12:17:36 +02002062/* This function propagates processes from frontend <from> to backend <to> so
2063 * that it is always guaranteed that a backend pointed to by a frontend is
2064 * bound to all of its processes. After that, if the target is a "listen"
2065 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02002066 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02002067 * checked first to ensure that <to> is already bound to all processes of
2068 * <from>, there is no risk of looping and we ensure to follow the shortest
2069 * path to the destination.
2070 *
2071 * It is possible to set <to> to NULL for the first call so that the function
2072 * takes care of visiting the initial frontend in <from>.
2073 *
2074 * It is important to note that the function relies on the fact that all names
2075 * have already been resolved.
2076 */
2077void propagate_processes(struct proxy *from, struct proxy *to)
2078{
2079 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002080
2081 if (to) {
2082 /* check whether we need to go down */
2083 if (from->bind_proc &&
2084 (from->bind_proc & to->bind_proc) == from->bind_proc)
2085 return;
2086
2087 if (!from->bind_proc && !to->bind_proc)
2088 return;
2089
2090 to->bind_proc = from->bind_proc ?
2091 (to->bind_proc | from->bind_proc) : 0;
2092
2093 /* now propagate down */
2094 from = to;
2095 }
2096
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01002097 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02002098 return;
2099
Willy Tarreauf6b70012014-12-18 14:00:43 +01002100 if (from->state == PR_STSTOPPED)
2101 return;
2102
Willy Tarreau64ab6072014-09-16 12:17:36 +02002103 /* default_backend */
2104 if (from->defbe.be)
2105 propagate_processes(from, from->defbe.be);
2106
2107 /* use_backend */
2108 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02002109 if (rule->dynamic)
2110 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002111 to = rule->be.backend;
2112 propagate_processes(from, to);
2113 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02002114}
2115
Willy Tarreaubb925012009-07-23 13:36:36 +02002116/*
2117 * Returns the error code, 0 if OK, or any combination of :
2118 * - ERR_ABORT: must abort ASAP
2119 * - ERR_FATAL: we can continue parsing but not start the service
2120 * - ERR_WARN: a warning has been emitted
2121 * - ERR_ALERT: an alert has been emitted
2122 * Only the two first ones can stop processing, the two others are just
2123 * indicators.
2124 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002125int check_config_validity()
2126{
2127 int cfgerr = 0;
2128 struct proxy *curproxy = NULL;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002129 struct stktable *t;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002130 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02002131 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002132 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002133 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002134 char *err;
William Lallemand48b4bb42017-10-23 14:36:34 +02002135 struct cfg_postparser *postparser;
Ben Draut054fbee2018-04-13 15:43:04 -06002136 struct dns_resolvers *curr_resolvers = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002137
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002138 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002139 /*
2140 * Now, check for the integrity of all that we have collected.
2141 */
2142
2143 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02002144 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002145
Willy Tarreau193b8c62012-11-22 00:17:38 +01002146 if (!global.tune.max_http_hdr)
2147 global.tune.max_http_hdr = MAX_HTTP_HDR;
2148
2149 if (!global.tune.cookie_len)
2150 global.tune.cookie_len = CAPTURE_LEN;
2151
Stéphane Cottin23e9e932017-05-18 08:58:41 +02002152 if (!global.tune.requri_len)
2153 global.tune.requri_len = REQURI_LEN;
2154
Willy Tarreau149ab772019-01-26 14:27:06 +01002155 if (!global.nbthread) {
2156 /* nbthread not set, thus automatic. In this case, and only if
2157 * running on a single process, we enable the same number of
2158 * threads as the number of CPUs the process is bound to. This
2159 * allows to easily control the number of threads using taskset.
2160 */
2161 global.nbthread = 1;
2162#if defined(USE_THREAD)
2163 if (global.nbproc == 1)
2164 global.nbthread = thread_cpus_enabled_at_boot;
2165 all_threads_mask = nbits(global.nbthread);
2166#endif
2167 }
2168
Willy Tarreau26f6ae12019-02-02 12:56:15 +01002169 if (global.nbproc > 1 && global.nbthread > 1) {
2170 ha_alert("config : cannot enable multiple processes if multiple threads are configured. Please use either nbproc or nbthread but not both.\n");
2171 err_code |= ERR_ALERT | ERR_FATAL;
2172 goto out;
2173 }
2174
Willy Tarreaubafbe012017-11-24 17:34:44 +01002175 pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
Emeric Brun96fd9262017-07-05 13:33:16 +02002176
Willy Tarreaubafbe012017-11-24 17:34:44 +01002177 pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
Willy Tarreau193b8c62012-11-22 00:17:38 +01002178
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002179 /* Post initialisation of the users and groups lists. */
2180 err_code = userlist_postinit();
2181 if (err_code != ERR_NONE)
2182 goto out;
2183
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002184 /* first, we will invert the proxy list order */
2185 curproxy = NULL;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002186 while (proxies_list) {
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002187 struct proxy *next;
2188
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002189 next = proxies_list->next;
2190 proxies_list->next = curproxy;
2191 curproxy = proxies_list;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002192 if (!next)
2193 break;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002194 proxies_list = next;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002195 }
2196
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002197 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002198 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002199 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002200 struct sticking_rule *mrule;
Christopher Faulete4e830d2017-09-18 14:51:41 +02002201 struct act_rule *arule;
Dragan Dosen1322d092015-09-22 16:05:32 +02002202 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002203 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01002204 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002205
Willy Tarreau050536d2012-10-04 08:47:34 +02002206 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002207 /* proxy ID not set, use automatic numbering with first
2208 * spare entry starting with next_pxid.
2209 */
2210 next_pxid = get_next_id(&used_proxy_id, next_pxid);
2211 curproxy->conf.id.key = curproxy->uuid = next_pxid;
2212 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002213 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01002214 next_pxid++;
2215
Willy Tarreau55ea7572007-06-17 19:56:27 +02002216
Willy Tarreaubaaee002006-06-26 02:48:02 +02002217 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02002218 /* ensure we don't keep listeners uselessly bound */
2219 stop_proxy(curproxy);
Dragan Dosen7d61a332019-05-07 14:16:18 +02002220 if (curproxy->table) {
2221 free((void *)curproxy->table->peers.name);
2222 curproxy->table->peers.p = NULL;
2223 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002224 continue;
2225 }
2226
Willy Tarreau102df612014-05-07 23:56:38 +02002227 /* Check multi-process mode compatibility for the current proxy */
2228
2229 if (curproxy->bind_proc) {
2230 /* an explicit bind-process was specified, let's check how many
2231 * processes remain.
2232 */
David Carliere6c39412015-07-02 07:00:17 +00002233 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02002234
Willy Tarreaua38a7172019-02-02 17:11:28 +01002235 curproxy->bind_proc &= all_proc_mask;
Willy Tarreau102df612014-05-07 23:56:38 +02002236 if (!curproxy->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002237 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 +02002238 curproxy->bind_proc = 1;
2239 }
2240 else if (!curproxy->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002241 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 +02002242 curproxy->bind_proc = 0;
2243 }
2244 }
2245
Willy Tarreau3d209582014-05-09 17:06:11 +02002246 /* check and reduce the bind-proc of each listener */
2247 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
2248 unsigned long mask;
2249
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002250 /* HTTP frontends with "h2" as ALPN/NPN will work in
2251 * HTTP/2 and absolutely require buffers 16kB or larger.
2252 */
2253#ifdef USE_OPENSSL
2254 if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
2255#ifdef OPENSSL_NPN_NEGOTIATED
2256 /* check NPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002257 if (bind_conf->ssl_conf.npn_str && strstr(bind_conf->ssl_conf.npn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002258 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",
2259 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002260 cfgerr++;
2261 }
2262#endif
2263#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
2264 /* check ALPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002265 if (bind_conf->ssl_conf.alpn_str && strstr(bind_conf->ssl_conf.alpn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002266 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",
2267 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002268 cfgerr++;
2269 }
2270#endif
2271 } /* HTTP && bufsize < 16384 */
2272#endif
2273
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002274 /* detect and address thread affinity inconsistencies */
Willy Tarreaue26993c2020-09-03 07:18:55 +02002275 mask = thread_mask(bind_conf->settings.bind_thread);
Willy Tarreau3d957172019-02-02 18:00:17 +01002276 if (!(mask & all_threads_mask)) {
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002277 unsigned long new_mask = 0;
2278
2279 while (mask) {
Willy Tarreau0c026f42018-08-01 19:12:20 +02002280 new_mask |= mask & all_threads_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002281 mask >>= global.nbthread;
2282 }
2283
Willy Tarreaue26993c2020-09-03 07:18:55 +02002284 bind_conf->settings.bind_thread = new_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002285 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",
2286 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
2287 }
2288
2289 /* detect process and nbproc affinity inconsistencies */
Willy Tarreaue26993c2020-09-03 07:18:55 +02002290 mask = proc_mask(bind_conf->settings.bind_proc) & proc_mask(curproxy->bind_proc);
Willy Tarreaua36b3242019-02-02 13:14:34 +01002291 if (!(mask & all_proc_mask)) {
2292 mask = proc_mask(curproxy->bind_proc) & all_proc_mask;
Willy Tarreaue26993c2020-09-03 07:18:55 +02002293 nbproc = my_popcountl(bind_conf->settings.bind_proc);
2294 bind_conf->settings.bind_proc = proc_mask(bind_conf->settings.bind_proc) & mask;
Willy Tarreau3d209582014-05-09 17:06:11 +02002295
Willy Tarreaue26993c2020-09-03 07:18:55 +02002296 if (!bind_conf->settings.bind_proc && nbproc == 1) {
Willy Tarreaua36b3242019-02-02 13:14:34 +01002297 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",
2298 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreaue26993c2020-09-03 07:18:55 +02002299 bind_conf->settings.bind_proc = mask & ~(mask - 1);
Willy Tarreaua36b3242019-02-02 13:14:34 +01002300 }
Willy Tarreaue26993c2020-09-03 07:18:55 +02002301 else if (!bind_conf->settings.bind_proc && nbproc > 1) {
Willy Tarreaua36b3242019-02-02 13:14:34 +01002302 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",
2303 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreaue26993c2020-09-03 07:18:55 +02002304 bind_conf->settings.bind_proc = 0;
Willy Tarreaua36b3242019-02-02 13:14:34 +01002305 }
Willy Tarreau3d209582014-05-09 17:06:11 +02002306 }
2307 }
2308
Willy Tarreauff01a212009-03-15 13:46:16 +01002309 switch (curproxy->mode) {
2310 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002311 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002312 if (!(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002313 ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
2314 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002315 cfgerr++;
2316 }
2317
2318 if (curproxy->srv != NULL)
Christopher Faulet767a84b2017-11-24 16:50:31 +01002319 ha_warning("config : servers will be ignored for %s '%s'.\n",
2320 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002321 break;
2322
2323 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002324 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002325 break;
2326
2327 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01002328 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01002329 break;
William Lallemandcf62f7e2018-10-26 14:47:40 +02002330
2331 case PR_MODE_CLI:
2332 cfgerr += proxy_cfg_ensure_no_http(curproxy);
2333 break;
Emeric Brun54932b42020-07-07 09:43:24 +02002334 case PR_MODE_SYSLOG:
2335 case PR_MODES:
2336 /* should not happen, bug gcc warn missing switch statement */
2337 ha_alert("config : %s '%s' cannot use syslog mode for this proxy.\n",
2338 proxy_type_str(curproxy), curproxy->id);
2339 cfgerr++;
2340 break;
Willy Tarreauff01a212009-03-15 13:46:16 +01002341 }
2342
Willy Tarreau58aa5cc2018-02-08 09:55:09 +01002343 if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002344 ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
2345 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauf3934b82015-08-11 11:36:45 +02002346 err_code |= ERR_WARN;
2347 }
2348
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002349 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02002350 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002351 if (curproxy->options & PR_O_TRANSP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002352 ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n",
2353 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002354 cfgerr++;
2355 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002356#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002357 else if (curproxy->srv == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002358 ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n",
2359 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002360 cfgerr++;
2361 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002362#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02002363 else if (curproxy->options & PR_O_DISPATCH) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002364 ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
2365 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002366 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002367 }
2368 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02002369 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002370 /* If no LB algo is set in a backend, and we're not in
2371 * transparent mode, dispatch mode nor proxy mode, we
2372 * want to use balance roundrobin by default.
2373 */
2374 curproxy->lbprm.algo &= ~BE_LB_ALGO;
2375 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002376 }
2377 }
Willy Tarreau193cf932007-09-17 10:17:23 +02002378
Willy Tarreau1620ec32011-08-06 17:05:02 +02002379 if (curproxy->options & PR_O_DISPATCH)
2380 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
2381 else if (curproxy->options & PR_O_HTTP_PROXY)
2382 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
2383 else if (curproxy->options & PR_O_TRANSP)
2384 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01002385
Christopher Faulete5870d82020-04-15 11:32:03 +02002386 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_HTTP_RS)) {
2387 ha_warning("config : %s '%s' uses http-check rules without 'option httpchk', so the rules are ignored.\n",
2388 proxy_type_str(curproxy), curproxy->id);
2389 err_code |= ERR_WARN;
2390 }
2391
2392 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_TCPCHK_CHK &&
Christopher Fauletc0fcbe42020-06-03 19:00:42 +02002393 (curproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) != TCPCHK_RULES_HTTP_CHK) {
Willy Tarreau1620ec32011-08-06 17:05:02 +02002394 if (curproxy->options & PR_O_DISABLE404) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002395 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2396 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002397 err_code |= ERR_WARN;
2398 curproxy->options &= ~PR_O_DISABLE404;
2399 }
2400 if (curproxy->options2 & PR_O2_CHK_SNDST) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002401 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2402 "send-state", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002403 err_code |= ERR_WARN;
2404 curproxy->options &= ~PR_O2_CHK_SNDST;
2405 }
Willy Tarreauef781042010-01-27 11:53:01 +01002406 }
2407
Simon Horman98637e52014-06-20 12:30:16 +09002408 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
2409 if (!global.external_check) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002410 ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
2411 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002412 cfgerr++;
2413 }
2414 if (!curproxy->check_command) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002415 ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
2416 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002417 cfgerr++;
2418 }
Willy Tarreaud96f1122019-12-03 07:07:36 +01002419 if (!(global.tune.options & GTUNE_INSECURE_FORK)) {
2420 ha_warning("Proxy '%s' : 'insecure-fork-wanted' not enabled in the global section, '%s' will likely fail.\n",
2421 curproxy->id, "option external-check");
2422 err_code |= ERR_WARN;
2423 }
Simon Horman98637e52014-06-20 12:30:16 +09002424 }
2425
Simon Horman64e34162015-02-06 11:11:57 +09002426 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002427 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002428 ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
2429 "'email-alert from', 'email-alert level' 'email-alert mailers', "
2430 "'email-alert myhostname', or 'email-alert to' "
2431 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
2432 "to be present).\n",
2433 proxy_type_str(curproxy), curproxy->id);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002434 err_code |= ERR_WARN;
2435 free_email_alert(curproxy);
2436 }
2437 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01002438 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09002439 }
2440
Simon Horman98637e52014-06-20 12:30:16 +09002441 if (curproxy->check_command) {
2442 int clear = 0;
2443 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002444 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2445 "external-check command", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002446 err_code |= ERR_WARN;
2447 clear = 1;
2448 }
2449 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002450 ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
2451 curproxy->id, "external-check command");
Simon Horman98637e52014-06-20 12:30:16 +09002452 cfgerr++;
2453 }
2454 if (clear) {
2455 free(curproxy->check_command);
2456 curproxy->check_command = NULL;
2457 }
2458 }
2459
2460 if (curproxy->check_path) {
2461 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002462 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2463 "external-check path", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002464 err_code |= ERR_WARN;
2465 free(curproxy->check_path);
2466 curproxy->check_path = NULL;
2467 }
2468 }
2469
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002470 /* if a default backend was specified, let's find it */
2471 if (curproxy->defbe.name) {
2472 struct proxy *target;
2473
Willy Tarreauafb39922015-05-26 12:04:09 +02002474 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002475 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002476 ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
2477 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002478 cfgerr++;
2479 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002480 ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
2481 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02002482 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002483 } else if (target->mode != curproxy->mode &&
2484 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2485
Christopher Faulet767a84b2017-11-24 16:50:31 +01002486 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
2487 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2488 curproxy->conf.file, curproxy->conf.line,
2489 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2490 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002491 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002492 } else {
2493 free(curproxy->defbe.name);
2494 curproxy->defbe.be = target;
Willy Tarreauff678132012-02-13 14:32:34 +01002495 /* Emit a warning if this proxy also has some servers */
2496 if (curproxy->srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002497 ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
2498 curproxy->id);
Willy Tarreauff678132012-02-13 14:32:34 +01002499 err_code |= ERR_WARN;
2500 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002501 }
2502 }
2503
Willy Tarreau55ea7572007-06-17 19:56:27 +02002504 /* find the target proxy for 'use_backend' rules */
2505 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002506 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002507 struct logformat_node *node;
2508 char *pxname;
2509
2510 /* Try to parse the string as a log format expression. If the result
2511 * of the parsing is only one entry containing a simple string, then
2512 * it's a standard string corresponding to a static rule, thus the
2513 * parsing is cancelled and be.name is restored to be resolved.
2514 */
2515 pxname = rule->be.name;
2516 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01002517 curproxy->conf.args.ctx = ARGC_UBK;
2518 curproxy->conf.args.file = rule->file;
2519 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002520 err = NULL;
2521 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002522 ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
2523 rule->file, rule->line, pxname, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002524 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002525 cfgerr++;
2526 continue;
2527 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002528 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
2529
2530 if (!LIST_ISEMPTY(&rule->be.expr)) {
2531 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
2532 rule->dynamic = 1;
2533 free(pxname);
2534 continue;
2535 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002536 /* Only one element in the list, a simple string: free the expression and
2537 * fall back to static rule
2538 */
2539 LIST_DEL(&node->list);
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002540 free(node->arg);
2541 free(node);
2542 }
2543
2544 rule->dynamic = 0;
2545 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002546
Willy Tarreauafb39922015-05-26 12:04:09 +02002547 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002548 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002549 ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
2550 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002551 cfgerr++;
2552 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002553 ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
2554 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002555 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002556 } else if (target->mode != curproxy->mode &&
2557 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2558
Christopher Faulet767a84b2017-11-24 16:50:31 +01002559 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
2560 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2561 curproxy->conf.file, curproxy->conf.line,
2562 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2563 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002564 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002565 } else {
2566 free((void *)rule->be.name);
2567 rule->be.backend = target;
2568 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002569 }
2570
Willy Tarreau64ab6072014-09-16 12:17:36 +02002571 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002572 list_for_each_entry(srule, &curproxy->server_rules, list) {
Jerome Magnin824186b2020-03-29 09:37:12 +02002573 struct server *target;
2574 struct logformat_node *node;
2575 char *server_name;
2576
2577 /* We try to parse the string as a log format expression. If the result of the parsing
2578 * is only one entry containing a single string, then it's a standard string corresponding
2579 * to a static rule, thus the parsing is cancelled and we fall back to setting srv.ptr.
2580 */
2581 server_name = srule->srv.name;
2582 LIST_INIT(&srule->expr);
2583 curproxy->conf.args.ctx = ARGC_USRV;
2584 err = NULL;
2585 if (!parse_logformat_string(server_name, curproxy, &srule->expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
2586 ha_alert("Parsing [%s:%d]; use-server rule failed to parse log-format '%s' : %s.\n",
2587 srule->file, srule->line, server_name, err);
2588 free(err);
2589 cfgerr++;
2590 continue;
2591 }
2592 node = LIST_NEXT(&srule->expr, struct logformat_node *, list);
2593
2594 if (!LIST_ISEMPTY(&srule->expr)) {
2595 if (node->type != LOG_FMT_TEXT || node->list.n != &srule->expr) {
2596 srule->dynamic = 1;
2597 free(server_name);
2598 continue;
2599 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002600 /* Only one element in the list, a simple string: free the expression and
2601 * fall back to static rule
2602 */
2603 LIST_DEL(&node->list);
Jerome Magnin824186b2020-03-29 09:37:12 +02002604 free(node->arg);
2605 free(node);
2606 }
2607
2608 srule->dynamic = 0;
2609 srule->srv.name = server_name;
2610 target = findserver(curproxy, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002611
2612 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002613 ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
2614 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002615 cfgerr++;
2616 continue;
2617 }
2618 free((void *)srule->srv.name);
2619 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002620 }
2621
Emeric Brunb982a3d2010-01-04 15:45:53 +01002622 /* find the target table for 'stick' rules */
2623 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002624 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002625
Emeric Brun1d33b292010-01-04 15:47:17 +01002626 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
2627 if (mrule->flags & STK_IS_STORE)
2628 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2629
Emeric Brunb982a3d2010-01-04 15:45:53 +01002630 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002631 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002632 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002633 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002634
2635 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002636 ha_alert("Proxy '%s': unable to find stick-table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002637 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002638 cfgerr++;
2639 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002640 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002641 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2642 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002643 cfgerr++;
2644 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002645 else if (target->proxy && curproxy->bind_proc & ~target->proxy->bind_proc) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002646 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2647 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002648 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002649 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002650 else {
2651 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002652 mrule->table.t = target;
2653 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002654 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002655 if (!in_proxies_list(target->proxies_list, curproxy)) {
2656 curproxy->next_stkt_ref = target->proxies_list;
2657 target->proxies_list = curproxy;
2658 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002659 }
2660 }
2661
2662 /* find the target table for 'store response' rules */
2663 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002664 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002665
Emeric Brun1d33b292010-01-04 15:47:17 +01002666 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2667
Emeric Brunb982a3d2010-01-04 15:45:53 +01002668 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002669 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002670 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002671 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002672
2673 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002674 ha_alert("Proxy '%s': unable to find store table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002675 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002676 cfgerr++;
2677 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002678 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002679 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2680 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002681 cfgerr++;
2682 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002683 else if (target->proxy && (curproxy->bind_proc & ~target->proxy->bind_proc)) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002684 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2685 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002686 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002687 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002688 else {
2689 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002690 mrule->table.t = target;
2691 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002692 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002693 if (!in_proxies_list(target->proxies_list, curproxy)) {
2694 curproxy->next_stkt_ref = target->proxies_list;
2695 target->proxies_list = curproxy;
2696 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002697 }
2698 }
2699
Christopher Faulete4e830d2017-09-18 14:51:41 +02002700 /* check validity for 'tcp-request' layer 4 rules */
2701 list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) {
2702 err = NULL;
2703 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002704 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002705 free(err);
Willy Tarreau5f53de72012-12-12 00:25:44 +01002706 cfgerr++;
2707 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02002708 }
2709
Christopher Faulete4e830d2017-09-18 14:51:41 +02002710 /* check validity for 'tcp-request' layer 5 rules */
2711 list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) {
2712 err = NULL;
2713 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002714 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002715 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002716 cfgerr++;
2717 }
2718 }
2719
Christopher Faulete4e830d2017-09-18 14:51:41 +02002720 /* check validity for 'tcp-request' layer 6 rules */
2721 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
2722 err = NULL;
2723 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002724 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002725 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002726 cfgerr++;
2727 }
2728 }
2729
Christopher Faulete4e830d2017-09-18 14:51:41 +02002730 /* check validity for 'http-request' layer 7 rules */
2731 list_for_each_entry(arule, &curproxy->http_req_rules, list) {
2732 err = NULL;
2733 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002734 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002735 free(err);
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002736 cfgerr++;
2737 }
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002738 }
2739
Christopher Faulete4e830d2017-09-18 14:51:41 +02002740 /* check validity for 'http-response' layer 7 rules */
2741 list_for_each_entry(arule, &curproxy->http_res_rules, list) {
2742 err = NULL;
2743 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002744 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002745 free(err);
Willy Tarreau09448f72014-06-25 18:12:15 +02002746 cfgerr++;
2747 }
Willy Tarreau09448f72014-06-25 18:12:15 +02002748 }
2749
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01002750 /* check validity for 'http-after-response' layer 7 rules */
2751 list_for_each_entry(arule, &curproxy->http_after_res_rules, list) {
2752 err = NULL;
2753 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
2754 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
2755 free(err);
2756 cfgerr++;
2757 }
2758 }
2759
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002760 if (curproxy->table && curproxy->table->peers.name) {
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002761 struct peers *curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002762
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002763 for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002764 if (strcmp(curpeers->id, curproxy->table->peers.name) == 0) {
2765 free((void *)curproxy->table->peers.name);
2766 curproxy->table->peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002767 break;
2768 }
2769 }
2770
2771 if (!curpeers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002772 ha_alert("Proxy '%s': unable to find sync peers '%s'.\n",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002773 curproxy->id, curproxy->table->peers.name);
2774 free((void *)curproxy->table->peers.name);
2775 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002776 cfgerr++;
2777 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002778 else if (curpeers->state == PR_STSTOPPED) {
2779 /* silently disable this peers section */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002780 curproxy->table->peers.p = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002781 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002782 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002783 ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
2784 curproxy->id, localpeer, curpeers->id);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002785 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002786 cfgerr++;
2787 }
2788 }
2789
Simon Horman9dc49962015-01-30 11:22:59 +09002790
2791 if (curproxy->email_alert.mailers.name) {
2792 struct mailers *curmailers = mailers;
2793
2794 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
Christopher Faulet0108bb32017-10-20 21:34:32 +02002795 if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name))
Simon Horman9dc49962015-01-30 11:22:59 +09002796 break;
Simon Horman9dc49962015-01-30 11:22:59 +09002797 }
Simon Horman9dc49962015-01-30 11:22:59 +09002798 if (!curmailers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002799 ha_alert("Proxy '%s': unable to find mailers '%s'.\n",
2800 curproxy->id, curproxy->email_alert.mailers.name);
Simon Horman9dc49962015-01-30 11:22:59 +09002801 free_email_alert(curproxy);
2802 cfgerr++;
2803 }
Christopher Faulet0108bb32017-10-20 21:34:32 +02002804 else {
2805 err = NULL;
2806 if (init_email_alert(curmailers, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002807 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulet0108bb32017-10-20 21:34:32 +02002808 free(err);
2809 cfgerr++;
2810 }
2811 }
Simon Horman9dc49962015-01-30 11:22:59 +09002812 }
2813
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002814 if (curproxy->uri_auth && curproxy->uri_auth != defproxy.uri_auth &&
Willy Tarreauff011f22011-01-06 17:51:27 +01002815 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002816 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002817 ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
2818 "proxy", curproxy->id);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002819 cfgerr++;
2820 goto out_uri_auth_compat;
2821 }
2822
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002823 if (curproxy->uri_auth && curproxy->uri_auth->userlist &&
2824 (curproxy->uri_auth != defproxy.uri_auth ||
2825 LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules))) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002826 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02002827 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002828 int i = 0;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002829 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
2830 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002831
2832 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002833 uri_auth_compat_req[i++] = "realm";
2834 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
2835 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002836
Willy Tarreau95fa4692010-02-01 13:05:50 +01002837 uri_auth_compat_req[i++] = "unless";
2838 uri_auth_compat_req[i++] = "{";
2839 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
2840 uri_auth_compat_req[i++] = "}";
2841 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002842
Willy Tarreauff011f22011-01-06 17:51:27 +01002843 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
2844 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002845 cfgerr++;
2846 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002847 }
2848
Willy Tarreauff011f22011-01-06 17:51:27 +01002849 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01002850
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002851 if (curproxy->uri_auth->auth_realm) {
2852 free(curproxy->uri_auth->auth_realm);
2853 curproxy->uri_auth->auth_realm = NULL;
2854 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002855 }
2856out_uri_auth_compat:
2857
Dragan Dosen43885c72015-10-01 13:18:13 +02002858 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02002859 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02002860 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
2861 if (!curproxy->conf.logformat_sd_string) {
2862 /* set the default logformat_sd_string */
2863 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
2864 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002865 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02002866 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002867 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02002868
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002869 /* compile the log format */
2870 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02002871 if (curproxy->conf.logformat_string != default_http_log_format &&
2872 curproxy->conf.logformat_string != default_tcp_log_format &&
2873 curproxy->conf.logformat_string != clf_http_log_format)
2874 free(curproxy->conf.logformat_string);
2875 curproxy->conf.logformat_string = NULL;
2876 free(curproxy->conf.lfs_file);
2877 curproxy->conf.lfs_file = NULL;
2878 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002879
2880 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2881 free(curproxy->conf.logformat_sd_string);
2882 curproxy->conf.logformat_sd_string = NULL;
2883 free(curproxy->conf.lfsd_file);
2884 curproxy->conf.lfsd_file = NULL;
2885 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002886 }
2887
Willy Tarreau62a61232013-04-12 18:13:46 +02002888 if (curproxy->conf.logformat_string) {
2889 curproxy->conf.args.ctx = ARGC_LOG;
2890 curproxy->conf.args.file = curproxy->conf.lfs_file;
2891 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002892 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002893 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat,
2894 LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002895 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002896 ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
2897 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002898 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002899 cfgerr++;
2900 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002901 curproxy->conf.args.file = NULL;
2902 curproxy->conf.args.line = 0;
2903 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002904
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002905 if (curproxy->conf.logformat_sd_string) {
2906 curproxy->conf.args.ctx = ARGC_LOGSD;
2907 curproxy->conf.args.file = curproxy->conf.lfsd_file;
2908 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002909 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002910 if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd,
2911 LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002912 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002913 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2914 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002915 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002916 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002917 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002918 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2919 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002920 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002921 cfgerr++;
2922 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002923 curproxy->conf.args.file = NULL;
2924 curproxy->conf.args.line = 0;
2925 }
2926
Willy Tarreau62a61232013-04-12 18:13:46 +02002927 if (curproxy->conf.uniqueid_format_string) {
2928 curproxy->conf.args.ctx = ARGC_UIF;
2929 curproxy->conf.args.file = curproxy->conf.uif_file;
2930 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002931 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002932 if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id,
2933 LOG_OPT_HTTP|LOG_OPT_MERGE_SPACES,
2934 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR
2935 : SMP_VAL_BE_HRQ_HDR,
2936 &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002937 ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
2938 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002939 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002940 cfgerr++;
2941 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002942 curproxy->conf.args.file = NULL;
2943 curproxy->conf.args.line = 0;
2944 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002945
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002946 /* only now we can check if some args remain unresolved.
2947 * This must be done after the users and groups resolution.
2948 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002949 cfgerr += smp_resolve_args(curproxy);
2950 if (!cfgerr)
2951 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01002952
Willy Tarreau2738a142006-07-08 17:28:09 +02002953 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002954 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02002955 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02002956 (!curproxy->timeout.connect ||
2957 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002958 ha_warning("config : missing timeouts for %s '%s'.\n"
2959 " | While not properly invalid, you will certainly encounter various problems\n"
2960 " | with such a configuration. To fix this, please ensure that all following\n"
2961 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
2962 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002963 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02002964 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02002965
Willy Tarreau1fa31262007-12-03 00:36:16 +01002966 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
2967 * We must still support older configurations, so let's find out whether those
2968 * parameters have been set or must be copied from contimeouts.
2969 */
2970 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002971 if (!curproxy->timeout.tarpit ||
2972 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01002973 /* tarpit timeout not set. We search in the following order:
2974 * default.tarpit, curr.connect, default.connect.
2975 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002976 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01002977 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002978 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002979 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002980 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002981 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002982 }
2983 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002984 (!curproxy->timeout.queue ||
2985 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01002986 /* queue timeout not set. We search in the following order:
2987 * default.queue, curr.connect, default.connect.
2988 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002989 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01002990 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002991 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002992 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002993 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002994 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002995 }
2996 }
2997
Christopher Faulete5870d82020-04-15 11:32:03 +02002998 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_TCP_RS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002999 ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
3000 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau215663d2014-06-13 18:30:23 +02003001 err_code |= ERR_WARN;
3002 }
3003
Willy Tarreau193b8c62012-11-22 00:17:38 +01003004 /* ensure that cookie capture length is not too large */
3005 if (curproxy->capture_len >= global.tune.cookie_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003006 ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n",
3007 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau193b8c62012-11-22 00:17:38 +01003008 err_code |= ERR_WARN;
3009 curproxy->capture_len = global.tune.cookie_len - 1;
3010 }
3011
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003012 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01003013 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003014 curproxy->req_cap_pool = create_pool("ptrcap",
3015 curproxy->nb_req_cap * sizeof(char *),
3016 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003017 }
3018
3019 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003020 curproxy->rsp_cap_pool = create_pool("ptrcap",
3021 curproxy->nb_rsp_cap * sizeof(char *),
3022 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003023 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003024
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003025 switch (curproxy->load_server_state_from_file) {
3026 case PR_SRV_STATE_FILE_UNSPEC:
3027 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
3028 break;
3029 case PR_SRV_STATE_FILE_GLOBAL:
3030 if (!global.server_state_file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003031 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",
3032 curproxy->id);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003033 err_code |= ERR_WARN;
3034 }
3035 break;
3036 }
3037
Willy Tarreaubaaee002006-06-26 02:48:02 +02003038 /* first, we will invert the servers list order */
3039 newsrv = NULL;
3040 while (curproxy->srv) {
3041 struct server *next;
3042
3043 next = curproxy->srv->next;
3044 curproxy->srv->next = newsrv;
3045 newsrv = curproxy->srv;
3046 if (!next)
3047 break;
3048 curproxy->srv = next;
3049 }
3050
Willy Tarreau17edc812014-01-03 12:14:34 +01003051 /* Check that no server name conflicts. This causes trouble in the stats.
3052 * We only emit a warning for the first conflict affecting each server,
3053 * in order to avoid combinatory explosion if all servers have the same
3054 * name. We do that only for servers which do not have an explicit ID,
3055 * because these IDs were made also for distinguishing them and we don't
3056 * want to annoy people who correctly manage them.
3057 */
3058 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3059 struct server *other_srv;
3060
3061 if (newsrv->puid)
3062 continue;
3063
3064 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
3065 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
Willy Tarreaub01302f2019-05-27 19:31:06 +02003066 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 +01003067 newsrv->conf.file, newsrv->conf.line,
3068 proxy_type_str(curproxy), curproxy->id,
3069 newsrv->id, other_srv->conf.line);
Willy Tarreaub01302f2019-05-27 19:31:06 +02003070 cfgerr++;
Willy Tarreau17edc812014-01-03 12:14:34 +01003071 break;
3072 }
3073 }
3074 }
3075
Willy Tarreaudd701652010-05-25 23:03:02 +02003076 /* assign automatic UIDs to servers which don't have one yet */
3077 next_id = 1;
3078 newsrv = curproxy->srv;
3079 while (newsrv != NULL) {
3080 if (!newsrv->puid) {
3081 /* server ID not set, use automatic numbering with first
3082 * spare entry starting with next_svid.
3083 */
3084 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
3085 newsrv->conf.id.key = newsrv->puid = next_id;
3086 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
Frédéric Lécaille84d60462019-05-17 14:29:15 +02003087 newsrv->conf.name.key = newsrv->id;
3088 ebis_insert(&curproxy->conf.used_server_name, &newsrv->conf.name);
Willy Tarreaudd701652010-05-25 23:03:02 +02003089 }
3090 next_id++;
3091 newsrv = newsrv->next;
3092 }
3093
Willy Tarreau20697042007-11-15 23:26:18 +01003094 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01003095 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02003096
Willy Tarreau62c3be22012-01-20 13:12:32 +01003097 /*
3098 * If this server supports a maxconn parameter, it needs a dedicated
3099 * tasks to fill the emptied slots when a connection leaves.
3100 * Also, resolve deferred tracking dependency if needed.
3101 */
3102 newsrv = curproxy->srv;
3103 while (newsrv != NULL) {
3104 if (newsrv->minconn > newsrv->maxconn) {
3105 /* Only 'minconn' was specified, or it was higher than or equal
3106 * to 'maxconn'. Let's turn this into maxconn and clean it, as
3107 * this will avoid further useless expensive computations.
3108 */
3109 newsrv->maxconn = newsrv->minconn;
3110 } else if (newsrv->maxconn && !newsrv->minconn) {
3111 /* minconn was not specified, so we set it to maxconn */
3112 newsrv->minconn = newsrv->maxconn;
3113 }
3114
Willy Tarreau17d45382016-12-22 21:16:08 +01003115 /* this will also properly set the transport layer for prod and checks */
Christopher Fauletf61f33a2020-03-27 18:55:49 +01003116 if (newsrv->use_ssl == 1 || newsrv->check.use_ssl == 1 || (newsrv->proxy->options & PR_O_TCPCHK_SSL)) {
Willy Tarreau17d45382016-12-22 21:16:08 +01003117 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
3118 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
3119 }
Emeric Brun94324a42012-10-11 14:00:19 +02003120
Willy Tarreau034c88c2017-01-23 23:36:45 +01003121 if ((newsrv->flags & SRV_F_FASTOPEN) &&
3122 ((curproxy->retry_type & (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)) !=
3123 (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)))
3124 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",
3125 newsrv->conf.file, newsrv->conf.line,
3126 proxy_type_str(curproxy), curproxy->id,
3127 newsrv->id);
3128
Willy Tarreau62c3be22012-01-20 13:12:32 +01003129 if (newsrv->trackit) {
3130 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02003131 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003132 char *pname, *sname;
3133
3134 pname = newsrv->trackit;
3135 sname = strrchr(pname, '/');
3136
3137 if (sname)
3138 *sname++ = '\0';
3139 else {
3140 sname = pname;
3141 pname = NULL;
3142 }
3143
3144 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02003145 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003146 if (!px) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003147 ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
3148 proxy_type_str(curproxy), curproxy->id,
3149 newsrv->id, pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003150 cfgerr++;
3151 goto next_srv;
3152 }
3153 } else
3154 px = curproxy;
3155
3156 srv = findserver(px, sname);
3157 if (!srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003158 ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
3159 proxy_type_str(curproxy), curproxy->id,
3160 newsrv->id, sname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003161 cfgerr++;
3162 goto next_srv;
3163 }
3164
Christopher Faulet8892e5d2020-03-26 19:48:20 +01003165 if (!srv->do_check && !srv->do_agent && !srv->track && !srv->trackit) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003166 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for "
3167 "tracking as it does not have any check nor agent enabled.\n",
3168 proxy_type_str(curproxy), curproxy->id,
3169 newsrv->id, px->id, srv->id);
Willy Tarreau32091232014-05-16 13:52:00 +02003170 cfgerr++;
3171 goto next_srv;
3172 }
3173
3174 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
3175
Frédéric Lécaille2efc6492017-03-14 14:32:17 +01003176 if (newsrv == srv || loop) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003177 ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it "
3178 "belongs to a tracking chain looping back to %s/%s.\n",
3179 proxy_type_str(curproxy), curproxy->id,
3180 newsrv->id, px->id, srv->id, px->id,
3181 newsrv == srv ? srv->id : loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003182 cfgerr++;
3183 goto next_srv;
3184 }
3185
3186 if (curproxy != px &&
3187 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003188 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for"
3189 "tracking: disable-on-404 option inconsistency.\n",
3190 proxy_type_str(curproxy), curproxy->id,
3191 newsrv->id, px->id, srv->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003192 cfgerr++;
3193 goto next_srv;
3194 }
3195
Willy Tarreau62c3be22012-01-20 13:12:32 +01003196 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01003197 newsrv->tracknext = srv->trackers;
3198 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003199
3200 free(newsrv->trackit);
3201 newsrv->trackit = NULL;
3202 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02003203
Willy Tarreau62c3be22012-01-20 13:12:32 +01003204 next_srv:
3205 newsrv = newsrv->next;
3206 }
3207
Olivier Houchard4e694042017-03-14 20:01:29 +01003208 /*
3209 * Try to generate dynamic cookies for servers now.
3210 * It couldn't be done earlier, since at the time we parsed
3211 * the server line, we may not have known yet that we
3212 * should use dynamic cookies, or the secret key may not
3213 * have been provided yet.
3214 */
3215 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
3216 newsrv = curproxy->srv;
3217 while (newsrv != NULL) {
3218 srv_set_dyncookie(newsrv);
3219 newsrv = newsrv->next;
3220 }
3221
3222 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003223 /* We have to initialize the server lookup mechanism depending
Joseph Herlanta14c03e2018-11-15 14:04:19 -08003224 * on what LB algorithm was chosen.
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003225 */
3226
3227 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
3228 switch (curproxy->lbprm.algo & BE_LB_KIND) {
3229 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02003230 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
3231 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3232 init_server_map(curproxy);
Willy Tarreau760e81d2018-05-03 07:20:40 +02003233 } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
3234 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3235 chash_init_server_tree(curproxy);
Willy Tarreau9757a382009-10-03 12:56:50 +02003236 } else {
3237 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
3238 fwrr_init_server_groups(curproxy);
3239 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003240 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003241
Willy Tarreau3ebb1162012-02-13 16:57:44 +01003242 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01003243 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
3244 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
3245 fwlc_init_server_tree(curproxy);
3246 } else {
3247 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
3248 fas_init_server_tree(curproxy);
3249 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003250 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003251
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003252 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003253 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
3254 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3255 chash_init_server_tree(curproxy);
3256 } else {
3257 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3258 init_server_map(curproxy);
3259 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003260 break;
3261 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003262 HA_SPIN_INIT(&curproxy->lbprm.lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003263
3264 if (curproxy->options & PR_O_LOGASAP)
3265 curproxy->to_log &= ~LW_BYTES;
3266
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003267 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003268 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
3269 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003270 ha_warning("config : log format ignored for %s '%s' since it has no log address.\n",
3271 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003272 err_code |= ERR_WARN;
3273 }
3274
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003275 if (curproxy->mode != PR_MODE_HTTP) {
3276 int optnum;
3277
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003278 if (curproxy->uri_auth) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003279 ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
3280 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003281 err_code |= ERR_WARN;
3282 curproxy->uri_auth = NULL;
3283 }
3284
Willy Tarreaude7dc882017-03-10 11:49:21 +01003285 if (curproxy->capture_name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003286 ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
3287 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003288 err_code |= ERR_WARN;
3289 }
3290
3291 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003292 ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
3293 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003294 err_code |= ERR_WARN;
3295 }
3296
3297 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003298 ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
3299 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003300 err_code |= ERR_WARN;
3301 }
3302
Willy Tarreaude7dc882017-03-10 11:49:21 +01003303 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003304 ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
3305 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003306 err_code |= ERR_WARN;
3307 }
3308
Willy Tarreau87cf5142011-08-19 22:57:24 +02003309 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003310 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3311 "forwardfor", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003312 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02003313 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003314 }
3315
3316 if (curproxy->options & PR_O_ORGTO) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003317 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3318 "originalto", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003319 err_code |= ERR_WARN;
3320 curproxy->options &= ~PR_O_ORGTO;
3321 }
3322
3323 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
3324 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
3325 (curproxy->cap & cfg_opts[optnum].cap) &&
3326 (curproxy->options & cfg_opts[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003327 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3328 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003329 err_code |= ERR_WARN;
3330 curproxy->options &= ~cfg_opts[optnum].val;
3331 }
3332 }
3333
3334 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
3335 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
3336 (curproxy->cap & cfg_opts2[optnum].cap) &&
3337 (curproxy->options2 & cfg_opts2[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003338 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3339 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003340 err_code |= ERR_WARN;
3341 curproxy->options2 &= ~cfg_opts2[optnum].val;
3342 }
3343 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003344
Willy Tarreau29fbe512015-08-20 19:35:14 +02003345#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003346 if (curproxy->conn_src.bind_hdr_occ) {
3347 curproxy->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003348 ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
3349 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003350 err_code |= ERR_WARN;
3351 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003352#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003353 }
3354
Willy Tarreaubaaee002006-06-26 02:48:02 +02003355 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01003356 * ensure that we're not cross-dressing a TCP server into HTTP.
3357 */
3358 newsrv = curproxy->srv;
3359 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01003360 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003361 ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
3362 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02003363 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01003364 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003365
Willy Tarreau0cec3312011-10-31 13:49:26 +01003366 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003367 ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
3368 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau0cec3312011-10-31 13:49:26 +01003369 err_code |= ERR_WARN;
3370 }
3371
Willy Tarreauc93cd162014-05-13 15:54:22 +02003372 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003373 ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
3374 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau82ffa392013-08-13 17:19:08 +02003375 err_code |= ERR_WARN;
3376 }
3377
Willy Tarreau29fbe512015-08-20 19:35:14 +02003378#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003379 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
3380 newsrv->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003381 ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
3382 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003383 err_code |= ERR_WARN;
3384 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003385#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01003386
Willy Tarreau46deab62018-04-28 07:18:15 +02003387 if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR)
3388 curproxy->options &= ~PR_O_REUSE_MASK;
3389
Willy Tarreau21d2af32008-02-14 20:25:24 +01003390 newsrv = newsrv->next;
3391 }
3392
Christopher Fauletd7c91962015-04-30 11:48:27 +02003393 /* Check filter configuration, if any */
3394 cfgerr += flt_check(curproxy);
3395
Willy Tarreauc1a21672009-08-16 22:37:44 +02003396 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02003397 if (!curproxy->accept)
3398 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02003399
Willy Tarreauc1a21672009-08-16 22:37:44 +02003400 if (curproxy->tcp_req.inspect_delay ||
3401 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02003402 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003403
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003404 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003405 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003406 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003407 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003408
William Lallemandcf62f7e2018-10-26 14:47:40 +02003409 if (curproxy->mode == PR_MODE_CLI) {
3410 curproxy->fe_req_ana |= AN_REQ_WAIT_CLI;
3411 curproxy->fe_rsp_ana |= AN_RES_WAIT_CLI;
3412 }
3413
Willy Tarreauc1a21672009-08-16 22:37:44 +02003414 /* both TCP and HTTP must check switching rules */
3415 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003416
3417 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003418 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003419 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3420 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 +01003421 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003422 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3423 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003424 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003425 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003426 }
3427
3428 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02003429 if (curproxy->tcp_req.inspect_delay ||
3430 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
3431 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
3432
Emeric Brun97679e72010-09-23 17:56:44 +02003433 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
3434 curproxy->be_rsp_ana |= AN_RES_INSPECT;
3435
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003436 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003437 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003438 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003439 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003440
3441 /* If the backend does requires RDP cookie persistence, we have to
3442 * enable the corresponding analyser.
3443 */
3444 if (curproxy->options2 & PR_O2_RDPC_PRST)
3445 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003446
3447 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003448 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003449 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3450 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 +01003451 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003452 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3453 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003454 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003455 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003456 }
Christopher Fauleta717b992018-04-10 14:43:00 +02003457
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003458 /* Check the mux protocols, if any, for each listener and server
Christopher Fauleta717b992018-04-10 14:43:00 +02003459 * attached to the current proxy */
3460 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3461 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003462 const struct mux_proto_list *mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003463
3464 if (!bind_conf->mux_proto)
3465 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003466
3467 /* it is possible that an incorrect mux was referenced
3468 * due to the proxy's mode not being taken into account
3469 * on first pass. Let's adjust it now.
3470 */
3471 mux_ent = conn_get_best_mux_entry(bind_conf->mux_proto->token, PROTO_SIDE_FE, mode);
3472
3473 if (!mux_ent || !isteq(mux_ent->token, bind_conf->mux_proto->token)) {
Christopher Fauleta717b992018-04-10 14:43:00 +02003474 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n",
3475 proxy_type_str(curproxy), curproxy->id,
3476 (int)bind_conf->mux_proto->token.len,
3477 bind_conf->mux_proto->token.ptr,
3478 bind_conf->arg, bind_conf->file, bind_conf->line);
3479 cfgerr++;
3480 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003481
3482 /* update the mux */
3483 bind_conf->mux_proto = mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003484 }
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003485 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3486 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003487 const struct mux_proto_list *mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003488
3489 if (!newsrv->mux_proto)
3490 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003491
3492 /* it is possible that an incorrect mux was referenced
3493 * due to the proxy's mode not being taken into account
3494 * on first pass. Let's adjust it now.
3495 */
3496 mux_ent = conn_get_best_mux_entry(newsrv->mux_proto->token, PROTO_SIDE_BE, mode);
3497
3498 if (!mux_ent || !isteq(mux_ent->token, newsrv->mux_proto->token)) {
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003499 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n",
3500 proxy_type_str(curproxy), curproxy->id,
3501 (int)newsrv->mux_proto->token.len,
3502 newsrv->mux_proto->token.ptr,
3503 newsrv->id, newsrv->conf.file, newsrv->conf.line);
3504 cfgerr++;
3505 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003506
3507 /* update the mux */
3508 newsrv->mux_proto = mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003509 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003510
3511 /* initialize idle conns lists */
3512 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3513 int i;
3514
Willy Tarreauad37c7a2020-07-17 14:18:36 +02003515 newsrv->available_conns = calloc(global.nbthread, sizeof(*newsrv->available_conns));
Willy Tarreau835daa12019-02-07 14:46:29 +01003516
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003517 if (!newsrv->available_conns) {
Willy Tarreau835daa12019-02-07 14:46:29 +01003518 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003519 newsrv->conf.file, newsrv->conf.line, newsrv->id);
Willy Tarreau835daa12019-02-07 14:46:29 +01003520 cfgerr++;
3521 continue;
3522 }
3523
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003524 for (i = 0; i < global.nbthread; i++)
3525 LIST_INIT(&newsrv->available_conns[i]);
Willy Tarreau980855b2019-02-07 14:59:29 +01003526
3527 if (newsrv->max_idle_conns != 0) {
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003528 if (idle_conn_task == NULL) {
3529 idle_conn_task = task_new(MAX_THREADS_MASK);
3530 if (!idle_conn_task)
3531 goto err;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003532
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003533 idle_conn_task->process = srv_cleanup_idle_connections;
3534 idle_conn_task->context = NULL;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003535
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003536 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003537 idle_conns[i].cleanup_task = task_new(1UL << i);
3538 if (!idle_conns[i].cleanup_task)
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003539 goto err;
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003540 idle_conns[i].cleanup_task->process = srv_cleanup_toremove_connections;
3541 idle_conns[i].cleanup_task->context = NULL;
Olivier Houchardf8f4c2e2020-06-29 20:15:59 +02003542 HA_SPIN_INIT(&idle_conns[i].takeover_lock);
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003543 MT_LIST_INIT(&idle_conns[i].toremove_conns);
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003544 }
3545 }
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003546
Willy Tarreau9b9c1742020-07-17 15:04:53 +02003547 newsrv->idle_conns = calloc((unsigned short)global.nbthread, sizeof(*newsrv->idle_conns));
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003548 if (!newsrv->idle_conns) {
3549 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3550 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3551 cfgerr++;
3552 continue;
3553 }
3554
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003555 for (i = 0; i < global.nbthread; i++)
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003556 MT_LIST_INIT(&newsrv->idle_conns[i]);
3557
Willy Tarreauad37c7a2020-07-17 14:18:36 +02003558 newsrv->safe_conns = calloc(global.nbthread, sizeof(*newsrv->safe_conns));
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003559 if (!newsrv->safe_conns) {
3560 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3561 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3562 cfgerr++;
3563 continue;
3564 }
3565
3566 for (i = 0; i < global.nbthread; i++)
3567 MT_LIST_INIT(&newsrv->safe_conns[i]);
3568
Tim Duesterhusb53dd032020-09-12 20:26:42 +02003569 newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
Olivier Houchardf1314812019-02-18 16:41:17 +01003570 if (!newsrv->curr_idle_thr)
3571 goto err;
Willy Tarreau980855b2019-02-07 14:59:29 +01003572 continue;
3573 err:
3574 ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
3575 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3576 cfgerr++;
3577 continue;
3578 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003579 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003580 }
3581
3582 /***********************************************************/
3583 /* At this point, target names have already been resolved. */
3584 /***********************************************************/
3585
3586 /* Check multi-process mode compatibility */
3587
3588 if (global.nbproc > 1 && global.stats_fe) {
3589 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3590 unsigned long mask;
3591
Willy Tarreau6daac192019-02-02 17:39:53 +01003592 mask = proc_mask(global.stats_fe->bind_proc) && all_proc_mask;
Willy Tarreaue26993c2020-09-03 07:18:55 +02003593 mask &= proc_mask(bind_conf->settings.bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003594
3595 /* stop here if more than one process is used */
Willy Tarreau9504dd62018-10-15 09:37:03 +02003596 if (atleast2(mask))
Willy Tarreau419ead82014-09-16 13:41:21 +02003597 break;
3598 }
3599 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003600 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 +02003601 }
3602 }
3603
3604 /* Make each frontend inherit bind-process from its listeners when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003605 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003606 if (curproxy->bind_proc)
3607 continue;
3608
3609 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3610 unsigned long mask;
3611
Willy Tarreaue26993c2020-09-03 07:18:55 +02003612 mask = proc_mask(bind_conf->settings.bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003613 curproxy->bind_proc |= mask;
3614 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003615 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003616 }
3617
3618 if (global.stats_fe) {
3619 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3620 unsigned long mask;
3621
Willy Tarreaue26993c2020-09-03 07:18:55 +02003622 mask = bind_conf->settings.bind_proc ? bind_conf->settings.bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02003623 global.stats_fe->bind_proc |= mask;
3624 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003625 global.stats_fe->bind_proc = proc_mask(global.stats_fe->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003626 }
3627
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003628 /* propagate bindings from frontends to backends. Don't do it if there
3629 * are any fatal errors as we must not call it with unresolved proxies.
3630 */
3631 if (!cfgerr) {
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003632 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003633 if (curproxy->cap & PR_CAP_FE)
3634 propagate_processes(curproxy, NULL);
3635 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003636 }
3637
3638 /* Bind each unbound backend to all processes when not specified. */
Willy Tarreau6daac192019-02-02 17:39:53 +01003639 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
3640 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003641
3642 /*******************************************************/
3643 /* At this step, all proxies have a non-null bind_proc */
3644 /*******************************************************/
3645
3646 /* perform the final checks before creating tasks */
3647
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003648 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003649 struct listener *listener;
3650 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003651
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003652 /* Configure SSL for each bind line.
3653 * Note: if configuration fails at some point, the ->ctx member
3654 * remains NULL so that listeners can later detach.
3655 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003656 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01003657 if (bind_conf->xprt->prepare_bind_conf &&
3658 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003659 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003660 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003661
Willy Tarreaue6b98942007-10-29 01:09:36 +01003662 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003663 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02003664 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003665 int nbproc;
3666
3667 nbproc = my_popcountl(curproxy->bind_proc &
Willy Tarreaue26993c2020-09-03 07:18:55 +02003668 (listener->bind_conf->settings.bind_proc ? listener->bind_conf->settings.bind_proc : curproxy->bind_proc) &
Willy Tarreaua38a7172019-02-02 17:11:28 +01003669 all_proc_mask);
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003670
3671 if (!nbproc) /* no intersection between listener and frontend */
3672 nbproc = 1;
3673
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003674 if (!listener->luid) {
3675 /* listener ID not set, use automatic numbering with first
3676 * spare entry starting with next_luid.
3677 */
3678 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
3679 listener->conf.id.key = listener->luid = next_id;
3680 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003681 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01003682 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003683
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003684 /* enable separate counters */
3685 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01003686 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003687 if (!listener->name)
3688 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003689 }
Willy Tarreau81796be2012-09-22 19:11:47 +02003690
Willy Tarreaue6b98942007-10-29 01:09:36 +01003691 if (curproxy->options & PR_O_TCP_NOLING)
3692 listener->options |= LI_O_NOLINGER;
Willy Tarreau16a21472012-11-19 12:39:59 +01003693 if (!listener->maxaccept)
3694 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
3695
3696 /* we want to have an optimal behaviour on single process mode to
3697 * maximize the work at once, but in multi-process we want to keep
3698 * some fairness between processes, so we target half of the max
3699 * number of events to be balanced over all the processes the proxy
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +05003700 * is bound to. Remember that maxaccept = -1 must be kept as it is
Willy Tarreau16a21472012-11-19 12:39:59 +01003701 * used to disable the limit.
3702 */
Christopher Faulet02f3cf12019-04-30 14:08:41 +02003703 if (listener->maxaccept > 0 && nbproc > 1) {
3704 listener->maxaccept = (listener->maxaccept + 1) / 2;
Willy Tarreau16a21472012-11-19 12:39:59 +01003705 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
3706 }
3707
Willy Tarreau9903f0e2015-04-04 18:50:31 +02003708 listener->accept = session_accept_fd;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003709 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01003710 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01003711
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003712 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02003713 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003714
Willy Tarreau620408f2016-10-21 16:37:51 +02003715 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
3716 listener->options |= LI_O_TCP_L5_RULES;
3717
Willy Tarreaude3041d2010-05-31 10:56:17 +02003718 if (curproxy->mon_mask.s_addr)
3719 listener->options |= LI_O_CHK_MONNET;
3720
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003721 /* smart accept mode is automatic in HTTP mode */
3722 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003723 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003724 !(curproxy->no_options2 & PR_O2_SMARTACC)))
3725 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01003726 }
3727
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003728 /* Release unused SSL configs */
3729 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01003730 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
3731 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003732 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003733
Willy Tarreaua38a7172019-02-02 17:11:28 +01003734 if (atleast2(curproxy->bind_proc & all_proc_mask)) {
Willy Tarreau102df612014-05-07 23:56:38 +02003735 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02003736 int count, maxproc = 0;
3737
3738 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreaue26993c2020-09-03 07:18:55 +02003739 count = my_popcountl(bind_conf->settings.bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003740 if (count > maxproc)
3741 maxproc = count;
3742 }
3743 /* backends have 0, frontends have 1 or more */
3744 if (maxproc != 1)
Christopher Faulet767a84b2017-11-24 16:50:31 +01003745 ha_warning("Proxy '%s': in multi-process mode, stats will be"
3746 " limited to process assigned to the current request.\n",
3747 curproxy->id);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003748
Willy Tarreau102df612014-05-07 23:56:38 +02003749 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003750 ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
3751 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003752 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003753 }
Willy Tarreau102df612014-05-07 23:56:38 +02003754 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003755 ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
3756 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003757 }
3758 }
Willy Tarreau918ff602011-07-25 16:33:49 +02003759
3760 /* create the task associated with the proxy */
Emeric Brunc60def82017-09-27 14:59:38 +02003761 curproxy->task = task_new(MAX_THREADS_MASK);
Willy Tarreau918ff602011-07-25 16:33:49 +02003762 if (curproxy->task) {
3763 curproxy->task->context = curproxy;
3764 curproxy->task->process = manage_proxy;
Willy Tarreau918ff602011-07-25 16:33:49 +02003765 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003766 ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
3767 curproxy->id);
Willy Tarreau918ff602011-07-25 16:33:49 +02003768 cfgerr++;
3769 }
Willy Tarreaub369a042014-09-16 13:21:03 +02003770 }
3771
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003772 /*
3773 * Recount currently required checks.
3774 */
3775
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003776 for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003777 int optnum;
3778
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003779 for (optnum = 0; cfg_opts[optnum].name; optnum++)
3780 if (curproxy->options & cfg_opts[optnum].val)
3781 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003782
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003783 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
3784 if (curproxy->options2 & cfg_opts2[optnum].val)
3785 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003786 }
3787
Willy Tarreau0fca4832015-05-01 19:12:05 +02003788 /* compute the required process bindings for the peers */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003789 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003790 if (curproxy->table && curproxy->table->peers.p)
3791 curproxy->table->peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
Willy Tarreau0fca4832015-05-01 19:12:05 +02003792
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01003793 /* compute the required process bindings for the peers from <stktables_list>
3794 * for all the stick-tables, the ones coming with "peers" sections included.
3795 */
3796 for (t = stktables_list; t; t = t->next) {
3797 struct proxy *p;
3798
3799 for (p = t->proxies_list; p; p = p->next_stkt_ref) {
3800 if (t->peers.p && t->peers.p->peers_fe) {
3801 t->peers.p->peers_fe->bind_proc |= p->bind_proc;
3802 }
3803 }
3804 }
3805
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003806 if (cfg_peers) {
3807 struct peers *curpeers = cfg_peers, **last;
Willy Tarreau122541c2011-09-07 21:24:49 +02003808 struct peer *p, *pb;
3809
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003810 /* In the case the peers frontend was not initialized by a
3811 stick-table used in the configuration, set its bind_proc
3812 by default to the first process. */
3813 while (curpeers) {
William Lallemand3ef2d562020-03-24 16:42:15 +01003814 if (curpeers->peers_fe) {
3815 if (curpeers->peers_fe->bind_proc == 0)
3816 curpeers->peers_fe->bind_proc = 1;
3817 }
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003818 curpeers = curpeers->next;
3819 }
3820
3821 curpeers = cfg_peers;
Willy Tarreau1e273012015-05-01 19:15:17 +02003822 /* Remove all peers sections which don't have a valid listener,
3823 * which are not used by any table, or which are bound to more
3824 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02003825 */
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003826 last = &cfg_peers;
Willy Tarreau122541c2011-09-07 21:24:49 +02003827 while (*last) {
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003828 struct stktable *t;
Willy Tarreau122541c2011-09-07 21:24:49 +02003829 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003830
3831 if (curpeers->state == PR_STSTOPPED) {
3832 /* the "disabled" keyword was present */
3833 if (curpeers->peers_fe)
3834 stop_proxy(curpeers->peers_fe);
3835 curpeers->peers_fe = NULL;
3836 }
Frédéric Lécaille5a4fe5a2019-10-04 08:30:04 +02003837 else if (!curpeers->peers_fe || !curpeers->peers_fe->id) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003838 ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
3839 curpeers->id, localpeer);
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003840 if (curpeers->peers_fe)
3841 stop_proxy(curpeers->peers_fe);
3842 curpeers->peers_fe = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003843 }
Willy Tarreau9504dd62018-10-15 09:37:03 +02003844 else if (atleast2(curpeers->peers_fe->bind_proc)) {
Willy Tarreau1e273012015-05-01 19:15:17 +02003845 /* either it's totally stopped or too much used */
3846 if (curpeers->peers_fe->bind_proc) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003847 ha_alert("Peers section '%s': peers referenced by sections "
3848 "running in different processes (%d different ones). "
3849 "Check global.nbproc and all tables' bind-process "
3850 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02003851 cfgerr++;
3852 }
3853 stop_proxy(curpeers->peers_fe);
3854 curpeers->peers_fe = NULL;
3855 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003856 else {
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003857 /* Initializes the transport layer of the server part of all the peers belonging to
3858 * <curpeers> section if required.
3859 * Note that ->srv is used by the local peer of a new process to connect to the local peer
3860 * of an old process.
3861 */
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003862 p = curpeers->remote;
3863 while (p) {
Frédéric Lécaille355b2032019-01-11 14:06:12 +01003864 if (p->srv) {
Christopher Fauletf61f33a2020-03-27 18:55:49 +01003865 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 +01003866 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(p->srv);
3867 }
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003868 p = p->next;
3869 }
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003870 /* Configure the SSL bindings of the local peer if required. */
3871 if (!LIST_ISEMPTY(&curpeers->peers_fe->conf.bind)) {
3872 struct list *l;
3873 struct bind_conf *bind_conf;
3874
3875 l = &curpeers->peers_fe->conf.bind;
3876 bind_conf = LIST_ELEM(l->n, typeof(bind_conf), by_fe);
3877 if (bind_conf->xprt->prepare_bind_conf &&
3878 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
3879 cfgerr++;
3880 }
Frédéric Lécaille8d78fa72019-05-20 18:22:52 +02003881 if (!peers_init_sync(curpeers) || !peers_alloc_dcache(curpeers)) {
Willy Tarreaud9443442018-10-15 11:18:03 +02003882 ha_alert("Peers section '%s': out of memory, giving up on peers.\n",
3883 curpeers->id);
3884 cfgerr++;
3885 break;
3886 }
Willy Tarreau122541c2011-09-07 21:24:49 +02003887 last = &curpeers->next;
3888 continue;
3889 }
3890
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003891 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02003892 p = curpeers->remote;
3893 while (p) {
3894 pb = p->next;
3895 free(p->id);
3896 free(p);
3897 p = pb;
3898 }
3899
3900 /* Destroy and unlink this curpeers section.
3901 * Note: curpeers is backed up into *last.
3902 */
3903 free(curpeers->id);
3904 curpeers = curpeers->next;
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003905 /* Reset any refereance to this peers section in the list of stick-tables */
3906 for (t = stktables_list; t; t = t->next) {
3907 if (t->peers.p && t->peers.p == *last)
3908 t->peers.p = NULL;
3909 }
Willy Tarreau122541c2011-09-07 21:24:49 +02003910 free(*last);
3911 *last = curpeers;
3912 }
3913 }
3914
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003915 for (t = stktables_list; t; t = t->next) {
3916 if (t->proxy)
3917 continue;
3918 if (!stktable_init(t)) {
3919 ha_alert("Proxy '%s': failed to initialize stick-table.\n", t->id);
3920 cfgerr++;
3921 }
3922 }
3923
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003924 /* initialize stick-tables on backend capable proxies. This must not
3925 * be done earlier because the data size may be discovered while parsing
3926 * other proxies.
3927 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003928 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003929 if (curproxy->state == PR_STSTOPPED || !curproxy->table)
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003930 continue;
3931
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003932 if (!stktable_init(curproxy->table)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003933 ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003934 cfgerr++;
3935 }
3936 }
3937
Simon Horman0d16a402015-01-30 11:22:58 +09003938 if (mailers) {
3939 struct mailers *curmailers = mailers, **last;
3940 struct mailer *m, *mb;
3941
3942 /* Remove all mailers sections which don't have a valid listener.
3943 * This can happen when a mailers section is never referenced.
3944 */
3945 last = &mailers;
3946 while (*last) {
3947 curmailers = *last;
3948 if (curmailers->users) {
3949 last = &curmailers->next;
3950 continue;
3951 }
3952
Christopher Faulet767a84b2017-11-24 16:50:31 +01003953 ha_warning("Removing incomplete section 'mailers %s'.\n",
3954 curmailers->id);
Simon Horman0d16a402015-01-30 11:22:58 +09003955
3956 m = curmailers->mailer_list;
3957 while (m) {
3958 mb = m->next;
3959 free(m->id);
3960 free(m);
3961 m = mb;
3962 }
3963
3964 /* Destroy and unlink this curmailers section.
3965 * Note: curmailers is backed up into *last.
3966 */
3967 free(curmailers->id);
3968 curmailers = curmailers->next;
3969 free(*last);
3970 *last = curmailers;
3971 }
3972 }
3973
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003974 /* Update server_state_file_name to backend name if backend is supposed to use
3975 * a server-state file locally defined and none has been provided */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003976 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003977 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
3978 curproxy->server_state_file_name == NULL)
3979 curproxy->server_state_file_name = strdup(curproxy->id);
3980 }
3981
Ben Draut054fbee2018-04-13 15:43:04 -06003982 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
3983 if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
3984 ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n",
3985 curr_resolvers->id, curr_resolvers->conf.file,
3986 curr_resolvers->conf.line);
3987 err_code |= ERR_WARN;
3988 }
3989 }
3990
William Lallemand48b4bb42017-10-23 14:36:34 +02003991 list_for_each_entry(postparser, &postparsers, list) {
3992 if (postparser->func)
3993 cfgerr += postparser->func();
3994 }
3995
Willy Tarreaubb925012009-07-23 13:36:36 +02003996 if (cfgerr > 0)
3997 err_code |= ERR_ALERT | ERR_FATAL;
3998 out:
3999 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004000}
4001
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004002/*
4003 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
4004 * parsing sessions.
4005 */
4006void cfg_register_keywords(struct cfg_kw_list *kwl)
4007{
4008 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
4009}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004010
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004011/*
4012 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
4013 */
4014void cfg_unregister_keywords(struct cfg_kw_list *kwl)
4015{
4016 LIST_DEL(&kwl->list);
4017 LIST_INIT(&kwl->list);
4018}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004019
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004020/* this function register new section in the haproxy configuration file.
4021 * <section_name> is the name of this new section and <section_parser>
4022 * is the called parser. If two section declaration have the same name,
4023 * only the first declared is used.
4024 */
4025int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +02004026 int (*section_parser)(const char *, int, char **, int),
4027 int (*post_section_parser)())
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004028{
4029 struct cfg_section *cs;
4030
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004031 list_for_each_entry(cs, &sections, list) {
4032 if (strcmp(cs->section_name, section_name) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004033 ha_alert("register section '%s': already registered.\n", section_name);
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004034 return 0;
4035 }
4036 }
4037
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004038 cs = calloc(1, sizeof(*cs));
4039 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004040 ha_alert("register section '%s': out of memory.\n", section_name);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004041 return 0;
4042 }
4043
4044 cs->section_name = section_name;
4045 cs->section_parser = section_parser;
William Lallemandd2ff56d2017-10-16 11:06:50 +02004046 cs->post_section_parser = post_section_parser;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004047
4048 LIST_ADDQ(&sections, &cs->list);
4049
4050 return 1;
4051}
4052
William Lallemand48b4bb42017-10-23 14:36:34 +02004053/* this function register a new function which will be called once the haproxy
4054 * configuration file has been parsed. It's useful to check dependencies
4055 * between sections or to resolve items once everything is parsed.
4056 */
4057int cfg_register_postparser(char *name, int (*func)())
4058{
4059 struct cfg_postparser *cp;
4060
4061 cp = calloc(1, sizeof(*cp));
4062 if (!cp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004063 ha_alert("register postparser '%s': out of memory.\n", name);
William Lallemand48b4bb42017-10-23 14:36:34 +02004064 return 0;
4065 }
4066 cp->name = name;
4067 cp->func = func;
4068
4069 LIST_ADDQ(&postparsers, &cp->list);
4070
4071 return 1;
4072}
4073
Willy Tarreaubaaee002006-06-26 02:48:02 +02004074/*
David Carlier845efb52015-09-25 11:49:18 +01004075 * free all config section entries
4076 */
4077void cfg_unregister_sections(void)
4078{
4079 struct cfg_section *cs, *ics;
4080
4081 list_for_each_entry_safe(cs, ics, &sections, list) {
4082 LIST_DEL(&cs->list);
4083 free(cs);
4084 }
4085}
4086
Christopher Faulet7110b402016-10-26 11:09:44 +02004087void cfg_backup_sections(struct list *backup_sections)
4088{
4089 struct cfg_section *cs, *ics;
4090
4091 list_for_each_entry_safe(cs, ics, &sections, list) {
4092 LIST_DEL(&cs->list);
4093 LIST_ADDQ(backup_sections, &cs->list);
4094 }
4095}
4096
4097void cfg_restore_sections(struct list *backup_sections)
4098{
4099 struct cfg_section *cs, *ics;
4100
4101 list_for_each_entry_safe(cs, ics, backup_sections, list) {
4102 LIST_DEL(&cs->list);
4103 LIST_ADDQ(&sections, &cs->list);
4104 }
4105}
4106
Willy Tarreaue6552512018-11-26 11:33:13 +01004107/* these are the config sections handled by default */
4108REGISTER_CONFIG_SECTION("listen", cfg_parse_listen, NULL);
4109REGISTER_CONFIG_SECTION("frontend", cfg_parse_listen, NULL);
4110REGISTER_CONFIG_SECTION("backend", cfg_parse_listen, NULL);
4111REGISTER_CONFIG_SECTION("defaults", cfg_parse_listen, NULL);
4112REGISTER_CONFIG_SECTION("global", cfg_parse_global, NULL);
4113REGISTER_CONFIG_SECTION("userlist", cfg_parse_users, NULL);
4114REGISTER_CONFIG_SECTION("peers", cfg_parse_peers, NULL);
4115REGISTER_CONFIG_SECTION("mailers", cfg_parse_mailers, NULL);
4116REGISTER_CONFIG_SECTION("namespace_list", cfg_parse_netns, NULL);
4117REGISTER_CONFIG_SECTION("resolvers", cfg_parse_resolvers, NULL);
Willy Tarreau659fbf02016-05-26 17:55:28 +02004118
David Carlier845efb52015-09-25 11:49:18 +01004119/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02004120 * Local variables:
4121 * c-indent-level: 8
4122 * c-basic-offset: 8
4123 * End:
4124 */