blob: cc5f9f76ece304369b744fb811168c5c605003a7 [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,
Thierry FOURNIER7fe3be72015-09-26 20:03:36 +0200132 NULL, 1);
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100133 if (!ss2)
134 goto fail;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200135
Emeric Brun3835c0d2020-07-07 09:46:09 +0200136 if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6
137 || ss2->ss_family == AF_CUST_UDP4
138 || ss2->ss_family == AF_CUST_UDP6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100139 if (!port && !end) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200140 memprintf(err, "missing port number: '%s'\n", str);
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100141 goto fail;
Emeric Bruned760922010-10-22 17:59:25 +0200142 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200143
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100144 if (!port || !end) {
145 memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str);
146 goto fail;
147 }
148
Emeric Bruned760922010-10-22 17:59:25 +0200149 if (port < 1 || port > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200150 memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str);
Emeric Bruned760922010-10-22 17:59:25 +0200151 goto fail;
152 }
153
154 if (end < 1 || end > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200155 memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str);
Emeric Bruned760922010-10-22 17:59:25 +0200156 goto fail;
157 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200158 }
Willy Tarreau40aa0702013-03-10 23:51:38 +0100159 else if (ss2->ss_family == AF_UNSPEC) {
160 socklen_t addr_len;
William Lallemand75ea0a02017-11-15 19:02:58 +0100161 inherited = 1;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100162
163 /* We want to attach to an already bound fd whose number
164 * is in the addr part of ss2 when cast to sockaddr_in.
165 * Note that by definition there is a single listener.
166 * We still have to determine the address family to
167 * register the correct protocol.
168 */
169 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
170 addr_len = sizeof(*ss2);
171 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
172 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
173 goto fail;
174 }
175
176 port = end = get_host_port(ss2);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200177
178 } else if (ss2->ss_family == AF_CUST_SOCKPAIR) {
179 socklen_t addr_len;
180 inherited = 1;
181
182 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
183 addr_len = sizeof(*ss2);
184 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
185 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
186 goto fail;
187 }
188
189 ss2->ss_family = AF_CUST_SOCKPAIR; /* reassign AF_CUST_SOCKPAIR because of getsockname */
190 port = end = 0;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100191 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200192
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100193 /* OK the address looks correct */
William Lallemand75ea0a02017-11-15 19:02:58 +0100194 if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) {
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200195 memprintf(err, "%s for address '%s'.\n", *err, str);
196 goto fail;
197 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200198 } /* end while(next) */
199 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200200 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200201 fail:
202 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200203 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200204}
205
William Lallemand6e62fb62015-04-28 16:55:23 +0200206/*
Willy Tarreauece9b072016-12-21 22:41:44 +0100207 * Report an error in <msg> when there are too many arguments. This version is
208 * intended to be used by keyword parsers so that the message will be included
209 * into the general error message. The index is the current keyword in args.
210 * Return 0 if the number of argument is correct, otherwise build a message and
211 * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The
212 * message may also be null, it will simply not be produced (useful to check only).
213 * <msg> and <err_code> are only affected on error.
214 */
215int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code)
216{
217 int i;
218
219 if (!*args[index + maxarg + 1])
220 return 0;
221
222 if (msg) {
223 *msg = NULL;
224 memprintf(msg, "%s", args[0]);
225 for (i = 1; i <= index; i++)
226 memprintf(msg, "%s %s", *msg, args[i]);
227
228 memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]);
229 }
230 if (err_code)
231 *err_code |= ERR_ALERT | ERR_FATAL;
232
233 return 1;
234}
235
236/*
237 * same as too_many_args_idx with a 0 index
238 */
239int too_many_args(int maxarg, char **args, char **msg, int *err_code)
240{
241 return too_many_args_idx(maxarg, 0, args, msg, err_code);
242}
243
244/*
William Lallemand6e62fb62015-04-28 16:55:23 +0200245 * Report a fatal Alert when there is too much arguments
246 * The index is the current keyword in args
247 * Return 0 if the number of argument is correct, otherwise emit an alert and return 1
248 * Fill err_code with an ERR_ALERT and an ERR_FATAL
249 */
250int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code)
251{
252 char *kw = NULL;
253 int i;
254
255 if (!*args[index + maxarg + 1])
256 return 0;
257
258 memprintf(&kw, "%s", args[0]);
259 for (i = 1; i <= index; i++) {
260 memprintf(&kw, "%s %s", kw, args[i]);
261 }
262
Christopher Faulet767a84b2017-11-24 16:50:31 +0100263 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 +0200264 free(kw);
265 *err_code |= ERR_ALERT | ERR_FATAL;
266 return 1;
267}
268
269/*
270 * same as alertif_too_many_args_idx with a 0 index
271 */
272int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code)
273{
274 return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code);
275}
276
Willy Tarreau61d18892009-03-31 10:49:21 +0200277
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100278/* Report it if a request ACL condition uses some keywords that are incompatible
279 * with the place where the ACL is used. It returns either 0 or ERR_WARN so that
280 * its result can be or'ed with err_code. Note that <cond> may be NULL and then
281 * will be ignored.
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100282 */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100283int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100284{
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100285 const struct acl *acl;
Willy Tarreau93fddf12013-03-31 22:59:32 +0200286 const char *kw;
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100287
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100288 if (!cond)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100289 return 0;
290
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100291 acl = acl_cond_conflicts(cond, where);
292 if (acl) {
293 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100294 ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n",
295 file, line, acl->name, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100296 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100297 ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
298 file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100299 return ERR_WARN;
300 }
301 if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100302 return 0;
303
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100304 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100305 ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
306 file, line, acl->name, kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100307 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100308 ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
309 file, line, kw, sample_ckp_names(where));
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100310 return ERR_WARN;
311}
312
Christopher Faulet62519022017-10-16 15:49:32 +0200313/* Parse a string representing a process number or a set of processes. It must
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100314 * be "all", "odd", "even", a number between 1 and <max> or a range with
Christopher Faulet5ab51772017-11-22 11:21:58 +0100315 * two such numbers delimited by a dash ('-'). On success, it returns
316 * 0. otherwise it returns 1 with an error message in <err>.
Christopher Faulet62519022017-10-16 15:49:32 +0200317 *
318 * Note: this function can also be used to parse a thread number or a set of
319 * threads.
320 */
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100321int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200322{
Christopher Faulet26028f62017-11-22 15:01:51 +0100323 if (autoinc) {
324 *autoinc = 0;
325 if (strncmp(arg, "auto:", 5) == 0) {
326 arg += 5;
327 *autoinc = 1;
328 }
329 }
330
Christopher Faulet62519022017-10-16 15:49:32 +0200331 if (strcmp(arg, "all") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100332 *proc |= ~0UL;
Christopher Faulet62519022017-10-16 15:49:32 +0200333 else if (strcmp(arg, "odd") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100334 *proc |= ~0UL/3UL; /* 0x555....555 */
Christopher Faulet62519022017-10-16 15:49:32 +0200335 else if (strcmp(arg, "even") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100336 *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Christopher Faulet62519022017-10-16 15:49:32 +0200337 else {
Christopher Faulet18cca782019-02-07 16:29:41 +0100338 const char *p, *dash = NULL;
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100339 unsigned int low, high;
340
Christopher Faulet18cca782019-02-07 16:29:41 +0100341 for (p = arg; *p; p++) {
342 if (*p == '-' && !dash)
343 dash = p;
Willy Tarreau90807112020-02-25 08:16:33 +0100344 else if (!isdigit((unsigned char)*p)) {
Christopher Faulet18cca782019-02-07 16:29:41 +0100345 memprintf(err, "'%s' is not a valid number/range.", arg);
346 return -1;
347 }
Christopher Faulet5ab51772017-11-22 11:21:58 +0100348 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100349
350 low = high = str2uic(arg);
Christopher Faulet18cca782019-02-07 16:29:41 +0100351 if (dash)
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100352 high = ((!*(dash+1)) ? max : str2uic(dash + 1));
Christopher Fauletff4121f2017-11-22 16:38:49 +0100353
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100354 if (high < low) {
355 unsigned int swap = low;
356 low = high;
357 high = swap;
358 }
359
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100360 if (low < 1 || low > max || high > max) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100361 memprintf(err, "'%s' is not a valid number/range."
362 " It supports numbers from 1 to %d.\n",
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100363 arg, max);
Christopher Faulet5ab51772017-11-22 11:21:58 +0100364 return 1;
365 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100366
367 for (;low <= high; low++)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100368 *proc |= 1UL << (low-1);
Christopher Faulet62519022017-10-16 15:49:32 +0200369 }
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100370 *proc &= ~0UL >> (LONGBITS - max);
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100371
Christopher Faulet5ab51772017-11-22 11:21:58 +0100372 return 0;
Christopher Faulet62519022017-10-16 15:49:32 +0200373}
374
David Carlier7e351ee2017-12-01 09:14:02 +0000375#ifdef USE_CPU_AFFINITY
Christopher Faulet62519022017-10-16 15:49:32 +0200376/* Parse cpu sets. Each CPU set is either a unique number between 0 and
377 * <LONGBITS> or a range with two such numbers delimited by a dash
378 * ('-'). Multiple CPU numbers or ranges may be specified. On success, it
379 * returns 0. otherwise it returns 1 with an error message in <err>.
380 */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100381unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200382{
383 int cur_arg = 0;
384
385 *cpu_set = 0;
386 while (*args[cur_arg]) {
387 char *dash;
388 unsigned int low, high;
389
Willy Tarreau90807112020-02-25 08:16:33 +0100390 if (!isdigit((unsigned char)*args[cur_arg])) {
Christopher Faulet62519022017-10-16 15:49:32 +0200391 memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]);
392 return -1;
393 }
394
395 low = high = str2uic(args[cur_arg]);
396 if ((dash = strchr(args[cur_arg], '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100397 high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1));
Christopher Faulet62519022017-10-16 15:49:32 +0200398
399 if (high < low) {
400 unsigned int swap = low;
401 low = high;
402 high = swap;
403 }
404
405 if (high >= LONGBITS) {
406 memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1);
407 return 1;
408 }
409
410 while (low <= high)
411 *cpu_set |= 1UL << low++;
412
413 cur_arg++;
414 }
415 return 0;
416}
David Carlier7e351ee2017-12-01 09:14:02 +0000417#endif
418
Willy Tarreau915e1eb2009-06-22 15:48:36 +0200419void init_default_instance()
Willy Tarreaubaaee002006-06-26 02:48:02 +0200420{
Willy Tarreau97cb7802010-01-03 20:23:58 +0100421 init_new_proxy(&defproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200422 defproxy.mode = PR_MODE_TCP;
423 defproxy.state = PR_STNEW;
424 defproxy.maxconn = cfg_maxpconn;
425 defproxy.conn_retries = CONN_RETRIES;
Joseph Lynch726ab712015-05-11 23:25:34 -0700426 defproxy.redispatch_after = 0;
Olivier Houchard86006a52018-12-14 19:37:49 +0100427 defproxy.options = PR_O_REUSE_SAFE;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100428 defproxy.max_out_conns = MAX_SRV_LIST;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100429
Simon Horman66183002013-02-23 10:16:43 +0900430 defproxy.defsrv.check.inter = DEF_CHKINTR;
431 defproxy.defsrv.check.fastinter = 0;
432 defproxy.defsrv.check.downinter = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900433 defproxy.defsrv.agent.inter = DEF_CHKINTR;
434 defproxy.defsrv.agent.fastinter = 0;
435 defproxy.defsrv.agent.downinter = 0;
Simon Horman58c32972013-11-25 10:46:38 +0900436 defproxy.defsrv.check.rise = DEF_RISETIME;
437 defproxy.defsrv.check.fall = DEF_FALLTIME;
438 defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
439 defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200440 defproxy.defsrv.check.port = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900441 defproxy.defsrv.agent.port = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100442 defproxy.defsrv.maxqueue = 0;
443 defproxy.defsrv.minconn = 0;
444 defproxy.defsrv.maxconn = 0;
Willy Tarreau9c538e02019-01-23 10:21:49 +0100445 defproxy.defsrv.max_reuse = -1;
Olivier Houchard006e3102018-12-10 18:30:32 +0100446 defproxy.defsrv.max_idle_conns = -1;
Willy Tarreau975b1552019-06-06 16:25:55 +0200447 defproxy.defsrv.pool_purge_delay = 5000;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100448 defproxy.defsrv.slowstart = 0;
449 defproxy.defsrv.onerror = DEF_HANA_ONERR;
450 defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
451 defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
Simon Horman64e34162015-02-06 11:11:57 +0900452
453 defproxy.email_alert.level = LOG_ALERT;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +0200454 defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200455}
456
Frédéric Lécaille18251032019-01-11 11:07:15 +0100457/* Allocate and initialize the frontend of a "peers" section found in
458 * file <file> at line <linenum> with <id> as ID.
459 * Return 0 if succeeded, -1 if not.
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200460 * Note that this function may be called from "default-server"
461 * or "peer" lines.
Frédéric Lécaille18251032019-01-11 11:07:15 +0100462 */
463static int init_peers_frontend(const char *file, int linenum,
464 const char *id, struct peers *peers)
465{
466 struct proxy *p;
467
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200468 if (peers->peers_fe) {
469 p = peers->peers_fe;
470 goto out;
471 }
Frédéric Lécaille9492c4e2019-01-11 11:47:12 +0100472
Frédéric Lécaille18251032019-01-11 11:07:15 +0100473 p = calloc(1, sizeof *p);
474 if (!p) {
475 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
476 return -1;
477 }
478
479 init_new_proxy(p);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200480 peers_setup_frontend(p);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100481 p->parent = peers;
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200482 /* Finally store this frontend. */
483 peers->peers_fe = p;
484
485 out:
486 if (id && !p->id)
487 p->id = strdup(id);
Frédéric Lécaille1055e682018-04-26 14:35:21 +0200488 free(p->conf.file);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100489 p->conf.args.file = p->conf.file = strdup(file);
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100490 if (linenum != -1)
491 p->conf.args.line = p->conf.line = linenum;
Frédéric Lécaille18251032019-01-11 11:07:15 +0100492
493 return 0;
494}
Willy Tarreauade5ec42010-01-28 19:33:49 +0100495
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100496/* Only change ->file, ->line and ->arg struct bind_conf member values
497 * if already present.
498 */
499static struct bind_conf *bind_conf_uniq_alloc(struct proxy *p,
500 const char *file, int line,
501 const char *arg, struct xprt_ops *xprt)
502{
503 struct bind_conf *bind_conf;
504
505 if (!LIST_ISEMPTY(&p->conf.bind)) {
506 bind_conf = LIST_ELEM((&p->conf.bind)->n, typeof(bind_conf), by_fe);
507 free(bind_conf->file);
508 bind_conf->file = strdup(file);
509 bind_conf->line = line;
510 if (arg) {
511 free(bind_conf->arg);
512 bind_conf->arg = strdup(arg);
513 }
514 }
515 else {
516 bind_conf = bind_conf_alloc(p, file, line, arg, xprt);
517 }
518
519 return bind_conf;
520}
521
522/*
523 * Allocate a new struct peer parsed at line <linenum> in file <file>
524 * to be added to <peers>.
525 * Returns the new allocated structure if succeeded, NULL if not.
526 */
527static struct peer *cfg_peers_add_peer(struct peers *peers,
528 const char *file, int linenum,
529 const char *id, int local)
530{
531 struct peer *p;
532
533 p = calloc(1, sizeof *p);
534 if (!p) {
535 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
536 return NULL;
537 }
538
539 /* the peers are linked backwards first */
540 peers->count++;
541 p->next = peers->remote;
542 peers->remote = p;
543 p->conf.file = strdup(file);
544 p->conf.line = linenum;
545 p->last_change = now.tv_sec;
546 p->xprt = xprt_get(XPRT_RAW);
547 p->sock_init_arg = NULL;
548 HA_SPIN_INIT(&p->lock);
549 if (id)
550 p->id = strdup(id);
551 if (local) {
552 p->local = 1;
553 peers->local = p;
554 }
555
556 return p;
557}
558
Willy Tarreaubaaee002006-06-26 02:48:02 +0200559/*
William Lallemand51097192015-04-14 16:35:22 +0200560 * Parse a line in a <listen>, <frontend> or <backend> section.
Willy Tarreau93893792009-07-23 13:19:11 +0200561 * Returns the error code, 0 if OK, or any combination of :
562 * - ERR_ABORT: must abort ASAP
563 * - ERR_FATAL: we can continue parsing but not start the service
564 * - ERR_WARN: a warning has been emitted
565 * - ERR_ALERT: an alert has been emitted
566 * Only the two first ones can stop processing, the two others are just
567 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200568 */
Emeric Brun32da3c42010-09-23 18:39:19 +0200569int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
570{
571 static struct peers *curpeers = NULL;
572 struct peer *newpeer = NULL;
573 const char *err;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200574 struct bind_conf *bind_conf;
575 struct listener *l;
Emeric Brun32da3c42010-09-23 18:39:19 +0200576 int err_code = 0;
Willy Tarreau902636f2013-03-10 19:44:48 +0100577 char *errmsg = NULL;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100578 static int bind_line, peer_line;
579
580 if (strcmp(args[0], "bind") == 0 || strcmp(args[0], "default-bind") == 0) {
581 int cur_arg;
582 static int kws_dumped;
583 struct bind_conf *bind_conf;
584 struct bind_kw *kw;
Emeric Brun32da3c42010-09-23 18:39:19 +0200585
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100586 cur_arg = 1;
587
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200588 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
589 err_code |= ERR_ALERT | ERR_ABORT;
590 goto out;
591 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100592
593 bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum,
594 NULL, xprt_get(XPRT_RAW));
595 if (*args[0] == 'b') {
596 struct listener *l;
597
598 if (peer_line) {
599 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
600 err_code |= ERR_ALERT | ERR_FATAL;
601 goto out;
602 }
603
604 if (!str2listener(args[1], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
605 if (errmsg && *errmsg) {
606 indent_msg(&errmsg, 2);
607 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
608 }
609 else
610 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
611 file, linenum, args[0], args[1], args[2]);
612 err_code |= ERR_FATAL;
613 goto out;
614 }
615 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
616 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100617 l->accept = session_accept_fd;
618 l->analysers |= curpeers->peers_fe->fe_req_ana;
619 l->default_target = curpeers->peers_fe->default_target;
620 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100621 global.maxsock++; /* for the listening socket */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100622
623 bind_line = 1;
624 if (cfg_peers->local) {
625 newpeer = cfg_peers->local;
626 }
627 else {
628 /* This peer is local.
629 * Note that we do not set the peer ID. This latter is initialized
630 * when parsing "peer" or "server" line.
631 */
632 newpeer = cfg_peers_add_peer(curpeers, file, linenum, NULL, 1);
633 if (!newpeer) {
634 err_code |= ERR_ALERT | ERR_ABORT;
635 goto out;
636 }
637 }
Willy Tarreau37159062020-08-27 07:48:42 +0200638 newpeer->addr = l->rx.addr;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100639 newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
640 cur_arg++;
641 }
642
643 while (*args[cur_arg] && (kw = bind_find_kw(args[cur_arg]))) {
644 int ret;
645
646 ret = kw->parse(args, cur_arg, curpeers->peers_fe, bind_conf, &errmsg);
647 err_code |= ret;
648 if (ret) {
649 if (errmsg && *errmsg) {
650 indent_msg(&errmsg, 2);
651 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
652 }
653 else
654 ha_alert("parsing [%s:%d]: error encountered while processing '%s'\n",
655 file, linenum, args[cur_arg]);
656 if (ret & ERR_FATAL)
657 goto out;
658 }
659 cur_arg += 1 + kw->skip;
660 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100661 if (*args[cur_arg] != 0) {
Tim Duesterhus04bcaa12019-05-12 22:54:50 +0200662 char *kws = NULL;
663
664 if (!kws_dumped) {
665 kws_dumped = 1;
666 bind_dump_kws(&kws);
667 indent_msg(&kws, 4);
668 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100669 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section.%s%s\n",
670 file, linenum, args[cur_arg], cursection,
671 kws ? " Registered keywords :" : "", kws ? kws: "");
672 free(kws);
673 err_code |= ERR_ALERT | ERR_FATAL;
674 goto out;
675 }
676 }
677 else if (strcmp(args[0], "default-server") == 0) {
678 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
679 err_code |= ERR_ALERT | ERR_ABORT;
680 goto out;
681 }
Emeric Brund3db3842020-07-21 16:54:36 +0200682 err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, 0, 1, 1);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200683 }
Frédéric Lécailleb6f759b2019-11-05 09:57:45 +0100684 else if (strcmp(args[0], "log") == 0) {
685 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
686 err_code |= ERR_ALERT | ERR_ABORT;
687 goto out;
688 }
689 if (!parse_logsrv(args, &curpeers->peers_fe->logsrvs, (kwm == KWM_NO), &errmsg)) {
690 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
691 err_code |= ERR_ALERT | ERR_FATAL;
692 goto out;
693 }
694 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200695 else if (strcmp(args[0], "peers") == 0) { /* new peers section */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100696 /* Initialize these static variables when entering a new "peers" section*/
697 bind_line = peer_line = 0;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100698 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100699 ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum);
Willy Tarreau54984722014-02-16 08:20:13 +0100700 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100701 goto out;
702 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200703
William Lallemand6e62fb62015-04-28 16:55:23 +0200704 if (alertif_too_many_args(1, file, linenum, args, &err_code))
705 goto out;
706
Emeric Brun32da3c42010-09-23 18:39:19 +0200707 err = invalid_char(args[1]);
708 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100709 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
710 file, linenum, *err, args[0], args[1]);
Willy Tarreau54984722014-02-16 08:20:13 +0100711 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100712 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200713 }
714
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200715 for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +0200716 /*
717 * If there are two proxies with the same name only following
718 * combinations are allowed:
719 */
720 if (strcmp(curpeers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100721 ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n",
722 file, linenum, args[1], curpeers->conf.file, curpeers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +0200723 err_code |= ERR_ALERT | ERR_FATAL;
Emeric Brun32da3c42010-09-23 18:39:19 +0200724 }
725 }
726
Vincent Bernat02779b62016-04-03 13:48:43 +0200727 if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100728 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +0200729 err_code |= ERR_ALERT | ERR_ABORT;
730 goto out;
731 }
732
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200733 curpeers->next = cfg_peers;
734 cfg_peers = curpeers;
Willy Tarreau8113a5d2012-10-04 08:01:43 +0200735 curpeers->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +0200736 curpeers->conf.line = linenum;
737 curpeers->last_change = now.tv_sec;
738 curpeers->id = strdup(args[1]);
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200739 curpeers->state = PR_STNEW;
Emeric Brun32da3c42010-09-23 18:39:19 +0200740 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200741 else if (strcmp(args[0], "peer") == 0 ||
742 strcmp(args[0], "server") == 0) { /* peer or server definition */
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100743 int local_peer, peer;
Emeric Brun32da3c42010-09-23 18:39:19 +0200744
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100745 peer = *args[0] == 'p';
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100746 local_peer = !strcmp(args[1], localpeer);
747 /* The local peer may have already partially been parsed on a "bind" line. */
748 if (*args[0] == 'p') {
749 if (bind_line) {
750 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
751 err_code |= ERR_ALERT | ERR_FATAL;
752 goto out;
753 }
754 peer_line = 1;
755 }
756 if (cfg_peers->local && !cfg_peers->local->id && local_peer) {
757 /* The local peer has already been initialized on a "bind" line.
758 * Let's use it and store its ID.
759 */
760 newpeer = cfg_peers->local;
761 newpeer->id = strdup(localpeer);
762 }
763 else {
764 if (local_peer && cfg_peers->local) {
765 ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d. %s\n",
766 file, linenum, args[0], args[1],
767 curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line, cfg_peers->local->id);
768 err_code |= ERR_FATAL;
769 goto out;
770 }
771 newpeer = cfg_peers_add_peer(curpeers, file, linenum, args[1], local_peer);
772 if (!newpeer) {
773 err_code |= ERR_ALERT | ERR_ABORT;
774 goto out;
775 }
776 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200777
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100778 /* Line number and peer ID are updated only if this peer is the local one. */
779 if (init_peers_frontend(file,
780 newpeer->local ? linenum: -1,
781 newpeer->local ? newpeer->id : NULL,
782 curpeers) != 0) {
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200783 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreaub36487e2013-03-10 18:37:42 +0100784 goto out;
785 }
Willy Tarreau2aa38802013-02-20 19:20:59 +0100786
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100787 /* This initializes curpeer->peers->peers_fe->srv.
788 * The server address is parsed only if we are parsing a "peer" line,
789 * or if we are parsing a "server" line and the current peer is not the local one.
790 */
Emeric Brund3db3842020-07-21 16:54:36 +0200791 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 +0200792 if (!curpeers->peers_fe->srv) {
793 /* Remove the newly allocated peer. */
794 if (newpeer != curpeers->local) {
795 struct peer *p;
796
797 p = curpeers->remote;
798 curpeers->remote = curpeers->remote->next;
799 free(p->id);
800 free(p);
801 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200802 goto out;
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200803 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200804
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100805 /* If the peer address has just been parsed, let's copy it to <newpeer>
806 * and initializes ->proto.
807 */
808 if (peer || !local_peer) {
809 newpeer->addr = curpeers->peers_fe->srv->addr;
810 newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
811 }
812
Willy Tarreaua261e9b2016-12-22 20:44:00 +0100813 newpeer->xprt = xprt_get(XPRT_RAW);
Willy Tarreaud02394b2012-05-11 18:32:18 +0200814 newpeer->sock_init_arg = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100815 HA_SPIN_INIT(&newpeer->lock);
Willy Tarreau26d8c592012-05-07 18:12:14 +0200816
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100817 newpeer->srv = curpeers->peers_fe->srv;
818 if (!newpeer->local)
Frédéric Lécaille6617e762018-04-25 15:13:38 +0200819 goto out;
820
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100821 /* The lines above are reserved to "peer" lines. */
822 if (*args[0] == 's')
Frédéric Lécaille4ba51982018-04-25 15:32:18 +0200823 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200824
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100825 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 +0100826
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100827 if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
828 if (errmsg && *errmsg) {
829 indent_msg(&errmsg, 2);
830 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 +0100831 }
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100832 else
833 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
834 file, linenum, args[0], args[1], args[2]);
835 err_code |= ERR_FATAL;
836 goto out;
837 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100838
839 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
840 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100841 l->accept = session_accept_fd;
842 l->analysers |= curpeers->peers_fe->fe_req_ana;
843 l->default_target = curpeers->peers_fe->default_target;
844 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100845 global.maxsock++; /* for the listening socket */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100846 }
847 else if (!strcmp(args[0], "table")) {
848 struct stktable *t, *other;
849 char *id;
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100850 size_t prefix_len;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100851
852 /* Line number and peer ID are updated only if this peer is the local one. */
853 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
854 err_code |= ERR_ALERT | ERR_ABORT;
855 goto out;
856 }
857
858 other = stktable_find_by_name(args[1]);
859 if (other) {
860 ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
861 file, linenum, args[1],
862 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
863 other->proxy ? other->id : other->peers.p->id,
864 other->conf.file, other->conf.line);
865 err_code |= ERR_ALERT | ERR_FATAL;
866 goto out;
867 }
868
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100869 /* Build the stick-table name, concatenating the "peers" section name
870 * followed by a '/' character and the table name argument.
871 */
872 chunk_reset(&trash);
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100873 if (!chunk_strcpy(&trash, curpeers->id)) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100874 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
875 file, linenum, args[0], args[1]);
876 err_code |= ERR_ALERT | ERR_FATAL;
877 goto out;
878 }
879
880 prefix_len = trash.data;
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100881 if (!chunk_memcat(&trash, "/", 1) || !chunk_strcat(&trash, args[1])) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100882 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
883 file, linenum, args[0], args[1]);
884 err_code |= ERR_ALERT | ERR_FATAL;
885 goto out;
886 }
887
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100888 t = calloc(1, sizeof *t);
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100889 id = strdup(trash.area);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100890 if (!t || !id) {
891 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
892 file, linenum, args[0], args[1]);
893 err_code |= ERR_ALERT | ERR_FATAL;
894 goto out;
895 }
896
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100897 err_code |= parse_stick_table(file, linenum, args, t, id, id + prefix_len, curpeers);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100898 if (err_code & ERR_FATAL)
899 goto out;
900
901 stktable_store_name(t);
902 t->next = stktables_list;
903 stktables_list = t;
904 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200905 else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
906 curpeers->state = PR_STSTOPPED;
907 }
908 else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
909 curpeers->state = PR_STNEW;
910 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200911 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100912 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Emeric Brun32da3c42010-09-23 18:39:19 +0200913 err_code |= ERR_ALERT | ERR_FATAL;
914 goto out;
915 }
916
917out:
Willy Tarreau902636f2013-03-10 19:44:48 +0100918 free(errmsg);
Emeric Brun32da3c42010-09-23 18:39:19 +0200919 return err_code;
920}
921
Baptiste Assmann325137d2015-04-13 23:40:55 +0200922/*
923 * Parse a <resolvers> section.
924 * Returns the error code, 0 if OK, or any combination of :
925 * - ERR_ABORT: must abort ASAP
926 * - ERR_FATAL: we can continue parsing but not start the service
927 * - ERR_WARN: a warning has been emitted
928 * - ERR_ALERT: an alert has been emitted
929 * Only the two first ones can stop processing, the two others are just
930 * indicators.
931 */
932int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
933{
934 static struct dns_resolvers *curr_resolvers = NULL;
935 struct dns_nameserver *newnameserver = NULL;
936 const char *err;
937 int err_code = 0;
938 char *errmsg = NULL;
939
940 if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */
941 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100942 ha_alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200943 err_code |= ERR_ALERT | ERR_ABORT;
944 goto out;
945 }
946
947 err = invalid_char(args[1]);
948 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100949 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
950 file, linenum, *err, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200951 err_code |= ERR_ALERT | ERR_ABORT;
952 goto out;
953 }
954
955 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
956 /* Error if two resolvers owns the same name */
957 if (strcmp(curr_resolvers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100958 ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n",
959 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200960 err_code |= ERR_ALERT | ERR_ABORT;
961 }
962 }
963
Vincent Bernat02779b62016-04-03 13:48:43 +0200964 if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100965 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200966 err_code |= ERR_ALERT | ERR_ABORT;
967 goto out;
968 }
969
970 /* default values */
971 LIST_ADDQ(&dns_resolvers, &curr_resolvers->list);
972 curr_resolvers->conf.file = strdup(file);
973 curr_resolvers->conf.line = linenum;
974 curr_resolvers->id = strdup(args[1]);
975 curr_resolvers->query_ids = EB_ROOT;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +0200976 /* default maximum response size */
977 curr_resolvers->accepted_payload_size = 512;
Baptiste Assmann987e16d2016-11-02 22:23:31 +0100978 /* default hold period for nx, other, refuse and timeout is 30s */
979 curr_resolvers->hold.nx = 30000;
980 curr_resolvers->hold.other = 30000;
981 curr_resolvers->hold.refused = 30000;
982 curr_resolvers->hold.timeout = 30000;
Baptiste Assmann686408b2017-08-18 10:15:42 +0200983 curr_resolvers->hold.obsolete = 0;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200984 /* default hold period for valid is 10s */
Baptiste Assmann4c5490a2015-07-14 21:42:49 +0200985 curr_resolvers->hold.valid = 10000;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200986 curr_resolvers->timeout.resolve = 1000;
987 curr_resolvers->timeout.retry = 1000;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200988 curr_resolvers->resolve_retries = 3;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200989 curr_resolvers->nb_nameservers = 0;
990 LIST_INIT(&curr_resolvers->nameservers);
991 LIST_INIT(&curr_resolvers->resolutions.curr);
992 LIST_INIT(&curr_resolvers->resolutions.wait);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100993 HA_SPIN_INIT(&curr_resolvers->lock);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200994 }
995 else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
996 struct sockaddr_storage *sk;
997 int port1, port2;
998 struct protocol *proto;
999
1000 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001001 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1002 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001003 err_code |= ERR_ALERT | ERR_FATAL;
1004 goto out;
1005 }
1006
1007 err = invalid_char(args[1]);
1008 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001009 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1010 file, linenum, *err, args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001011 err_code |= ERR_ALERT | ERR_FATAL;
1012 goto out;
1013 }
1014
Christopher Faulet67957bd2017-09-27 11:00:59 +02001015 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
Baptiste Assmanna315c552015-11-02 22:55:49 +01001016 /* Error if two resolvers owns the same name */
1017 if (strcmp(newnameserver->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001018 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 -06001019 file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line);
Baptiste Assmanna315c552015-11-02 22:55:49 +01001020 err_code |= ERR_ALERT | ERR_FATAL;
1021 }
1022 }
1023
Vincent Bernat02779b62016-04-03 13:48:43 +02001024 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001025 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001026 err_code |= ERR_ALERT | ERR_ABORT;
1027 goto out;
1028 }
1029
1030 /* the nameservers are linked backward first */
Christopher Faulet67957bd2017-09-27 11:00:59 +02001031 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001032 newnameserver->resolvers = curr_resolvers;
1033 newnameserver->conf.file = strdup(file);
1034 newnameserver->conf.line = linenum;
1035 newnameserver->id = strdup(args[1]);
1036
Willy Tarreau48ef4c92017-01-06 18:32:38 +01001037 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001038 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001039 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001040 err_code |= ERR_ALERT | ERR_FATAL;
1041 goto out;
1042 }
1043
Willy Tarreaue42d87f2020-09-16 20:04:17 +02001044 /* handle nicely the case where "udp@" is forced */
1045 if (sk->ss_family == AF_CUST_UDP4)
1046 sk->ss_family = AF_INET;
1047 else if (sk->ss_family == AF_CUST_UDP6)
1048 sk->ss_family = AF_INET6;
1049
Baptiste Assmann325137d2015-04-13 23:40:55 +02001050 proto = protocol_by_family(sk->ss_family);
Willy Tarreaue42d87f2020-09-16 20:04:17 +02001051 if (!proto) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001052 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
Baptiste Assmann325137d2015-04-13 23:40:55 +02001053 file, linenum, args[0], args[1]);
1054 err_code |= ERR_ALERT | ERR_FATAL;
1055 goto out;
1056 }
1057
1058 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001059 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
1060 file, linenum, args[0], args[1], args[2]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001061 err_code |= ERR_ALERT | ERR_FATAL;
1062 goto out;
1063 }
1064
Baptiste Assmann7f43fa92016-01-21 00:59:46 +01001065 if (!port1 && !port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001066 ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n",
1067 file, linenum, args[0], args[1]);
Baptiste Assmann7f43fa92016-01-21 00:59:46 +01001068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071
Baptiste Assmann325137d2015-04-13 23:40:55 +02001072 newnameserver->addr = *sk;
1073 }
Ben Draut44e609b2018-05-29 15:40:08 -06001074 else if (strcmp(args[0], "parse-resolv-conf") == 0) {
1075 const char *whitespace = "\r\n\t ";
1076 char *resolv_line = NULL;
1077 int resolv_linenum = 0;
1078 FILE *f = NULL;
1079 char *address = NULL;
1080 struct sockaddr_storage *sk = NULL;
1081 struct protocol *proto;
1082 int duplicate_name = 0;
1083
1084 if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) {
1085 ha_alert("parsing [%s:%d] : out of memory.\n",
1086 file, linenum);
1087 err_code |= ERR_ALERT | ERR_FATAL;
1088 goto resolv_out;
1089 }
1090
1091 if ((f = fopen("/etc/resolv.conf", "r")) == NULL) {
1092 ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n",
1093 file, linenum);
1094 err_code |= ERR_ALERT | ERR_FATAL;
1095 goto resolv_out;
1096 }
1097
1098 sk = calloc(1, sizeof(*sk));
1099 if (sk == NULL) {
1100 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n",
1101 resolv_linenum);
1102 err_code |= ERR_ALERT | ERR_FATAL;
1103 goto resolv_out;
1104 }
1105
1106 while (fgets(resolv_line, LINESIZE, f) != NULL) {
1107 resolv_linenum++;
1108 if (strncmp(resolv_line, "nameserver", 10) != 0)
1109 continue;
1110
1111 address = strtok(resolv_line + 10, whitespace);
1112 if (address == resolv_line + 10)
1113 continue;
1114
1115 if (address == NULL) {
1116 ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n",
1117 resolv_linenum);
1118 err_code |= ERR_WARN;
1119 continue;
1120 }
1121
1122 duplicate_name = 0;
1123 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
1124 if (strcmp(newnameserver->id, address) == 0) {
1125 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",
1126 resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line);
1127 err_code |= ERR_WARN;
1128 duplicate_name = 1;
1129 }
1130 }
1131
1132 if (duplicate_name)
1133 continue;
1134
1135 memset(sk, 0, sizeof(*sk));
Willy Tarreau78675252020-05-28 18:07:10 +02001136 if (!str2ip2(address, sk, 1)) {
1137 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 -06001138 resolv_linenum, address);
1139 err_code |= ERR_WARN;
1140 continue;
1141 }
1142
1143 set_host_port(sk, 53);
1144
1145 proto = protocol_by_family(sk->ss_family);
1146 if (!proto || !proto->connect) {
1147 ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n",
1148 resolv_linenum, address);
1149 err_code |= ERR_WARN;
1150 continue;
1151 }
1152
1153 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
1154 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1155 err_code |= ERR_ALERT | ERR_FATAL;
1156 goto resolv_out;
1157 }
1158
1159 newnameserver->conf.file = strdup("/etc/resolv.conf");
1160 if (newnameserver->conf.file == NULL) {
1161 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1162 err_code |= ERR_ALERT | ERR_FATAL;
1163 goto resolv_out;
1164 }
1165
1166 newnameserver->id = strdup(address);
1167 if (newnameserver->id == NULL) {
1168 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1169 err_code |= ERR_ALERT | ERR_FATAL;
1170 goto resolv_out;
1171 }
1172
1173 newnameserver->resolvers = curr_resolvers;
1174 newnameserver->conf.line = resolv_linenum;
1175 newnameserver->addr = *sk;
1176
1177 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
1178 }
1179
1180resolv_out:
1181 free(sk);
1182 free(resolv_line);
1183 if (f != NULL)
1184 fclose(f);
1185 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001186 else if (strcmp(args[0], "hold") == 0) { /* hold periods */
1187 const char *res;
1188 unsigned int time;
1189
1190 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001191 ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n",
1192 file, linenum, args[0]);
1193 ha_alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n");
Baptiste Assmann325137d2015-04-13 23:40:55 +02001194 err_code |= ERR_ALERT | ERR_FATAL;
1195 goto out;
1196 }
1197 res = parse_time_err(args[2], &time, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001198 if (res == PARSE_TIME_OVER) {
1199 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1200 file, linenum, args[1], args[0]);
1201 err_code |= ERR_ALERT | ERR_FATAL;
1202 goto out;
1203 }
1204 else if (res == PARSE_TIME_UNDER) {
1205 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1206 file, linenum, args[1], args[0]);
1207 err_code |= ERR_ALERT | ERR_FATAL;
1208 goto out;
1209 }
1210 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001211 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
1212 file, linenum, *res, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001213 err_code |= ERR_ALERT | ERR_FATAL;
1214 goto out;
1215 }
Baptiste Assmann987e16d2016-11-02 22:23:31 +01001216 if (strcmp(args[1], "nx") == 0)
1217 curr_resolvers->hold.nx = time;
1218 else if (strcmp(args[1], "other") == 0)
1219 curr_resolvers->hold.other = time;
1220 else if (strcmp(args[1], "refused") == 0)
1221 curr_resolvers->hold.refused = time;
1222 else if (strcmp(args[1], "timeout") == 0)
1223 curr_resolvers->hold.timeout = time;
1224 else if (strcmp(args[1], "valid") == 0)
Baptiste Assmann325137d2015-04-13 23:40:55 +02001225 curr_resolvers->hold.valid = time;
Olivier Houcharda8c6db82017-07-06 18:46:47 +02001226 else if (strcmp(args[1], "obsolete") == 0)
1227 curr_resolvers->hold.obsolete = time;
Baptiste Assmann325137d2015-04-13 23:40:55 +02001228 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001229 ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n",
1230 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001231 err_code |= ERR_ALERT | ERR_FATAL;
1232 goto out;
1233 }
1234
1235 }
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001236 else if (strcmp(args[0], "accepted_payload_size") == 0) {
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001237 int i = 0;
1238
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001239 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001240 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1241 file, linenum, args[0]);
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001242 err_code |= ERR_ALERT | ERR_FATAL;
1243 goto out;
1244 }
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001245
1246 i = atoi(args[1]);
Willy Tarreau0c219be2017-08-22 12:01:26 +02001247 if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001248 ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n",
1249 file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]);
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001250 err_code |= ERR_ALERT | ERR_FATAL;
1251 goto out;
1252 }
1253
1254 curr_resolvers->accepted_payload_size = i;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001255 }
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001256 else if (strcmp(args[0], "resolution_pool_size") == 0) {
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001257 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 +01001258 file, linenum, args[0]);
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001259 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001260 goto out;
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001261 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001262 else if (strcmp(args[0], "resolve_retries") == 0) {
1263 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001264 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1265 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001266 err_code |= ERR_ALERT | ERR_FATAL;
1267 goto out;
1268 }
1269 curr_resolvers->resolve_retries = atoi(args[1]);
1270 }
1271 else if (strcmp(args[0], "timeout") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001272 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001273 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n",
1274 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001275 err_code |= ERR_ALERT | ERR_FATAL;
1276 goto out;
1277 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001278 else if (strcmp(args[1], "retry") == 0 ||
1279 strcmp(args[1], "resolve") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001280 const char *res;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001281 unsigned int tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001282
1283 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001284 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1285 file, linenum, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001289 res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001290 if (res == PARSE_TIME_OVER) {
1291 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1292 file, linenum, args[2], args[0], args[1]);
1293 err_code |= ERR_ALERT | ERR_FATAL;
1294 goto out;
1295 }
1296 else if (res == PARSE_TIME_UNDER) {
1297 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1298 file, linenum, args[2], args[0], args[1]);
1299 err_code |= ERR_ALERT | ERR_FATAL;
1300 goto out;
1301 }
1302 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001303 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1304 file, linenum, *res, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001305 err_code |= ERR_ALERT | ERR_FATAL;
1306 goto out;
1307 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001308 if (args[1][2] == 't')
1309 curr_resolvers->timeout.retry = tout;
1310 else
1311 curr_resolvers->timeout.resolve = tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001312 }
1313 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001314 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n",
1315 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001316 err_code |= ERR_ALERT | ERR_FATAL;
1317 goto out;
1318 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001319 } /* neither "nameserver" nor "resolvers" */
1320 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001321 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325
1326 out:
1327 free(errmsg);
1328 return err_code;
1329}
Simon Horman0d16a402015-01-30 11:22:58 +09001330
1331/*
William Lallemand51097192015-04-14 16:35:22 +02001332 * Parse a line in a <listen>, <frontend> or <backend> section.
Simon Horman0d16a402015-01-30 11:22:58 +09001333 * Returns the error code, 0 if OK, or any combination of :
1334 * - ERR_ABORT: must abort ASAP
1335 * - ERR_FATAL: we can continue parsing but not start the service
1336 * - ERR_WARN: a warning has been emitted
1337 * - ERR_ALERT: an alert has been emitted
1338 * Only the two first ones can stop processing, the two others are just
1339 * indicators.
1340 */
1341int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
1342{
1343 static struct mailers *curmailers = NULL;
1344 struct mailer *newmailer = NULL;
1345 const char *err;
1346 int err_code = 0;
1347 char *errmsg = NULL;
1348
1349 if (strcmp(args[0], "mailers") == 0) { /* new mailers section */
1350 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001351 ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001352 err_code |= ERR_ALERT | ERR_ABORT;
1353 goto out;
1354 }
1355
1356 err = invalid_char(args[1]);
1357 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001358 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1359 file, linenum, *err, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001360 err_code |= ERR_ALERT | ERR_ABORT;
1361 goto out;
1362 }
1363
1364 for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) {
1365 /*
1366 * If there are two proxies with the same name only following
1367 * combinations are allowed:
1368 */
1369 if (strcmp(curmailers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001370 ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n",
1371 file, linenum, args[1], curmailers->conf.file, curmailers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02001372 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman0d16a402015-01-30 11:22:58 +09001373 }
1374 }
1375
Vincent Bernat02779b62016-04-03 13:48:43 +02001376 if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001377 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001378 err_code |= ERR_ALERT | ERR_ABORT;
1379 goto out;
1380 }
1381
1382 curmailers->next = mailers;
1383 mailers = curmailers;
1384 curmailers->conf.file = strdup(file);
1385 curmailers->conf.line = linenum;
1386 curmailers->id = strdup(args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001387 curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
1388 * But need enough time so that timeouts don't occur
1389 * during tcp procssing. For now just us an arbitrary default. */
Simon Horman0d16a402015-01-30 11:22:58 +09001390 }
1391 else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
1392 struct sockaddr_storage *sk;
1393 int port1, port2;
1394 struct protocol *proto;
1395
1396 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001397 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1398 file, linenum, args[0]);
Simon Horman0d16a402015-01-30 11:22:58 +09001399 err_code |= ERR_ALERT | ERR_FATAL;
1400 goto out;
1401 }
1402
1403 err = invalid_char(args[1]);
1404 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001405 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1406 file, linenum, *err, args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001407 err_code |= ERR_ALERT | ERR_FATAL;
1408 goto out;
1409 }
1410
Vincent Bernat02779b62016-04-03 13:48:43 +02001411 if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001412 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001413 err_code |= ERR_ALERT | ERR_ABORT;
1414 goto out;
1415 }
1416
1417 /* the mailers are linked backwards first */
1418 curmailers->count++;
1419 newmailer->next = curmailers->mailer_list;
1420 curmailers->mailer_list = newmailer;
1421 newmailer->mailers = curmailers;
1422 newmailer->conf.file = strdup(file);
1423 newmailer->conf.line = linenum;
1424
1425 newmailer->id = strdup(args[1]);
1426
Willy Tarreau48ef4c92017-01-06 18:32:38 +01001427 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Simon Horman0d16a402015-01-30 11:22:58 +09001428 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001429 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Simon Horman0d16a402015-01-30 11:22:58 +09001430 err_code |= ERR_ALERT | ERR_FATAL;
1431 goto out;
1432 }
1433
1434 proto = protocol_by_family(sk->ss_family);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09001435 if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001436 ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n",
1437 file, linenum, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001438 err_code |= ERR_ALERT | ERR_FATAL;
1439 goto out;
1440 }
1441
1442 if (port1 != port2) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001443 ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
1444 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09001445 err_code |= ERR_ALERT | ERR_FATAL;
1446 goto out;
1447 }
1448
1449 if (!port1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001450 ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
1451 file, linenum, args[0], args[1], args[2]);
Simon Horman0d16a402015-01-30 11:22:58 +09001452 err_code |= ERR_ALERT | ERR_FATAL;
1453 goto out;
1454 }
1455
1456 newmailer->addr = *sk;
1457 newmailer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01001458 newmailer->xprt = xprt_get(XPRT_RAW);
Simon Horman0d16a402015-01-30 11:22:58 +09001459 newmailer->sock_init_arg = NULL;
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001460 }
1461 else if (strcmp(args[0], "timeout") == 0) {
1462 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001463 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
1464 file, linenum, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001465 err_code |= ERR_ALERT | ERR_FATAL;
1466 goto out;
1467 }
1468 else if (strcmp(args[1], "mail") == 0) {
1469 const char *res;
1470 unsigned int timeout_mail;
1471 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001472 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1473 file, linenum, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001474 err_code |= ERR_ALERT | ERR_FATAL;
1475 goto out;
1476 }
1477 res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001478 if (res == PARSE_TIME_OVER) {
1479 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1480 file, linenum, args[2], args[0], args[1]);
1481 err_code |= ERR_ALERT | ERR_FATAL;
1482 goto out;
1483 }
1484 else if (res == PARSE_TIME_UNDER) {
1485 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1486 file, linenum, args[2], args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001487 err_code |= ERR_ALERT | ERR_FATAL;
1488 goto out;
1489 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001490 else if (res) {
1491 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1492 file, linenum, *res, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001493 err_code |= ERR_ALERT | ERR_FATAL;
1494 goto out;
1495 }
1496 curmailers->timeout.mail = timeout_mail;
1497 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001498 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001499 file, linenum, args[0], args[1]);
1500 err_code |= ERR_ALERT | ERR_FATAL;
1501 goto out;
1502 }
1503 }
Simon Horman0d16a402015-01-30 11:22:58 +09001504 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001505 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Simon Horman0d16a402015-01-30 11:22:58 +09001506 err_code |= ERR_ALERT | ERR_FATAL;
1507 goto out;
1508 }
1509
1510out:
1511 free(errmsg);
1512 return err_code;
1513}
1514
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001515void free_email_alert(struct proxy *p)
Simon Horman9dc49962015-01-30 11:22:59 +09001516{
1517 free(p->email_alert.mailers.name);
1518 p->email_alert.mailers.name = NULL;
1519 free(p->email_alert.from);
1520 p->email_alert.from = NULL;
1521 free(p->email_alert.to);
1522 p->email_alert.to = NULL;
1523 free(p->email_alert.myhostname);
1524 p->email_alert.myhostname = NULL;
1525}
1526
Willy Tarreaubaaee002006-06-26 02:48:02 +02001527
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001528int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001529cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
1530{
Willy Tarreaue5733232019-05-22 19:24:06 +02001531#ifdef USE_NS
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001532 const char *err;
1533 const char *item = args[0];
1534
1535 if (!strcmp(item, "namespace_list")) {
1536 return 0;
1537 }
1538 else if (!strcmp(item, "namespace")) {
1539 size_t idx = 1;
1540 const char *current;
1541 while (*(current = args[idx++])) {
1542 err = invalid_char(current);
1543 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001544 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1545 file, linenum, *err, item, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001546 return ERR_ALERT | ERR_FATAL;
1547 }
1548
1549 if (netns_store_lookup(current, strlen(current))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001550 ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
1551 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001552 return ERR_ALERT | ERR_FATAL;
1553 }
1554 if (!netns_store_insert(current)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001555 ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
1556 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001557 return ERR_ALERT | ERR_FATAL;
1558 }
1559 }
1560 }
1561
1562 return 0;
1563#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001564 ha_alert("parsing [%s:%d]: namespace support is not compiled in.",
1565 file, linenum);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001566 return ERR_ALERT | ERR_FATAL;
1567#endif
1568}
1569
1570int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001571cfg_parse_users(const char *file, int linenum, char **args, int kwm)
1572{
1573
1574 int err_code = 0;
1575 const char *err;
1576
1577 if (!strcmp(args[0], "userlist")) { /* new userlist */
1578 struct userlist *newul;
1579
1580 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001581 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1582 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001583 err_code |= ERR_ALERT | ERR_FATAL;
1584 goto out;
1585 }
William Lallemand6e62fb62015-04-28 16:55:23 +02001586 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1587 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001588
1589 err = invalid_char(args[1]);
1590 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001591 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1592 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001593 err_code |= ERR_ALERT | ERR_FATAL;
1594 goto out;
1595 }
1596
1597 for (newul = userlist; newul; newul = newul->next)
1598 if (!strcmp(newul->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001599 ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
1600 file, linenum, args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001601 err_code |= ERR_WARN;
1602 goto out;
1603 }
1604
Vincent Bernat02779b62016-04-03 13:48:43 +02001605 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001606 if (!newul) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001607 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001608 err_code |= ERR_ALERT | ERR_ABORT;
1609 goto out;
1610 }
1611
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001612 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001613 if (!newul->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001614 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001615 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01001616 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001617 goto out;
1618 }
1619
1620 newul->next = userlist;
1621 userlist = newul;
1622
1623 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001624 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001625 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001626 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001627
1628 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001629 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1630 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001631 err_code |= ERR_ALERT | ERR_FATAL;
1632 goto out;
1633 }
1634
1635 err = invalid_char(args[1]);
1636 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001637 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1638 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001639 err_code |= ERR_ALERT | ERR_FATAL;
1640 goto out;
1641 }
1642
William Lallemand4ac9f542015-05-28 18:03:51 +02001643 if (!userlist)
1644 goto out;
1645
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001646 for (ag = userlist->groups; ag; ag = ag->next)
1647 if (!strcmp(ag->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001648 ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
1649 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001650 err_code |= ERR_ALERT;
1651 goto out;
1652 }
1653
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001654 ag = calloc(1, sizeof(*ag));
1655 if (!ag) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001656 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001657 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001658 goto out;
1659 }
1660
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001661 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01001662 if (!ag->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001663 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001664 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01001665 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001666 goto out;
1667 }
1668
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001669 cur_arg = 2;
1670
1671 while (*args[cur_arg]) {
1672 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001673 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001674 cur_arg += 2;
1675 continue;
1676 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001677 ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
1678 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001679 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01001680 free(ag->groupusers);
1681 free(ag->name);
1682 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001683 goto out;
1684 }
1685 }
1686
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001687 ag->next = userlist->groups;
1688 userlist->groups = ag;
1689
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001690 } else if (!strcmp(args[0], "user")) { /* new user */
1691 struct auth_users *newuser;
1692 int cur_arg;
1693
1694 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001695 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1696 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001697 err_code |= ERR_ALERT | ERR_FATAL;
1698 goto out;
1699 }
William Lallemand4ac9f542015-05-28 18:03:51 +02001700 if (!userlist)
1701 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001702
1703 for (newuser = userlist->users; newuser; newuser = newuser->next)
1704 if (!strcmp(newuser->user, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001705 ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
1706 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001707 err_code |= ERR_ALERT;
1708 goto out;
1709 }
1710
Vincent Bernat02779b62016-04-03 13:48:43 +02001711 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001712 if (!newuser) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001713 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001714 err_code |= ERR_ALERT | ERR_ABORT;
1715 goto out;
1716 }
1717
1718 newuser->user = strdup(args[1]);
1719
1720 newuser->next = userlist->users;
1721 userlist->users = newuser;
1722
1723 cur_arg = 2;
1724
1725 while (*args[cur_arg]) {
1726 if (!strcmp(args[cur_arg], "password")) {
Willy Tarreaue5733232019-05-22 19:24:06 +02001727#ifdef USE_LIBCRYPT
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001728 if (!crypt("", args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001729 ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
1730 file, linenum, newuser->user);
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001731 err_code |= ERR_ALERT | ERR_FATAL;
1732 goto out;
1733 }
1734#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001735 ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
1736 file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001737 err_code |= ERR_ALERT;
1738#endif
1739 newuser->pass = strdup(args[cur_arg + 1]);
1740 cur_arg += 2;
1741 continue;
1742 } else if (!strcmp(args[cur_arg], "insecure-password")) {
1743 newuser->pass = strdup(args[cur_arg + 1]);
1744 newuser->flags |= AU_O_INSECURE;
1745 cur_arg += 2;
1746 continue;
1747 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001748 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001749 cur_arg += 2;
1750 continue;
1751 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001752 ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
1753 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001754 err_code |= ERR_ALERT | ERR_FATAL;
1755 goto out;
1756 }
1757 }
1758 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001759 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 +01001760 err_code |= ERR_ALERT | ERR_FATAL;
1761 }
1762
1763out:
1764 return err_code;
1765}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001766
Christopher Faulet79bdef32016-11-04 22:36:15 +01001767int
1768cfg_parse_scope(const char *file, int linenum, char *line)
1769{
1770 char *beg, *end, *scope = NULL;
1771 int err_code = 0;
1772 const char *err;
1773
1774 beg = line + 1;
1775 end = strchr(beg, ']');
1776
1777 /* Detect end of scope declaration */
1778 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001779 ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n",
1780 file, linenum);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001781 err_code |= ERR_ALERT | ERR_FATAL;
1782 goto out;
1783 }
1784
1785 /* Get scope name and check its validity */
1786 scope = my_strndup(beg, end-beg);
1787 err = invalid_char(scope);
1788 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001789 ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
1790 file, linenum, *err);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001791 err_code |= ERR_ALERT | ERR_ABORT;
1792 goto out;
1793 }
1794
1795 /* Be sure to have a scope declaration alone on its line */
1796 line = end+1;
1797 while (isspace((unsigned char)*line))
1798 line++;
1799 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001800 ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
1801 file, linenum, *line);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001802 err_code |= ERR_ALERT | ERR_ABORT;
1803 goto out;
1804 }
1805
1806 /* We have a valid scope declaration, save it */
1807 free(cfg_scope);
1808 cfg_scope = scope;
1809 scope = NULL;
1810
1811 out:
1812 free(scope);
1813 return err_code;
1814}
1815
Frédéric Lécaillea41d5312018-01-29 12:05:07 +01001816int
1817cfg_parse_track_sc_num(unsigned int *track_sc_num,
1818 const char *arg, const char *end, char **errmsg)
1819{
1820 const char *p;
1821 unsigned int num;
1822
1823 p = arg;
1824 num = read_uint64(&arg, end);
1825
1826 if (arg != end) {
1827 memprintf(errmsg, "Wrong track-sc number '%s'", p);
1828 return -1;
1829 }
1830
1831 if (num >= MAX_SESS_STKCTR) {
1832 memprintf(errmsg, "%u track-sc number exceeding "
1833 "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1);
1834 return -1;
1835 }
1836
1837 *track_sc_num = num;
1838 return 0;
1839}
1840
Willy Tarreaubaaee002006-06-26 02:48:02 +02001841/*
1842 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02001843 * Returns the error code, 0 if OK, or any combination of :
1844 * - ERR_ABORT: must abort ASAP
1845 * - ERR_FATAL: we can continue parsing but not start the service
1846 * - ERR_WARN: a warning has been emitted
1847 * - ERR_ALERT: an alert has been emitted
1848 * Only the two first ones can stop processing, the two others are just
1849 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001850 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02001851int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001852{
William Lallemand64e84512015-05-12 14:25:37 +02001853 char *thisline;
1854 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001855 FILE *f;
1856 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02001857 int err_code = 0;
William Lallemandd2ff56d2017-10-16 11:06:50 +02001858 struct cfg_section *cs = NULL, *pcs = NULL;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001859 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02001860 int readbytes = 0;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001861 char *outline = NULL;
1862 size_t outlen = 0;
1863 size_t outlinesize = 0;
Willy Tarreau32234e72020-06-16 17:14:33 +02001864 int fatal = 0;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001865 int missing_lf = -1;
William Lallemand64e84512015-05-12 14:25:37 +02001866
1867 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001868 ha_alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02001869 return -1;
1870 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001871
David Carlier97880bb2016-04-08 10:35:26 +01001872 if ((f=fopen(file,"r")) == NULL) {
1873 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001874 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01001875 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001876
William Lallemandb2f07452015-05-12 14:27:13 +02001877next_line:
William Lallemand64e84512015-05-12 14:25:37 +02001878 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02001879 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001880 char *end;
1881 char *args[MAX_LINE_ARGS + 1];
1882 char *line = thisline;
1883
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001884 if (missing_lf != -1) {
Tim Duesterhusf92afb72020-08-18 22:00:04 +02001885 ha_alert("parsing [%s:%d]: Stray NUL character at position %d.\n",
1886 file, linenum, (missing_lf + 1));
1887 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001888 missing_lf = -1;
Tim Duesterhusf92afb72020-08-18 22:00:04 +02001889 break;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001890 }
1891
Willy Tarreaubaaee002006-06-26 02:48:02 +02001892 linenum++;
1893
Willy Tarreau32234e72020-06-16 17:14:33 +02001894 if (fatal >= 50) {
1895 ha_alert("parsing [%s:%d]: too many fatal errors (%d), stopping now.\n", file, linenum, fatal);
1896 break;
1897 }
1898
Willy Tarreaubaaee002006-06-26 02:48:02 +02001899 end = line + strlen(line);
1900
William Lallemand64e84512015-05-12 14:25:37 +02001901 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001902 /* Check if we reached the limit and the last char is not \n.
1903 * Watch out for the last line without the terminating '\n'!
1904 */
William Lallemand64e84512015-05-12 14:25:37 +02001905 char *newline;
1906 int newlinesize = linesize * 2;
1907
1908 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
1909 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001910 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
1911 file, linenum);
William Lallemand64e84512015-05-12 14:25:37 +02001912 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001913 fatal++;
Willy Tarreau40cb26f2020-06-25 09:37:54 +02001914 linenum--;
William Lallemand64e84512015-05-12 14:25:37 +02001915 continue;
1916 }
1917
1918 readbytes = linesize - 1;
1919 linesize = newlinesize;
1920 thisline = newline;
Willy Tarreau40cb26f2020-06-25 09:37:54 +02001921 linenum--;
William Lallemand64e84512015-05-12 14:25:37 +02001922 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001923 }
1924
William Lallemand64e84512015-05-12 14:25:37 +02001925 readbytes = 0;
1926
Willy Tarreau08488f62020-06-26 17:24:54 +02001927 if (end > line && *(end-1) == '\n') {
Tim Duesterhus70f58992020-06-22 22:57:44 +02001928 /* kill trailing LF */
1929 *(end - 1) = 0;
1930 }
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001931 else {
1932 /* mark this line as truncated */
1933 missing_lf = end - line;
1934 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001935
Willy Tarreaubaaee002006-06-26 02:48:02 +02001936 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02001937 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02001938 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02001939
Joseph Herlanta14c03e2018-11-15 14:04:19 -08001940 if (*line == '[') {/* This is the beginning if a scope */
Christopher Faulet79bdef32016-11-04 22:36:15 +01001941 err_code |= cfg_parse_scope(file, linenum, line);
1942 goto next_line;
1943 }
1944
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001945 while (1) {
1946 uint32_t err;
1947 char *errptr;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001948
Willy Tarreau61dd44b2020-06-25 07:35:42 +02001949 arg = MAX_LINE_ARGS + 1;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001950 outlen = outlinesize;
1951 err = parse_line(line, outline, &outlen, args, &arg,
1952 PARSE_OPT_ENV | PARSE_OPT_DQUOTE | PARSE_OPT_SQUOTE |
1953 PARSE_OPT_BKSLASH | PARSE_OPT_SHARP, &errptr);
1954
1955 if (err & PARSE_ERR_QUOTE) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001956 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1957
1958 ha_alert("parsing [%s:%d]: unmatched quote at position %d:\n"
1959 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001960 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001961 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001962 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001963 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001964
1965 if (err & PARSE_ERR_BRACE) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001966 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1967
1968 ha_alert("parsing [%s:%d]: unmatched brace in environment variable name at position %d:\n"
1969 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001970 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001971 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001972 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001973 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001974
1975 if (err & PARSE_ERR_VARNAME) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001976 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1977
1978 ha_alert("parsing [%s:%d]: forbidden first char in environment variable name at position %d:\n"
1979 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001980 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001981 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001982 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001983 }
William Lallemandb2f07452015-05-12 14:27:13 +02001984
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001985 if (err & PARSE_ERR_HEX) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001986 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1987
1988 ha_alert("parsing [%s:%d]: truncated or invalid hexadecimal sequence at position %d:\n"
1989 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001990 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus9f658a52020-06-16 18:14:21 +02001991 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001992 goto next_line;
1993 }
William Lallemandb2f07452015-05-12 14:27:13 +02001994
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001995 if (err & (PARSE_ERR_TOOLARGE|PARSE_ERR_OVERLAP)) {
1996 outlinesize = (outlen + 1023) & -1024;
1997 outline = realloc(outline, outlinesize);
1998 if (outline == NULL) {
1999 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
2000 file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02002001 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02002002 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02002003 goto next_line;
William Lallemandb2f07452015-05-12 14:27:13 +02002004 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02002005 /* try again */
2006 continue;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002007 }
Willy Tarreau07d47062020-06-25 07:41:22 +02002008
2009 if (err & PARSE_ERR_TOOMANY) {
2010 /* only check this *after* being sure the output is allocated */
2011 ha_alert("parsing [%s:%d]: too many words, truncating after word %d, position %ld: <%s>.\n",
2012 file, linenum, MAX_LINE_ARGS, (long)(args[MAX_LINE_ARGS-1] - outline + 1), args[MAX_LINE_ARGS-1]);
2013 err_code |= ERR_ALERT | ERR_FATAL;
2014 fatal++;
2015 goto next_line;
2016 }
2017
Willy Tarreau9e1758e2020-06-16 16:32:59 +02002018 /* everything's OK */
2019 break;
William Lallemandf9873ba2015-05-05 17:37:14 +02002020 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002021
2022 /* empty line */
2023 if (!**args)
2024 continue;
2025
Willy Tarreau3842f002009-06-14 11:39:52 +02002026 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002027 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02002028 char *tmp;
2029
Willy Tarreau3842f002009-06-14 11:39:52 +02002030 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02002031 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002032 for (arg=0; *args[arg+1]; arg++)
2033 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02002034 *tmp = '\0'; // fix the next arg to \0
2035 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002036 }
Willy Tarreau3842f002009-06-14 11:39:52 +02002037 else if (!strcmp(args[0], "default")) {
2038 kwm = KWM_DEF;
2039 for (arg=0; *args[arg+1]; arg++)
2040 args[arg] = args[arg+1]; // shift args after inversion
2041 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002042
William Dauchyec730982019-10-27 20:08:10 +01002043 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 &&
2044 strcmp(args[0], "log") != 0 && strcmp(args[0], "busy-polling") != 0 &&
Willy Tarreaud96f1122019-12-03 07:07:36 +01002045 strcmp(args[0], "set-dumpable") != 0 && strcmp(args[0], "strict-limits") != 0 &&
2046 strcmp(args[0], "insecure-fork-wanted") != 0) {
William Dauchyec730982019-10-27 20:08:10 +01002047 ha_alert("parsing [%s:%d]: negation/default currently "
William Dauchy0fec3ab2019-10-27 20:08:11 +01002048 "supported only for options, log, busy-polling, "
Willy Tarreaud96f1122019-12-03 07:07:36 +01002049 "set-dumpable, strict-limits, and insecure-fork-wanted.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02002050 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02002051 fatal++;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002052 }
2053
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002054 /* detect section start */
2055 list_for_each_entry(ics, &sections, list) {
2056 if (strcmp(args[0], ics->section_name) == 0) {
2057 cursection = ics->section_name;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002058 pcs = cs;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002059 cs = ics;
2060 break;
2061 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002062 }
2063
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002064 if (pcs && pcs->post_section_parser) {
Willy Tarreau32234e72020-06-16 17:14:33 +02002065 int status;
2066
2067 status = pcs->post_section_parser();
2068 err_code |= status;
2069 if (status & ERR_FATAL)
2070 fatal++;
2071
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002072 if (err_code & ERR_ABORT)
2073 goto err;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002074 }
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002075 pcs = NULL;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002076
William Lallemandd2ff56d2017-10-16 11:06:50 +02002077 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002078 ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02002079 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02002080 fatal++;
William Lallemandd2ff56d2017-10-16 11:06:50 +02002081 } else {
Willy Tarreau32234e72020-06-16 17:14:33 +02002082 int status;
2083
2084 status = cs->section_parser(file, linenum, args, kwm);
2085 err_code |= status;
2086 if (status & ERR_FATAL)
2087 fatal++;
2088
William Lallemandd2ff56d2017-10-16 11:06:50 +02002089 if (err_code & ERR_ABORT)
2090 goto err;
2091 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002092 }
William Lallemandd2ff56d2017-10-16 11:06:50 +02002093
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02002094 if (missing_lf != -1) {
Tim Duesterhusf92afb72020-08-18 22:00:04 +02002095 ha_alert("parsing [%s:%d]: Missing LF on last line, file might have been truncated at position %d.\n",
2096 file, linenum, (missing_lf + 1));
2097 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02002098 }
2099
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002100 if (cs && cs->post_section_parser)
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002101 err_code |= cs->post_section_parser();
William Lallemandd2ff56d2017-10-16 11:06:50 +02002102
2103err:
Christopher Faulet79bdef32016-11-04 22:36:15 +01002104 free(cfg_scope);
2105 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01002106 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02002107 free(thisline);
Willy Tarreau9e1758e2020-06-16 16:32:59 +02002108 free(outline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002109 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02002110 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002111}
2112
Willy Tarreau64ab6072014-09-16 12:17:36 +02002113/* This function propagates processes from frontend <from> to backend <to> so
2114 * that it is always guaranteed that a backend pointed to by a frontend is
2115 * bound to all of its processes. After that, if the target is a "listen"
2116 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02002117 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02002118 * checked first to ensure that <to> is already bound to all processes of
2119 * <from>, there is no risk of looping and we ensure to follow the shortest
2120 * path to the destination.
2121 *
2122 * It is possible to set <to> to NULL for the first call so that the function
2123 * takes care of visiting the initial frontend in <from>.
2124 *
2125 * It is important to note that the function relies on the fact that all names
2126 * have already been resolved.
2127 */
2128void propagate_processes(struct proxy *from, struct proxy *to)
2129{
2130 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002131
2132 if (to) {
2133 /* check whether we need to go down */
2134 if (from->bind_proc &&
2135 (from->bind_proc & to->bind_proc) == from->bind_proc)
2136 return;
2137
2138 if (!from->bind_proc && !to->bind_proc)
2139 return;
2140
2141 to->bind_proc = from->bind_proc ?
2142 (to->bind_proc | from->bind_proc) : 0;
2143
2144 /* now propagate down */
2145 from = to;
2146 }
2147
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01002148 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02002149 return;
2150
Willy Tarreauf6b70012014-12-18 14:00:43 +01002151 if (from->state == PR_STSTOPPED)
2152 return;
2153
Willy Tarreau64ab6072014-09-16 12:17:36 +02002154 /* default_backend */
2155 if (from->defbe.be)
2156 propagate_processes(from, from->defbe.be);
2157
2158 /* use_backend */
2159 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02002160 if (rule->dynamic)
2161 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002162 to = rule->be.backend;
2163 propagate_processes(from, to);
2164 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02002165}
2166
Willy Tarreaubb925012009-07-23 13:36:36 +02002167/*
2168 * Returns the error code, 0 if OK, or any combination of :
2169 * - ERR_ABORT: must abort ASAP
2170 * - ERR_FATAL: we can continue parsing but not start the service
2171 * - ERR_WARN: a warning has been emitted
2172 * - ERR_ALERT: an alert has been emitted
2173 * Only the two first ones can stop processing, the two others are just
2174 * indicators.
2175 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002176int check_config_validity()
2177{
2178 int cfgerr = 0;
2179 struct proxy *curproxy = NULL;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002180 struct stktable *t;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002181 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02002182 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002183 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002184 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002185 char *err;
William Lallemand48b4bb42017-10-23 14:36:34 +02002186 struct cfg_postparser *postparser;
Ben Draut054fbee2018-04-13 15:43:04 -06002187 struct dns_resolvers *curr_resolvers = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002188
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002189 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002190 /*
2191 * Now, check for the integrity of all that we have collected.
2192 */
2193
2194 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02002195 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002196
Willy Tarreau193b8c62012-11-22 00:17:38 +01002197 if (!global.tune.max_http_hdr)
2198 global.tune.max_http_hdr = MAX_HTTP_HDR;
2199
2200 if (!global.tune.cookie_len)
2201 global.tune.cookie_len = CAPTURE_LEN;
2202
Stéphane Cottin23e9e932017-05-18 08:58:41 +02002203 if (!global.tune.requri_len)
2204 global.tune.requri_len = REQURI_LEN;
2205
Willy Tarreau149ab772019-01-26 14:27:06 +01002206 if (!global.nbthread) {
2207 /* nbthread not set, thus automatic. In this case, and only if
2208 * running on a single process, we enable the same number of
2209 * threads as the number of CPUs the process is bound to. This
2210 * allows to easily control the number of threads using taskset.
2211 */
2212 global.nbthread = 1;
2213#if defined(USE_THREAD)
2214 if (global.nbproc == 1)
2215 global.nbthread = thread_cpus_enabled_at_boot;
2216 all_threads_mask = nbits(global.nbthread);
2217#endif
2218 }
2219
Willy Tarreau26f6ae12019-02-02 12:56:15 +01002220 if (global.nbproc > 1 && global.nbthread > 1) {
2221 ha_alert("config : cannot enable multiple processes if multiple threads are configured. Please use either nbproc or nbthread but not both.\n");
2222 err_code |= ERR_ALERT | ERR_FATAL;
2223 goto out;
2224 }
2225
Willy Tarreaubafbe012017-11-24 17:34:44 +01002226 pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
Emeric Brun96fd9262017-07-05 13:33:16 +02002227
Willy Tarreaubafbe012017-11-24 17:34:44 +01002228 pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
Willy Tarreau193b8c62012-11-22 00:17:38 +01002229
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002230 /* Post initialisation of the users and groups lists. */
2231 err_code = userlist_postinit();
2232 if (err_code != ERR_NONE)
2233 goto out;
2234
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002235 /* first, we will invert the proxy list order */
2236 curproxy = NULL;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002237 while (proxies_list) {
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002238 struct proxy *next;
2239
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002240 next = proxies_list->next;
2241 proxies_list->next = curproxy;
2242 curproxy = proxies_list;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002243 if (!next)
2244 break;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002245 proxies_list = next;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002246 }
2247
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002248 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002249 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002250 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002251 struct sticking_rule *mrule;
Christopher Faulete4e830d2017-09-18 14:51:41 +02002252 struct act_rule *arule;
Dragan Dosen1322d092015-09-22 16:05:32 +02002253 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002254 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01002255 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002256
Willy Tarreau050536d2012-10-04 08:47:34 +02002257 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002258 /* proxy ID not set, use automatic numbering with first
2259 * spare entry starting with next_pxid.
2260 */
2261 next_pxid = get_next_id(&used_proxy_id, next_pxid);
2262 curproxy->conf.id.key = curproxy->uuid = next_pxid;
2263 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002264 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01002265 next_pxid++;
2266
Willy Tarreau55ea7572007-06-17 19:56:27 +02002267
Willy Tarreaubaaee002006-06-26 02:48:02 +02002268 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02002269 /* ensure we don't keep listeners uselessly bound */
2270 stop_proxy(curproxy);
Dragan Dosen7d61a332019-05-07 14:16:18 +02002271 if (curproxy->table) {
2272 free((void *)curproxy->table->peers.name);
2273 curproxy->table->peers.p = NULL;
2274 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002275 continue;
2276 }
2277
Willy Tarreau102df612014-05-07 23:56:38 +02002278 /* Check multi-process mode compatibility for the current proxy */
2279
2280 if (curproxy->bind_proc) {
2281 /* an explicit bind-process was specified, let's check how many
2282 * processes remain.
2283 */
David Carliere6c39412015-07-02 07:00:17 +00002284 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02002285
Willy Tarreaua38a7172019-02-02 17:11:28 +01002286 curproxy->bind_proc &= all_proc_mask;
Willy Tarreau102df612014-05-07 23:56:38 +02002287 if (!curproxy->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002288 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 +02002289 curproxy->bind_proc = 1;
2290 }
2291 else if (!curproxy->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002292 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 +02002293 curproxy->bind_proc = 0;
2294 }
2295 }
2296
Willy Tarreau3d209582014-05-09 17:06:11 +02002297 /* check and reduce the bind-proc of each listener */
2298 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
2299 unsigned long mask;
2300
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002301 /* HTTP frontends with "h2" as ALPN/NPN will work in
2302 * HTTP/2 and absolutely require buffers 16kB or larger.
2303 */
2304#ifdef USE_OPENSSL
2305 if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
2306#ifdef OPENSSL_NPN_NEGOTIATED
2307 /* check NPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002308 if (bind_conf->ssl_conf.npn_str && strstr(bind_conf->ssl_conf.npn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002309 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",
2310 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002311 cfgerr++;
2312 }
2313#endif
2314#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
2315 /* check ALPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002316 if (bind_conf->ssl_conf.alpn_str && strstr(bind_conf->ssl_conf.alpn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002317 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",
2318 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002319 cfgerr++;
2320 }
2321#endif
2322 } /* HTTP && bufsize < 16384 */
2323#endif
2324
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002325 /* detect and address thread affinity inconsistencies */
Willy Tarreaue26993c2020-09-03 07:18:55 +02002326 mask = thread_mask(bind_conf->settings.bind_thread);
Willy Tarreau3d957172019-02-02 18:00:17 +01002327 if (!(mask & all_threads_mask)) {
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002328 unsigned long new_mask = 0;
2329
2330 while (mask) {
Willy Tarreau0c026f42018-08-01 19:12:20 +02002331 new_mask |= mask & all_threads_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002332 mask >>= global.nbthread;
2333 }
2334
Willy Tarreaue26993c2020-09-03 07:18:55 +02002335 bind_conf->settings.bind_thread = new_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002336 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",
2337 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
2338 }
2339
2340 /* detect process and nbproc affinity inconsistencies */
Willy Tarreaue26993c2020-09-03 07:18:55 +02002341 mask = proc_mask(bind_conf->settings.bind_proc) & proc_mask(curproxy->bind_proc);
Willy Tarreaua36b3242019-02-02 13:14:34 +01002342 if (!(mask & all_proc_mask)) {
2343 mask = proc_mask(curproxy->bind_proc) & all_proc_mask;
Willy Tarreaue26993c2020-09-03 07:18:55 +02002344 nbproc = my_popcountl(bind_conf->settings.bind_proc);
2345 bind_conf->settings.bind_proc = proc_mask(bind_conf->settings.bind_proc) & mask;
Willy Tarreau3d209582014-05-09 17:06:11 +02002346
Willy Tarreaue26993c2020-09-03 07:18:55 +02002347 if (!bind_conf->settings.bind_proc && nbproc == 1) {
Willy Tarreaua36b3242019-02-02 13:14:34 +01002348 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",
2349 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreaue26993c2020-09-03 07:18:55 +02002350 bind_conf->settings.bind_proc = mask & ~(mask - 1);
Willy Tarreaua36b3242019-02-02 13:14:34 +01002351 }
Willy Tarreaue26993c2020-09-03 07:18:55 +02002352 else if (!bind_conf->settings.bind_proc && nbproc > 1) {
Willy Tarreaua36b3242019-02-02 13:14:34 +01002353 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",
2354 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreaue26993c2020-09-03 07:18:55 +02002355 bind_conf->settings.bind_proc = 0;
Willy Tarreaua36b3242019-02-02 13:14:34 +01002356 }
Willy Tarreau3d209582014-05-09 17:06:11 +02002357 }
2358 }
2359
Willy Tarreauff01a212009-03-15 13:46:16 +01002360 switch (curproxy->mode) {
2361 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002362 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002363 if (!(curproxy->cap & PR_CAP_FE)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002364 ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
2365 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002366 cfgerr++;
2367 }
2368
2369 if (curproxy->srv != NULL)
Christopher Faulet767a84b2017-11-24 16:50:31 +01002370 ha_warning("config : servers will be ignored for %s '%s'.\n",
2371 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01002372 break;
2373
2374 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002375 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002376 break;
2377
2378 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01002379 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01002380 break;
William Lallemandcf62f7e2018-10-26 14:47:40 +02002381
2382 case PR_MODE_CLI:
2383 cfgerr += proxy_cfg_ensure_no_http(curproxy);
2384 break;
Emeric Brun54932b42020-07-07 09:43:24 +02002385 case PR_MODE_SYSLOG:
2386 case PR_MODES:
2387 /* should not happen, bug gcc warn missing switch statement */
2388 ha_alert("config : %s '%s' cannot use syslog mode for this proxy.\n",
2389 proxy_type_str(curproxy), curproxy->id);
2390 cfgerr++;
2391 break;
Willy Tarreauff01a212009-03-15 13:46:16 +01002392 }
2393
Willy Tarreau58aa5cc2018-02-08 09:55:09 +01002394 if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002395 ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
2396 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauf3934b82015-08-11 11:36:45 +02002397 err_code |= ERR_WARN;
2398 }
2399
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002400 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02002401 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002402 if (curproxy->options & PR_O_TRANSP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002403 ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n",
2404 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002405 cfgerr++;
2406 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002407#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002408 else if (curproxy->srv == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002409 ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n",
2410 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002411 cfgerr++;
2412 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002413#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02002414 else if (curproxy->options & PR_O_DISPATCH) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002415 ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
2416 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002417 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002418 }
2419 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02002420 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002421 /* If no LB algo is set in a backend, and we're not in
2422 * transparent mode, dispatch mode nor proxy mode, we
2423 * want to use balance roundrobin by default.
2424 */
2425 curproxy->lbprm.algo &= ~BE_LB_ALGO;
2426 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002427 }
2428 }
Willy Tarreau193cf932007-09-17 10:17:23 +02002429
Willy Tarreau1620ec32011-08-06 17:05:02 +02002430 if (curproxy->options & PR_O_DISPATCH)
2431 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
2432 else if (curproxy->options & PR_O_HTTP_PROXY)
2433 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
2434 else if (curproxy->options & PR_O_TRANSP)
2435 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01002436
Christopher Faulete5870d82020-04-15 11:32:03 +02002437 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_HTTP_RS)) {
2438 ha_warning("config : %s '%s' uses http-check rules without 'option httpchk', so the rules are ignored.\n",
2439 proxy_type_str(curproxy), curproxy->id);
2440 err_code |= ERR_WARN;
2441 }
2442
2443 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_TCPCHK_CHK &&
Christopher Fauletc0fcbe42020-06-03 19:00:42 +02002444 (curproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) != TCPCHK_RULES_HTTP_CHK) {
Willy Tarreau1620ec32011-08-06 17:05:02 +02002445 if (curproxy->options & PR_O_DISABLE404) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002446 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2447 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002448 err_code |= ERR_WARN;
2449 curproxy->options &= ~PR_O_DISABLE404;
2450 }
2451 if (curproxy->options2 & PR_O2_CHK_SNDST) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002452 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2453 "send-state", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002454 err_code |= ERR_WARN;
2455 curproxy->options &= ~PR_O2_CHK_SNDST;
2456 }
Willy Tarreauef781042010-01-27 11:53:01 +01002457 }
2458
Simon Horman98637e52014-06-20 12:30:16 +09002459 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
2460 if (!global.external_check) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002461 ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
2462 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002463 cfgerr++;
2464 }
2465 if (!curproxy->check_command) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002466 ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
2467 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002468 cfgerr++;
2469 }
Willy Tarreaud96f1122019-12-03 07:07:36 +01002470 if (!(global.tune.options & GTUNE_INSECURE_FORK)) {
2471 ha_warning("Proxy '%s' : 'insecure-fork-wanted' not enabled in the global section, '%s' will likely fail.\n",
2472 curproxy->id, "option external-check");
2473 err_code |= ERR_WARN;
2474 }
Simon Horman98637e52014-06-20 12:30:16 +09002475 }
2476
Simon Horman64e34162015-02-06 11:11:57 +09002477 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002478 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002479 ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
2480 "'email-alert from', 'email-alert level' 'email-alert mailers', "
2481 "'email-alert myhostname', or 'email-alert to' "
2482 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
2483 "to be present).\n",
2484 proxy_type_str(curproxy), curproxy->id);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002485 err_code |= ERR_WARN;
2486 free_email_alert(curproxy);
2487 }
2488 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01002489 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09002490 }
2491
Simon Horman98637e52014-06-20 12:30:16 +09002492 if (curproxy->check_command) {
2493 int clear = 0;
2494 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002495 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2496 "external-check command", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002497 err_code |= ERR_WARN;
2498 clear = 1;
2499 }
2500 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002501 ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
2502 curproxy->id, "external-check command");
Simon Horman98637e52014-06-20 12:30:16 +09002503 cfgerr++;
2504 }
2505 if (clear) {
2506 free(curproxy->check_command);
2507 curproxy->check_command = NULL;
2508 }
2509 }
2510
2511 if (curproxy->check_path) {
2512 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002513 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2514 "external-check path", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002515 err_code |= ERR_WARN;
2516 free(curproxy->check_path);
2517 curproxy->check_path = NULL;
2518 }
2519 }
2520
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002521 /* if a default backend was specified, let's find it */
2522 if (curproxy->defbe.name) {
2523 struct proxy *target;
2524
Willy Tarreauafb39922015-05-26 12:04:09 +02002525 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002526 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002527 ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
2528 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002529 cfgerr++;
2530 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002531 ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
2532 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02002533 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002534 } else if (target->mode != curproxy->mode &&
2535 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2536
Christopher Faulet767a84b2017-11-24 16:50:31 +01002537 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
2538 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2539 curproxy->conf.file, curproxy->conf.line,
2540 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2541 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002542 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002543 } else {
2544 free(curproxy->defbe.name);
2545 curproxy->defbe.be = target;
Willy Tarreauff678132012-02-13 14:32:34 +01002546 /* Emit a warning if this proxy also has some servers */
2547 if (curproxy->srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002548 ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
2549 curproxy->id);
Willy Tarreauff678132012-02-13 14:32:34 +01002550 err_code |= ERR_WARN;
2551 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002552 }
2553 }
2554
Willy Tarreau55ea7572007-06-17 19:56:27 +02002555 /* find the target proxy for 'use_backend' rules */
2556 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002557 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002558 struct logformat_node *node;
2559 char *pxname;
2560
2561 /* Try to parse the string as a log format expression. If the result
2562 * of the parsing is only one entry containing a simple string, then
2563 * it's a standard string corresponding to a static rule, thus the
2564 * parsing is cancelled and be.name is restored to be resolved.
2565 */
2566 pxname = rule->be.name;
2567 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01002568 curproxy->conf.args.ctx = ARGC_UBK;
2569 curproxy->conf.args.file = rule->file;
2570 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002571 err = NULL;
2572 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002573 ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
2574 rule->file, rule->line, pxname, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002575 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002576 cfgerr++;
2577 continue;
2578 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002579 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
2580
2581 if (!LIST_ISEMPTY(&rule->be.expr)) {
2582 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
2583 rule->dynamic = 1;
2584 free(pxname);
2585 continue;
2586 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002587 /* Only one element in the list, a simple string: free the expression and
2588 * fall back to static rule
2589 */
2590 LIST_DEL(&node->list);
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002591 free(node->arg);
2592 free(node);
2593 }
2594
2595 rule->dynamic = 0;
2596 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002597
Willy Tarreauafb39922015-05-26 12:04:09 +02002598 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002599 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002600 ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
2601 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002602 cfgerr++;
2603 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002604 ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
2605 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002606 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002607 } else if (target->mode != curproxy->mode &&
2608 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2609
Christopher Faulet767a84b2017-11-24 16:50:31 +01002610 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
2611 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2612 curproxy->conf.file, curproxy->conf.line,
2613 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2614 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002615 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002616 } else {
2617 free((void *)rule->be.name);
2618 rule->be.backend = target;
2619 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002620 }
2621
Willy Tarreau64ab6072014-09-16 12:17:36 +02002622 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002623 list_for_each_entry(srule, &curproxy->server_rules, list) {
Jerome Magnin824186b2020-03-29 09:37:12 +02002624 struct server *target;
2625 struct logformat_node *node;
2626 char *server_name;
2627
2628 /* We try to parse the string as a log format expression. If the result of the parsing
2629 * is only one entry containing a single string, then it's a standard string corresponding
2630 * to a static rule, thus the parsing is cancelled and we fall back to setting srv.ptr.
2631 */
2632 server_name = srule->srv.name;
2633 LIST_INIT(&srule->expr);
2634 curproxy->conf.args.ctx = ARGC_USRV;
2635 err = NULL;
2636 if (!parse_logformat_string(server_name, curproxy, &srule->expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
2637 ha_alert("Parsing [%s:%d]; use-server rule failed to parse log-format '%s' : %s.\n",
2638 srule->file, srule->line, server_name, err);
2639 free(err);
2640 cfgerr++;
2641 continue;
2642 }
2643 node = LIST_NEXT(&srule->expr, struct logformat_node *, list);
2644
2645 if (!LIST_ISEMPTY(&srule->expr)) {
2646 if (node->type != LOG_FMT_TEXT || node->list.n != &srule->expr) {
2647 srule->dynamic = 1;
2648 free(server_name);
2649 continue;
2650 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002651 /* Only one element in the list, a simple string: free the expression and
2652 * fall back to static rule
2653 */
2654 LIST_DEL(&node->list);
Jerome Magnin824186b2020-03-29 09:37:12 +02002655 free(node->arg);
2656 free(node);
2657 }
2658
2659 srule->dynamic = 0;
2660 srule->srv.name = server_name;
2661 target = findserver(curproxy, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002662
2663 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002664 ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
2665 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002666 cfgerr++;
2667 continue;
2668 }
2669 free((void *)srule->srv.name);
2670 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002671 }
2672
Emeric Brunb982a3d2010-01-04 15:45:53 +01002673 /* find the target table for 'stick' rules */
2674 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002675 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002676
Emeric Brun1d33b292010-01-04 15:47:17 +01002677 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
2678 if (mrule->flags & STK_IS_STORE)
2679 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2680
Emeric Brunb982a3d2010-01-04 15:45:53 +01002681 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002682 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002683 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002684 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002685
2686 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002687 ha_alert("Proxy '%s': unable to find stick-table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002688 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002689 cfgerr++;
2690 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002691 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002692 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2693 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002694 cfgerr++;
2695 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002696 else if (target->proxy && curproxy->bind_proc & ~target->proxy->bind_proc) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002697 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2698 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002699 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002700 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002701 else {
2702 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002703 mrule->table.t = target;
2704 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002705 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002706 if (!in_proxies_list(target->proxies_list, curproxy)) {
2707 curproxy->next_stkt_ref = target->proxies_list;
2708 target->proxies_list = curproxy;
2709 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002710 }
2711 }
2712
2713 /* find the target table for 'store response' rules */
2714 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002715 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002716
Emeric Brun1d33b292010-01-04 15:47:17 +01002717 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2718
Emeric Brunb982a3d2010-01-04 15:45:53 +01002719 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002720 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002721 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002722 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002723
2724 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002725 ha_alert("Proxy '%s': unable to find store table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002726 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002727 cfgerr++;
2728 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002729 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002730 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2731 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002732 cfgerr++;
2733 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002734 else if (target->proxy && (curproxy->bind_proc & ~target->proxy->bind_proc)) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002735 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2736 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002737 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002738 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002739 else {
2740 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002741 mrule->table.t = target;
2742 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002743 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002744 if (!in_proxies_list(target->proxies_list, curproxy)) {
2745 curproxy->next_stkt_ref = target->proxies_list;
2746 target->proxies_list = curproxy;
2747 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002748 }
2749 }
2750
Christopher Faulete4e830d2017-09-18 14:51:41 +02002751 /* check validity for 'tcp-request' layer 4 rules */
2752 list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) {
2753 err = NULL;
2754 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002755 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002756 free(err);
Willy Tarreau5f53de72012-12-12 00:25:44 +01002757 cfgerr++;
2758 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02002759 }
2760
Christopher Faulete4e830d2017-09-18 14:51:41 +02002761 /* check validity for 'tcp-request' layer 5 rules */
2762 list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) {
2763 err = NULL;
2764 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002765 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002766 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002767 cfgerr++;
2768 }
2769 }
2770
Christopher Faulete4e830d2017-09-18 14:51:41 +02002771 /* check validity for 'tcp-request' layer 6 rules */
2772 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
2773 err = NULL;
2774 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002775 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002776 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002777 cfgerr++;
2778 }
2779 }
2780
Christopher Faulete4e830d2017-09-18 14:51:41 +02002781 /* check validity for 'http-request' layer 7 rules */
2782 list_for_each_entry(arule, &curproxy->http_req_rules, list) {
2783 err = NULL;
2784 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002785 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002786 free(err);
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002787 cfgerr++;
2788 }
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002789 }
2790
Christopher Faulete4e830d2017-09-18 14:51:41 +02002791 /* check validity for 'http-response' layer 7 rules */
2792 list_for_each_entry(arule, &curproxy->http_res_rules, list) {
2793 err = NULL;
2794 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002795 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002796 free(err);
Willy Tarreau09448f72014-06-25 18:12:15 +02002797 cfgerr++;
2798 }
Willy Tarreau09448f72014-06-25 18:12:15 +02002799 }
2800
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01002801 /* check validity for 'http-after-response' layer 7 rules */
2802 list_for_each_entry(arule, &curproxy->http_after_res_rules, list) {
2803 err = NULL;
2804 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
2805 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
2806 free(err);
2807 cfgerr++;
2808 }
2809 }
2810
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002811 if (curproxy->table && curproxy->table->peers.name) {
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002812 struct peers *curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002813
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002814 for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002815 if (strcmp(curpeers->id, curproxy->table->peers.name) == 0) {
2816 free((void *)curproxy->table->peers.name);
2817 curproxy->table->peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002818 break;
2819 }
2820 }
2821
2822 if (!curpeers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002823 ha_alert("Proxy '%s': unable to find sync peers '%s'.\n",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002824 curproxy->id, curproxy->table->peers.name);
2825 free((void *)curproxy->table->peers.name);
2826 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002827 cfgerr++;
2828 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002829 else if (curpeers->state == PR_STSTOPPED) {
2830 /* silently disable this peers section */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002831 curproxy->table->peers.p = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002832 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002833 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002834 ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
2835 curproxy->id, localpeer, curpeers->id);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002836 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002837 cfgerr++;
2838 }
2839 }
2840
Simon Horman9dc49962015-01-30 11:22:59 +09002841
2842 if (curproxy->email_alert.mailers.name) {
2843 struct mailers *curmailers = mailers;
2844
2845 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
Christopher Faulet0108bb32017-10-20 21:34:32 +02002846 if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name))
Simon Horman9dc49962015-01-30 11:22:59 +09002847 break;
Simon Horman9dc49962015-01-30 11:22:59 +09002848 }
Simon Horman9dc49962015-01-30 11:22:59 +09002849 if (!curmailers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002850 ha_alert("Proxy '%s': unable to find mailers '%s'.\n",
2851 curproxy->id, curproxy->email_alert.mailers.name);
Simon Horman9dc49962015-01-30 11:22:59 +09002852 free_email_alert(curproxy);
2853 cfgerr++;
2854 }
Christopher Faulet0108bb32017-10-20 21:34:32 +02002855 else {
2856 err = NULL;
2857 if (init_email_alert(curmailers, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002858 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulet0108bb32017-10-20 21:34:32 +02002859 free(err);
2860 cfgerr++;
2861 }
2862 }
Simon Horman9dc49962015-01-30 11:22:59 +09002863 }
2864
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002865 if (curproxy->uri_auth && curproxy->uri_auth != defproxy.uri_auth &&
Willy Tarreauff011f22011-01-06 17:51:27 +01002866 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002867 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002868 ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
2869 "proxy", curproxy->id);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002870 cfgerr++;
2871 goto out_uri_auth_compat;
2872 }
2873
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002874 if (curproxy->uri_auth && curproxy->uri_auth->userlist &&
2875 (curproxy->uri_auth != defproxy.uri_auth ||
2876 LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules))) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002877 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02002878 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002879 int i = 0;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002880 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
2881 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002882
2883 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002884 uri_auth_compat_req[i++] = "realm";
2885 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
2886 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002887
Willy Tarreau95fa4692010-02-01 13:05:50 +01002888 uri_auth_compat_req[i++] = "unless";
2889 uri_auth_compat_req[i++] = "{";
2890 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
2891 uri_auth_compat_req[i++] = "}";
2892 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002893
Willy Tarreauff011f22011-01-06 17:51:27 +01002894 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
2895 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002896 cfgerr++;
2897 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002898 }
2899
Willy Tarreauff011f22011-01-06 17:51:27 +01002900 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01002901
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002902 if (curproxy->uri_auth->auth_realm) {
2903 free(curproxy->uri_auth->auth_realm);
2904 curproxy->uri_auth->auth_realm = NULL;
2905 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002906 }
2907out_uri_auth_compat:
2908
Dragan Dosen43885c72015-10-01 13:18:13 +02002909 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02002910 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02002911 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
2912 if (!curproxy->conf.logformat_sd_string) {
2913 /* set the default logformat_sd_string */
2914 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
2915 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002916 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02002917 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002918 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02002919
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002920 /* compile the log format */
2921 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02002922 if (curproxy->conf.logformat_string != default_http_log_format &&
2923 curproxy->conf.logformat_string != default_tcp_log_format &&
2924 curproxy->conf.logformat_string != clf_http_log_format)
2925 free(curproxy->conf.logformat_string);
2926 curproxy->conf.logformat_string = NULL;
2927 free(curproxy->conf.lfs_file);
2928 curproxy->conf.lfs_file = NULL;
2929 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002930
2931 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2932 free(curproxy->conf.logformat_sd_string);
2933 curproxy->conf.logformat_sd_string = NULL;
2934 free(curproxy->conf.lfsd_file);
2935 curproxy->conf.lfsd_file = NULL;
2936 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002937 }
2938
Willy Tarreau62a61232013-04-12 18:13:46 +02002939 if (curproxy->conf.logformat_string) {
2940 curproxy->conf.args.ctx = ARGC_LOG;
2941 curproxy->conf.args.file = curproxy->conf.lfs_file;
2942 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002943 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002944 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat,
2945 LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002946 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002947 ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
2948 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002949 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002950 cfgerr++;
2951 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002952 curproxy->conf.args.file = NULL;
2953 curproxy->conf.args.line = 0;
2954 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002955
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002956 if (curproxy->conf.logformat_sd_string) {
2957 curproxy->conf.args.ctx = ARGC_LOGSD;
2958 curproxy->conf.args.file = curproxy->conf.lfsd_file;
2959 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002960 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002961 if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd,
2962 LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002963 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002964 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2965 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002966 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002967 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002968 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002969 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2970 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002971 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002972 cfgerr++;
2973 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002974 curproxy->conf.args.file = NULL;
2975 curproxy->conf.args.line = 0;
2976 }
2977
Willy Tarreau62a61232013-04-12 18:13:46 +02002978 if (curproxy->conf.uniqueid_format_string) {
2979 curproxy->conf.args.ctx = ARGC_UIF;
2980 curproxy->conf.args.file = curproxy->conf.uif_file;
2981 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002982 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002983 if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id,
2984 LOG_OPT_HTTP|LOG_OPT_MERGE_SPACES,
2985 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR
2986 : SMP_VAL_BE_HRQ_HDR,
2987 &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002988 ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
2989 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002990 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002991 cfgerr++;
2992 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002993 curproxy->conf.args.file = NULL;
2994 curproxy->conf.args.line = 0;
2995 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002996
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002997 /* only now we can check if some args remain unresolved.
2998 * This must be done after the users and groups resolution.
2999 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02003000 cfgerr += smp_resolve_args(curproxy);
3001 if (!cfgerr)
3002 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01003003
Willy Tarreau2738a142006-07-08 17:28:09 +02003004 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003005 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02003006 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02003007 (!curproxy->timeout.connect ||
3008 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003009 ha_warning("config : missing timeouts for %s '%s'.\n"
3010 " | While not properly invalid, you will certainly encounter various problems\n"
3011 " | with such a configuration. To fix this, please ensure that all following\n"
3012 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
3013 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02003014 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02003015 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02003016
Willy Tarreau1fa31262007-12-03 00:36:16 +01003017 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
3018 * We must still support older configurations, so let's find out whether those
3019 * parameters have been set or must be copied from contimeouts.
3020 */
3021 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003022 if (!curproxy->timeout.tarpit ||
3023 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01003024 /* tarpit timeout not set. We search in the following order:
3025 * default.tarpit, curr.connect, default.connect.
3026 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003027 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01003028 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003029 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003030 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003031 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003032 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01003033 }
3034 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003035 (!curproxy->timeout.queue ||
3036 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01003037 /* queue timeout not set. We search in the following order:
3038 * default.queue, curr.connect, default.connect.
3039 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003040 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01003041 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003042 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003043 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003044 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003045 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01003046 }
3047 }
3048
Christopher Faulete5870d82020-04-15 11:32:03 +02003049 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_TCP_RS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003050 ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
3051 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau215663d2014-06-13 18:30:23 +02003052 err_code |= ERR_WARN;
3053 }
3054
Willy Tarreau193b8c62012-11-22 00:17:38 +01003055 /* ensure that cookie capture length is not too large */
3056 if (curproxy->capture_len >= global.tune.cookie_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003057 ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n",
3058 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau193b8c62012-11-22 00:17:38 +01003059 err_code |= ERR_WARN;
3060 curproxy->capture_len = global.tune.cookie_len - 1;
3061 }
3062
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003063 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01003064 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003065 curproxy->req_cap_pool = create_pool("ptrcap",
3066 curproxy->nb_req_cap * sizeof(char *),
3067 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003068 }
3069
3070 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003071 curproxy->rsp_cap_pool = create_pool("ptrcap",
3072 curproxy->nb_rsp_cap * sizeof(char *),
3073 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003074 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003075
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003076 switch (curproxy->load_server_state_from_file) {
3077 case PR_SRV_STATE_FILE_UNSPEC:
3078 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
3079 break;
3080 case PR_SRV_STATE_FILE_GLOBAL:
3081 if (!global.server_state_file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003082 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",
3083 curproxy->id);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003084 err_code |= ERR_WARN;
3085 }
3086 break;
3087 }
3088
Willy Tarreaubaaee002006-06-26 02:48:02 +02003089 /* first, we will invert the servers list order */
3090 newsrv = NULL;
3091 while (curproxy->srv) {
3092 struct server *next;
3093
3094 next = curproxy->srv->next;
3095 curproxy->srv->next = newsrv;
3096 newsrv = curproxy->srv;
3097 if (!next)
3098 break;
3099 curproxy->srv = next;
3100 }
3101
Willy Tarreau17edc812014-01-03 12:14:34 +01003102 /* Check that no server name conflicts. This causes trouble in the stats.
3103 * We only emit a warning for the first conflict affecting each server,
3104 * in order to avoid combinatory explosion if all servers have the same
3105 * name. We do that only for servers which do not have an explicit ID,
3106 * because these IDs were made also for distinguishing them and we don't
3107 * want to annoy people who correctly manage them.
3108 */
3109 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3110 struct server *other_srv;
3111
3112 if (newsrv->puid)
3113 continue;
3114
3115 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
3116 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
Willy Tarreaub01302f2019-05-27 19:31:06 +02003117 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 +01003118 newsrv->conf.file, newsrv->conf.line,
3119 proxy_type_str(curproxy), curproxy->id,
3120 newsrv->id, other_srv->conf.line);
Willy Tarreaub01302f2019-05-27 19:31:06 +02003121 cfgerr++;
Willy Tarreau17edc812014-01-03 12:14:34 +01003122 break;
3123 }
3124 }
3125 }
3126
Willy Tarreaudd701652010-05-25 23:03:02 +02003127 /* assign automatic UIDs to servers which don't have one yet */
3128 next_id = 1;
3129 newsrv = curproxy->srv;
3130 while (newsrv != NULL) {
3131 if (!newsrv->puid) {
3132 /* server ID not set, use automatic numbering with first
3133 * spare entry starting with next_svid.
3134 */
3135 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
3136 newsrv->conf.id.key = newsrv->puid = next_id;
3137 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
Frédéric Lécaille84d60462019-05-17 14:29:15 +02003138 newsrv->conf.name.key = newsrv->id;
3139 ebis_insert(&curproxy->conf.used_server_name, &newsrv->conf.name);
Willy Tarreaudd701652010-05-25 23:03:02 +02003140 }
3141 next_id++;
3142 newsrv = newsrv->next;
3143 }
3144
Willy Tarreau20697042007-11-15 23:26:18 +01003145 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01003146 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02003147
Willy Tarreau62c3be22012-01-20 13:12:32 +01003148 /*
3149 * If this server supports a maxconn parameter, it needs a dedicated
3150 * tasks to fill the emptied slots when a connection leaves.
3151 * Also, resolve deferred tracking dependency if needed.
3152 */
3153 newsrv = curproxy->srv;
3154 while (newsrv != NULL) {
3155 if (newsrv->minconn > newsrv->maxconn) {
3156 /* Only 'minconn' was specified, or it was higher than or equal
3157 * to 'maxconn'. Let's turn this into maxconn and clean it, as
3158 * this will avoid further useless expensive computations.
3159 */
3160 newsrv->maxconn = newsrv->minconn;
3161 } else if (newsrv->maxconn && !newsrv->minconn) {
3162 /* minconn was not specified, so we set it to maxconn */
3163 newsrv->minconn = newsrv->maxconn;
3164 }
3165
Willy Tarreau17d45382016-12-22 21:16:08 +01003166 /* this will also properly set the transport layer for prod and checks */
Christopher Fauletf61f33a2020-03-27 18:55:49 +01003167 if (newsrv->use_ssl == 1 || newsrv->check.use_ssl == 1 || (newsrv->proxy->options & PR_O_TCPCHK_SSL)) {
Willy Tarreau17d45382016-12-22 21:16:08 +01003168 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
3169 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
3170 }
Emeric Brun94324a42012-10-11 14:00:19 +02003171
Willy Tarreau034c88c2017-01-23 23:36:45 +01003172 if ((newsrv->flags & SRV_F_FASTOPEN) &&
3173 ((curproxy->retry_type & (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)) !=
3174 (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)))
3175 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",
3176 newsrv->conf.file, newsrv->conf.line,
3177 proxy_type_str(curproxy), curproxy->id,
3178 newsrv->id);
3179
Willy Tarreau62c3be22012-01-20 13:12:32 +01003180 if (newsrv->trackit) {
3181 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02003182 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003183 char *pname, *sname;
3184
3185 pname = newsrv->trackit;
3186 sname = strrchr(pname, '/');
3187
3188 if (sname)
3189 *sname++ = '\0';
3190 else {
3191 sname = pname;
3192 pname = NULL;
3193 }
3194
3195 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02003196 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003197 if (!px) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003198 ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
3199 proxy_type_str(curproxy), curproxy->id,
3200 newsrv->id, pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003201 cfgerr++;
3202 goto next_srv;
3203 }
3204 } else
3205 px = curproxy;
3206
3207 srv = findserver(px, sname);
3208 if (!srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003209 ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
3210 proxy_type_str(curproxy), curproxy->id,
3211 newsrv->id, sname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003212 cfgerr++;
3213 goto next_srv;
3214 }
3215
Christopher Faulet8892e5d2020-03-26 19:48:20 +01003216 if (!srv->do_check && !srv->do_agent && !srv->track && !srv->trackit) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003217 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for "
3218 "tracking as it does not have any check nor agent enabled.\n",
3219 proxy_type_str(curproxy), curproxy->id,
3220 newsrv->id, px->id, srv->id);
Willy Tarreau32091232014-05-16 13:52:00 +02003221 cfgerr++;
3222 goto next_srv;
3223 }
3224
3225 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
3226
Frédéric Lécaille2efc6492017-03-14 14:32:17 +01003227 if (newsrv == srv || loop) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003228 ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it "
3229 "belongs to a tracking chain looping back to %s/%s.\n",
3230 proxy_type_str(curproxy), curproxy->id,
3231 newsrv->id, px->id, srv->id, px->id,
3232 newsrv == srv ? srv->id : loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003233 cfgerr++;
3234 goto next_srv;
3235 }
3236
3237 if (curproxy != px &&
3238 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003239 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for"
3240 "tracking: disable-on-404 option inconsistency.\n",
3241 proxy_type_str(curproxy), curproxy->id,
3242 newsrv->id, px->id, srv->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003243 cfgerr++;
3244 goto next_srv;
3245 }
3246
Willy Tarreau62c3be22012-01-20 13:12:32 +01003247 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01003248 newsrv->tracknext = srv->trackers;
3249 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003250
3251 free(newsrv->trackit);
3252 newsrv->trackit = NULL;
3253 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02003254
Willy Tarreau62c3be22012-01-20 13:12:32 +01003255 next_srv:
3256 newsrv = newsrv->next;
3257 }
3258
Olivier Houchard4e694042017-03-14 20:01:29 +01003259 /*
3260 * Try to generate dynamic cookies for servers now.
3261 * It couldn't be done earlier, since at the time we parsed
3262 * the server line, we may not have known yet that we
3263 * should use dynamic cookies, or the secret key may not
3264 * have been provided yet.
3265 */
3266 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
3267 newsrv = curproxy->srv;
3268 while (newsrv != NULL) {
3269 srv_set_dyncookie(newsrv);
3270 newsrv = newsrv->next;
3271 }
3272
3273 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003274 /* We have to initialize the server lookup mechanism depending
Joseph Herlanta14c03e2018-11-15 14:04:19 -08003275 * on what LB algorithm was chosen.
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003276 */
3277
3278 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
3279 switch (curproxy->lbprm.algo & BE_LB_KIND) {
3280 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02003281 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
3282 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3283 init_server_map(curproxy);
Willy Tarreau760e81d2018-05-03 07:20:40 +02003284 } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
3285 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3286 chash_init_server_tree(curproxy);
Willy Tarreau9757a382009-10-03 12:56:50 +02003287 } else {
3288 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
3289 fwrr_init_server_groups(curproxy);
3290 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003291 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003292
Willy Tarreau3ebb1162012-02-13 16:57:44 +01003293 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01003294 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
3295 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
3296 fwlc_init_server_tree(curproxy);
3297 } else {
3298 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
3299 fas_init_server_tree(curproxy);
3300 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003301 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003302
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003303 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003304 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
3305 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3306 chash_init_server_tree(curproxy);
3307 } else {
3308 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3309 init_server_map(curproxy);
3310 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003311 break;
3312 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003313 HA_SPIN_INIT(&curproxy->lbprm.lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003314
3315 if (curproxy->options & PR_O_LOGASAP)
3316 curproxy->to_log &= ~LW_BYTES;
3317
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003318 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003319 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
3320 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003321 ha_warning("config : log format ignored for %s '%s' since it has no log address.\n",
3322 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003323 err_code |= ERR_WARN;
3324 }
3325
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003326 if (curproxy->mode != PR_MODE_HTTP) {
3327 int optnum;
3328
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003329 if (curproxy->uri_auth) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003330 ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
3331 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003332 err_code |= ERR_WARN;
3333 curproxy->uri_auth = NULL;
3334 }
3335
Willy Tarreaude7dc882017-03-10 11:49:21 +01003336 if (curproxy->capture_name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003337 ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
3338 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003339 err_code |= ERR_WARN;
3340 }
3341
3342 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003343 ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
3344 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003345 err_code |= ERR_WARN;
3346 }
3347
3348 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003349 ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
3350 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003351 err_code |= ERR_WARN;
3352 }
3353
Willy Tarreaude7dc882017-03-10 11:49:21 +01003354 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003355 ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
3356 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003357 err_code |= ERR_WARN;
3358 }
3359
Willy Tarreau87cf5142011-08-19 22:57:24 +02003360 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003361 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3362 "forwardfor", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003363 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02003364 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003365 }
3366
3367 if (curproxy->options & PR_O_ORGTO) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003368 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3369 "originalto", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003370 err_code |= ERR_WARN;
3371 curproxy->options &= ~PR_O_ORGTO;
3372 }
3373
3374 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
3375 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
3376 (curproxy->cap & cfg_opts[optnum].cap) &&
3377 (curproxy->options & cfg_opts[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003378 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3379 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003380 err_code |= ERR_WARN;
3381 curproxy->options &= ~cfg_opts[optnum].val;
3382 }
3383 }
3384
3385 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
3386 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
3387 (curproxy->cap & cfg_opts2[optnum].cap) &&
3388 (curproxy->options2 & cfg_opts2[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003389 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3390 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003391 err_code |= ERR_WARN;
3392 curproxy->options2 &= ~cfg_opts2[optnum].val;
3393 }
3394 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003395
Willy Tarreau29fbe512015-08-20 19:35:14 +02003396#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003397 if (curproxy->conn_src.bind_hdr_occ) {
3398 curproxy->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003399 ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
3400 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003401 err_code |= ERR_WARN;
3402 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003403#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003404 }
3405
Willy Tarreaubaaee002006-06-26 02:48:02 +02003406 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01003407 * ensure that we're not cross-dressing a TCP server into HTTP.
3408 */
3409 newsrv = curproxy->srv;
3410 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01003411 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003412 ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
3413 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02003414 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01003415 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003416
Willy Tarreau0cec3312011-10-31 13:49:26 +01003417 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003418 ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
3419 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau0cec3312011-10-31 13:49:26 +01003420 err_code |= ERR_WARN;
3421 }
3422
Willy Tarreauc93cd162014-05-13 15:54:22 +02003423 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003424 ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
3425 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau82ffa392013-08-13 17:19:08 +02003426 err_code |= ERR_WARN;
3427 }
3428
Willy Tarreau29fbe512015-08-20 19:35:14 +02003429#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003430 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
3431 newsrv->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003432 ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
3433 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003434 err_code |= ERR_WARN;
3435 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003436#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01003437
Willy Tarreau46deab62018-04-28 07:18:15 +02003438 if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR)
3439 curproxy->options &= ~PR_O_REUSE_MASK;
3440
Willy Tarreau21d2af32008-02-14 20:25:24 +01003441 newsrv = newsrv->next;
3442 }
3443
Christopher Fauletd7c91962015-04-30 11:48:27 +02003444 /* Check filter configuration, if any */
3445 cfgerr += flt_check(curproxy);
3446
Willy Tarreauc1a21672009-08-16 22:37:44 +02003447 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02003448 if (!curproxy->accept)
3449 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02003450
Willy Tarreauc1a21672009-08-16 22:37:44 +02003451 if (curproxy->tcp_req.inspect_delay ||
3452 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02003453 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003454
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003455 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003456 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003457 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003458 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003459
William Lallemandcf62f7e2018-10-26 14:47:40 +02003460 if (curproxy->mode == PR_MODE_CLI) {
3461 curproxy->fe_req_ana |= AN_REQ_WAIT_CLI;
3462 curproxy->fe_rsp_ana |= AN_RES_WAIT_CLI;
3463 }
3464
Willy Tarreauc1a21672009-08-16 22:37:44 +02003465 /* both TCP and HTTP must check switching rules */
3466 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003467
3468 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003469 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003470 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3471 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 +01003472 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003473 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3474 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003475 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003476 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003477 }
3478
3479 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02003480 if (curproxy->tcp_req.inspect_delay ||
3481 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
3482 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
3483
Emeric Brun97679e72010-09-23 17:56:44 +02003484 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
3485 curproxy->be_rsp_ana |= AN_RES_INSPECT;
3486
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003487 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003488 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003489 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003490 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003491
3492 /* If the backend does requires RDP cookie persistence, we have to
3493 * enable the corresponding analyser.
3494 */
3495 if (curproxy->options2 & PR_O2_RDPC_PRST)
3496 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003497
3498 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003499 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003500 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3501 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 +01003502 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003503 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3504 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003505 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003506 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003507 }
Christopher Fauleta717b992018-04-10 14:43:00 +02003508
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003509 /* Check the mux protocols, if any, for each listener and server
Christopher Fauleta717b992018-04-10 14:43:00 +02003510 * attached to the current proxy */
3511 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3512 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003513 const struct mux_proto_list *mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003514
3515 if (!bind_conf->mux_proto)
3516 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003517
3518 /* it is possible that an incorrect mux was referenced
3519 * due to the proxy's mode not being taken into account
3520 * on first pass. Let's adjust it now.
3521 */
3522 mux_ent = conn_get_best_mux_entry(bind_conf->mux_proto->token, PROTO_SIDE_FE, mode);
3523
3524 if (!mux_ent || !isteq(mux_ent->token, bind_conf->mux_proto->token)) {
Christopher Fauleta717b992018-04-10 14:43:00 +02003525 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n",
3526 proxy_type_str(curproxy), curproxy->id,
3527 (int)bind_conf->mux_proto->token.len,
3528 bind_conf->mux_proto->token.ptr,
3529 bind_conf->arg, bind_conf->file, bind_conf->line);
3530 cfgerr++;
3531 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003532
3533 /* update the mux */
3534 bind_conf->mux_proto = mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003535 }
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003536 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3537 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003538 const struct mux_proto_list *mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003539
3540 if (!newsrv->mux_proto)
3541 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003542
3543 /* it is possible that an incorrect mux was referenced
3544 * due to the proxy's mode not being taken into account
3545 * on first pass. Let's adjust it now.
3546 */
3547 mux_ent = conn_get_best_mux_entry(newsrv->mux_proto->token, PROTO_SIDE_BE, mode);
3548
3549 if (!mux_ent || !isteq(mux_ent->token, newsrv->mux_proto->token)) {
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003550 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n",
3551 proxy_type_str(curproxy), curproxy->id,
3552 (int)newsrv->mux_proto->token.len,
3553 newsrv->mux_proto->token.ptr,
3554 newsrv->id, newsrv->conf.file, newsrv->conf.line);
3555 cfgerr++;
3556 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003557
3558 /* update the mux */
3559 newsrv->mux_proto = mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003560 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003561
3562 /* initialize idle conns lists */
3563 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3564 int i;
3565
Willy Tarreauad37c7a2020-07-17 14:18:36 +02003566 newsrv->available_conns = calloc(global.nbthread, sizeof(*newsrv->available_conns));
Willy Tarreau835daa12019-02-07 14:46:29 +01003567
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003568 if (!newsrv->available_conns) {
Willy Tarreau835daa12019-02-07 14:46:29 +01003569 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003570 newsrv->conf.file, newsrv->conf.line, newsrv->id);
Willy Tarreau835daa12019-02-07 14:46:29 +01003571 cfgerr++;
3572 continue;
3573 }
3574
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003575 for (i = 0; i < global.nbthread; i++)
3576 LIST_INIT(&newsrv->available_conns[i]);
Willy Tarreau980855b2019-02-07 14:59:29 +01003577
3578 if (newsrv->max_idle_conns != 0) {
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003579 if (idle_conn_task == NULL) {
3580 idle_conn_task = task_new(MAX_THREADS_MASK);
3581 if (!idle_conn_task)
3582 goto err;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003583
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003584 idle_conn_task->process = srv_cleanup_idle_connections;
3585 idle_conn_task->context = NULL;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003586
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003587 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003588 idle_conns[i].cleanup_task = task_new(1UL << i);
3589 if (!idle_conns[i].cleanup_task)
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003590 goto err;
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003591 idle_conns[i].cleanup_task->process = srv_cleanup_toremove_connections;
3592 idle_conns[i].cleanup_task->context = NULL;
Olivier Houchardf8f4c2e2020-06-29 20:15:59 +02003593 HA_SPIN_INIT(&idle_conns[i].takeover_lock);
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003594 MT_LIST_INIT(&idle_conns[i].toremove_conns);
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003595 }
3596 }
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003597
Willy Tarreau9b9c1742020-07-17 15:04:53 +02003598 newsrv->idle_conns = calloc((unsigned short)global.nbthread, sizeof(*newsrv->idle_conns));
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003599 if (!newsrv->idle_conns) {
3600 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3601 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3602 cfgerr++;
3603 continue;
3604 }
3605
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003606 for (i = 0; i < global.nbthread; i++)
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003607 MT_LIST_INIT(&newsrv->idle_conns[i]);
3608
Willy Tarreauad37c7a2020-07-17 14:18:36 +02003609 newsrv->safe_conns = calloc(global.nbthread, sizeof(*newsrv->safe_conns));
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003610 if (!newsrv->safe_conns) {
3611 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3612 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3613 cfgerr++;
3614 continue;
3615 }
3616
3617 for (i = 0; i < global.nbthread; i++)
3618 MT_LIST_INIT(&newsrv->safe_conns[i]);
3619
Tim Duesterhusb53dd032020-09-12 20:26:42 +02003620 newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
Olivier Houchardf1314812019-02-18 16:41:17 +01003621 if (!newsrv->curr_idle_thr)
3622 goto err;
Willy Tarreau980855b2019-02-07 14:59:29 +01003623 continue;
3624 err:
3625 ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
3626 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3627 cfgerr++;
3628 continue;
3629 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003630 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003631 }
3632
3633 /***********************************************************/
3634 /* At this point, target names have already been resolved. */
3635 /***********************************************************/
3636
3637 /* Check multi-process mode compatibility */
3638
3639 if (global.nbproc > 1 && global.stats_fe) {
3640 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3641 unsigned long mask;
3642
Willy Tarreau6daac192019-02-02 17:39:53 +01003643 mask = proc_mask(global.stats_fe->bind_proc) && all_proc_mask;
Willy Tarreaue26993c2020-09-03 07:18:55 +02003644 mask &= proc_mask(bind_conf->settings.bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003645
3646 /* stop here if more than one process is used */
Willy Tarreau9504dd62018-10-15 09:37:03 +02003647 if (atleast2(mask))
Willy Tarreau419ead82014-09-16 13:41:21 +02003648 break;
3649 }
3650 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003651 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 +02003652 }
3653 }
3654
3655 /* Make each frontend inherit bind-process from its listeners when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003656 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003657 if (curproxy->bind_proc)
3658 continue;
3659
3660 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3661 unsigned long mask;
3662
Willy Tarreaue26993c2020-09-03 07:18:55 +02003663 mask = proc_mask(bind_conf->settings.bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003664 curproxy->bind_proc |= mask;
3665 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003666 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003667 }
3668
3669 if (global.stats_fe) {
3670 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3671 unsigned long mask;
3672
Willy Tarreaue26993c2020-09-03 07:18:55 +02003673 mask = bind_conf->settings.bind_proc ? bind_conf->settings.bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02003674 global.stats_fe->bind_proc |= mask;
3675 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003676 global.stats_fe->bind_proc = proc_mask(global.stats_fe->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003677 }
3678
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003679 /* propagate bindings from frontends to backends. Don't do it if there
3680 * are any fatal errors as we must not call it with unresolved proxies.
3681 */
3682 if (!cfgerr) {
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003683 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003684 if (curproxy->cap & PR_CAP_FE)
3685 propagate_processes(curproxy, NULL);
3686 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003687 }
3688
3689 /* Bind each unbound backend to all processes when not specified. */
Willy Tarreau6daac192019-02-02 17:39:53 +01003690 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
3691 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003692
3693 /*******************************************************/
3694 /* At this step, all proxies have a non-null bind_proc */
3695 /*******************************************************/
3696
3697 /* perform the final checks before creating tasks */
3698
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003699 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003700 struct listener *listener;
3701 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003702
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003703 /* Configure SSL for each bind line.
3704 * Note: if configuration fails at some point, the ->ctx member
3705 * remains NULL so that listeners can later detach.
3706 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003707 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01003708 if (bind_conf->xprt->prepare_bind_conf &&
3709 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003710 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003711 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003712
Willy Tarreaue6b98942007-10-29 01:09:36 +01003713 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003714 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02003715 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003716 int nbproc;
3717
3718 nbproc = my_popcountl(curproxy->bind_proc &
Willy Tarreaue26993c2020-09-03 07:18:55 +02003719 (listener->bind_conf->settings.bind_proc ? listener->bind_conf->settings.bind_proc : curproxy->bind_proc) &
Willy Tarreaua38a7172019-02-02 17:11:28 +01003720 all_proc_mask);
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003721
3722 if (!nbproc) /* no intersection between listener and frontend */
3723 nbproc = 1;
3724
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003725 if (!listener->luid) {
3726 /* listener ID not set, use automatic numbering with first
3727 * spare entry starting with next_luid.
3728 */
3729 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
3730 listener->conf.id.key = listener->luid = next_id;
3731 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003732 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01003733 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003734
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003735 /* enable separate counters */
3736 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01003737 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003738 if (!listener->name)
3739 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003740 }
Willy Tarreau81796be2012-09-22 19:11:47 +02003741
Willy Tarreaue6b98942007-10-29 01:09:36 +01003742 if (curproxy->options & PR_O_TCP_NOLING)
3743 listener->options |= LI_O_NOLINGER;
Willy Tarreau16a21472012-11-19 12:39:59 +01003744 if (!listener->maxaccept)
3745 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
3746
3747 /* we want to have an optimal behaviour on single process mode to
3748 * maximize the work at once, but in multi-process we want to keep
3749 * some fairness between processes, so we target half of the max
3750 * number of events to be balanced over all the processes the proxy
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +05003751 * is bound to. Remember that maxaccept = -1 must be kept as it is
Willy Tarreau16a21472012-11-19 12:39:59 +01003752 * used to disable the limit.
3753 */
Christopher Faulet02f3cf12019-04-30 14:08:41 +02003754 if (listener->maxaccept > 0 && nbproc > 1) {
3755 listener->maxaccept = (listener->maxaccept + 1) / 2;
Willy Tarreau16a21472012-11-19 12:39:59 +01003756 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
3757 }
3758
Willy Tarreau9903f0e2015-04-04 18:50:31 +02003759 listener->accept = session_accept_fd;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003760 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01003761 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01003762
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003763 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02003764 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003765
Willy Tarreau620408f2016-10-21 16:37:51 +02003766 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
3767 listener->options |= LI_O_TCP_L5_RULES;
3768
Willy Tarreaude3041d2010-05-31 10:56:17 +02003769 if (curproxy->mon_mask.s_addr)
3770 listener->options |= LI_O_CHK_MONNET;
3771
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003772 /* smart accept mode is automatic in HTTP mode */
3773 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003774 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003775 !(curproxy->no_options2 & PR_O2_SMARTACC)))
3776 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01003777 }
3778
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003779 /* Release unused SSL configs */
3780 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01003781 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
3782 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003783 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003784
Willy Tarreaua38a7172019-02-02 17:11:28 +01003785 if (atleast2(curproxy->bind_proc & all_proc_mask)) {
Willy Tarreau102df612014-05-07 23:56:38 +02003786 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02003787 int count, maxproc = 0;
3788
3789 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreaue26993c2020-09-03 07:18:55 +02003790 count = my_popcountl(bind_conf->settings.bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003791 if (count > maxproc)
3792 maxproc = count;
3793 }
3794 /* backends have 0, frontends have 1 or more */
3795 if (maxproc != 1)
Christopher Faulet767a84b2017-11-24 16:50:31 +01003796 ha_warning("Proxy '%s': in multi-process mode, stats will be"
3797 " limited to process assigned to the current request.\n",
3798 curproxy->id);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003799
Willy Tarreau102df612014-05-07 23:56:38 +02003800 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003801 ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
3802 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003803 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003804 }
Willy Tarreau102df612014-05-07 23:56:38 +02003805 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003806 ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
3807 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003808 }
3809 }
Willy Tarreau918ff602011-07-25 16:33:49 +02003810
3811 /* create the task associated with the proxy */
Emeric Brunc60def82017-09-27 14:59:38 +02003812 curproxy->task = task_new(MAX_THREADS_MASK);
Willy Tarreau918ff602011-07-25 16:33:49 +02003813 if (curproxy->task) {
3814 curproxy->task->context = curproxy;
3815 curproxy->task->process = manage_proxy;
Willy Tarreau918ff602011-07-25 16:33:49 +02003816 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003817 ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
3818 curproxy->id);
Willy Tarreau918ff602011-07-25 16:33:49 +02003819 cfgerr++;
3820 }
Willy Tarreaub369a042014-09-16 13:21:03 +02003821 }
3822
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003823 /*
3824 * Recount currently required checks.
3825 */
3826
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003827 for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003828 int optnum;
3829
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003830 for (optnum = 0; cfg_opts[optnum].name; optnum++)
3831 if (curproxy->options & cfg_opts[optnum].val)
3832 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003833
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003834 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
3835 if (curproxy->options2 & cfg_opts2[optnum].val)
3836 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003837 }
3838
Willy Tarreau0fca4832015-05-01 19:12:05 +02003839 /* compute the required process bindings for the peers */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003840 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003841 if (curproxy->table && curproxy->table->peers.p)
3842 curproxy->table->peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
Willy Tarreau0fca4832015-05-01 19:12:05 +02003843
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01003844 /* compute the required process bindings for the peers from <stktables_list>
3845 * for all the stick-tables, the ones coming with "peers" sections included.
3846 */
3847 for (t = stktables_list; t; t = t->next) {
3848 struct proxy *p;
3849
3850 for (p = t->proxies_list; p; p = p->next_stkt_ref) {
3851 if (t->peers.p && t->peers.p->peers_fe) {
3852 t->peers.p->peers_fe->bind_proc |= p->bind_proc;
3853 }
3854 }
3855 }
3856
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003857 if (cfg_peers) {
3858 struct peers *curpeers = cfg_peers, **last;
Willy Tarreau122541c2011-09-07 21:24:49 +02003859 struct peer *p, *pb;
3860
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003861 /* In the case the peers frontend was not initialized by a
3862 stick-table used in the configuration, set its bind_proc
3863 by default to the first process. */
3864 while (curpeers) {
William Lallemand3ef2d562020-03-24 16:42:15 +01003865 if (curpeers->peers_fe) {
3866 if (curpeers->peers_fe->bind_proc == 0)
3867 curpeers->peers_fe->bind_proc = 1;
3868 }
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003869 curpeers = curpeers->next;
3870 }
3871
3872 curpeers = cfg_peers;
Willy Tarreau1e273012015-05-01 19:15:17 +02003873 /* Remove all peers sections which don't have a valid listener,
3874 * which are not used by any table, or which are bound to more
3875 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02003876 */
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003877 last = &cfg_peers;
Willy Tarreau122541c2011-09-07 21:24:49 +02003878 while (*last) {
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003879 struct stktable *t;
Willy Tarreau122541c2011-09-07 21:24:49 +02003880 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003881
3882 if (curpeers->state == PR_STSTOPPED) {
3883 /* the "disabled" keyword was present */
3884 if (curpeers->peers_fe)
3885 stop_proxy(curpeers->peers_fe);
3886 curpeers->peers_fe = NULL;
3887 }
Frédéric Lécaille5a4fe5a2019-10-04 08:30:04 +02003888 else if (!curpeers->peers_fe || !curpeers->peers_fe->id) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003889 ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
3890 curpeers->id, localpeer);
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003891 if (curpeers->peers_fe)
3892 stop_proxy(curpeers->peers_fe);
3893 curpeers->peers_fe = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003894 }
Willy Tarreau9504dd62018-10-15 09:37:03 +02003895 else if (atleast2(curpeers->peers_fe->bind_proc)) {
Willy Tarreau1e273012015-05-01 19:15:17 +02003896 /* either it's totally stopped or too much used */
3897 if (curpeers->peers_fe->bind_proc) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003898 ha_alert("Peers section '%s': peers referenced by sections "
3899 "running in different processes (%d different ones). "
3900 "Check global.nbproc and all tables' bind-process "
3901 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02003902 cfgerr++;
3903 }
3904 stop_proxy(curpeers->peers_fe);
3905 curpeers->peers_fe = NULL;
3906 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003907 else {
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003908 /* Initializes the transport layer of the server part of all the peers belonging to
3909 * <curpeers> section if required.
3910 * Note that ->srv is used by the local peer of a new process to connect to the local peer
3911 * of an old process.
3912 */
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003913 p = curpeers->remote;
3914 while (p) {
Frédéric Lécaille355b2032019-01-11 14:06:12 +01003915 if (p->srv) {
Christopher Fauletf61f33a2020-03-27 18:55:49 +01003916 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 +01003917 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(p->srv);
3918 }
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003919 p = p->next;
3920 }
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003921 /* Configure the SSL bindings of the local peer if required. */
3922 if (!LIST_ISEMPTY(&curpeers->peers_fe->conf.bind)) {
3923 struct list *l;
3924 struct bind_conf *bind_conf;
3925
3926 l = &curpeers->peers_fe->conf.bind;
3927 bind_conf = LIST_ELEM(l->n, typeof(bind_conf), by_fe);
3928 if (bind_conf->xprt->prepare_bind_conf &&
3929 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
3930 cfgerr++;
3931 }
Frédéric Lécaille8d78fa72019-05-20 18:22:52 +02003932 if (!peers_init_sync(curpeers) || !peers_alloc_dcache(curpeers)) {
Willy Tarreaud9443442018-10-15 11:18:03 +02003933 ha_alert("Peers section '%s': out of memory, giving up on peers.\n",
3934 curpeers->id);
3935 cfgerr++;
3936 break;
3937 }
Willy Tarreau122541c2011-09-07 21:24:49 +02003938 last = &curpeers->next;
3939 continue;
3940 }
3941
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003942 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02003943 p = curpeers->remote;
3944 while (p) {
3945 pb = p->next;
3946 free(p->id);
3947 free(p);
3948 p = pb;
3949 }
3950
3951 /* Destroy and unlink this curpeers section.
3952 * Note: curpeers is backed up into *last.
3953 */
3954 free(curpeers->id);
3955 curpeers = curpeers->next;
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003956 /* Reset any refereance to this peers section in the list of stick-tables */
3957 for (t = stktables_list; t; t = t->next) {
3958 if (t->peers.p && t->peers.p == *last)
3959 t->peers.p = NULL;
3960 }
Willy Tarreau122541c2011-09-07 21:24:49 +02003961 free(*last);
3962 *last = curpeers;
3963 }
3964 }
3965
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003966 for (t = stktables_list; t; t = t->next) {
3967 if (t->proxy)
3968 continue;
3969 if (!stktable_init(t)) {
3970 ha_alert("Proxy '%s': failed to initialize stick-table.\n", t->id);
3971 cfgerr++;
3972 }
3973 }
3974
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003975 /* initialize stick-tables on backend capable proxies. This must not
3976 * be done earlier because the data size may be discovered while parsing
3977 * other proxies.
3978 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003979 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003980 if (curproxy->state == PR_STSTOPPED || !curproxy->table)
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003981 continue;
3982
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003983 if (!stktable_init(curproxy->table)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003984 ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003985 cfgerr++;
3986 }
3987 }
3988
Simon Horman0d16a402015-01-30 11:22:58 +09003989 if (mailers) {
3990 struct mailers *curmailers = mailers, **last;
3991 struct mailer *m, *mb;
3992
3993 /* Remove all mailers sections which don't have a valid listener.
3994 * This can happen when a mailers section is never referenced.
3995 */
3996 last = &mailers;
3997 while (*last) {
3998 curmailers = *last;
3999 if (curmailers->users) {
4000 last = &curmailers->next;
4001 continue;
4002 }
4003
Christopher Faulet767a84b2017-11-24 16:50:31 +01004004 ha_warning("Removing incomplete section 'mailers %s'.\n",
4005 curmailers->id);
Simon Horman0d16a402015-01-30 11:22:58 +09004006
4007 m = curmailers->mailer_list;
4008 while (m) {
4009 mb = m->next;
4010 free(m->id);
4011 free(m);
4012 m = mb;
4013 }
4014
4015 /* Destroy and unlink this curmailers section.
4016 * Note: curmailers is backed up into *last.
4017 */
4018 free(curmailers->id);
4019 curmailers = curmailers->next;
4020 free(*last);
4021 *last = curmailers;
4022 }
4023 }
4024
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02004025 /* Update server_state_file_name to backend name if backend is supposed to use
4026 * a server-state file locally defined and none has been provided */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01004027 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02004028 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
4029 curproxy->server_state_file_name == NULL)
4030 curproxy->server_state_file_name = strdup(curproxy->id);
4031 }
4032
Ben Draut054fbee2018-04-13 15:43:04 -06004033 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
4034 if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
4035 ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n",
4036 curr_resolvers->id, curr_resolvers->conf.file,
4037 curr_resolvers->conf.line);
4038 err_code |= ERR_WARN;
4039 }
4040 }
4041
William Lallemand48b4bb42017-10-23 14:36:34 +02004042 list_for_each_entry(postparser, &postparsers, list) {
4043 if (postparser->func)
4044 cfgerr += postparser->func();
4045 }
4046
Willy Tarreaubb925012009-07-23 13:36:36 +02004047 if (cfgerr > 0)
4048 err_code |= ERR_ALERT | ERR_FATAL;
4049 out:
4050 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004051}
4052
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004053/*
4054 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
4055 * parsing sessions.
4056 */
4057void cfg_register_keywords(struct cfg_kw_list *kwl)
4058{
4059 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
4060}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004061
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004062/*
4063 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
4064 */
4065void cfg_unregister_keywords(struct cfg_kw_list *kwl)
4066{
4067 LIST_DEL(&kwl->list);
4068 LIST_INIT(&kwl->list);
4069}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004070
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004071/* this function register new section in the haproxy configuration file.
4072 * <section_name> is the name of this new section and <section_parser>
4073 * is the called parser. If two section declaration have the same name,
4074 * only the first declared is used.
4075 */
4076int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +02004077 int (*section_parser)(const char *, int, char **, int),
4078 int (*post_section_parser)())
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004079{
4080 struct cfg_section *cs;
4081
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004082 list_for_each_entry(cs, &sections, list) {
4083 if (strcmp(cs->section_name, section_name) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004084 ha_alert("register section '%s': already registered.\n", section_name);
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004085 return 0;
4086 }
4087 }
4088
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004089 cs = calloc(1, sizeof(*cs));
4090 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004091 ha_alert("register section '%s': out of memory.\n", section_name);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004092 return 0;
4093 }
4094
4095 cs->section_name = section_name;
4096 cs->section_parser = section_parser;
William Lallemandd2ff56d2017-10-16 11:06:50 +02004097 cs->post_section_parser = post_section_parser;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004098
4099 LIST_ADDQ(&sections, &cs->list);
4100
4101 return 1;
4102}
4103
William Lallemand48b4bb42017-10-23 14:36:34 +02004104/* this function register a new function which will be called once the haproxy
4105 * configuration file has been parsed. It's useful to check dependencies
4106 * between sections or to resolve items once everything is parsed.
4107 */
4108int cfg_register_postparser(char *name, int (*func)())
4109{
4110 struct cfg_postparser *cp;
4111
4112 cp = calloc(1, sizeof(*cp));
4113 if (!cp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004114 ha_alert("register postparser '%s': out of memory.\n", name);
William Lallemand48b4bb42017-10-23 14:36:34 +02004115 return 0;
4116 }
4117 cp->name = name;
4118 cp->func = func;
4119
4120 LIST_ADDQ(&postparsers, &cp->list);
4121
4122 return 1;
4123}
4124
Willy Tarreaubaaee002006-06-26 02:48:02 +02004125/*
David Carlier845efb52015-09-25 11:49:18 +01004126 * free all config section entries
4127 */
4128void cfg_unregister_sections(void)
4129{
4130 struct cfg_section *cs, *ics;
4131
4132 list_for_each_entry_safe(cs, ics, &sections, list) {
4133 LIST_DEL(&cs->list);
4134 free(cs);
4135 }
4136}
4137
Christopher Faulet7110b402016-10-26 11:09:44 +02004138void cfg_backup_sections(struct list *backup_sections)
4139{
4140 struct cfg_section *cs, *ics;
4141
4142 list_for_each_entry_safe(cs, ics, &sections, list) {
4143 LIST_DEL(&cs->list);
4144 LIST_ADDQ(backup_sections, &cs->list);
4145 }
4146}
4147
4148void cfg_restore_sections(struct list *backup_sections)
4149{
4150 struct cfg_section *cs, *ics;
4151
4152 list_for_each_entry_safe(cs, ics, backup_sections, list) {
4153 LIST_DEL(&cs->list);
4154 LIST_ADDQ(&sections, &cs->list);
4155 }
4156}
4157
Willy Tarreaue6552512018-11-26 11:33:13 +01004158/* these are the config sections handled by default */
4159REGISTER_CONFIG_SECTION("listen", cfg_parse_listen, NULL);
4160REGISTER_CONFIG_SECTION("frontend", cfg_parse_listen, NULL);
4161REGISTER_CONFIG_SECTION("backend", cfg_parse_listen, NULL);
4162REGISTER_CONFIG_SECTION("defaults", cfg_parse_listen, NULL);
4163REGISTER_CONFIG_SECTION("global", cfg_parse_global, NULL);
4164REGISTER_CONFIG_SECTION("userlist", cfg_parse_users, NULL);
4165REGISTER_CONFIG_SECTION("peers", cfg_parse_peers, NULL);
4166REGISTER_CONFIG_SECTION("mailers", cfg_parse_mailers, NULL);
4167REGISTER_CONFIG_SECTION("namespace_list", cfg_parse_netns, NULL);
4168REGISTER_CONFIG_SECTION("resolvers", cfg_parse_resolvers, NULL);
Willy Tarreau659fbf02016-05-26 17:55:28 +02004169
David Carlier845efb52015-09-25 11:49:18 +01004170/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02004171 * Local variables:
4172 * c-indent-level: 8
4173 * c-basic-offset: 8
4174 * End:
4175 */