blob: 4dd01bb6319b923412163494dbe92916f7817749 [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>
Frédéric Lécaille884f2e92020-11-23 14:23:21 +010081#include <haproxy/xprt_quic.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020082
83
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +010084/* Used to chain configuration sections definitions. This list
85 * stores struct cfg_section
86 */
87struct list sections = LIST_HEAD_INIT(sections);
88
William Lallemand48b4bb42017-10-23 14:36:34 +020089struct list postparsers = LIST_HEAD_INIT(postparsers);
90
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010091char *cursection = NULL;
92struct proxy defproxy = { }; /* fake proxy used to assign default values on all instances */
Willy Tarreauc8d5b952019-02-27 17:25:52 +010093int cfg_maxpconn = 0; /* # of simultaneous connections per proxy (-N) */
Willy Tarreau5af24ef2009-03-15 15:23:16 +010094int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
Christopher Faulet79bdef32016-11-04 22:36:15 +010095char *cfg_scope = NULL; /* the current scope during the configuration parsing */
Willy Tarreaubaaee002006-06-26 02:48:02 +020096
Willy Tarreau5b2c3362008-07-09 19:39:06 +020097/* List head of all known configuration keywords */
Willy Tarreau36b9e222018-11-11 15:19:52 +010098struct cfg_kw_list cfg_keywords = {
Willy Tarreau5b2c3362008-07-09 19:39:06 +020099 .list = LIST_HEAD_INIT(cfg_keywords.list)
100};
101
Willy Tarreaubaaee002006-06-26 02:48:02 +0200102/*
103 * converts <str> to a list of listeners which are dynamically allocated.
104 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
105 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
106 * - <port> is a numerical port from 1 to 65535 ;
107 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
108 * This can be repeated as many times as necessary, separated by a coma.
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200109 * Function returns 1 for success or 0 if error. In case of errors, if <err> is
110 * not NULL, it must be a valid pointer to either NULL or a freeable area that
111 * will be replaced with an error message.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200112 */
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200113int 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 +0200114{
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200115 struct protocol *proto;
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100116 char *next, *dupstr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200117 int port, end;
118
119 next = dupstr = strdup(str);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200120
Willy Tarreaubaaee002006-06-26 02:48:02 +0200121 while (next && *next) {
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200122 struct sockaddr_storage *ss2;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100123 int fd = -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200124
125 str = next;
126 /* 1) look for the end of the first address */
Krzysztof Piotr Oledzki52d522b2009-01-27 16:57:08 +0100127 if ((next = strchr(str, ',')) != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200128 *next++ = 0;
129 }
130
Willy Tarreau5fc93282020-09-16 18:25:03 +0200131 ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err,
Willy Tarreau72b8c1f2015-09-08 15:50:19 +0200132 curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
Willy Tarreau32819932020-09-04 15:53:16 +0200133 NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE |
Willy Tarreau5e1779a2020-09-16 16:28:08 +0200134 PA_O_SOCKET_FD | PA_O_STREAM | PA_O_XPRT);
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100135 if (!ss2)
136 goto fail;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200137
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100138 /* OK the address looks correct */
Frédéric Lécaille884f2e92020-11-23 14:23:21 +0100139
140#ifdef USE_QUIC
141 /* The transport layer automatically switches to QUIC when QUIC
142 * is selected, regardless of bind_conf settings. We then need
143 * to initialize QUIC params.
144 */
145 if (proto->sock_type == SOCK_DGRAM && proto->ctrl_type == SOCK_STREAM) {
146 bind_conf->xprt = xprt_get(XPRT_QUIC);
147 quic_transport_params_init(&bind_conf->quic_params, 1);
148 }
149#endif
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200150 if (!create_listeners(bind_conf, ss2, port, end, fd, proto, err)) {
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200151 memprintf(err, "%s for address '%s'.\n", *err, str);
152 goto fail;
153 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200154 } /* end while(next) */
155 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200156 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200157 fail:
158 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200159 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200160}
161
William Lallemand6e62fb62015-04-28 16:55:23 +0200162/*
Willy Tarreauaa333122020-09-16 15:13:04 +0200163 * converts <str> to a list of datagram-oriented listeners which are dynamically
164 * allocated.
165 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
166 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
167 * - <port> is a numerical port from 1 to 65535 ;
168 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
169 * This can be repeated as many times as necessary, separated by a coma.
170 * Function returns 1 for success or 0 if error. In case of errors, if <err> is
171 * not NULL, it must be a valid pointer to either NULL or a freeable area that
172 * will be replaced with an error message.
173 */
174int str2receiver(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err)
175{
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200176 struct protocol *proto;
Willy Tarreauaa333122020-09-16 15:13:04 +0200177 char *next, *dupstr;
178 int port, end;
179
180 next = dupstr = strdup(str);
181
182 while (next && *next) {
183 struct sockaddr_storage *ss2;
184 int fd = -1;
185
186 str = next;
187 /* 1) look for the end of the first address */
188 if ((next = strchr(str, ',')) != NULL) {
189 *next++ = 0;
190 }
191
Willy Tarreau5fc93282020-09-16 18:25:03 +0200192 ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err,
Willy Tarreauaa333122020-09-16 15:13:04 +0200193 curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
194 NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE |
195 PA_O_SOCKET_FD | PA_O_DGRAM | PA_O_XPRT);
196 if (!ss2)
197 goto fail;
198
199 /* OK the address looks correct */
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200200 if (!create_listeners(bind_conf, ss2, port, end, fd, proto, err)) {
Willy Tarreauaa333122020-09-16 15:13:04 +0200201 memprintf(err, "%s for address '%s'.\n", *err, str);
202 goto fail;
203 }
204 } /* end while(next) */
205 free(dupstr);
206 return 1;
207 fail:
208 free(dupstr);
209 return 0;
210}
211
212/*
Willy Tarreauece9b072016-12-21 22:41:44 +0100213 * Report an error in <msg> when there are too many arguments. This version is
214 * intended to be used by keyword parsers so that the message will be included
215 * into the general error message. The index is the current keyword in args.
216 * Return 0 if the number of argument is correct, otherwise build a message and
217 * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The
218 * message may also be null, it will simply not be produced (useful to check only).
219 * <msg> and <err_code> are only affected on error.
220 */
221int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code)
222{
223 int i;
224
225 if (!*args[index + maxarg + 1])
226 return 0;
227
228 if (msg) {
229 *msg = NULL;
230 memprintf(msg, "%s", args[0]);
231 for (i = 1; i <= index; i++)
232 memprintf(msg, "%s %s", *msg, args[i]);
233
234 memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]);
235 }
236 if (err_code)
237 *err_code |= ERR_ALERT | ERR_FATAL;
238
239 return 1;
240}
241
242/*
243 * same as too_many_args_idx with a 0 index
244 */
245int too_many_args(int maxarg, char **args, char **msg, int *err_code)
246{
247 return too_many_args_idx(maxarg, 0, args, msg, err_code);
248}
249
250/*
William Lallemand6e62fb62015-04-28 16:55:23 +0200251 * Report a fatal Alert when there is too much arguments
252 * The index is the current keyword in args
253 * Return 0 if the number of argument is correct, otherwise emit an alert and return 1
254 * Fill err_code with an ERR_ALERT and an ERR_FATAL
255 */
256int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code)
257{
258 char *kw = NULL;
259 int i;
260
261 if (!*args[index + maxarg + 1])
262 return 0;
263
264 memprintf(&kw, "%s", args[0]);
265 for (i = 1; i <= index; i++) {
266 memprintf(&kw, "%s %s", kw, args[i]);
267 }
268
Christopher Faulet767a84b2017-11-24 16:50:31 +0100269 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 +0200270 free(kw);
271 *err_code |= ERR_ALERT | ERR_FATAL;
272 return 1;
273}
274
275/*
276 * same as alertif_too_many_args_idx with a 0 index
277 */
278int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code)
279{
280 return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code);
281}
282
Willy Tarreau61d18892009-03-31 10:49:21 +0200283
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100284/* Report it if a request ACL condition uses some keywords that are incompatible
285 * with the place where the ACL is used. It returns either 0 or ERR_WARN so that
286 * its result can be or'ed with err_code. Note that <cond> may be NULL and then
287 * will be ignored.
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100288 */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100289int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100290{
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100291 const struct acl *acl;
Willy Tarreau93fddf12013-03-31 22:59:32 +0200292 const char *kw;
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100293
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100294 if (!cond)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100295 return 0;
296
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100297 acl = acl_cond_conflicts(cond, where);
298 if (acl) {
299 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100300 ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n",
301 file, line, acl->name, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100302 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100303 ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
304 file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100305 return ERR_WARN;
306 }
307 if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100308 return 0;
309
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100310 if (acl->name && *acl->name)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100311 ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
312 file, line, acl->name, kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100313 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100314 ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
315 file, line, kw, sample_ckp_names(where));
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100316 return ERR_WARN;
317}
318
Christopher Faulet62519022017-10-16 15:49:32 +0200319/* Parse a string representing a process number or a set of processes. It must
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100320 * be "all", "odd", "even", a number between 1 and <max> or a range with
Christopher Faulet5ab51772017-11-22 11:21:58 +0100321 * two such numbers delimited by a dash ('-'). On success, it returns
322 * 0. otherwise it returns 1 with an error message in <err>.
Christopher Faulet62519022017-10-16 15:49:32 +0200323 *
324 * Note: this function can also be used to parse a thread number or a set of
325 * threads.
326 */
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100327int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200328{
Christopher Faulet26028f62017-11-22 15:01:51 +0100329 if (autoinc) {
330 *autoinc = 0;
331 if (strncmp(arg, "auto:", 5) == 0) {
332 arg += 5;
333 *autoinc = 1;
334 }
335 }
336
Christopher Faulet62519022017-10-16 15:49:32 +0200337 if (strcmp(arg, "all") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100338 *proc |= ~0UL;
Christopher Faulet62519022017-10-16 15:49:32 +0200339 else if (strcmp(arg, "odd") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100340 *proc |= ~0UL/3UL; /* 0x555....555 */
Christopher Faulet62519022017-10-16 15:49:32 +0200341 else if (strcmp(arg, "even") == 0)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100342 *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Christopher Faulet62519022017-10-16 15:49:32 +0200343 else {
Christopher Faulet18cca782019-02-07 16:29:41 +0100344 const char *p, *dash = NULL;
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100345 unsigned int low, high;
346
Christopher Faulet18cca782019-02-07 16:29:41 +0100347 for (p = arg; *p; p++) {
348 if (*p == '-' && !dash)
349 dash = p;
Willy Tarreau90807112020-02-25 08:16:33 +0100350 else if (!isdigit((unsigned char)*p)) {
Christopher Faulet18cca782019-02-07 16:29:41 +0100351 memprintf(err, "'%s' is not a valid number/range.", arg);
352 return -1;
353 }
Christopher Faulet5ab51772017-11-22 11:21:58 +0100354 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100355
356 low = high = str2uic(arg);
Christopher Faulet18cca782019-02-07 16:29:41 +0100357 if (dash)
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100358 high = ((!*(dash+1)) ? max : str2uic(dash + 1));
Christopher Fauletff4121f2017-11-22 16:38:49 +0100359
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100360 if (high < low) {
361 unsigned int swap = low;
362 low = high;
363 high = swap;
364 }
365
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100366 if (low < 1 || low > max || high > max) {
Christopher Fauletcb6a9452017-11-22 16:50:41 +0100367 memprintf(err, "'%s' is not a valid number/range."
368 " It supports numbers from 1 to %d.\n",
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100369 arg, max);
Christopher Faulet5ab51772017-11-22 11:21:58 +0100370 return 1;
371 }
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100372
373 for (;low <= high; low++)
Christopher Faulet5ab51772017-11-22 11:21:58 +0100374 *proc |= 1UL << (low-1);
Christopher Faulet62519022017-10-16 15:49:32 +0200375 }
Willy Tarreauc9a82e42019-01-26 13:25:14 +0100376 *proc &= ~0UL >> (LONGBITS - max);
Christopher Faulet1dcb9cb2017-11-22 10:24:40 +0100377
Christopher Faulet5ab51772017-11-22 11:21:58 +0100378 return 0;
Christopher Faulet62519022017-10-16 15:49:32 +0200379}
380
David Carlier7e351ee2017-12-01 09:14:02 +0000381#ifdef USE_CPU_AFFINITY
Christopher Faulet62519022017-10-16 15:49:32 +0200382/* Parse cpu sets. Each CPU set is either a unique number between 0 and
383 * <LONGBITS> or a range with two such numbers delimited by a dash
384 * ('-'). Multiple CPU numbers or ranges may be specified. On success, it
385 * returns 0. otherwise it returns 1 with an error message in <err>.
386 */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100387unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err)
Christopher Faulet62519022017-10-16 15:49:32 +0200388{
389 int cur_arg = 0;
390
391 *cpu_set = 0;
392 while (*args[cur_arg]) {
393 char *dash;
394 unsigned int low, high;
395
Willy Tarreau90807112020-02-25 08:16:33 +0100396 if (!isdigit((unsigned char)*args[cur_arg])) {
Christopher Faulet62519022017-10-16 15:49:32 +0200397 memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]);
398 return -1;
399 }
400
401 low = high = str2uic(args[cur_arg]);
402 if ((dash = strchr(args[cur_arg], '-')) != NULL)
Christopher Fauletff4121f2017-11-22 16:38:49 +0100403 high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1));
Christopher Faulet62519022017-10-16 15:49:32 +0200404
405 if (high < low) {
406 unsigned int swap = low;
407 low = high;
408 high = swap;
409 }
410
411 if (high >= LONGBITS) {
412 memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1);
413 return 1;
414 }
415
416 while (low <= high)
417 *cpu_set |= 1UL << low++;
418
419 cur_arg++;
420 }
421 return 0;
422}
David Carlier7e351ee2017-12-01 09:14:02 +0000423#endif
424
Willy Tarreau915e1eb2009-06-22 15:48:36 +0200425void init_default_instance()
Willy Tarreaubaaee002006-06-26 02:48:02 +0200426{
Willy Tarreau97cb7802010-01-03 20:23:58 +0100427 init_new_proxy(&defproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200428 defproxy.mode = PR_MODE_TCP;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200429 defproxy.disabled = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200430 defproxy.maxconn = cfg_maxpconn;
431 defproxy.conn_retries = CONN_RETRIES;
Joseph Lynch726ab712015-05-11 23:25:34 -0700432 defproxy.redispatch_after = 0;
Olivier Houchard86006a52018-12-14 19:37:49 +0100433 defproxy.options = PR_O_REUSE_SAFE;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100434 defproxy.max_out_conns = MAX_SRV_LIST;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100435
Simon Horman66183002013-02-23 10:16:43 +0900436 defproxy.defsrv.check.inter = DEF_CHKINTR;
437 defproxy.defsrv.check.fastinter = 0;
438 defproxy.defsrv.check.downinter = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900439 defproxy.defsrv.agent.inter = DEF_CHKINTR;
440 defproxy.defsrv.agent.fastinter = 0;
441 defproxy.defsrv.agent.downinter = 0;
Simon Horman58c32972013-11-25 10:46:38 +0900442 defproxy.defsrv.check.rise = DEF_RISETIME;
443 defproxy.defsrv.check.fall = DEF_FALLTIME;
444 defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
445 defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200446 defproxy.defsrv.check.port = 0;
Simon Hormand60d6912013-11-25 10:46:36 +0900447 defproxy.defsrv.agent.port = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100448 defproxy.defsrv.maxqueue = 0;
449 defproxy.defsrv.minconn = 0;
450 defproxy.defsrv.maxconn = 0;
Willy Tarreau9c538e02019-01-23 10:21:49 +0100451 defproxy.defsrv.max_reuse = -1;
Olivier Houchard006e3102018-12-10 18:30:32 +0100452 defproxy.defsrv.max_idle_conns = -1;
Willy Tarreau975b1552019-06-06 16:25:55 +0200453 defproxy.defsrv.pool_purge_delay = 5000;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100454 defproxy.defsrv.slowstart = 0;
455 defproxy.defsrv.onerror = DEF_HANA_ONERR;
456 defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
457 defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
Simon Horman64e34162015-02-06 11:11:57 +0900458
459 defproxy.email_alert.level = LOG_ALERT;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +0200460 defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200461}
462
Frédéric Lécaille18251032019-01-11 11:07:15 +0100463/* Allocate and initialize the frontend of a "peers" section found in
464 * file <file> at line <linenum> with <id> as ID.
465 * Return 0 if succeeded, -1 if not.
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200466 * Note that this function may be called from "default-server"
467 * or "peer" lines.
Frédéric Lécaille18251032019-01-11 11:07:15 +0100468 */
469static int init_peers_frontend(const char *file, int linenum,
470 const char *id, struct peers *peers)
471{
472 struct proxy *p;
473
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200474 if (peers->peers_fe) {
475 p = peers->peers_fe;
476 goto out;
477 }
Frédéric Lécaille9492c4e2019-01-11 11:47:12 +0100478
Frédéric Lécaille18251032019-01-11 11:07:15 +0100479 p = calloc(1, sizeof *p);
480 if (!p) {
481 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
482 return -1;
483 }
484
485 init_new_proxy(p);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200486 peers_setup_frontend(p);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100487 p->parent = peers;
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200488 /* Finally store this frontend. */
489 peers->peers_fe = p;
490
491 out:
492 if (id && !p->id)
493 p->id = strdup(id);
Frédéric Lécaille1055e682018-04-26 14:35:21 +0200494 free(p->conf.file);
Frédéric Lécaille18251032019-01-11 11:07:15 +0100495 p->conf.args.file = p->conf.file = strdup(file);
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100496 if (linenum != -1)
497 p->conf.args.line = p->conf.line = linenum;
Frédéric Lécaille18251032019-01-11 11:07:15 +0100498
499 return 0;
500}
Willy Tarreauade5ec42010-01-28 19:33:49 +0100501
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100502/* Only change ->file, ->line and ->arg struct bind_conf member values
503 * if already present.
504 */
505static struct bind_conf *bind_conf_uniq_alloc(struct proxy *p,
506 const char *file, int line,
507 const char *arg, struct xprt_ops *xprt)
508{
509 struct bind_conf *bind_conf;
510
511 if (!LIST_ISEMPTY(&p->conf.bind)) {
512 bind_conf = LIST_ELEM((&p->conf.bind)->n, typeof(bind_conf), by_fe);
513 free(bind_conf->file);
514 bind_conf->file = strdup(file);
515 bind_conf->line = line;
516 if (arg) {
517 free(bind_conf->arg);
518 bind_conf->arg = strdup(arg);
519 }
520 }
521 else {
522 bind_conf = bind_conf_alloc(p, file, line, arg, xprt);
523 }
524
525 return bind_conf;
526}
527
528/*
529 * Allocate a new struct peer parsed at line <linenum> in file <file>
530 * to be added to <peers>.
531 * Returns the new allocated structure if succeeded, NULL if not.
532 */
533static struct peer *cfg_peers_add_peer(struct peers *peers,
534 const char *file, int linenum,
535 const char *id, int local)
536{
537 struct peer *p;
538
539 p = calloc(1, sizeof *p);
540 if (!p) {
541 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
542 return NULL;
543 }
544
545 /* the peers are linked backwards first */
546 peers->count++;
547 p->next = peers->remote;
548 peers->remote = p;
549 p->conf.file = strdup(file);
550 p->conf.line = linenum;
551 p->last_change = now.tv_sec;
552 p->xprt = xprt_get(XPRT_RAW);
553 p->sock_init_arg = NULL;
554 HA_SPIN_INIT(&p->lock);
555 if (id)
556 p->id = strdup(id);
557 if (local) {
558 p->local = 1;
559 peers->local = p;
560 }
561
562 return p;
563}
564
Willy Tarreaubaaee002006-06-26 02:48:02 +0200565/*
William Lallemand51097192015-04-14 16:35:22 +0200566 * Parse a line in a <listen>, <frontend> or <backend> section.
Willy Tarreau93893792009-07-23 13:19:11 +0200567 * Returns the error code, 0 if OK, or any combination of :
568 * - ERR_ABORT: must abort ASAP
569 * - ERR_FATAL: we can continue parsing but not start the service
570 * - ERR_WARN: a warning has been emitted
571 * - ERR_ALERT: an alert has been emitted
572 * Only the two first ones can stop processing, the two others are just
573 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200574 */
Emeric Brun32da3c42010-09-23 18:39:19 +0200575int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
576{
577 static struct peers *curpeers = NULL;
578 struct peer *newpeer = NULL;
579 const char *err;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200580 struct bind_conf *bind_conf;
581 struct listener *l;
Emeric Brun32da3c42010-09-23 18:39:19 +0200582 int err_code = 0;
Willy Tarreau902636f2013-03-10 19:44:48 +0100583 char *errmsg = NULL;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100584 static int bind_line, peer_line;
585
586 if (strcmp(args[0], "bind") == 0 || strcmp(args[0], "default-bind") == 0) {
587 int cur_arg;
588 static int kws_dumped;
589 struct bind_conf *bind_conf;
590 struct bind_kw *kw;
Emeric Brun32da3c42010-09-23 18:39:19 +0200591
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100592 cur_arg = 1;
593
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200594 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
595 err_code |= ERR_ALERT | ERR_ABORT;
596 goto out;
597 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100598
599 bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum,
600 NULL, xprt_get(XPRT_RAW));
601 if (*args[0] == 'b') {
602 struct listener *l;
603
604 if (peer_line) {
605 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
606 err_code |= ERR_ALERT | ERR_FATAL;
607 goto out;
608 }
609
610 if (!str2listener(args[1], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
611 if (errmsg && *errmsg) {
612 indent_msg(&errmsg, 2);
613 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
614 }
615 else
616 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
617 file, linenum, args[0], args[1], args[2]);
618 err_code |= ERR_FATAL;
619 goto out;
620 }
621 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
622 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100623 l->accept = session_accept_fd;
624 l->analysers |= curpeers->peers_fe->fe_req_ana;
625 l->default_target = curpeers->peers_fe->default_target;
626 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100627 global.maxsock++; /* for the listening socket */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100628
629 bind_line = 1;
630 if (cfg_peers->local) {
631 newpeer = cfg_peers->local;
632 }
633 else {
634 /* This peer is local.
635 * Note that we do not set the peer ID. This latter is initialized
636 * when parsing "peer" or "server" line.
637 */
638 newpeer = cfg_peers_add_peer(curpeers, file, linenum, NULL, 1);
639 if (!newpeer) {
640 err_code |= ERR_ALERT | ERR_ABORT;
641 goto out;
642 }
643 }
Willy Tarreau37159062020-08-27 07:48:42 +0200644 newpeer->addr = l->rx.addr;
Willy Tarreau5fc93282020-09-16 18:25:03 +0200645 newpeer->proto = l->rx.proto;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100646 cur_arg++;
647 }
648
649 while (*args[cur_arg] && (kw = bind_find_kw(args[cur_arg]))) {
650 int ret;
651
652 ret = kw->parse(args, cur_arg, curpeers->peers_fe, bind_conf, &errmsg);
653 err_code |= ret;
654 if (ret) {
655 if (errmsg && *errmsg) {
656 indent_msg(&errmsg, 2);
657 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
658 }
659 else
660 ha_alert("parsing [%s:%d]: error encountered while processing '%s'\n",
661 file, linenum, args[cur_arg]);
662 if (ret & ERR_FATAL)
663 goto out;
664 }
665 cur_arg += 1 + kw->skip;
666 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100667 if (*args[cur_arg] != 0) {
Tim Duesterhus04bcaa12019-05-12 22:54:50 +0200668 char *kws = NULL;
669
670 if (!kws_dumped) {
671 kws_dumped = 1;
672 bind_dump_kws(&kws);
673 indent_msg(&kws, 4);
674 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100675 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section.%s%s\n",
676 file, linenum, args[cur_arg], cursection,
677 kws ? " Registered keywords :" : "", kws ? kws: "");
678 free(kws);
679 err_code |= ERR_ALERT | ERR_FATAL;
680 goto out;
681 }
682 }
683 else if (strcmp(args[0], "default-server") == 0) {
684 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
685 err_code |= ERR_ALERT | ERR_ABORT;
686 goto out;
687 }
Emeric Brund3db3842020-07-21 16:54:36 +0200688 err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, 0, 1, 1);
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200689 }
Frédéric Lécailleb6f759b2019-11-05 09:57:45 +0100690 else if (strcmp(args[0], "log") == 0) {
691 if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
692 err_code |= ERR_ALERT | ERR_ABORT;
693 goto out;
694 }
695 if (!parse_logsrv(args, &curpeers->peers_fe->logsrvs, (kwm == KWM_NO), &errmsg)) {
696 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
697 err_code |= ERR_ALERT | ERR_FATAL;
698 goto out;
699 }
700 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200701 else if (strcmp(args[0], "peers") == 0) { /* new peers section */
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100702 /* Initialize these static variables when entering a new "peers" section*/
703 bind_line = peer_line = 0;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100704 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100705 ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum);
Willy Tarreau54984722014-02-16 08:20:13 +0100706 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100707 goto out;
708 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200709
William Lallemand6e62fb62015-04-28 16:55:23 +0200710 if (alertif_too_many_args(1, file, linenum, args, &err_code))
711 goto out;
712
Emeric Brun32da3c42010-09-23 18:39:19 +0200713 err = invalid_char(args[1]);
714 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100715 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
716 file, linenum, *err, args[0], args[1]);
Willy Tarreau54984722014-02-16 08:20:13 +0100717 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +0100718 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200719 }
720
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200721 for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
Emeric Brun32da3c42010-09-23 18:39:19 +0200722 /*
723 * If there are two proxies with the same name only following
724 * combinations are allowed:
725 */
726 if (strcmp(curpeers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100727 ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n",
728 file, linenum, args[1], curpeers->conf.file, curpeers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +0200729 err_code |= ERR_ALERT | ERR_FATAL;
Emeric Brun32da3c42010-09-23 18:39:19 +0200730 }
731 }
732
Vincent Bernat02779b62016-04-03 13:48:43 +0200733 if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100734 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Emeric Brun32da3c42010-09-23 18:39:19 +0200735 err_code |= ERR_ALERT | ERR_ABORT;
736 goto out;
737 }
738
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200739 curpeers->next = cfg_peers;
740 cfg_peers = curpeers;
Willy Tarreau8113a5d2012-10-04 08:01:43 +0200741 curpeers->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +0200742 curpeers->conf.line = linenum;
743 curpeers->last_change = now.tv_sec;
744 curpeers->id = strdup(args[1]);
Willy Tarreau1ad64ac2020-09-24 08:48:08 +0200745 curpeers->disabled = 0;
Emeric Brun32da3c42010-09-23 18:39:19 +0200746 }
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200747 else if (strcmp(args[0], "peer") == 0 ||
748 strcmp(args[0], "server") == 0) { /* peer or server definition */
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100749 int local_peer, peer;
Emeric Brun32da3c42010-09-23 18:39:19 +0200750
Frédéric Lécaille04636b72019-01-31 06:48:16 +0100751 peer = *args[0] == 'p';
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100752 local_peer = !strcmp(args[1], localpeer);
753 /* The local peer may have already partially been parsed on a "bind" line. */
754 if (*args[0] == 'p') {
755 if (bind_line) {
756 ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760 peer_line = 1;
761 }
762 if (cfg_peers->local && !cfg_peers->local->id && local_peer) {
763 /* The local peer has already been initialized on a "bind" line.
764 * Let's use it and store its ID.
765 */
766 newpeer = cfg_peers->local;
767 newpeer->id = strdup(localpeer);
768 }
769 else {
770 if (local_peer && cfg_peers->local) {
771 ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d. %s\n",
772 file, linenum, args[0], args[1],
773 curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line, cfg_peers->local->id);
774 err_code |= ERR_FATAL;
775 goto out;
776 }
777 newpeer = cfg_peers_add_peer(curpeers, file, linenum, args[1], local_peer);
778 if (!newpeer) {
779 err_code |= ERR_ALERT | ERR_ABORT;
780 goto out;
781 }
782 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200783
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100784 /* Line number and peer ID are updated only if this peer is the local one. */
785 if (init_peers_frontend(file,
786 newpeer->local ? linenum: -1,
787 newpeer->local ? newpeer->id : NULL,
788 curpeers) != 0) {
Frédéric Lécaillec06b5d42018-04-26 10:06:41 +0200789 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreaub36487e2013-03-10 18:37:42 +0100790 goto out;
791 }
Willy Tarreau2aa38802013-02-20 19:20:59 +0100792
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100793 /* This initializes curpeer->peers->peers_fe->srv.
794 * The server address is parsed only if we are parsing a "peer" line,
795 * or if we are parsing a "server" line and the current peer is not the local one.
796 */
Emeric Brund3db3842020-07-21 16:54:36 +0200797 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 +0200798 if (!curpeers->peers_fe->srv) {
799 /* Remove the newly allocated peer. */
800 if (newpeer != curpeers->local) {
801 struct peer *p;
802
803 p = curpeers->remote;
804 curpeers->remote = curpeers->remote->next;
805 free(p->id);
806 free(p);
807 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200808 goto out;
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200809 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200810
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100811 /* If the peer address has just been parsed, let's copy it to <newpeer>
812 * and initializes ->proto.
813 */
814 if (peer || !local_peer) {
815 newpeer->addr = curpeers->peers_fe->srv->addr;
816 newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
817 }
818
Willy Tarreaua261e9b2016-12-22 20:44:00 +0100819 newpeer->xprt = xprt_get(XPRT_RAW);
Willy Tarreaud02394b2012-05-11 18:32:18 +0200820 newpeer->sock_init_arg = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100821 HA_SPIN_INIT(&newpeer->lock);
Willy Tarreau26d8c592012-05-07 18:12:14 +0200822
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +0100823 newpeer->srv = curpeers->peers_fe->srv;
824 if (!newpeer->local)
Frédéric Lécaille6617e762018-04-25 15:13:38 +0200825 goto out;
826
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100827 /* The lines above are reserved to "peer" lines. */
828 if (*args[0] == 's')
Frédéric Lécaille4ba51982018-04-25 15:32:18 +0200829 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +0200830
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100831 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 +0100832
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100833 if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
834 if (errmsg && *errmsg) {
835 indent_msg(&errmsg, 2);
836 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 +0100837 }
Frédéric Lécaille91694d52019-01-11 11:43:53 +0100838 else
839 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
840 file, linenum, args[0], args[1], args[2]);
841 err_code |= ERR_FATAL;
842 goto out;
843 }
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100844
845 l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
846 l->maxaccept = 1;
Frédéric Lécaille355b2032019-01-11 14:06:12 +0100847 l->accept = session_accept_fd;
848 l->analysers |= curpeers->peers_fe->fe_req_ana;
849 l->default_target = curpeers->peers_fe->default_target;
850 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
Willy Tarreau18215cb2019-02-27 16:25:28 +0100851 global.maxsock++; /* for the listening socket */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100852 }
853 else if (!strcmp(args[0], "table")) {
854 struct stktable *t, *other;
855 char *id;
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100856 size_t prefix_len;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100857
858 /* Line number and peer ID are updated only if this peer is the local one. */
859 if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
860 err_code |= ERR_ALERT | ERR_ABORT;
861 goto out;
862 }
863
864 other = stktable_find_by_name(args[1]);
865 if (other) {
866 ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
867 file, linenum, args[1],
868 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
869 other->proxy ? other->id : other->peers.p->id,
870 other->conf.file, other->conf.line);
871 err_code |= ERR_ALERT | ERR_FATAL;
872 goto out;
873 }
874
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100875 /* Build the stick-table name, concatenating the "peers" section name
876 * followed by a '/' character and the table name argument.
877 */
878 chunk_reset(&trash);
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100879 if (!chunk_strcpy(&trash, curpeers->id)) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100880 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
881 file, linenum, args[0], args[1]);
882 err_code |= ERR_ALERT | ERR_FATAL;
883 goto out;
884 }
885
886 prefix_len = trash.data;
Frédéric Lécaille7fcc24d2019-03-20 15:09:45 +0100887 if (!chunk_memcat(&trash, "/", 1) || !chunk_strcat(&trash, args[1])) {
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100888 ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
889 file, linenum, args[0], args[1]);
890 err_code |= ERR_ALERT | ERR_FATAL;
891 goto out;
892 }
893
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100894 t = calloc(1, sizeof *t);
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100895 id = strdup(trash.area);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100896 if (!t || !id) {
897 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
898 file, linenum, args[0], args[1]);
Eric Salama1aab9112020-09-18 11:55:17 +0200899 free(t);
900 free(id);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100901 err_code |= ERR_ALERT | ERR_FATAL;
902 goto out;
903 }
904
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100905 err_code |= parse_stick_table(file, linenum, args, t, id, id + prefix_len, curpeers);
Eric Salama1aab9112020-09-18 11:55:17 +0200906 if (err_code & ERR_FATAL) {
907 free(t);
908 free(id);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100909 goto out;
Eric Salama1aab9112020-09-18 11:55:17 +0200910 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +0100911
912 stktable_store_name(t);
913 t->next = stktables_list;
914 stktables_list = t;
915 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200916 else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
Willy Tarreau1ad64ac2020-09-24 08:48:08 +0200917 curpeers->disabled = 1;
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200918 }
919 else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
Willy Tarreau1ad64ac2020-09-24 08:48:08 +0200920 curpeers->disabled = 0;
Willy Tarreau77e4bd12015-05-01 20:02:17 +0200921 }
Emeric Brun32da3c42010-09-23 18:39:19 +0200922 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100923 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Emeric Brun32da3c42010-09-23 18:39:19 +0200924 err_code |= ERR_ALERT | ERR_FATAL;
925 goto out;
926 }
927
928out:
Willy Tarreau902636f2013-03-10 19:44:48 +0100929 free(errmsg);
Emeric Brun32da3c42010-09-23 18:39:19 +0200930 return err_code;
931}
932
Baptiste Assmann325137d2015-04-13 23:40:55 +0200933/*
934 * Parse a <resolvers> section.
935 * Returns the error code, 0 if OK, or any combination of :
936 * - ERR_ABORT: must abort ASAP
937 * - ERR_FATAL: we can continue parsing but not start the service
938 * - ERR_WARN: a warning has been emitted
939 * - ERR_ALERT: an alert has been emitted
940 * Only the two first ones can stop processing, the two others are just
941 * indicators.
942 */
943int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
944{
945 static struct dns_resolvers *curr_resolvers = NULL;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200946 const char *err;
947 int err_code = 0;
948 char *errmsg = NULL;
949
950 if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */
951 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100952 ha_alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200953 err_code |= ERR_ALERT | ERR_ABORT;
954 goto out;
955 }
956
957 err = invalid_char(args[1]);
958 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100959 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
960 file, linenum, *err, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200961 err_code |= ERR_ALERT | ERR_ABORT;
962 goto out;
963 }
964
965 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
966 /* Error if two resolvers owns the same name */
967 if (strcmp(curr_resolvers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100968 ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n",
969 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200970 err_code |= ERR_ALERT | ERR_ABORT;
971 }
972 }
973
Vincent Bernat02779b62016-04-03 13:48:43 +0200974 if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100975 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +0200976 err_code |= ERR_ALERT | ERR_ABORT;
977 goto out;
978 }
979
980 /* default values */
981 LIST_ADDQ(&dns_resolvers, &curr_resolvers->list);
982 curr_resolvers->conf.file = strdup(file);
983 curr_resolvers->conf.line = linenum;
984 curr_resolvers->id = strdup(args[1]);
985 curr_resolvers->query_ids = EB_ROOT;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +0200986 /* default maximum response size */
987 curr_resolvers->accepted_payload_size = 512;
Baptiste Assmann987e16d2016-11-02 22:23:31 +0100988 /* default hold period for nx, other, refuse and timeout is 30s */
989 curr_resolvers->hold.nx = 30000;
990 curr_resolvers->hold.other = 30000;
991 curr_resolvers->hold.refused = 30000;
992 curr_resolvers->hold.timeout = 30000;
Baptiste Assmann686408b2017-08-18 10:15:42 +0200993 curr_resolvers->hold.obsolete = 0;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200994 /* default hold period for valid is 10s */
Baptiste Assmann4c5490a2015-07-14 21:42:49 +0200995 curr_resolvers->hold.valid = 10000;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200996 curr_resolvers->timeout.resolve = 1000;
997 curr_resolvers->timeout.retry = 1000;
Baptiste Assmann325137d2015-04-13 23:40:55 +0200998 curr_resolvers->resolve_retries = 3;
Christopher Faulet67957bd2017-09-27 11:00:59 +0200999 curr_resolvers->nb_nameservers = 0;
1000 LIST_INIT(&curr_resolvers->nameservers);
1001 LIST_INIT(&curr_resolvers->resolutions.curr);
1002 LIST_INIT(&curr_resolvers->resolutions.wait);
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001003 HA_SPIN_INIT(&curr_resolvers->lock);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001004 }
1005 else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
Eric Salama9139ec32020-11-13 15:56:36 +01001006 struct dns_nameserver *newnameserver = NULL;
Baptiste Assmann325137d2015-04-13 23:40:55 +02001007 struct sockaddr_storage *sk;
1008 int port1, port2;
Baptiste Assmann325137d2015-04-13 23:40:55 +02001009
1010 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001011 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1012 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001013 err_code |= ERR_ALERT | ERR_FATAL;
1014 goto out;
1015 }
1016
1017 err = invalid_char(args[1]);
1018 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001019 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1020 file, linenum, *err, args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001021 err_code |= ERR_ALERT | ERR_FATAL;
1022 goto out;
1023 }
1024
Christopher Faulet67957bd2017-09-27 11:00:59 +02001025 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
Baptiste Assmanna315c552015-11-02 22:55:49 +01001026 /* Error if two resolvers owns the same name */
1027 if (strcmp(newnameserver->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001028 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 -06001029 file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line);
Baptiste Assmanna315c552015-11-02 22:55:49 +01001030 err_code |= ERR_ALERT | ERR_FATAL;
1031 }
1032 }
1033
Vincent Bernat02779b62016-04-03 13:48:43 +02001034 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001035 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001036 err_code |= ERR_ALERT | ERR_ABORT;
1037 goto out;
1038 }
1039
1040 /* the nameservers are linked backward first */
Christopher Faulet67957bd2017-09-27 11:00:59 +02001041 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001042 newnameserver->resolvers = curr_resolvers;
1043 newnameserver->conf.file = strdup(file);
1044 newnameserver->conf.line = linenum;
1045 newnameserver->id = strdup(args[1]);
1046
Willy Tarreau5fc93282020-09-16 18:25:03 +02001047 sk = str2sa_range(args[2], NULL, &port1, &port2, NULL, NULL,
1048 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_DGRAM);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001049 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001050 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001051 err_code |= ERR_ALERT | ERR_FATAL;
1052 goto out;
1053 }
1054
Baptiste Assmann325137d2015-04-13 23:40:55 +02001055 newnameserver->addr = *sk;
1056 }
Ben Draut44e609b2018-05-29 15:40:08 -06001057 else if (strcmp(args[0], "parse-resolv-conf") == 0) {
Eric Salama9139ec32020-11-13 15:56:36 +01001058 struct dns_nameserver *newnameserver = NULL;
Ben Draut44e609b2018-05-29 15:40:08 -06001059 const char *whitespace = "\r\n\t ";
1060 char *resolv_line = NULL;
1061 int resolv_linenum = 0;
1062 FILE *f = NULL;
1063 char *address = NULL;
1064 struct sockaddr_storage *sk = NULL;
1065 struct protocol *proto;
1066 int duplicate_name = 0;
1067
1068 if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) {
1069 ha_alert("parsing [%s:%d] : out of memory.\n",
1070 file, linenum);
1071 err_code |= ERR_ALERT | ERR_FATAL;
1072 goto resolv_out;
1073 }
1074
1075 if ((f = fopen("/etc/resolv.conf", "r")) == NULL) {
1076 ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n",
1077 file, linenum);
1078 err_code |= ERR_ALERT | ERR_FATAL;
1079 goto resolv_out;
1080 }
1081
1082 sk = calloc(1, sizeof(*sk));
1083 if (sk == NULL) {
1084 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n",
1085 resolv_linenum);
1086 err_code |= ERR_ALERT | ERR_FATAL;
1087 goto resolv_out;
1088 }
1089
1090 while (fgets(resolv_line, LINESIZE, f) != NULL) {
1091 resolv_linenum++;
1092 if (strncmp(resolv_line, "nameserver", 10) != 0)
1093 continue;
1094
1095 address = strtok(resolv_line + 10, whitespace);
1096 if (address == resolv_line + 10)
1097 continue;
1098
1099 if (address == NULL) {
1100 ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n",
1101 resolv_linenum);
1102 err_code |= ERR_WARN;
1103 continue;
1104 }
1105
1106 duplicate_name = 0;
1107 list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) {
1108 if (strcmp(newnameserver->id, address) == 0) {
1109 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",
1110 resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line);
1111 err_code |= ERR_WARN;
1112 duplicate_name = 1;
1113 }
1114 }
1115
1116 if (duplicate_name)
1117 continue;
1118
1119 memset(sk, 0, sizeof(*sk));
Willy Tarreau78675252020-05-28 18:07:10 +02001120 if (!str2ip2(address, sk, 1)) {
1121 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 -06001122 resolv_linenum, address);
1123 err_code |= ERR_WARN;
1124 continue;
1125 }
1126
1127 set_host_port(sk, 53);
1128
1129 proto = protocol_by_family(sk->ss_family);
1130 if (!proto || !proto->connect) {
1131 ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n",
1132 resolv_linenum, address);
1133 err_code |= ERR_WARN;
1134 continue;
1135 }
1136
1137 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
1138 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1139 err_code |= ERR_ALERT | ERR_FATAL;
1140 goto resolv_out;
1141 }
1142
1143 newnameserver->conf.file = strdup("/etc/resolv.conf");
1144 if (newnameserver->conf.file == NULL) {
1145 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1146 err_code |= ERR_ALERT | ERR_FATAL;
Eric Salama9139ec32020-11-13 15:56:36 +01001147 free(newnameserver);
Ben Draut44e609b2018-05-29 15:40:08 -06001148 goto resolv_out;
1149 }
1150
1151 newnameserver->id = strdup(address);
1152 if (newnameserver->id == NULL) {
1153 ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
1154 err_code |= ERR_ALERT | ERR_FATAL;
Eric Salama9139ec32020-11-13 15:56:36 +01001155 free((char *)newnameserver->conf.file);
1156 free(newnameserver);
Ben Draut44e609b2018-05-29 15:40:08 -06001157 goto resolv_out;
1158 }
1159
1160 newnameserver->resolvers = curr_resolvers;
1161 newnameserver->conf.line = resolv_linenum;
1162 newnameserver->addr = *sk;
1163
1164 LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list);
1165 }
1166
1167resolv_out:
1168 free(sk);
1169 free(resolv_line);
1170 if (f != NULL)
1171 fclose(f);
1172 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001173 else if (strcmp(args[0], "hold") == 0) { /* hold periods */
1174 const char *res;
1175 unsigned int time;
1176
1177 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001178 ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n",
1179 file, linenum, args[0]);
1180 ha_alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n");
Baptiste Assmann325137d2015-04-13 23:40:55 +02001181 err_code |= ERR_ALERT | ERR_FATAL;
1182 goto out;
1183 }
1184 res = parse_time_err(args[2], &time, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001185 if (res == PARSE_TIME_OVER) {
1186 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1187 file, linenum, args[1], args[0]);
1188 err_code |= ERR_ALERT | ERR_FATAL;
1189 goto out;
1190 }
1191 else if (res == PARSE_TIME_UNDER) {
1192 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1193 file, linenum, args[1], args[0]);
1194 err_code |= ERR_ALERT | ERR_FATAL;
1195 goto out;
1196 }
1197 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001198 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
1199 file, linenum, *res, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001200 err_code |= ERR_ALERT | ERR_FATAL;
1201 goto out;
1202 }
Baptiste Assmann987e16d2016-11-02 22:23:31 +01001203 if (strcmp(args[1], "nx") == 0)
1204 curr_resolvers->hold.nx = time;
1205 else if (strcmp(args[1], "other") == 0)
1206 curr_resolvers->hold.other = time;
1207 else if (strcmp(args[1], "refused") == 0)
1208 curr_resolvers->hold.refused = time;
1209 else if (strcmp(args[1], "timeout") == 0)
1210 curr_resolvers->hold.timeout = time;
1211 else if (strcmp(args[1], "valid") == 0)
Baptiste Assmann325137d2015-04-13 23:40:55 +02001212 curr_resolvers->hold.valid = time;
Olivier Houcharda8c6db82017-07-06 18:46:47 +02001213 else if (strcmp(args[1], "obsolete") == 0)
1214 curr_resolvers->hold.obsolete = time;
Baptiste Assmann325137d2015-04-13 23:40:55 +02001215 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001216 ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n",
1217 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001218 err_code |= ERR_ALERT | ERR_FATAL;
1219 goto out;
1220 }
1221
1222 }
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001223 else if (strcmp(args[0], "accepted_payload_size") == 0) {
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001224 int i = 0;
1225
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001226 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001227 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1228 file, linenum, args[0]);
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001229 err_code |= ERR_ALERT | ERR_FATAL;
1230 goto out;
1231 }
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001232
1233 i = atoi(args[1]);
Willy Tarreau0c219be2017-08-22 12:01:26 +02001234 if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001235 ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n",
1236 file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]);
Baptiste Assmann9d8dbbc2017-08-18 23:35:08 +02001237 err_code |= ERR_ALERT | ERR_FATAL;
1238 goto out;
1239 }
1240
1241 curr_resolvers->accepted_payload_size = i;
Baptiste Assmann2af08fe2017-08-14 00:13:01 +02001242 }
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001243 else if (strcmp(args[0], "resolution_pool_size") == 0) {
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001244 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 +01001245 file, linenum, args[0]);
Tim Duesterhus3506dae2019-05-14 20:57:56 +02001246 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001247 goto out;
Baptiste Assmann201c07f2017-05-22 15:17:15 +02001248 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001249 else if (strcmp(args[0], "resolve_retries") == 0) {
1250 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001251 ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
1252 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001253 err_code |= ERR_ALERT | ERR_FATAL;
1254 goto out;
1255 }
1256 curr_resolvers->resolve_retries = atoi(args[1]);
1257 }
1258 else if (strcmp(args[0], "timeout") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001259 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001260 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n",
1261 file, linenum, args[0]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001262 err_code |= ERR_ALERT | ERR_FATAL;
1263 goto out;
1264 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001265 else if (strcmp(args[1], "retry") == 0 ||
1266 strcmp(args[1], "resolve") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001267 const char *res;
Christopher Faulet67957bd2017-09-27 11:00:59 +02001268 unsigned int tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001269
1270 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001271 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1272 file, linenum, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001273 err_code |= ERR_ALERT | ERR_FATAL;
1274 goto out;
1275 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001276 res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001277 if (res == PARSE_TIME_OVER) {
1278 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1279 file, linenum, args[2], args[0], args[1]);
1280 err_code |= ERR_ALERT | ERR_FATAL;
1281 goto out;
1282 }
1283 else if (res == PARSE_TIME_UNDER) {
1284 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1285 file, linenum, args[2], args[0], args[1]);
1286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
1289 else if (res) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001290 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1291 file, linenum, *res, args[0], args[1]);
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001292 err_code |= ERR_ALERT | ERR_FATAL;
1293 goto out;
1294 }
Christopher Faulet67957bd2017-09-27 11:00:59 +02001295 if (args[1][2] == 't')
1296 curr_resolvers->timeout.retry = tout;
1297 else
1298 curr_resolvers->timeout.resolve = tout;
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01001299 }
1300 else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001301 ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n",
1302 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001303 err_code |= ERR_ALERT | ERR_FATAL;
1304 goto out;
1305 }
Eric Salama9139ec32020-11-13 15:56:36 +01001306 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02001307 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001308 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Baptiste Assmann325137d2015-04-13 23:40:55 +02001309 err_code |= ERR_ALERT | ERR_FATAL;
1310 goto out;
1311 }
1312
1313 out:
1314 free(errmsg);
1315 return err_code;
1316}
Simon Horman0d16a402015-01-30 11:22:58 +09001317
1318/*
William Lallemand51097192015-04-14 16:35:22 +02001319 * Parse a line in a <listen>, <frontend> or <backend> section.
Simon Horman0d16a402015-01-30 11:22:58 +09001320 * Returns the error code, 0 if OK, or any combination of :
1321 * - ERR_ABORT: must abort ASAP
1322 * - ERR_FATAL: we can continue parsing but not start the service
1323 * - ERR_WARN: a warning has been emitted
1324 * - ERR_ALERT: an alert has been emitted
1325 * Only the two first ones can stop processing, the two others are just
1326 * indicators.
1327 */
1328int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
1329{
1330 static struct mailers *curmailers = NULL;
1331 struct mailer *newmailer = NULL;
1332 const char *err;
1333 int err_code = 0;
1334 char *errmsg = NULL;
1335
1336 if (strcmp(args[0], "mailers") == 0) { /* new mailers section */
1337 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001338 ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001339 err_code |= ERR_ALERT | ERR_ABORT;
1340 goto out;
1341 }
1342
1343 err = invalid_char(args[1]);
1344 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001345 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1346 file, linenum, *err, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001347 err_code |= ERR_ALERT | ERR_ABORT;
1348 goto out;
1349 }
1350
1351 for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) {
1352 /*
1353 * If there are two proxies with the same name only following
1354 * combinations are allowed:
1355 */
1356 if (strcmp(curmailers->id, args[1]) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001357 ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n",
1358 file, linenum, args[1], curmailers->conf.file, curmailers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02001359 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman0d16a402015-01-30 11:22:58 +09001360 }
1361 }
1362
Vincent Bernat02779b62016-04-03 13:48:43 +02001363 if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001364 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001365 err_code |= ERR_ALERT | ERR_ABORT;
1366 goto out;
1367 }
1368
1369 curmailers->next = mailers;
1370 mailers = curmailers;
1371 curmailers->conf.file = strdup(file);
1372 curmailers->conf.line = linenum;
1373 curmailers->id = strdup(args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001374 curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
1375 * But need enough time so that timeouts don't occur
1376 * during tcp procssing. For now just us an arbitrary default. */
Simon Horman0d16a402015-01-30 11:22:58 +09001377 }
1378 else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
1379 struct sockaddr_storage *sk;
1380 int port1, port2;
1381 struct protocol *proto;
1382
1383 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001384 ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1385 file, linenum, args[0]);
Simon Horman0d16a402015-01-30 11:22:58 +09001386 err_code |= ERR_ALERT | ERR_FATAL;
1387 goto out;
1388 }
1389
1390 err = invalid_char(args[1]);
1391 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001392 ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1393 file, linenum, *err, args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001394 err_code |= ERR_ALERT | ERR_FATAL;
1395 goto out;
1396 }
1397
Vincent Bernat02779b62016-04-03 13:48:43 +02001398 if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001399 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Simon Horman0d16a402015-01-30 11:22:58 +09001400 err_code |= ERR_ALERT | ERR_ABORT;
1401 goto out;
1402 }
1403
1404 /* the mailers are linked backwards first */
1405 curmailers->count++;
1406 newmailer->next = curmailers->mailer_list;
1407 curmailers->mailer_list = newmailer;
1408 newmailer->mailers = curmailers;
1409 newmailer->conf.file = strdup(file);
1410 newmailer->conf.line = linenum;
1411
1412 newmailer->id = strdup(args[1]);
1413
Willy Tarreau5fc93282020-09-16 18:25:03 +02001414 sk = str2sa_range(args[2], NULL, &port1, &port2, NULL, &proto,
Willy Tarreau65ec4e32020-09-16 19:17:08 +02001415 &errmsg, NULL, NULL,
1416 PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT);
Simon Horman0d16a402015-01-30 11:22:58 +09001417 if (!sk) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001418 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Simon Horman0d16a402015-01-30 11:22:58 +09001419 err_code |= ERR_ALERT | ERR_FATAL;
1420 goto out;
1421 }
1422
Willy Tarreau65ec4e32020-09-16 19:17:08 +02001423 if (proto->sock_prot != IPPROTO_TCP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001424 ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n",
1425 file, linenum, args[0], args[1]);
Simon Horman0d16a402015-01-30 11:22:58 +09001426 err_code |= ERR_ALERT | ERR_FATAL;
1427 goto out;
1428 }
1429
Simon Horman0d16a402015-01-30 11:22:58 +09001430 newmailer->addr = *sk;
1431 newmailer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01001432 newmailer->xprt = xprt_get(XPRT_RAW);
Simon Horman0d16a402015-01-30 11:22:58 +09001433 newmailer->sock_init_arg = NULL;
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001434 }
1435 else if (strcmp(args[0], "timeout") == 0) {
1436 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001437 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
1438 file, linenum, args[0]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001439 err_code |= ERR_ALERT | ERR_FATAL;
1440 goto out;
1441 }
1442 else if (strcmp(args[1], "mail") == 0) {
1443 const char *res;
1444 unsigned int timeout_mail;
1445 if (!*args[2]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001446 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
1447 file, linenum, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001448 err_code |= ERR_ALERT | ERR_FATAL;
1449 goto out;
1450 }
1451 res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001452 if (res == PARSE_TIME_OVER) {
1453 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
1454 file, linenum, args[2], args[0], args[1]);
1455 err_code |= ERR_ALERT | ERR_FATAL;
1456 goto out;
1457 }
1458 else if (res == PARSE_TIME_UNDER) {
1459 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
1460 file, linenum, args[2], args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001461 err_code |= ERR_ALERT | ERR_FATAL;
1462 goto out;
1463 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001464 else if (res) {
1465 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
1466 file, linenum, *res, args[0], args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001467 err_code |= ERR_ALERT | ERR_FATAL;
1468 goto out;
1469 }
1470 curmailers->timeout.mail = timeout_mail;
1471 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001472 ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
Pieter Baauw235fcfc2016-02-13 15:33:40 +01001473 file, linenum, args[0], args[1]);
1474 err_code |= ERR_ALERT | ERR_FATAL;
1475 goto out;
1476 }
1477 }
Simon Horman0d16a402015-01-30 11:22:58 +09001478 else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001479 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Simon Horman0d16a402015-01-30 11:22:58 +09001480 err_code |= ERR_ALERT | ERR_FATAL;
1481 goto out;
1482 }
1483
1484out:
1485 free(errmsg);
1486 return err_code;
1487}
1488
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001489void free_email_alert(struct proxy *p)
Simon Horman9dc49962015-01-30 11:22:59 +09001490{
1491 free(p->email_alert.mailers.name);
1492 p->email_alert.mailers.name = NULL;
1493 free(p->email_alert.from);
1494 p->email_alert.from = NULL;
1495 free(p->email_alert.to);
1496 p->email_alert.to = NULL;
1497 free(p->email_alert.myhostname);
1498 p->email_alert.myhostname = NULL;
1499}
1500
Willy Tarreaubaaee002006-06-26 02:48:02 +02001501
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001502int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001503cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
1504{
Willy Tarreaue5733232019-05-22 19:24:06 +02001505#ifdef USE_NS
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001506 const char *err;
1507 const char *item = args[0];
1508
1509 if (!strcmp(item, "namespace_list")) {
1510 return 0;
1511 }
1512 else if (!strcmp(item, "namespace")) {
1513 size_t idx = 1;
1514 const char *current;
1515 while (*(current = args[idx++])) {
1516 err = invalid_char(current);
1517 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001518 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1519 file, linenum, *err, item, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001520 return ERR_ALERT | ERR_FATAL;
1521 }
1522
1523 if (netns_store_lookup(current, strlen(current))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001524 ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
1525 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001526 return ERR_ALERT | ERR_FATAL;
1527 }
1528 if (!netns_store_insert(current)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001529 ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
1530 file, linenum, current);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001531 return ERR_ALERT | ERR_FATAL;
1532 }
1533 }
1534 }
1535
1536 return 0;
1537#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001538 ha_alert("parsing [%s:%d]: namespace support is not compiled in.",
1539 file, linenum);
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001540 return ERR_ALERT | ERR_FATAL;
1541#endif
1542}
1543
1544int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001545cfg_parse_users(const char *file, int linenum, char **args, int kwm)
1546{
1547
1548 int err_code = 0;
1549 const char *err;
1550
1551 if (!strcmp(args[0], "userlist")) { /* new userlist */
1552 struct userlist *newul;
1553
1554 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001555 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1556 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001557 err_code |= ERR_ALERT | ERR_FATAL;
1558 goto out;
1559 }
William Lallemand6e62fb62015-04-28 16:55:23 +02001560 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1561 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001562
1563 err = invalid_char(args[1]);
1564 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001565 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1566 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001567 err_code |= ERR_ALERT | ERR_FATAL;
1568 goto out;
1569 }
1570
1571 for (newul = userlist; newul; newul = newul->next)
1572 if (!strcmp(newul->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001573 ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
1574 file, linenum, args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001575 err_code |= ERR_WARN;
1576 goto out;
1577 }
1578
Vincent Bernat02779b62016-04-03 13:48:43 +02001579 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001580 if (!newul) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001581 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001582 err_code |= ERR_ALERT | ERR_ABORT;
1583 goto out;
1584 }
1585
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001586 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001587 if (!newul->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001588 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001589 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01001590 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001591 goto out;
1592 }
1593
1594 newul->next = userlist;
1595 userlist = newul;
1596
1597 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001598 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001599 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001600 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001601
1602 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001603 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1604 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001605 err_code |= ERR_ALERT | ERR_FATAL;
1606 goto out;
1607 }
1608
1609 err = invalid_char(args[1]);
1610 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001611 ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
1612 file, linenum, *err, args[0], args[1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001613 err_code |= ERR_ALERT | ERR_FATAL;
1614 goto out;
1615 }
1616
William Lallemand4ac9f542015-05-28 18:03:51 +02001617 if (!userlist)
1618 goto out;
1619
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001620 for (ag = userlist->groups; ag; ag = ag->next)
1621 if (!strcmp(ag->name, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001622 ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
1623 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001624 err_code |= ERR_ALERT;
1625 goto out;
1626 }
1627
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001628 ag = calloc(1, sizeof(*ag));
1629 if (!ag) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001630 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001631 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001632 goto out;
1633 }
1634
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001635 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01001636 if (!ag->name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001637 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001638 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01001639 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001640 goto out;
1641 }
1642
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001643 cur_arg = 2;
1644
1645 while (*args[cur_arg]) {
1646 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001647 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001648 cur_arg += 2;
1649 continue;
1650 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001651 ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
1652 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001653 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01001654 free(ag->groupusers);
1655 free(ag->name);
1656 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001657 goto out;
1658 }
1659 }
1660
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001661 ag->next = userlist->groups;
1662 userlist->groups = ag;
1663
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001664 } else if (!strcmp(args[0], "user")) { /* new user */
1665 struct auth_users *newuser;
1666 int cur_arg;
1667
1668 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001669 ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
1670 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001671 err_code |= ERR_ALERT | ERR_FATAL;
1672 goto out;
1673 }
William Lallemand4ac9f542015-05-28 18:03:51 +02001674 if (!userlist)
1675 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001676
1677 for (newuser = userlist->users; newuser; newuser = newuser->next)
1678 if (!strcmp(newuser->user, args[1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001679 ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
1680 file, linenum, args[1], userlist->name);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001681 err_code |= ERR_ALERT;
1682 goto out;
1683 }
1684
Vincent Bernat02779b62016-04-03 13:48:43 +02001685 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001686 if (!newuser) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001687 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001688 err_code |= ERR_ALERT | ERR_ABORT;
1689 goto out;
1690 }
1691
1692 newuser->user = strdup(args[1]);
1693
1694 newuser->next = userlist->users;
1695 userlist->users = newuser;
1696
1697 cur_arg = 2;
1698
1699 while (*args[cur_arg]) {
1700 if (!strcmp(args[cur_arg], "password")) {
Willy Tarreaue5733232019-05-22 19:24:06 +02001701#ifdef USE_LIBCRYPT
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001702 if (!crypt("", args[cur_arg + 1])) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001703 ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
1704 file, linenum, newuser->user);
Cyril Bonté1a0191d2014-08-29 20:20:02 +02001705 err_code |= ERR_ALERT | ERR_FATAL;
1706 goto out;
1707 }
1708#else
Christopher Faulet767a84b2017-11-24 16:50:31 +01001709 ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
1710 file, linenum);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001711 err_code |= ERR_ALERT;
1712#endif
1713 newuser->pass = strdup(args[cur_arg + 1]);
1714 cur_arg += 2;
1715 continue;
1716 } else if (!strcmp(args[cur_arg], "insecure-password")) {
1717 newuser->pass = strdup(args[cur_arg + 1]);
1718 newuser->flags |= AU_O_INSECURE;
1719 cur_arg += 2;
1720 continue;
1721 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01001722 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001723 cur_arg += 2;
1724 continue;
1725 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001726 ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
1727 file, linenum, args[0]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01001728 err_code |= ERR_ALERT | ERR_FATAL;
1729 goto out;
1730 }
1731 }
1732 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001733 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 +01001734 err_code |= ERR_ALERT | ERR_FATAL;
1735 }
1736
1737out:
1738 return err_code;
1739}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001740
Christopher Faulet79bdef32016-11-04 22:36:15 +01001741int
1742cfg_parse_scope(const char *file, int linenum, char *line)
1743{
1744 char *beg, *end, *scope = NULL;
1745 int err_code = 0;
1746 const char *err;
1747
1748 beg = line + 1;
1749 end = strchr(beg, ']');
1750
1751 /* Detect end of scope declaration */
1752 if (!end || end == beg) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001753 ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n",
1754 file, linenum);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001755 err_code |= ERR_ALERT | ERR_FATAL;
1756 goto out;
1757 }
1758
1759 /* Get scope name and check its validity */
1760 scope = my_strndup(beg, end-beg);
1761 err = invalid_char(scope);
1762 if (err) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001763 ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
1764 file, linenum, *err);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001765 err_code |= ERR_ALERT | ERR_ABORT;
1766 goto out;
1767 }
1768
1769 /* Be sure to have a scope declaration alone on its line */
1770 line = end+1;
1771 while (isspace((unsigned char)*line))
1772 line++;
1773 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001774 ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
1775 file, linenum, *line);
Christopher Faulet79bdef32016-11-04 22:36:15 +01001776 err_code |= ERR_ALERT | ERR_ABORT;
1777 goto out;
1778 }
1779
1780 /* We have a valid scope declaration, save it */
1781 free(cfg_scope);
1782 cfg_scope = scope;
1783 scope = NULL;
1784
1785 out:
1786 free(scope);
1787 return err_code;
1788}
1789
Frédéric Lécaillea41d5312018-01-29 12:05:07 +01001790int
1791cfg_parse_track_sc_num(unsigned int *track_sc_num,
1792 const char *arg, const char *end, char **errmsg)
1793{
1794 const char *p;
1795 unsigned int num;
1796
1797 p = arg;
1798 num = read_uint64(&arg, end);
1799
1800 if (arg != end) {
1801 memprintf(errmsg, "Wrong track-sc number '%s'", p);
1802 return -1;
1803 }
1804
1805 if (num >= MAX_SESS_STKCTR) {
1806 memprintf(errmsg, "%u track-sc number exceeding "
1807 "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1);
1808 return -1;
1809 }
1810
1811 *track_sc_num = num;
1812 return 0;
1813}
1814
Willy Tarreaubaaee002006-06-26 02:48:02 +02001815/*
1816 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02001817 * Returns the error code, 0 if OK, or any combination of :
1818 * - ERR_ABORT: must abort ASAP
1819 * - ERR_FATAL: we can continue parsing but not start the service
1820 * - ERR_WARN: a warning has been emitted
1821 * - ERR_ALERT: an alert has been emitted
1822 * Only the two first ones can stop processing, the two others are just
1823 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001824 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02001825int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001826{
William Lallemand64e84512015-05-12 14:25:37 +02001827 char *thisline;
1828 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001829 FILE *f;
1830 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02001831 int err_code = 0;
William Lallemandd2ff56d2017-10-16 11:06:50 +02001832 struct cfg_section *cs = NULL, *pcs = NULL;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001833 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02001834 int readbytes = 0;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001835 char *outline = NULL;
1836 size_t outlen = 0;
1837 size_t outlinesize = 0;
Willy Tarreau32234e72020-06-16 17:14:33 +02001838 int fatal = 0;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001839 int missing_lf = -1;
William Lallemand64e84512015-05-12 14:25:37 +02001840
1841 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001842 ha_alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02001843 return -1;
1844 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01001845
David Carlier97880bb2016-04-08 10:35:26 +01001846 if ((f=fopen(file,"r")) == NULL) {
1847 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001848 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01001849 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001850
William Lallemandb2f07452015-05-12 14:27:13 +02001851next_line:
William Lallemand64e84512015-05-12 14:25:37 +02001852 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02001853 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001854 char *end;
1855 char *args[MAX_LINE_ARGS + 1];
1856 char *line = thisline;
1857
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001858 if (missing_lf != -1) {
Tim Duesterhusf92afb72020-08-18 22:00:04 +02001859 ha_alert("parsing [%s:%d]: Stray NUL character at position %d.\n",
1860 file, linenum, (missing_lf + 1));
1861 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001862 missing_lf = -1;
Tim Duesterhusf92afb72020-08-18 22:00:04 +02001863 break;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001864 }
1865
Willy Tarreaubaaee002006-06-26 02:48:02 +02001866 linenum++;
1867
Willy Tarreau32234e72020-06-16 17:14:33 +02001868 if (fatal >= 50) {
1869 ha_alert("parsing [%s:%d]: too many fatal errors (%d), stopping now.\n", file, linenum, fatal);
1870 break;
1871 }
1872
Willy Tarreaubaaee002006-06-26 02:48:02 +02001873 end = line + strlen(line);
1874
William Lallemand64e84512015-05-12 14:25:37 +02001875 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001876 /* Check if we reached the limit and the last char is not \n.
1877 * Watch out for the last line without the terminating '\n'!
1878 */
William Lallemand64e84512015-05-12 14:25:37 +02001879 char *newline;
1880 int newlinesize = linesize * 2;
1881
1882 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
1883 if (newline == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01001884 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
1885 file, linenum);
William Lallemand64e84512015-05-12 14:25:37 +02001886 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001887 fatal++;
Willy Tarreau40cb26f2020-06-25 09:37:54 +02001888 linenum--;
William Lallemand64e84512015-05-12 14:25:37 +02001889 continue;
1890 }
1891
1892 readbytes = linesize - 1;
1893 linesize = newlinesize;
1894 thisline = newline;
Willy Tarreau40cb26f2020-06-25 09:37:54 +02001895 linenum--;
William Lallemand64e84512015-05-12 14:25:37 +02001896 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01001897 }
1898
William Lallemand64e84512015-05-12 14:25:37 +02001899 readbytes = 0;
1900
Willy Tarreau08488f62020-06-26 17:24:54 +02001901 if (end > line && *(end-1) == '\n') {
Tim Duesterhus70f58992020-06-22 22:57:44 +02001902 /* kill trailing LF */
1903 *(end - 1) = 0;
1904 }
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02001905 else {
1906 /* mark this line as truncated */
1907 missing_lf = end - line;
1908 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001909
Willy Tarreaubaaee002006-06-26 02:48:02 +02001910 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02001911 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02001912 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02001913
Joseph Herlanta14c03e2018-11-15 14:04:19 -08001914 if (*line == '[') {/* This is the beginning if a scope */
Christopher Faulet79bdef32016-11-04 22:36:15 +01001915 err_code |= cfg_parse_scope(file, linenum, line);
1916 goto next_line;
1917 }
1918
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001919 while (1) {
1920 uint32_t err;
1921 char *errptr;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001922
Willy Tarreau61dd44b2020-06-25 07:35:42 +02001923 arg = MAX_LINE_ARGS + 1;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001924 outlen = outlinesize;
1925 err = parse_line(line, outline, &outlen, args, &arg,
1926 PARSE_OPT_ENV | PARSE_OPT_DQUOTE | PARSE_OPT_SQUOTE |
Amaury Denoyellefa41cb62020-10-01 14:32:35 +02001927 PARSE_OPT_BKSLASH | PARSE_OPT_SHARP | PARSE_OPT_WORD_EXPAND,
1928 &errptr);
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001929
1930 if (err & PARSE_ERR_QUOTE) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001931 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1932
1933 ha_alert("parsing [%s:%d]: unmatched quote at position %d:\n"
1934 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001935 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001936 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001937 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001938 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001939
1940 if (err & PARSE_ERR_BRACE) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001941 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1942
1943 ha_alert("parsing [%s:%d]: unmatched brace in environment variable name at position %d:\n"
1944 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001945 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001946 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001947 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001948 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001949
1950 if (err & PARSE_ERR_VARNAME) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001951 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1952
1953 ha_alert("parsing [%s:%d]: forbidden first char in environment variable name at position %d:\n"
1954 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001955 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001956 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001957 goto next_line;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001958 }
William Lallemandb2f07452015-05-12 14:27:13 +02001959
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001960 if (err & PARSE_ERR_HEX) {
Willy Tarreauc54e5ad2020-06-25 09:15:40 +02001961 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1962
1963 ha_alert("parsing [%s:%d]: truncated or invalid hexadecimal sequence at position %d:\n"
1964 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001965 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus9f658a52020-06-16 18:14:21 +02001966 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001967 goto next_line;
1968 }
William Lallemandb2f07452015-05-12 14:27:13 +02001969
Amaury Denoyellefa41cb62020-10-01 14:32:35 +02001970 if (err & PARSE_ERR_WRONG_EXPAND) {
1971 size_t newpos = sanitize_for_printing(line, errptr - line, 80);
1972
1973 ha_alert("parsing [%s:%d]: truncated or invalid word expansion sequence at position %d:\n"
1974 " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^");
1975 err_code |= ERR_ALERT | ERR_FATAL;
1976 fatal++;
1977 goto next_line;
1978 }
1979
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001980 if (err & (PARSE_ERR_TOOLARGE|PARSE_ERR_OVERLAP)) {
1981 outlinesize = (outlen + 1023) & -1024;
1982 outline = realloc(outline, outlinesize);
1983 if (outline == NULL) {
1984 ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
1985 file, linenum);
William Lallemandb2f07452015-05-12 14:27:13 +02001986 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02001987 fatal++;
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001988 goto next_line;
William Lallemandb2f07452015-05-12 14:27:13 +02001989 }
Willy Tarreau9e1758e2020-06-16 16:32:59 +02001990 /* try again */
1991 continue;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001992 }
Willy Tarreau07d47062020-06-25 07:41:22 +02001993
1994 if (err & PARSE_ERR_TOOMANY) {
1995 /* only check this *after* being sure the output is allocated */
1996 ha_alert("parsing [%s:%d]: too many words, truncating after word %d, position %ld: <%s>.\n",
1997 file, linenum, MAX_LINE_ARGS, (long)(args[MAX_LINE_ARGS-1] - outline + 1), args[MAX_LINE_ARGS-1]);
1998 err_code |= ERR_ALERT | ERR_FATAL;
1999 fatal++;
2000 goto next_line;
2001 }
2002
Willy Tarreau9e1758e2020-06-16 16:32:59 +02002003 /* everything's OK */
2004 break;
William Lallemandf9873ba2015-05-05 17:37:14 +02002005 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002006
2007 /* empty line */
2008 if (!**args)
2009 continue;
2010
Willy Tarreau3842f002009-06-14 11:39:52 +02002011 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002012 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02002013 char *tmp;
2014
Willy Tarreau3842f002009-06-14 11:39:52 +02002015 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02002016 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002017 for (arg=0; *args[arg+1]; arg++)
2018 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02002019 *tmp = '\0'; // fix the next arg to \0
2020 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002021 }
Willy Tarreau3842f002009-06-14 11:39:52 +02002022 else if (!strcmp(args[0], "default")) {
2023 kwm = KWM_DEF;
2024 for (arg=0; *args[arg+1]; arg++)
2025 args[arg] = args[arg+1]; // shift args after inversion
2026 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002027
William Dauchyec730982019-10-27 20:08:10 +01002028 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 &&
2029 strcmp(args[0], "log") != 0 && strcmp(args[0], "busy-polling") != 0 &&
Willy Tarreaud96f1122019-12-03 07:07:36 +01002030 strcmp(args[0], "set-dumpable") != 0 && strcmp(args[0], "strict-limits") != 0 &&
2031 strcmp(args[0], "insecure-fork-wanted") != 0) {
William Dauchyec730982019-10-27 20:08:10 +01002032 ha_alert("parsing [%s:%d]: negation/default currently "
William Dauchy0fec3ab2019-10-27 20:08:11 +01002033 "supported only for options, log, busy-polling, "
Willy Tarreaud96f1122019-12-03 07:07:36 +01002034 "set-dumpable, strict-limits, and insecure-fork-wanted.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02002035 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02002036 fatal++;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01002037 }
2038
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002039 /* detect section start */
2040 list_for_each_entry(ics, &sections, list) {
2041 if (strcmp(args[0], ics->section_name) == 0) {
2042 cursection = ics->section_name;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002043 pcs = cs;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01002044 cs = ics;
2045 break;
2046 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002047 }
2048
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002049 if (pcs && pcs->post_section_parser) {
Willy Tarreau32234e72020-06-16 17:14:33 +02002050 int status;
2051
2052 status = pcs->post_section_parser();
2053 err_code |= status;
2054 if (status & ERR_FATAL)
2055 fatal++;
2056
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002057 if (err_code & ERR_ABORT)
2058 goto err;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002059 }
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002060 pcs = NULL;
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002061
William Lallemandd2ff56d2017-10-16 11:06:50 +02002062 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002063 ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02002064 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau32234e72020-06-16 17:14:33 +02002065 fatal++;
William Lallemandd2ff56d2017-10-16 11:06:50 +02002066 } else {
Willy Tarreau32234e72020-06-16 17:14:33 +02002067 int status;
2068
2069 status = cs->section_parser(file, linenum, args, kwm);
2070 err_code |= status;
2071 if (status & ERR_FATAL)
2072 fatal++;
2073
William Lallemandd2ff56d2017-10-16 11:06:50 +02002074 if (err_code & ERR_ABORT)
2075 goto err;
2076 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002077 }
William Lallemandd2ff56d2017-10-16 11:06:50 +02002078
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02002079 if (missing_lf != -1) {
Tim Duesterhusf92afb72020-08-18 22:00:04 +02002080 ha_alert("parsing [%s:%d]: Missing LF on last line, file might have been truncated at position %d.\n",
2081 file, linenum, (missing_lf + 1));
2082 err_code |= ERR_ALERT | ERR_FATAL;
Tim Duesterhus2fd5bdb2020-06-22 22:57:45 +02002083 }
2084
Christopher Fauletbf7a9592018-12-02 09:37:38 +01002085 if (cs && cs->post_section_parser)
Christopher Faulet7805e2b2018-11-30 13:50:47 +01002086 err_code |= cs->post_section_parser();
William Lallemandd2ff56d2017-10-16 11:06:50 +02002087
2088err:
Christopher Faulet79bdef32016-11-04 22:36:15 +01002089 free(cfg_scope);
2090 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01002091 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02002092 free(thisline);
Willy Tarreau9e1758e2020-06-16 16:32:59 +02002093 free(outline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002094 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02002095 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002096}
2097
Willy Tarreau64ab6072014-09-16 12:17:36 +02002098/* This function propagates processes from frontend <from> to backend <to> so
2099 * that it is always guaranteed that a backend pointed to by a frontend is
2100 * bound to all of its processes. After that, if the target is a "listen"
2101 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02002102 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02002103 * checked first to ensure that <to> is already bound to all processes of
2104 * <from>, there is no risk of looping and we ensure to follow the shortest
2105 * path to the destination.
2106 *
2107 * It is possible to set <to> to NULL for the first call so that the function
2108 * takes care of visiting the initial frontend in <from>.
2109 *
2110 * It is important to note that the function relies on the fact that all names
2111 * have already been resolved.
2112 */
2113void propagate_processes(struct proxy *from, struct proxy *to)
2114{
2115 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002116
2117 if (to) {
2118 /* check whether we need to go down */
2119 if (from->bind_proc &&
2120 (from->bind_proc & to->bind_proc) == from->bind_proc)
2121 return;
2122
2123 if (!from->bind_proc && !to->bind_proc)
2124 return;
2125
2126 to->bind_proc = from->bind_proc ?
2127 (to->bind_proc | from->bind_proc) : 0;
2128
2129 /* now propagate down */
2130 from = to;
2131 }
2132
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01002133 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02002134 return;
2135
Willy Tarreauc3914d42020-09-24 08:39:22 +02002136 if (from->disabled)
Willy Tarreauf6b70012014-12-18 14:00:43 +01002137 return;
2138
Willy Tarreau64ab6072014-09-16 12:17:36 +02002139 /* default_backend */
2140 if (from->defbe.be)
2141 propagate_processes(from, from->defbe.be);
2142
2143 /* use_backend */
2144 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02002145 if (rule->dynamic)
2146 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02002147 to = rule->be.backend;
2148 propagate_processes(from, to);
2149 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02002150}
2151
Willy Tarreaubb925012009-07-23 13:36:36 +02002152/*
2153 * Returns the error code, 0 if OK, or any combination of :
2154 * - ERR_ABORT: must abort ASAP
2155 * - ERR_FATAL: we can continue parsing but not start the service
2156 * - ERR_WARN: a warning has been emitted
2157 * - ERR_ALERT: an alert has been emitted
2158 * Only the two first ones can stop processing, the two others are just
2159 * indicators.
2160 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002161int check_config_validity()
2162{
2163 int cfgerr = 0;
2164 struct proxy *curproxy = NULL;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002165 struct stktable *t;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002166 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02002167 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002168 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002169 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002170 char *err;
William Lallemand48b4bb42017-10-23 14:36:34 +02002171 struct cfg_postparser *postparser;
Ben Draut054fbee2018-04-13 15:43:04 -06002172 struct dns_resolvers *curr_resolvers = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002173
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002174 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002175 /*
2176 * Now, check for the integrity of all that we have collected.
2177 */
2178
2179 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02002180 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002181
Willy Tarreau193b8c62012-11-22 00:17:38 +01002182 if (!global.tune.max_http_hdr)
2183 global.tune.max_http_hdr = MAX_HTTP_HDR;
2184
2185 if (!global.tune.cookie_len)
2186 global.tune.cookie_len = CAPTURE_LEN;
2187
Stéphane Cottin23e9e932017-05-18 08:58:41 +02002188 if (!global.tune.requri_len)
2189 global.tune.requri_len = REQURI_LEN;
2190
Willy Tarreau149ab772019-01-26 14:27:06 +01002191 if (!global.nbthread) {
2192 /* nbthread not set, thus automatic. In this case, and only if
2193 * running on a single process, we enable the same number of
2194 * threads as the number of CPUs the process is bound to. This
2195 * allows to easily control the number of threads using taskset.
2196 */
2197 global.nbthread = 1;
2198#if defined(USE_THREAD)
2199 if (global.nbproc == 1)
2200 global.nbthread = thread_cpus_enabled_at_boot;
2201 all_threads_mask = nbits(global.nbthread);
2202#endif
2203 }
2204
Willy Tarreau26f6ae12019-02-02 12:56:15 +01002205 if (global.nbproc > 1 && global.nbthread > 1) {
2206 ha_alert("config : cannot enable multiple processes if multiple threads are configured. Please use either nbproc or nbthread but not both.\n");
2207 err_code |= ERR_ALERT | ERR_FATAL;
2208 goto out;
2209 }
2210
Willy Tarreaubafbe012017-11-24 17:34:44 +01002211 pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
Emeric Brun96fd9262017-07-05 13:33:16 +02002212
Willy Tarreaubafbe012017-11-24 17:34:44 +01002213 pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
Willy Tarreau193b8c62012-11-22 00:17:38 +01002214
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002215 /* Post initialisation of the users and groups lists. */
2216 err_code = userlist_postinit();
2217 if (err_code != ERR_NONE)
2218 goto out;
2219
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002220 /* first, we will invert the proxy list order */
2221 curproxy = NULL;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002222 while (proxies_list) {
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002223 struct proxy *next;
2224
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002225 next = proxies_list->next;
2226 proxies_list->next = curproxy;
2227 curproxy = proxies_list;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002228 if (!next)
2229 break;
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002230 proxies_list = next;
Willy Tarreau55bc0f82009-03-15 14:51:53 +01002231 }
2232
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002233 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002234 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002235 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002236 struct sticking_rule *mrule;
Christopher Faulete4e830d2017-09-18 14:51:41 +02002237 struct act_rule *arule;
Dragan Dosen1322d092015-09-22 16:05:32 +02002238 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002239 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01002240 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002241
Willy Tarreau050536d2012-10-04 08:47:34 +02002242 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002243 /* proxy ID not set, use automatic numbering with first
2244 * spare entry starting with next_pxid.
2245 */
2246 next_pxid = get_next_id(&used_proxy_id, next_pxid);
2247 curproxy->conf.id.key = curproxy->uuid = next_pxid;
2248 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002249 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01002250 next_pxid++;
2251
Willy Tarreau55ea7572007-06-17 19:56:27 +02002252
Willy Tarreauc3914d42020-09-24 08:39:22 +02002253 if (curproxy->disabled) {
Willy Tarreau02b092f2020-10-07 18:36:54 +02002254 /* ensure we don't keep listeners uselessly bound. We
2255 * can't disable their listeners yet (fdtab not
2256 * allocated yet) but let's skip them.
2257 */
Dragan Dosen7d61a332019-05-07 14:16:18 +02002258 if (curproxy->table) {
2259 free((void *)curproxy->table->peers.name);
Willy Tarreau02b092f2020-10-07 18:36:54 +02002260 curproxy->table->peers.name = NULL;
Dragan Dosen7d61a332019-05-07 14:16:18 +02002261 curproxy->table->peers.p = NULL;
2262 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002263 continue;
2264 }
2265
Willy Tarreau102df612014-05-07 23:56:38 +02002266 /* Check multi-process mode compatibility for the current proxy */
2267
2268 if (curproxy->bind_proc) {
2269 /* an explicit bind-process was specified, let's check how many
2270 * processes remain.
2271 */
David Carliere6c39412015-07-02 07:00:17 +00002272 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02002273
Willy Tarreaua38a7172019-02-02 17:11:28 +01002274 curproxy->bind_proc &= all_proc_mask;
Willy Tarreau102df612014-05-07 23:56:38 +02002275 if (!curproxy->bind_proc && nbproc == 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002276 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 +02002277 curproxy->bind_proc = 1;
2278 }
2279 else if (!curproxy->bind_proc && nbproc > 1) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002280 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 +02002281 curproxy->bind_proc = 0;
2282 }
2283 }
2284
Willy Tarreau3d209582014-05-09 17:06:11 +02002285 /* check and reduce the bind-proc of each listener */
2286 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
2287 unsigned long mask;
2288
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002289 /* HTTP frontends with "h2" as ALPN/NPN will work in
2290 * HTTP/2 and absolutely require buffers 16kB or larger.
2291 */
2292#ifdef USE_OPENSSL
2293 if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) {
2294#ifdef OPENSSL_NPN_NEGOTIATED
2295 /* check NPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002296 if (bind_conf->ssl_conf.npn_str && strstr(bind_conf->ssl_conf.npn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002297 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",
2298 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002299 cfgerr++;
2300 }
2301#endif
2302#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
2303 /* check ALPN */
Willy Tarreau4db49c02018-11-11 10:36:25 +01002304 if (bind_conf->ssl_conf.alpn_str && strstr(bind_conf->ssl_conf.alpn_str, "\002h2")) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002305 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",
2306 curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize);
Willy Tarreau45a66cc2017-11-24 11:28:00 +01002307 cfgerr++;
2308 }
2309#endif
2310 } /* HTTP && bufsize < 16384 */
2311#endif
2312
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002313 /* detect and address thread affinity inconsistencies */
Willy Tarreaue26993c2020-09-03 07:18:55 +02002314 mask = thread_mask(bind_conf->settings.bind_thread);
Willy Tarreau3d957172019-02-02 18:00:17 +01002315 if (!(mask & all_threads_mask)) {
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002316 unsigned long new_mask = 0;
2317
2318 while (mask) {
Willy Tarreau0c026f42018-08-01 19:12:20 +02002319 new_mask |= mask & all_threads_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002320 mask >>= global.nbthread;
2321 }
2322
Willy Tarreaue26993c2020-09-03 07:18:55 +02002323 bind_conf->settings.bind_thread = new_mask;
Willy Tarreauc477b6f2018-07-27 18:07:41 +02002324 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",
2325 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask);
2326 }
2327
2328 /* detect process and nbproc affinity inconsistencies */
Willy Tarreaue26993c2020-09-03 07:18:55 +02002329 mask = proc_mask(bind_conf->settings.bind_proc) & proc_mask(curproxy->bind_proc);
Willy Tarreaua36b3242019-02-02 13:14:34 +01002330 if (!(mask & all_proc_mask)) {
2331 mask = proc_mask(curproxy->bind_proc) & all_proc_mask;
Willy Tarreaue26993c2020-09-03 07:18:55 +02002332 nbproc = my_popcountl(bind_conf->settings.bind_proc);
2333 bind_conf->settings.bind_proc = proc_mask(bind_conf->settings.bind_proc) & mask;
Willy Tarreau3d209582014-05-09 17:06:11 +02002334
Willy Tarreaue26993c2020-09-03 07:18:55 +02002335 if (!bind_conf->settings.bind_proc && nbproc == 1) {
Willy Tarreaua36b3242019-02-02 13:14:34 +01002336 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",
2337 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreaue26993c2020-09-03 07:18:55 +02002338 bind_conf->settings.bind_proc = mask & ~(mask - 1);
Willy Tarreaua36b3242019-02-02 13:14:34 +01002339 }
Willy Tarreaue26993c2020-09-03 07:18:55 +02002340 else if (!bind_conf->settings.bind_proc && nbproc > 1) {
Willy Tarreaua36b3242019-02-02 13:14:34 +01002341 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",
2342 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
Willy Tarreaue26993c2020-09-03 07:18:55 +02002343 bind_conf->settings.bind_proc = 0;
Willy Tarreaua36b3242019-02-02 13:14:34 +01002344 }
Willy Tarreau3d209582014-05-09 17:06:11 +02002345 }
2346 }
2347
Willy Tarreauff01a212009-03-15 13:46:16 +01002348 switch (curproxy->mode) {
Willy Tarreauff01a212009-03-15 13:46:16 +01002349 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02002350 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01002351 break;
2352
2353 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01002354 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01002355 break;
William Lallemandcf62f7e2018-10-26 14:47:40 +02002356
2357 case PR_MODE_CLI:
2358 cfgerr += proxy_cfg_ensure_no_http(curproxy);
2359 break;
Emeric Brun54932b42020-07-07 09:43:24 +02002360 case PR_MODE_SYSLOG:
Willy Tarreaua389c9e2020-10-07 17:49:42 +02002361 case PR_MODE_PEERS:
Emeric Brun54932b42020-07-07 09:43:24 +02002362 case PR_MODES:
2363 /* should not happen, bug gcc warn missing switch statement */
Willy Tarreaua389c9e2020-10-07 17:49:42 +02002364 ha_alert("config : %s '%s' cannot use peers or syslog mode for this proxy. NOTE: PLEASE REPORT THIS TO DEVELOPERS AS YOU'RE NOT SUPPOSED TO BE ABLE TO CREATE A CONFIGURATION TRIGGERING THIS!\n",
Emeric Brun54932b42020-07-07 09:43:24 +02002365 proxy_type_str(curproxy), curproxy->id);
2366 cfgerr++;
2367 break;
Willy Tarreauff01a212009-03-15 13:46:16 +01002368 }
2369
Willy Tarreau58aa5cc2018-02-08 09:55:09 +01002370 if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002371 ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
2372 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauf3934b82015-08-11 11:36:45 +02002373 err_code |= ERR_WARN;
2374 }
2375
Willy Tarreau77e0dae2020-10-14 15:44:27 +02002376 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02002377 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002378 if (curproxy->options & PR_O_TRANSP) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002379 ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n",
2380 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002381 cfgerr++;
2382 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002383#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002384 else if (curproxy->srv == NULL) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002385 ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n",
2386 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002387 cfgerr++;
2388 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002389#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02002390 else if (curproxy->options & PR_O_DISPATCH) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002391 ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
2392 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002393 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002394 }
2395 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02002396 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002397 /* If no LB algo is set in a backend, and we're not in
2398 * transparent mode, dispatch mode nor proxy mode, we
2399 * want to use balance roundrobin by default.
2400 */
2401 curproxy->lbprm.algo &= ~BE_LB_ALGO;
2402 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002403 }
2404 }
Willy Tarreau193cf932007-09-17 10:17:23 +02002405
Willy Tarreau1620ec32011-08-06 17:05:02 +02002406 if (curproxy->options & PR_O_DISPATCH)
2407 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
2408 else if (curproxy->options & PR_O_HTTP_PROXY)
2409 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
2410 else if (curproxy->options & PR_O_TRANSP)
2411 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01002412
Christopher Faulete5870d82020-04-15 11:32:03 +02002413 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_HTTP_RS)) {
2414 ha_warning("config : %s '%s' uses http-check rules without 'option httpchk', so the rules are ignored.\n",
2415 proxy_type_str(curproxy), curproxy->id);
2416 err_code |= ERR_WARN;
2417 }
2418
2419 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_TCPCHK_CHK &&
Christopher Fauletc0fcbe42020-06-03 19:00:42 +02002420 (curproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) != TCPCHK_RULES_HTTP_CHK) {
Willy Tarreau1620ec32011-08-06 17:05:02 +02002421 if (curproxy->options & PR_O_DISABLE404) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002422 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2423 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002424 err_code |= ERR_WARN;
2425 curproxy->options &= ~PR_O_DISABLE404;
2426 }
2427 if (curproxy->options2 & PR_O2_CHK_SNDST) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002428 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
2429 "send-state", proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1620ec32011-08-06 17:05:02 +02002430 err_code |= ERR_WARN;
2431 curproxy->options &= ~PR_O2_CHK_SNDST;
2432 }
Willy Tarreauef781042010-01-27 11:53:01 +01002433 }
2434
Simon Horman98637e52014-06-20 12:30:16 +09002435 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
2436 if (!global.external_check) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002437 ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
2438 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002439 cfgerr++;
2440 }
2441 if (!curproxy->check_command) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002442 ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
2443 curproxy->id, "option external-check");
Simon Horman98637e52014-06-20 12:30:16 +09002444 cfgerr++;
2445 }
Willy Tarreaud96f1122019-12-03 07:07:36 +01002446 if (!(global.tune.options & GTUNE_INSECURE_FORK)) {
2447 ha_warning("Proxy '%s' : 'insecure-fork-wanted' not enabled in the global section, '%s' will likely fail.\n",
2448 curproxy->id, "option external-check");
2449 err_code |= ERR_WARN;
2450 }
Simon Horman98637e52014-06-20 12:30:16 +09002451 }
2452
Simon Horman64e34162015-02-06 11:11:57 +09002453 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002454 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002455 ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
2456 "'email-alert from', 'email-alert level' 'email-alert mailers', "
2457 "'email-alert myhostname', or 'email-alert to' "
2458 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
2459 "to be present).\n",
2460 proxy_type_str(curproxy), curproxy->id);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002461 err_code |= ERR_WARN;
2462 free_email_alert(curproxy);
2463 }
2464 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01002465 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09002466 }
2467
Simon Horman98637e52014-06-20 12:30:16 +09002468 if (curproxy->check_command) {
2469 int clear = 0;
2470 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002471 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2472 "external-check command", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002473 err_code |= ERR_WARN;
2474 clear = 1;
2475 }
2476 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002477 ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
2478 curproxy->id, "external-check command");
Simon Horman98637e52014-06-20 12:30:16 +09002479 cfgerr++;
2480 }
2481 if (clear) {
2482 free(curproxy->check_command);
2483 curproxy->check_command = NULL;
2484 }
2485 }
2486
2487 if (curproxy->check_path) {
2488 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002489 ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
2490 "external-check path", proxy_type_str(curproxy), curproxy->id);
Simon Horman98637e52014-06-20 12:30:16 +09002491 err_code |= ERR_WARN;
2492 free(curproxy->check_path);
2493 curproxy->check_path = NULL;
2494 }
2495 }
2496
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002497 /* if a default backend was specified, let's find it */
2498 if (curproxy->defbe.name) {
2499 struct proxy *target;
2500
Willy Tarreauafb39922015-05-26 12:04:09 +02002501 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002502 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002503 ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
2504 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002505 cfgerr++;
2506 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002507 ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
2508 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02002509 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002510 } else if (target->mode != curproxy->mode &&
2511 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2512
Christopher Faulet767a84b2017-11-24 16:50:31 +01002513 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
2514 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2515 curproxy->conf.file, curproxy->conf.line,
2516 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2517 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002518 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002519 } else {
2520 free(curproxy->defbe.name);
2521 curproxy->defbe.be = target;
Willy Tarreauff678132012-02-13 14:32:34 +01002522 /* Emit a warning if this proxy also has some servers */
2523 if (curproxy->srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002524 ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
2525 curproxy->id);
Willy Tarreauff678132012-02-13 14:32:34 +01002526 err_code |= ERR_WARN;
2527 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002528 }
2529 }
2530
Willy Tarreau55ea7572007-06-17 19:56:27 +02002531 /* find the target proxy for 'use_backend' rules */
2532 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02002533 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002534 struct logformat_node *node;
2535 char *pxname;
2536
2537 /* Try to parse the string as a log format expression. If the result
2538 * of the parsing is only one entry containing a simple string, then
2539 * it's a standard string corresponding to a static rule, thus the
2540 * parsing is cancelled and be.name is restored to be resolved.
2541 */
2542 pxname = rule->be.name;
2543 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01002544 curproxy->conf.args.ctx = ARGC_UBK;
2545 curproxy->conf.args.file = rule->file;
2546 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002547 err = NULL;
2548 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002549 ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
2550 rule->file, rule->line, pxname, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002551 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002552 cfgerr++;
2553 continue;
2554 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002555 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
2556
2557 if (!LIST_ISEMPTY(&rule->be.expr)) {
2558 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
2559 rule->dynamic = 1;
2560 free(pxname);
2561 continue;
2562 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002563 /* Only one element in the list, a simple string: free the expression and
2564 * fall back to static rule
2565 */
2566 LIST_DEL(&node->list);
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01002567 free(node->arg);
2568 free(node);
2569 }
2570
2571 rule->dynamic = 0;
2572 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002573
Willy Tarreauafb39922015-05-26 12:04:09 +02002574 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01002575 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002576 ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
2577 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002578 cfgerr++;
2579 } else if (target == curproxy) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002580 ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
2581 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02002582 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02002583 } else if (target->mode != curproxy->mode &&
2584 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
2585
Christopher Faulet767a84b2017-11-24 16:50:31 +01002586 ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
2587 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
2588 curproxy->conf.file, curproxy->conf.line,
2589 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
2590 target->conf.file, target->conf.line);
Willy Tarreauafb39922015-05-26 12:04:09 +02002591 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002592 } else {
2593 free((void *)rule->be.name);
2594 rule->be.backend = target;
2595 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002596 }
2597
Willy Tarreau64ab6072014-09-16 12:17:36 +02002598 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002599 list_for_each_entry(srule, &curproxy->server_rules, list) {
Jerome Magnin824186b2020-03-29 09:37:12 +02002600 struct server *target;
2601 struct logformat_node *node;
2602 char *server_name;
2603
2604 /* We try to parse the string as a log format expression. If the result of the parsing
2605 * is only one entry containing a single string, then it's a standard string corresponding
2606 * to a static rule, thus the parsing is cancelled and we fall back to setting srv.ptr.
2607 */
2608 server_name = srule->srv.name;
2609 LIST_INIT(&srule->expr);
2610 curproxy->conf.args.ctx = ARGC_USRV;
2611 err = NULL;
2612 if (!parse_logformat_string(server_name, curproxy, &srule->expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
2613 ha_alert("Parsing [%s:%d]; use-server rule failed to parse log-format '%s' : %s.\n",
2614 srule->file, srule->line, server_name, err);
2615 free(err);
2616 cfgerr++;
2617 continue;
2618 }
2619 node = LIST_NEXT(&srule->expr, struct logformat_node *, list);
2620
2621 if (!LIST_ISEMPTY(&srule->expr)) {
2622 if (node->type != LOG_FMT_TEXT || node->list.n != &srule->expr) {
2623 srule->dynamic = 1;
2624 free(server_name);
2625 continue;
2626 }
Christopher Fauletf82ea4a2020-05-07 15:59:33 +02002627 /* Only one element in the list, a simple string: free the expression and
2628 * fall back to static rule
2629 */
2630 LIST_DEL(&node->list);
Jerome Magnin824186b2020-03-29 09:37:12 +02002631 free(node->arg);
2632 free(node);
2633 }
2634
2635 srule->dynamic = 0;
2636 srule->srv.name = server_name;
2637 target = findserver(curproxy, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002638
2639 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002640 ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
2641 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02002642 cfgerr++;
2643 continue;
2644 }
2645 free((void *)srule->srv.name);
2646 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02002647 }
2648
Emeric Brunb982a3d2010-01-04 15:45:53 +01002649 /* find the target table for 'stick' rules */
2650 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002651 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002652
Emeric Brun1d33b292010-01-04 15:47:17 +01002653 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
2654 if (mrule->flags & STK_IS_STORE)
2655 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2656
Emeric Brunb982a3d2010-01-04 15:45:53 +01002657 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002658 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002659 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002660 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002661
2662 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002663 ha_alert("Proxy '%s': unable to find stick-table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002664 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002665 cfgerr++;
2666 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002667 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002668 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2669 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002670 cfgerr++;
2671 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002672 else if (target->proxy && curproxy->bind_proc & ~target->proxy->bind_proc) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002673 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2674 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002675 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002676 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002677 else {
2678 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002679 mrule->table.t = target;
2680 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002681 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002682 if (!in_proxies_list(target->proxies_list, curproxy)) {
2683 curproxy->next_stkt_ref = target->proxies_list;
2684 target->proxies_list = curproxy;
2685 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002686 }
2687 }
2688
2689 /* find the target table for 'store response' rules */
2690 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002691 struct stktable *target;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002692
Emeric Brun1d33b292010-01-04 15:47:17 +01002693 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
2694
Emeric Brunb982a3d2010-01-04 15:45:53 +01002695 if (mrule->table.name)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002696 target = stktable_find_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002697 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002698 target = curproxy->table;
Emeric Brunb982a3d2010-01-04 15:45:53 +01002699
2700 if (!target) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002701 ha_alert("Proxy '%s': unable to find store table '%s'.\n",
Willy Tarreau508d2322020-01-24 07:19:34 +01002702 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002703 cfgerr++;
2704 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002705 else if (!stktable_compatible_sample(mrule->expr, target->type)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002706 ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
2707 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
Emeric Brunb982a3d2010-01-04 15:45:53 +01002708 cfgerr++;
2709 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002710 else if (target->proxy && (curproxy->bind_proc & ~target->proxy->bind_proc)) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002711 ha_alert("Proxy '%s': stick-table '%s' referenced 'stick-store' rule not present on all processes covered by proxy '%s'.\n",
2712 curproxy->id, target->id, curproxy->id);
Willy Tarreau1a0fe3b2019-02-06 10:25:07 +01002713 cfgerr++;
Willy Tarreau151e1ca2019-02-05 11:38:38 +01002714 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002715 else {
2716 free((void *)mrule->table.name);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002717 mrule->table.t = target;
2718 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_ID, NULL);
Frédéric Lécailledb52d902019-05-17 10:12:52 +02002719 stktable_alloc_data_type(target, STKTABLE_DT_SERVER_NAME, NULL);
Frédéric Lécaille9c3a0ce2019-09-02 14:02:28 +02002720 if (!in_proxies_list(target->proxies_list, curproxy)) {
2721 curproxy->next_stkt_ref = target->proxies_list;
2722 target->proxies_list = curproxy;
2723 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01002724 }
2725 }
2726
Christopher Faulete4e830d2017-09-18 14:51:41 +02002727 /* check validity for 'tcp-request' layer 4 rules */
2728 list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) {
2729 err = NULL;
2730 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002731 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002732 free(err);
Willy Tarreau5f53de72012-12-12 00:25:44 +01002733 cfgerr++;
2734 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02002735 }
2736
Christopher Faulete4e830d2017-09-18 14:51:41 +02002737 /* check validity for 'tcp-request' layer 5 rules */
2738 list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) {
2739 err = NULL;
2740 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002741 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002742 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002743 cfgerr++;
2744 }
2745 }
2746
Christopher Faulete4e830d2017-09-18 14:51:41 +02002747 /* check validity for 'tcp-request' layer 6 rules */
2748 list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
2749 err = NULL;
2750 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002751 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002752 free(err);
Baptiste Assmanne9544932015-11-03 23:31:35 +01002753 cfgerr++;
2754 }
2755 }
2756
Christopher Faulete4e830d2017-09-18 14:51:41 +02002757 /* check validity for 'http-request' layer 7 rules */
2758 list_for_each_entry(arule, &curproxy->http_req_rules, list) {
2759 err = NULL;
2760 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002761 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002762 free(err);
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002763 cfgerr++;
2764 }
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08002765 }
2766
Christopher Faulete4e830d2017-09-18 14:51:41 +02002767 /* check validity for 'http-response' layer 7 rules */
2768 list_for_each_entry(arule, &curproxy->http_res_rules, list) {
2769 err = NULL;
2770 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002771 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulete4e830d2017-09-18 14:51:41 +02002772 free(err);
Willy Tarreau09448f72014-06-25 18:12:15 +02002773 cfgerr++;
2774 }
Willy Tarreau09448f72014-06-25 18:12:15 +02002775 }
2776
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01002777 /* check validity for 'http-after-response' layer 7 rules */
2778 list_for_each_entry(arule, &curproxy->http_after_res_rules, list) {
2779 err = NULL;
2780 if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
2781 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
2782 free(err);
2783 cfgerr++;
2784 }
2785 }
2786
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002787 if (curproxy->table && curproxy->table->peers.name) {
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002788 struct peers *curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002789
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02002790 for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002791 if (strcmp(curpeers->id, curproxy->table->peers.name) == 0) {
2792 free((void *)curproxy->table->peers.name);
2793 curproxy->table->peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002794 break;
2795 }
2796 }
2797
2798 if (!curpeers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002799 ha_alert("Proxy '%s': unable to find sync peers '%s'.\n",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002800 curproxy->id, curproxy->table->peers.name);
2801 free((void *)curproxy->table->peers.name);
2802 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002803 cfgerr++;
2804 }
Willy Tarreau1ad64ac2020-09-24 08:48:08 +02002805 else if (curpeers->disabled) {
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002806 /* silently disable this peers section */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002807 curproxy->table->peers.p = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002808 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002809 else if (!curpeers->peers_fe) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002810 ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
2811 curproxy->id, localpeer, curpeers->id);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002812 curproxy->table->peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02002813 cfgerr++;
2814 }
2815 }
2816
Simon Horman9dc49962015-01-30 11:22:59 +09002817
2818 if (curproxy->email_alert.mailers.name) {
2819 struct mailers *curmailers = mailers;
2820
2821 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
Christopher Faulet0108bb32017-10-20 21:34:32 +02002822 if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name))
Simon Horman9dc49962015-01-30 11:22:59 +09002823 break;
Simon Horman9dc49962015-01-30 11:22:59 +09002824 }
Simon Horman9dc49962015-01-30 11:22:59 +09002825 if (!curmailers) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002826 ha_alert("Proxy '%s': unable to find mailers '%s'.\n",
2827 curproxy->id, curproxy->email_alert.mailers.name);
Simon Horman9dc49962015-01-30 11:22:59 +09002828 free_email_alert(curproxy);
2829 cfgerr++;
2830 }
Christopher Faulet0108bb32017-10-20 21:34:32 +02002831 else {
2832 err = NULL;
2833 if (init_email_alert(curmailers, curproxy, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002834 ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
Christopher Faulet0108bb32017-10-20 21:34:32 +02002835 free(err);
2836 cfgerr++;
2837 }
2838 }
Simon Horman9dc49962015-01-30 11:22:59 +09002839 }
2840
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002841 if (curproxy->uri_auth && curproxy->uri_auth != defproxy.uri_auth &&
Willy Tarreauff011f22011-01-06 17:51:27 +01002842 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002843 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002844 ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
2845 "proxy", curproxy->id);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002846 cfgerr++;
2847 goto out_uri_auth_compat;
2848 }
2849
Willy Tarreauee4f5f82019-10-09 09:59:22 +02002850 if (curproxy->uri_auth && curproxy->uri_auth->userlist &&
2851 (curproxy->uri_auth != defproxy.uri_auth ||
2852 LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules))) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002853 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02002854 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002855 int i = 0;
Willy Tarreau95fa4692010-02-01 13:05:50 +01002856 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
2857 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002858
2859 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002860 uri_auth_compat_req[i++] = "realm";
2861 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
2862 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002863
Willy Tarreau95fa4692010-02-01 13:05:50 +01002864 uri_auth_compat_req[i++] = "unless";
2865 uri_auth_compat_req[i++] = "{";
2866 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
2867 uri_auth_compat_req[i++] = "}";
2868 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002869
Willy Tarreauff011f22011-01-06 17:51:27 +01002870 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
2871 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01002872 cfgerr++;
2873 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002874 }
2875
Willy Tarreauff011f22011-01-06 17:51:27 +01002876 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01002877
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002878 if (curproxy->uri_auth->auth_realm) {
2879 free(curproxy->uri_auth->auth_realm);
2880 curproxy->uri_auth->auth_realm = NULL;
2881 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01002882 }
2883out_uri_auth_compat:
2884
Dragan Dosen43885c72015-10-01 13:18:13 +02002885 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02002886 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02002887 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
2888 if (!curproxy->conf.logformat_sd_string) {
2889 /* set the default logformat_sd_string */
2890 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
2891 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002892 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02002893 }
Dragan Dosen1322d092015-09-22 16:05:32 +02002894 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02002895
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002896 /* compile the log format */
2897 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02002898 if (curproxy->conf.logformat_string != default_http_log_format &&
2899 curproxy->conf.logformat_string != default_tcp_log_format &&
2900 curproxy->conf.logformat_string != clf_http_log_format)
2901 free(curproxy->conf.logformat_string);
2902 curproxy->conf.logformat_string = NULL;
2903 free(curproxy->conf.lfs_file);
2904 curproxy->conf.lfs_file = NULL;
2905 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002906
2907 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2908 free(curproxy->conf.logformat_sd_string);
2909 curproxy->conf.logformat_sd_string = NULL;
2910 free(curproxy->conf.lfsd_file);
2911 curproxy->conf.lfsd_file = NULL;
2912 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002913 }
2914
Willy Tarreau62a61232013-04-12 18:13:46 +02002915 if (curproxy->conf.logformat_string) {
2916 curproxy->conf.args.ctx = ARGC_LOG;
2917 curproxy->conf.args.file = curproxy->conf.lfs_file;
2918 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002919 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002920 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat,
2921 LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002922 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002923 ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
2924 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002925 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002926 cfgerr++;
2927 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002928 curproxy->conf.args.file = NULL;
2929 curproxy->conf.args.line = 0;
2930 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002931
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002932 if (curproxy->conf.logformat_sd_string) {
2933 curproxy->conf.args.ctx = ARGC_LOGSD;
2934 curproxy->conf.args.file = curproxy->conf.lfsd_file;
2935 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002936 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002937 if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd,
2938 LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002939 SMP_VAL_FE_LOG_END, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002940 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2941 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002942 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002943 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002944 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002945 ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
2946 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002947 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01002948 cfgerr++;
2949 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002950 curproxy->conf.args.file = NULL;
2951 curproxy->conf.args.line = 0;
2952 }
2953
Willy Tarreau62a61232013-04-12 18:13:46 +02002954 if (curproxy->conf.uniqueid_format_string) {
2955 curproxy->conf.args.ctx = ARGC_UIF;
2956 curproxy->conf.args.file = curproxy->conf.uif_file;
2957 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01002958 err = NULL;
Dragan Dosen1e3b16f2020-06-23 18:16:44 +02002959 if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id,
2960 LOG_OPT_HTTP|LOG_OPT_MERGE_SPACES,
2961 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR
2962 : SMP_VAL_BE_HRQ_HDR,
2963 &err)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002964 ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
2965 curproxy->conf.uif_file, curproxy->conf.uif_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++;
2968 }
Willy Tarreau62a61232013-04-12 18:13:46 +02002969 curproxy->conf.args.file = NULL;
2970 curproxy->conf.args.line = 0;
2971 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002972
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01002973 /* only now we can check if some args remain unresolved.
2974 * This must be done after the users and groups resolution.
2975 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002976 cfgerr += smp_resolve_args(curproxy);
2977 if (!cfgerr)
2978 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01002979
Willy Tarreau2738a142006-07-08 17:28:09 +02002980 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002981 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02002982 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02002983 (!curproxy->timeout.connect ||
2984 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01002985 ha_warning("config : missing timeouts for %s '%s'.\n"
2986 " | While not properly invalid, you will certainly encounter various problems\n"
2987 " | with such a configuration. To fix this, please ensure that all following\n"
2988 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
2989 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02002990 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02002991 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02002992
Willy Tarreau1fa31262007-12-03 00:36:16 +01002993 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
2994 * We must still support older configurations, so let's find out whether those
2995 * parameters have been set or must be copied from contimeouts.
2996 */
2997 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02002998 if (!curproxy->timeout.tarpit ||
2999 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01003000 /* tarpit timeout not set. We search in the following order:
3001 * default.tarpit, curr.connect, default.connect.
3002 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003003 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01003004 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003005 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003006 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003007 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003008 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01003009 }
3010 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003011 (!curproxy->timeout.queue ||
3012 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01003013 /* queue timeout not set. We search in the following order:
3014 * default.queue, curr.connect, default.connect.
3015 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003016 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01003017 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003018 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003019 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02003020 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01003021 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01003022 }
3023 }
3024
Christopher Faulete5870d82020-04-15 11:32:03 +02003025 if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_TCP_RS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003026 ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
3027 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau215663d2014-06-13 18:30:23 +02003028 err_code |= ERR_WARN;
3029 }
3030
Willy Tarreau193b8c62012-11-22 00:17:38 +01003031 /* ensure that cookie capture length is not too large */
3032 if (curproxy->capture_len >= global.tune.cookie_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003033 ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n",
3034 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau193b8c62012-11-22 00:17:38 +01003035 err_code |= ERR_WARN;
3036 curproxy->capture_len = global.tune.cookie_len - 1;
3037 }
3038
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003039 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01003040 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003041 curproxy->req_cap_pool = create_pool("ptrcap",
3042 curproxy->nb_req_cap * sizeof(char *),
3043 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003044 }
3045
3046 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02003047 curproxy->rsp_cap_pool = create_pool("ptrcap",
3048 curproxy->nb_rsp_cap * sizeof(char *),
3049 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01003050 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003051
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003052 switch (curproxy->load_server_state_from_file) {
3053 case PR_SRV_STATE_FILE_UNSPEC:
3054 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
3055 break;
3056 case PR_SRV_STATE_FILE_GLOBAL:
3057 if (!global.server_state_file) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003058 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",
3059 curproxy->id);
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003060 err_code |= ERR_WARN;
3061 }
3062 break;
3063 }
3064
Willy Tarreaubaaee002006-06-26 02:48:02 +02003065 /* first, we will invert the servers list order */
3066 newsrv = NULL;
3067 while (curproxy->srv) {
3068 struct server *next;
3069
3070 next = curproxy->srv->next;
3071 curproxy->srv->next = newsrv;
3072 newsrv = curproxy->srv;
3073 if (!next)
3074 break;
3075 curproxy->srv = next;
3076 }
3077
Willy Tarreau17edc812014-01-03 12:14:34 +01003078 /* Check that no server name conflicts. This causes trouble in the stats.
3079 * We only emit a warning for the first conflict affecting each server,
3080 * in order to avoid combinatory explosion if all servers have the same
3081 * name. We do that only for servers which do not have an explicit ID,
3082 * because these IDs were made also for distinguishing them and we don't
3083 * want to annoy people who correctly manage them.
3084 */
3085 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3086 struct server *other_srv;
3087
3088 if (newsrv->puid)
3089 continue;
3090
3091 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
3092 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
Willy Tarreaub01302f2019-05-27 19:31:06 +02003093 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 +01003094 newsrv->conf.file, newsrv->conf.line,
3095 proxy_type_str(curproxy), curproxy->id,
3096 newsrv->id, other_srv->conf.line);
Willy Tarreaub01302f2019-05-27 19:31:06 +02003097 cfgerr++;
Willy Tarreau17edc812014-01-03 12:14:34 +01003098 break;
3099 }
3100 }
3101 }
3102
Willy Tarreaudd701652010-05-25 23:03:02 +02003103 /* assign automatic UIDs to servers which don't have one yet */
3104 next_id = 1;
3105 newsrv = curproxy->srv;
3106 while (newsrv != NULL) {
3107 if (!newsrv->puid) {
3108 /* server ID not set, use automatic numbering with first
3109 * spare entry starting with next_svid.
3110 */
3111 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
3112 newsrv->conf.id.key = newsrv->puid = next_id;
3113 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
Frédéric Lécaille84d60462019-05-17 14:29:15 +02003114 newsrv->conf.name.key = newsrv->id;
3115 ebis_insert(&curproxy->conf.used_server_name, &newsrv->conf.name);
Willy Tarreaudd701652010-05-25 23:03:02 +02003116 }
3117 next_id++;
3118 newsrv = newsrv->next;
3119 }
3120
Willy Tarreau20697042007-11-15 23:26:18 +01003121 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01003122 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02003123
Willy Tarreau62c3be22012-01-20 13:12:32 +01003124 /*
3125 * If this server supports a maxconn parameter, it needs a dedicated
3126 * tasks to fill the emptied slots when a connection leaves.
3127 * Also, resolve deferred tracking dependency if needed.
3128 */
3129 newsrv = curproxy->srv;
3130 while (newsrv != NULL) {
3131 if (newsrv->minconn > newsrv->maxconn) {
3132 /* Only 'minconn' was specified, or it was higher than or equal
3133 * to 'maxconn'. Let's turn this into maxconn and clean it, as
3134 * this will avoid further useless expensive computations.
3135 */
3136 newsrv->maxconn = newsrv->minconn;
3137 } else if (newsrv->maxconn && !newsrv->minconn) {
3138 /* minconn was not specified, so we set it to maxconn */
3139 newsrv->minconn = newsrv->maxconn;
3140 }
3141
William Dauchyf6370442020-11-14 19:25:33 +01003142 /* this will also properly set the transport layer for
3143 * prod and checks
3144 * if default-server have use_ssl, prerare ssl init
3145 * without activating it */
3146 if (newsrv->use_ssl == 1 || newsrv->check.use_ssl == 1 ||
3147 (newsrv->proxy->options & PR_O_TCPCHK_SSL) ||
3148 (newsrv->use_ssl != 1 && curproxy->defsrv.use_ssl == 1)) {
Willy Tarreau17d45382016-12-22 21:16:08 +01003149 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
3150 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
3151 }
Emeric Brun94324a42012-10-11 14:00:19 +02003152
Willy Tarreau034c88c2017-01-23 23:36:45 +01003153 if ((newsrv->flags & SRV_F_FASTOPEN) &&
3154 ((curproxy->retry_type & (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)) !=
3155 (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)))
3156 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",
3157 newsrv->conf.file, newsrv->conf.line,
3158 proxy_type_str(curproxy), curproxy->id,
3159 newsrv->id);
3160
Willy Tarreau62c3be22012-01-20 13:12:32 +01003161 if (newsrv->trackit) {
3162 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02003163 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003164 char *pname, *sname;
3165
3166 pname = newsrv->trackit;
3167 sname = strrchr(pname, '/');
3168
3169 if (sname)
3170 *sname++ = '\0';
3171 else {
3172 sname = pname;
3173 pname = NULL;
3174 }
3175
3176 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02003177 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003178 if (!px) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003179 ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
3180 proxy_type_str(curproxy), curproxy->id,
3181 newsrv->id, pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003182 cfgerr++;
3183 goto next_srv;
3184 }
3185 } else
3186 px = curproxy;
3187
3188 srv = findserver(px, sname);
3189 if (!srv) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003190 ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
3191 proxy_type_str(curproxy), curproxy->id,
3192 newsrv->id, sname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003193 cfgerr++;
3194 goto next_srv;
3195 }
3196
Christopher Faulet8892e5d2020-03-26 19:48:20 +01003197 if (!srv->do_check && !srv->do_agent && !srv->track && !srv->trackit) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003198 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for "
3199 "tracking as it does not have any check nor agent enabled.\n",
3200 proxy_type_str(curproxy), curproxy->id,
3201 newsrv->id, px->id, srv->id);
Willy Tarreau32091232014-05-16 13:52:00 +02003202 cfgerr++;
3203 goto next_srv;
3204 }
3205
3206 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
3207
Frédéric Lécaille2efc6492017-03-14 14:32:17 +01003208 if (newsrv == srv || loop) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003209 ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it "
3210 "belongs to a tracking chain looping back to %s/%s.\n",
3211 proxy_type_str(curproxy), curproxy->id,
3212 newsrv->id, px->id, srv->id, px->id,
3213 newsrv == srv ? srv->id : loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003214 cfgerr++;
3215 goto next_srv;
3216 }
3217
3218 if (curproxy != px &&
3219 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003220 ha_alert("config : %s '%s', server '%s': unable to use %s/%s for"
3221 "tracking: disable-on-404 option inconsistency.\n",
3222 proxy_type_str(curproxy), curproxy->id,
3223 newsrv->id, px->id, srv->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01003224 cfgerr++;
3225 goto next_srv;
3226 }
3227
Willy Tarreau62c3be22012-01-20 13:12:32 +01003228 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01003229 newsrv->tracknext = srv->trackers;
3230 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01003231
3232 free(newsrv->trackit);
3233 newsrv->trackit = NULL;
3234 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02003235
Willy Tarreau62c3be22012-01-20 13:12:32 +01003236 next_srv:
3237 newsrv = newsrv->next;
3238 }
3239
Olivier Houchard4e694042017-03-14 20:01:29 +01003240 /*
3241 * Try to generate dynamic cookies for servers now.
3242 * It couldn't be done earlier, since at the time we parsed
3243 * the server line, we may not have known yet that we
3244 * should use dynamic cookies, or the secret key may not
3245 * have been provided yet.
3246 */
3247 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
3248 newsrv = curproxy->srv;
3249 while (newsrv != NULL) {
3250 srv_set_dyncookie(newsrv);
3251 newsrv = newsrv->next;
3252 }
3253
3254 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003255 /* We have to initialize the server lookup mechanism depending
Joseph Herlanta14c03e2018-11-15 14:04:19 -08003256 * on what LB algorithm was chosen.
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003257 */
3258
3259 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
3260 switch (curproxy->lbprm.algo & BE_LB_KIND) {
3261 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02003262 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
3263 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3264 init_server_map(curproxy);
Willy Tarreau760e81d2018-05-03 07:20:40 +02003265 } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
3266 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3267 chash_init_server_tree(curproxy);
Willy Tarreau9757a382009-10-03 12:56:50 +02003268 } else {
3269 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
3270 fwrr_init_server_groups(curproxy);
3271 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003272 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003273
Willy Tarreau3ebb1162012-02-13 16:57:44 +01003274 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01003275 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
3276 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
3277 fwlc_init_server_tree(curproxy);
3278 } else {
3279 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
3280 fas_init_server_tree(curproxy);
3281 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003282 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003283
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003284 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003285 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
3286 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
3287 chash_init_server_tree(curproxy);
3288 } else {
3289 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
3290 init_server_map(curproxy);
3291 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02003292 break;
3293 }
Willy Tarreaucd10def2020-10-17 18:48:47 +02003294 HA_RWLOCK_INIT(&curproxy->lbprm.lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003295
3296 if (curproxy->options & PR_O_LOGASAP)
3297 curproxy->to_log &= ~LW_BYTES;
3298
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003299 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02003300 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
3301 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003302 ha_warning("config : log format ignored for %s '%s' since it has no log address.\n",
3303 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02003304 err_code |= ERR_WARN;
3305 }
3306
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003307 if (curproxy->mode != PR_MODE_HTTP) {
3308 int optnum;
3309
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003310 if (curproxy->uri_auth) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003311 ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
3312 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003313 err_code |= ERR_WARN;
3314 curproxy->uri_auth = NULL;
3315 }
3316
Willy Tarreaude7dc882017-03-10 11:49:21 +01003317 if (curproxy->capture_name) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003318 ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
3319 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003320 err_code |= ERR_WARN;
3321 }
3322
3323 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003324 ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
3325 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003326 err_code |= ERR_WARN;
3327 }
3328
3329 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003330 ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
3331 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003332 err_code |= ERR_WARN;
3333 }
3334
Willy Tarreaude7dc882017-03-10 11:49:21 +01003335 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003336 ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
3337 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaude7dc882017-03-10 11:49:21 +01003338 err_code |= ERR_WARN;
3339 }
3340
Willy Tarreau87cf5142011-08-19 22:57:24 +02003341 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003342 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3343 "forwardfor", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003344 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02003345 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003346 }
3347
3348 if (curproxy->options & PR_O_ORGTO) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003349 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3350 "originalto", proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003351 err_code |= ERR_WARN;
3352 curproxy->options &= ~PR_O_ORGTO;
3353 }
3354
3355 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
3356 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
3357 (curproxy->cap & cfg_opts[optnum].cap) &&
3358 (curproxy->options & cfg_opts[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003359 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3360 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003361 err_code |= ERR_WARN;
3362 curproxy->options &= ~cfg_opts[optnum].val;
3363 }
3364 }
3365
3366 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
3367 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
3368 (curproxy->cap & cfg_opts2[optnum].cap) &&
3369 (curproxy->options2 & cfg_opts2[optnum].val)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003370 ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
3371 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003372 err_code |= ERR_WARN;
3373 curproxy->options2 &= ~cfg_opts2[optnum].val;
3374 }
3375 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003376
Willy Tarreau29fbe512015-08-20 19:35:14 +02003377#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003378 if (curproxy->conn_src.bind_hdr_occ) {
3379 curproxy->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003380 ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
3381 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003382 err_code |= ERR_WARN;
3383 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003384#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01003385 }
3386
Willy Tarreaubaaee002006-06-26 02:48:02 +02003387 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01003388 * ensure that we're not cross-dressing a TCP server into HTTP.
3389 */
3390 newsrv = curproxy->srv;
3391 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01003392 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003393 ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
3394 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02003395 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01003396 }
Willy Tarreaubce70882009-09-07 11:51:47 +02003397
Willy Tarreau0cec3312011-10-31 13:49:26 +01003398 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003399 ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
3400 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau0cec3312011-10-31 13:49:26 +01003401 err_code |= ERR_WARN;
3402 }
3403
Willy Tarreauc93cd162014-05-13 15:54:22 +02003404 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003405 ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
3406 proxy_type_str(curproxy), curproxy->id, newsrv->id);
Willy Tarreau82ffa392013-08-13 17:19:08 +02003407 err_code |= ERR_WARN;
3408 }
3409
Willy Tarreau29fbe512015-08-20 19:35:14 +02003410#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01003411 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
3412 newsrv->conn_src.bind_hdr_occ = 0;
Christopher Faulet767a84b2017-11-24 16:50:31 +01003413 ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
3414 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02003415 err_code |= ERR_WARN;
3416 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02003417#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01003418
Willy Tarreau46deab62018-04-28 07:18:15 +02003419 if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR)
3420 curproxy->options &= ~PR_O_REUSE_MASK;
3421
Willy Tarreau21d2af32008-02-14 20:25:24 +01003422 newsrv = newsrv->next;
3423 }
3424
Christopher Fauletd7c91962015-04-30 11:48:27 +02003425 /* Check filter configuration, if any */
3426 cfgerr += flt_check(curproxy);
3427
Willy Tarreauc1a21672009-08-16 22:37:44 +02003428 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02003429 if (!curproxy->accept)
3430 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02003431
Willy Tarreauc1a21672009-08-16 22:37:44 +02003432 if (curproxy->tcp_req.inspect_delay ||
3433 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02003434 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003435
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003436 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003437 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003438 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003439 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003440
William Lallemandcf62f7e2018-10-26 14:47:40 +02003441 if (curproxy->mode == PR_MODE_CLI) {
3442 curproxy->fe_req_ana |= AN_REQ_WAIT_CLI;
3443 curproxy->fe_rsp_ana |= AN_RES_WAIT_CLI;
3444 }
3445
Willy Tarreauc1a21672009-08-16 22:37:44 +02003446 /* both TCP and HTTP must check switching rules */
3447 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003448
3449 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003450 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003451 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3452 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 +01003453 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003454 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3455 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003456 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003457 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003458 }
3459
3460 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02003461 if (curproxy->tcp_req.inspect_delay ||
3462 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
3463 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
3464
Emeric Brun97679e72010-09-23 17:56:44 +02003465 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
3466 curproxy->be_rsp_ana |= AN_RES_INSPECT;
3467
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003468 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02003469 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02003470 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02003471 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003472
3473 /* If the backend does requires RDP cookie persistence, we have to
3474 * enable the corresponding analyser.
3475 */
3476 if (curproxy->options2 & PR_O2_RDPC_PRST)
3477 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02003478
3479 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01003480 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003481 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
3482 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 +01003483 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01003484 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
3485 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01003486 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02003487 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02003488 }
Christopher Fauleta717b992018-04-10 14:43:00 +02003489
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003490 /* Check the mux protocols, if any, for each listener and server
Christopher Fauleta717b992018-04-10 14:43:00 +02003491 * attached to the current proxy */
3492 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3493 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003494 const struct mux_proto_list *mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003495
3496 if (!bind_conf->mux_proto)
3497 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003498
3499 /* it is possible that an incorrect mux was referenced
3500 * due to the proxy's mode not being taken into account
3501 * on first pass. Let's adjust it now.
3502 */
3503 mux_ent = conn_get_best_mux_entry(bind_conf->mux_proto->token, PROTO_SIDE_FE, mode);
3504
3505 if (!mux_ent || !isteq(mux_ent->token, bind_conf->mux_proto->token)) {
Christopher Fauleta717b992018-04-10 14:43:00 +02003506 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n",
3507 proxy_type_str(curproxy), curproxy->id,
3508 (int)bind_conf->mux_proto->token.len,
3509 bind_conf->mux_proto->token.ptr,
3510 bind_conf->arg, bind_conf->file, bind_conf->line);
3511 cfgerr++;
3512 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003513
3514 /* update the mux */
3515 bind_conf->mux_proto = mux_ent;
Christopher Fauleta717b992018-04-10 14:43:00 +02003516 }
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003517 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3518 int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
Willy Tarreau76a551d2018-12-02 13:09:09 +01003519 const struct mux_proto_list *mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003520
3521 if (!newsrv->mux_proto)
3522 continue;
Willy Tarreau76a551d2018-12-02 13:09:09 +01003523
3524 /* it is possible that an incorrect mux was referenced
3525 * due to the proxy's mode not being taken into account
3526 * on first pass. Let's adjust it now.
3527 */
3528 mux_ent = conn_get_best_mux_entry(newsrv->mux_proto->token, PROTO_SIDE_BE, mode);
3529
3530 if (!mux_ent || !isteq(mux_ent->token, newsrv->mux_proto->token)) {
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003531 ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n",
3532 proxy_type_str(curproxy), curproxy->id,
3533 (int)newsrv->mux_proto->token.len,
3534 newsrv->mux_proto->token.ptr,
3535 newsrv->id, newsrv->conf.file, newsrv->conf.line);
3536 cfgerr++;
3537 }
Willy Tarreau76a551d2018-12-02 13:09:09 +01003538
3539 /* update the mux */
3540 newsrv->mux_proto = mux_ent;
Christopher Faulet8ed0a3e2018-04-10 14:45:45 +02003541 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003542
3543 /* initialize idle conns lists */
3544 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
3545 int i;
3546
Willy Tarreauad37c7a2020-07-17 14:18:36 +02003547 newsrv->available_conns = calloc(global.nbthread, sizeof(*newsrv->available_conns));
Willy Tarreau835daa12019-02-07 14:46:29 +01003548
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003549 if (!newsrv->available_conns) {
Willy Tarreau835daa12019-02-07 14:46:29 +01003550 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003551 newsrv->conf.file, newsrv->conf.line, newsrv->id);
Willy Tarreau835daa12019-02-07 14:46:29 +01003552 cfgerr++;
3553 continue;
3554 }
3555
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003556 for (i = 0; i < global.nbthread; i++)
3557 LIST_INIT(&newsrv->available_conns[i]);
Willy Tarreau980855b2019-02-07 14:59:29 +01003558
3559 if (newsrv->max_idle_conns != 0) {
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003560 if (idle_conn_task == NULL) {
3561 idle_conn_task = task_new(MAX_THREADS_MASK);
3562 if (!idle_conn_task)
3563 goto err;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003564
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003565 idle_conn_task->process = srv_cleanup_idle_connections;
3566 idle_conn_task->context = NULL;
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003567
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003568 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003569 idle_conns[i].cleanup_task = task_new(1UL << i);
3570 if (!idle_conns[i].cleanup_task)
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003571 goto err;
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003572 idle_conns[i].cleanup_task->process = srv_cleanup_toremove_connections;
3573 idle_conns[i].cleanup_task->context = NULL;
Olivier Houchardf8f4c2e2020-06-29 20:15:59 +02003574 HA_SPIN_INIT(&idle_conns[i].takeover_lock);
Willy Tarreau4d82bf52020-06-28 00:19:17 +02003575 MT_LIST_INIT(&idle_conns[i].toremove_conns);
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003576 }
3577 }
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003578
Willy Tarreau9b9c1742020-07-17 15:04:53 +02003579 newsrv->idle_conns = calloc((unsigned short)global.nbthread, sizeof(*newsrv->idle_conns));
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003580 if (!newsrv->idle_conns) {
3581 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3582 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3583 cfgerr++;
3584 continue;
3585 }
3586
Olivier Houchard9ea5d362019-02-14 18:29:09 +01003587 for (i = 0; i < global.nbthread; i++)
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003588 MT_LIST_INIT(&newsrv->idle_conns[i]);
3589
Willy Tarreauad37c7a2020-07-17 14:18:36 +02003590 newsrv->safe_conns = calloc(global.nbthread, sizeof(*newsrv->safe_conns));
Olivier Houcharddc2f2752020-02-13 19:12:07 +01003591 if (!newsrv->safe_conns) {
3592 ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
3593 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3594 cfgerr++;
3595 continue;
3596 }
3597
3598 for (i = 0; i < global.nbthread; i++)
3599 MT_LIST_INIT(&newsrv->safe_conns[i]);
3600
Tim Duesterhusb53dd032020-09-12 20:26:42 +02003601 newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
Olivier Houchardf1314812019-02-18 16:41:17 +01003602 if (!newsrv->curr_idle_thr)
3603 goto err;
Willy Tarreau980855b2019-02-07 14:59:29 +01003604 continue;
3605 err:
3606 ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
3607 newsrv->conf.file, newsrv->conf.line, newsrv->id);
3608 cfgerr++;
3609 continue;
3610 }
Willy Tarreau835daa12019-02-07 14:46:29 +01003611 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003612 }
3613
3614 /***********************************************************/
3615 /* At this point, target names have already been resolved. */
3616 /***********************************************************/
3617
3618 /* Check multi-process mode compatibility */
3619
3620 if (global.nbproc > 1 && global.stats_fe) {
3621 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3622 unsigned long mask;
3623
Willy Tarreau6daac192019-02-02 17:39:53 +01003624 mask = proc_mask(global.stats_fe->bind_proc) && all_proc_mask;
Willy Tarreaue26993c2020-09-03 07:18:55 +02003625 mask &= proc_mask(bind_conf->settings.bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003626
3627 /* stop here if more than one process is used */
Willy Tarreau9504dd62018-10-15 09:37:03 +02003628 if (atleast2(mask))
Willy Tarreau419ead82014-09-16 13:41:21 +02003629 break;
3630 }
3631 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003632 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 +02003633 }
3634 }
3635
3636 /* Make each frontend inherit bind-process from its listeners when not specified. */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003637 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003638 if (curproxy->bind_proc)
3639 continue;
3640
3641 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
3642 unsigned long mask;
3643
Willy Tarreaue26993c2020-09-03 07:18:55 +02003644 mask = proc_mask(bind_conf->settings.bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003645 curproxy->bind_proc |= mask;
3646 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003647 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003648 }
3649
3650 if (global.stats_fe) {
3651 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
3652 unsigned long mask;
3653
Willy Tarreaue26993c2020-09-03 07:18:55 +02003654 mask = bind_conf->settings.bind_proc ? bind_conf->settings.bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02003655 global.stats_fe->bind_proc |= mask;
3656 }
Willy Tarreau6daac192019-02-02 17:39:53 +01003657 global.stats_fe->bind_proc = proc_mask(global.stats_fe->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003658 }
3659
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003660 /* propagate bindings from frontends to backends. Don't do it if there
3661 * are any fatal errors as we must not call it with unresolved proxies.
3662 */
3663 if (!cfgerr) {
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003664 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02003665 if (curproxy->cap & PR_CAP_FE)
3666 propagate_processes(curproxy, NULL);
3667 }
Willy Tarreau419ead82014-09-16 13:41:21 +02003668 }
3669
3670 /* Bind each unbound backend to all processes when not specified. */
Willy Tarreau6daac192019-02-02 17:39:53 +01003671 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
3672 curproxy->bind_proc = proc_mask(curproxy->bind_proc);
Willy Tarreau419ead82014-09-16 13:41:21 +02003673
3674 /*******************************************************/
3675 /* At this step, all proxies have a non-null bind_proc */
3676 /*******************************************************/
3677
3678 /* perform the final checks before creating tasks */
3679
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003680 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreau419ead82014-09-16 13:41:21 +02003681 struct listener *listener;
3682 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003683
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003684 /* Configure SSL for each bind line.
3685 * Note: if configuration fails at some point, the ->ctx member
3686 * remains NULL so that listeners can later detach.
3687 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003688 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01003689 if (bind_conf->xprt->prepare_bind_conf &&
3690 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003691 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003692 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003693
Willy Tarreaue6b98942007-10-29 01:09:36 +01003694 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003695 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02003696 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003697 int nbproc;
3698
3699 nbproc = my_popcountl(curproxy->bind_proc &
Willy Tarreaue26993c2020-09-03 07:18:55 +02003700 (listener->bind_conf->settings.bind_proc ? listener->bind_conf->settings.bind_proc : curproxy->bind_proc) &
Willy Tarreaua38a7172019-02-02 17:11:28 +01003701 all_proc_mask);
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02003702
3703 if (!nbproc) /* no intersection between listener and frontend */
3704 nbproc = 1;
3705
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003706 if (!listener->luid) {
3707 /* listener ID not set, use automatic numbering with first
3708 * spare entry starting with next_luid.
3709 */
3710 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
3711 listener->conf.id.key = listener->luid = next_id;
3712 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003713 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01003714 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003715
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003716 /* enable separate counters */
3717 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01003718 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003719 if (!listener->name)
3720 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003721 }
Willy Tarreau81796be2012-09-22 19:11:47 +02003722
Willy Tarreaue6b98942007-10-29 01:09:36 +01003723 if (curproxy->options & PR_O_TCP_NOLING)
3724 listener->options |= LI_O_NOLINGER;
Willy Tarreau16a21472012-11-19 12:39:59 +01003725 if (!listener->maxaccept)
3726 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
3727
3728 /* we want to have an optimal behaviour on single process mode to
3729 * maximize the work at once, but in multi-process we want to keep
3730 * some fairness between processes, so we target half of the max
3731 * number of events to be balanced over all the processes the proxy
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +05003732 * is bound to. Remember that maxaccept = -1 must be kept as it is
Willy Tarreau16a21472012-11-19 12:39:59 +01003733 * used to disable the limit.
3734 */
Christopher Faulet02f3cf12019-04-30 14:08:41 +02003735 if (listener->maxaccept > 0 && nbproc > 1) {
3736 listener->maxaccept = (listener->maxaccept + 1) / 2;
Willy Tarreau16a21472012-11-19 12:39:59 +01003737 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
3738 }
3739
Willy Tarreau9903f0e2015-04-04 18:50:31 +02003740 listener->accept = session_accept_fd;
Willy Tarreauc1a21672009-08-16 22:37:44 +02003741 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01003742 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01003743
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003744 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02003745 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02003746
Willy Tarreau620408f2016-10-21 16:37:51 +02003747 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
3748 listener->options |= LI_O_TCP_L5_RULES;
3749
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003750 /* smart accept mode is automatic in HTTP mode */
3751 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003752 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003753 !(curproxy->no_options2 & PR_O2_SMARTACC)))
3754 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01003755 }
3756
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003757 /* Release unused SSL configs */
3758 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01003759 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
3760 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02003761 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02003762
Willy Tarreaua38a7172019-02-02 17:11:28 +01003763 if (atleast2(curproxy->bind_proc & all_proc_mask)) {
Willy Tarreau102df612014-05-07 23:56:38 +02003764 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02003765 int count, maxproc = 0;
3766
3767 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreaue26993c2020-09-03 07:18:55 +02003768 count = my_popcountl(bind_conf->settings.bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003769 if (count > maxproc)
3770 maxproc = count;
3771 }
3772 /* backends have 0, frontends have 1 or more */
3773 if (maxproc != 1)
Christopher Faulet767a84b2017-11-24 16:50:31 +01003774 ha_warning("Proxy '%s': in multi-process mode, stats will be"
3775 " limited to process assigned to the current request.\n",
3776 curproxy->id);
Willy Tarreaueb791e02014-09-16 15:11:04 +02003777
Willy Tarreau102df612014-05-07 23:56:38 +02003778 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003779 ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
3780 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003781 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003782 }
Willy Tarreau102df612014-05-07 23:56:38 +02003783 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003784 ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
3785 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01003786 }
3787 }
Willy Tarreau918ff602011-07-25 16:33:49 +02003788
3789 /* create the task associated with the proxy */
Emeric Brunc60def82017-09-27 14:59:38 +02003790 curproxy->task = task_new(MAX_THREADS_MASK);
Willy Tarreau918ff602011-07-25 16:33:49 +02003791 if (curproxy->task) {
3792 curproxy->task->context = curproxy;
3793 curproxy->task->process = manage_proxy;
Willy Tarreau918ff602011-07-25 16:33:49 +02003794 } else {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003795 ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n",
3796 curproxy->id);
Willy Tarreau918ff602011-07-25 16:33:49 +02003797 cfgerr++;
3798 }
Willy Tarreaub369a042014-09-16 13:21:03 +02003799 }
3800
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003801 /*
3802 * Recount currently required checks.
3803 */
3804
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003805 for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003806 int optnum;
3807
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003808 for (optnum = 0; cfg_opts[optnum].name; optnum++)
3809 if (curproxy->options & cfg_opts[optnum].val)
3810 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003811
Willy Tarreau66aa61f2009-01-18 21:44:07 +01003812 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
3813 if (curproxy->options2 & cfg_opts2[optnum].val)
3814 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01003815 }
3816
Willy Tarreau0fca4832015-05-01 19:12:05 +02003817 /* compute the required process bindings for the peers */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003818 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003819 if (curproxy->table && curproxy->table->peers.p)
3820 curproxy->table->peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
Willy Tarreau0fca4832015-05-01 19:12:05 +02003821
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01003822 /* compute the required process bindings for the peers from <stktables_list>
3823 * for all the stick-tables, the ones coming with "peers" sections included.
3824 */
3825 for (t = stktables_list; t; t = t->next) {
3826 struct proxy *p;
3827
3828 for (p = t->proxies_list; p; p = p->next_stkt_ref) {
3829 if (t->peers.p && t->peers.p->peers_fe) {
3830 t->peers.p->peers_fe->bind_proc |= p->bind_proc;
3831 }
3832 }
3833 }
3834
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003835 if (cfg_peers) {
3836 struct peers *curpeers = cfg_peers, **last;
Willy Tarreau122541c2011-09-07 21:24:49 +02003837 struct peer *p, *pb;
3838
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003839 /* In the case the peers frontend was not initialized by a
3840 stick-table used in the configuration, set its bind_proc
3841 by default to the first process. */
3842 while (curpeers) {
William Lallemand3ef2d562020-03-24 16:42:15 +01003843 if (curpeers->peers_fe) {
3844 if (curpeers->peers_fe->bind_proc == 0)
3845 curpeers->peers_fe->bind_proc = 1;
3846 }
William Lallemanda2cfd7e2020-03-24 16:02:48 +01003847 curpeers = curpeers->next;
3848 }
3849
3850 curpeers = cfg_peers;
Willy Tarreau1e273012015-05-01 19:15:17 +02003851 /* Remove all peers sections which don't have a valid listener,
3852 * which are not used by any table, or which are bound to more
3853 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02003854 */
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +02003855 last = &cfg_peers;
Willy Tarreau122541c2011-09-07 21:24:49 +02003856 while (*last) {
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003857 struct stktable *t;
Willy Tarreau122541c2011-09-07 21:24:49 +02003858 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003859
Willy Tarreau1ad64ac2020-09-24 08:48:08 +02003860 if (curpeers->disabled) {
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003861 /* the "disabled" keyword was present */
3862 if (curpeers->peers_fe)
3863 stop_proxy(curpeers->peers_fe);
3864 curpeers->peers_fe = NULL;
3865 }
Frédéric Lécaille5a4fe5a2019-10-04 08:30:04 +02003866 else if (!curpeers->peers_fe || !curpeers->peers_fe->id) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003867 ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
3868 curpeers->id, localpeer);
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003869 if (curpeers->peers_fe)
3870 stop_proxy(curpeers->peers_fe);
3871 curpeers->peers_fe = NULL;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003872 }
Willy Tarreau9504dd62018-10-15 09:37:03 +02003873 else if (atleast2(curpeers->peers_fe->bind_proc)) {
Willy Tarreau1e273012015-05-01 19:15:17 +02003874 /* either it's totally stopped or too much used */
3875 if (curpeers->peers_fe->bind_proc) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003876 ha_alert("Peers section '%s': peers referenced by sections "
3877 "running in different processes (%d different ones). "
3878 "Check global.nbproc and all tables' bind-process "
3879 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02003880 cfgerr++;
3881 }
3882 stop_proxy(curpeers->peers_fe);
3883 curpeers->peers_fe = NULL;
3884 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003885 else {
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003886 /* Initializes the transport layer of the server part of all the peers belonging to
3887 * <curpeers> section if required.
3888 * Note that ->srv is used by the local peer of a new process to connect to the local peer
3889 * of an old process.
3890 */
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003891 p = curpeers->remote;
3892 while (p) {
Frédéric Lécaille355b2032019-01-11 14:06:12 +01003893 if (p->srv) {
Christopher Fauletf61f33a2020-03-27 18:55:49 +01003894 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 +01003895 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(p->srv);
3896 }
Frédéric Lécaille1055e682018-04-26 14:35:21 +02003897 p = p->next;
3898 }
Frédéric Lécaille76d2cef2019-02-12 19:12:32 +01003899 /* Configure the SSL bindings of the local peer if required. */
3900 if (!LIST_ISEMPTY(&curpeers->peers_fe->conf.bind)) {
3901 struct list *l;
3902 struct bind_conf *bind_conf;
3903
3904 l = &curpeers->peers_fe->conf.bind;
3905 bind_conf = LIST_ELEM(l->n, typeof(bind_conf), by_fe);
3906 if (bind_conf->xprt->prepare_bind_conf &&
3907 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
3908 cfgerr++;
3909 }
Frédéric Lécaille8d78fa72019-05-20 18:22:52 +02003910 if (!peers_init_sync(curpeers) || !peers_alloc_dcache(curpeers)) {
Willy Tarreaud9443442018-10-15 11:18:03 +02003911 ha_alert("Peers section '%s': out of memory, giving up on peers.\n",
3912 curpeers->id);
3913 cfgerr++;
3914 break;
3915 }
Willy Tarreau122541c2011-09-07 21:24:49 +02003916 last = &curpeers->next;
3917 continue;
3918 }
3919
Willy Tarreau77e4bd12015-05-01 20:02:17 +02003920 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02003921 p = curpeers->remote;
3922 while (p) {
3923 pb = p->next;
3924 free(p->id);
3925 free(p);
3926 p = pb;
3927 }
3928
3929 /* Destroy and unlink this curpeers section.
3930 * Note: curpeers is backed up into *last.
3931 */
3932 free(curpeers->id);
3933 curpeers = curpeers->next;
Frédéric Lécaille87eacbb2020-03-24 20:08:30 +01003934 /* Reset any refereance to this peers section in the list of stick-tables */
3935 for (t = stktables_list; t; t = t->next) {
3936 if (t->peers.p && t->peers.p == *last)
3937 t->peers.p = NULL;
3938 }
Willy Tarreau122541c2011-09-07 21:24:49 +02003939 free(*last);
3940 *last = curpeers;
3941 }
3942 }
3943
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003944 for (t = stktables_list; t; t = t->next) {
3945 if (t->proxy)
3946 continue;
3947 if (!stktable_init(t)) {
3948 ha_alert("Proxy '%s': failed to initialize stick-table.\n", t->id);
3949 cfgerr++;
3950 }
3951 }
3952
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003953 /* initialize stick-tables on backend capable proxies. This must not
3954 * be done earlier because the data size may be discovered while parsing
3955 * other proxies.
3956 */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003957 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Willy Tarreauc3914d42020-09-24 08:39:22 +02003958 if (curproxy->disabled || !curproxy->table)
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003959 continue;
3960
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003961 if (!stktable_init(curproxy->table)) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01003962 ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
Willy Tarreau6866f3f2015-05-01 19:09:08 +02003963 cfgerr++;
3964 }
3965 }
3966
Simon Horman0d16a402015-01-30 11:22:58 +09003967 if (mailers) {
3968 struct mailers *curmailers = mailers, **last;
3969 struct mailer *m, *mb;
3970
3971 /* Remove all mailers sections which don't have a valid listener.
3972 * This can happen when a mailers section is never referenced.
3973 */
3974 last = &mailers;
3975 while (*last) {
3976 curmailers = *last;
3977 if (curmailers->users) {
3978 last = &curmailers->next;
3979 continue;
3980 }
3981
Christopher Faulet767a84b2017-11-24 16:50:31 +01003982 ha_warning("Removing incomplete section 'mailers %s'.\n",
3983 curmailers->id);
Simon Horman0d16a402015-01-30 11:22:58 +09003984
3985 m = curmailers->mailer_list;
3986 while (m) {
3987 mb = m->next;
3988 free(m->id);
3989 free(m);
3990 m = mb;
3991 }
3992
3993 /* Destroy and unlink this curmailers section.
3994 * Note: curmailers is backed up into *last.
3995 */
3996 free(curmailers->id);
3997 curmailers = curmailers->next;
3998 free(*last);
3999 *last = curmailers;
4000 }
4001 }
4002
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02004003 /* Update server_state_file_name to backend name if backend is supposed to use
4004 * a server-state file locally defined and none has been provided */
Olivier Houchardfbc74e82017-11-24 16:54:05 +01004005 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02004006 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
4007 curproxy->server_state_file_name == NULL)
4008 curproxy->server_state_file_name = strdup(curproxy->id);
4009 }
4010
Ben Draut054fbee2018-04-13 15:43:04 -06004011 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
4012 if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
4013 ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n",
4014 curr_resolvers->id, curr_resolvers->conf.file,
4015 curr_resolvers->conf.line);
4016 err_code |= ERR_WARN;
4017 }
4018 }
4019
William Lallemand48b4bb42017-10-23 14:36:34 +02004020 list_for_each_entry(postparser, &postparsers, list) {
4021 if (postparser->func)
4022 cfgerr += postparser->func();
4023 }
4024
Willy Tarreaubb925012009-07-23 13:36:36 +02004025 if (cfgerr > 0)
4026 err_code |= ERR_ALERT | ERR_FATAL;
4027 out:
4028 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004029}
4030
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004031/*
4032 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
4033 * parsing sessions.
4034 */
4035void cfg_register_keywords(struct cfg_kw_list *kwl)
4036{
4037 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
4038}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004039
Willy Tarreau5b2c3362008-07-09 19:39:06 +02004040/*
4041 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
4042 */
4043void cfg_unregister_keywords(struct cfg_kw_list *kwl)
4044{
4045 LIST_DEL(&kwl->list);
4046 LIST_INIT(&kwl->list);
4047}
Willy Tarreaubaaee002006-06-26 02:48:02 +02004048
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004049/* this function register new section in the haproxy configuration file.
4050 * <section_name> is the name of this new section and <section_parser>
4051 * is the called parser. If two section declaration have the same name,
4052 * only the first declared is used.
4053 */
4054int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +02004055 int (*section_parser)(const char *, int, char **, int),
4056 int (*post_section_parser)())
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004057{
4058 struct cfg_section *cs;
4059
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004060 list_for_each_entry(cs, &sections, list) {
4061 if (strcmp(cs->section_name, section_name) == 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004062 ha_alert("register section '%s': already registered.\n", section_name);
Willy Tarreau5e4261b2016-05-17 16:16:09 +02004063 return 0;
4064 }
4065 }
4066
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004067 cs = calloc(1, sizeof(*cs));
4068 if (!cs) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004069 ha_alert("register section '%s': out of memory.\n", section_name);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004070 return 0;
4071 }
4072
4073 cs->section_name = section_name;
4074 cs->section_parser = section_parser;
William Lallemandd2ff56d2017-10-16 11:06:50 +02004075 cs->post_section_parser = post_section_parser;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01004076
4077 LIST_ADDQ(&sections, &cs->list);
4078
4079 return 1;
4080}
4081
William Lallemand48b4bb42017-10-23 14:36:34 +02004082/* this function register a new function which will be called once the haproxy
4083 * configuration file has been parsed. It's useful to check dependencies
4084 * between sections or to resolve items once everything is parsed.
4085 */
4086int cfg_register_postparser(char *name, int (*func)())
4087{
4088 struct cfg_postparser *cp;
4089
4090 cp = calloc(1, sizeof(*cp));
4091 if (!cp) {
Christopher Faulet767a84b2017-11-24 16:50:31 +01004092 ha_alert("register postparser '%s': out of memory.\n", name);
William Lallemand48b4bb42017-10-23 14:36:34 +02004093 return 0;
4094 }
4095 cp->name = name;
4096 cp->func = func;
4097
4098 LIST_ADDQ(&postparsers, &cp->list);
4099
4100 return 1;
4101}
4102
Willy Tarreaubaaee002006-06-26 02:48:02 +02004103/*
David Carlier845efb52015-09-25 11:49:18 +01004104 * free all config section entries
4105 */
4106void cfg_unregister_sections(void)
4107{
4108 struct cfg_section *cs, *ics;
4109
4110 list_for_each_entry_safe(cs, ics, &sections, list) {
4111 LIST_DEL(&cs->list);
4112 free(cs);
4113 }
4114}
4115
Christopher Faulet7110b402016-10-26 11:09:44 +02004116void cfg_backup_sections(struct list *backup_sections)
4117{
4118 struct cfg_section *cs, *ics;
4119
4120 list_for_each_entry_safe(cs, ics, &sections, list) {
4121 LIST_DEL(&cs->list);
4122 LIST_ADDQ(backup_sections, &cs->list);
4123 }
4124}
4125
4126void cfg_restore_sections(struct list *backup_sections)
4127{
4128 struct cfg_section *cs, *ics;
4129
4130 list_for_each_entry_safe(cs, ics, backup_sections, list) {
4131 LIST_DEL(&cs->list);
4132 LIST_ADDQ(&sections, &cs->list);
4133 }
4134}
4135
Willy Tarreaue6552512018-11-26 11:33:13 +01004136/* these are the config sections handled by default */
4137REGISTER_CONFIG_SECTION("listen", cfg_parse_listen, NULL);
4138REGISTER_CONFIG_SECTION("frontend", cfg_parse_listen, NULL);
4139REGISTER_CONFIG_SECTION("backend", cfg_parse_listen, NULL);
4140REGISTER_CONFIG_SECTION("defaults", cfg_parse_listen, NULL);
4141REGISTER_CONFIG_SECTION("global", cfg_parse_global, NULL);
4142REGISTER_CONFIG_SECTION("userlist", cfg_parse_users, NULL);
4143REGISTER_CONFIG_SECTION("peers", cfg_parse_peers, NULL);
4144REGISTER_CONFIG_SECTION("mailers", cfg_parse_mailers, NULL);
4145REGISTER_CONFIG_SECTION("namespace_list", cfg_parse_netns, NULL);
4146REGISTER_CONFIG_SECTION("resolvers", cfg_parse_resolvers, NULL);
Willy Tarreau659fbf02016-05-26 17:55:28 +02004147
David Carlier845efb52015-09-25 11:49:18 +01004148/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02004149 * Local variables:
4150 * c-indent-level: 8
4151 * c-basic-offset: 8
4152 * End:
4153 */