blob: 85b44df5ffc94b63a030dff18a320f9694c108f0 [file] [log] [blame]
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001#define _GNU_SOURCE /* for cpu_set_t from haproxy/cpuset.h */
Willy Tarreau36b9e222018-11-11 15:19:52 +01002#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <ctype.h>
7#include <pwd.h>
8#include <grp.h>
9#include <errno.h>
10#include <sys/types.h>
11#include <sys/stat.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010012#include <unistd.h>
13
Eric Salama7cea6062020-10-02 11:58:19 +020014#include <haproxy/buf.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020015#include <haproxy/cfgparse.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020016#ifdef USE_CPU_AFFINITY
Amaury Denoyellec90932b2021-04-14 16:16:03 +020017#include <haproxy/cpuset.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020018#endif
Willy Tarreau0a3bd392020-06-04 08:52:38 +020019#include <haproxy/compression.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020020#include <haproxy/global.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020021#include <haproxy/log.h>
Dragan Dosen13cd54c2020-06-18 18:24:05 +020022#include <haproxy/peers.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020023#include <haproxy/tools.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010024
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010025/* some keywords that are still being parsed using strcmp() and are not
26 * registered anywhere. They are used as suggestions for mistyped words.
27 */
28static const char *common_kw_list[] = {
29 "global", "daemon", "master-worker", "noepoll", "nokqueue",
30 "noevports", "nopoll", "busy-polling", "set-dumpable",
31 "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice",
32 "nogetaddrinfo", "noreuseport", "quiet", "zero-warning",
33 "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept",
Willy Tarreaueb9d90a2021-06-11 15:29:31 +020034 "tune.recv_enough", "tune.buffers.limit",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010035 "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite",
36 "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server",
37 "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize",
38 "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr",
39 "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid",
Willy Tarreau51ec03a2021-09-22 11:55:22 +020040 "external-check", "user", "group", "nbproc", "maxconn",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010041 "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate",
42 "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n",
43 "chroot", "description", "node", "pidfile", "unix-bind", "log",
44 "log-send-hostname", "server-state-base", "server-state-file",
45 "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv",
46 "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +010047 "numa-cpu-mapping", "defaults", "listen", "frontend", "backend",
Frédéric Lécaille372508c2022-05-06 08:53:16 +020048 "peers", "resolvers", "cluster-secret",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010049 NULL /* must be last */
50};
51
Willy Tarreau36b9e222018-11-11 15:19:52 +010052/*
53 * parse a line in a <global> section. Returns the error code, 0 if OK, or
54 * any combination of :
55 * - ERR_ABORT: must abort ASAP
56 * - ERR_FATAL: we can continue parsing but not start the service
57 * - ERR_WARN: a warning has been emitted
58 * - ERR_ALERT: an alert has been emitted
59 * Only the two first ones can stop processing, the two others are just
60 * indicators.
61 */
62int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
63{
64 int err_code = 0;
65 char *errmsg = NULL;
66
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010067 if (strcmp(args[0], "global") == 0) { /* new section */
Willy Tarreau36b9e222018-11-11 15:19:52 +010068 /* no option, nothing special to do */
69 alertif_too_many_args(0, file, linenum, args, &err_code);
70 goto out;
71 }
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +020072 else if (strcmp(args[0], "expose-experimental-directives") == 0) {
73 experimental_directives_allowed = 1;
74 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010075 else if (strcmp(args[0], "daemon") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010076 if (alertif_too_many_args(0, file, linenum, args, &err_code))
77 goto out;
78 global.mode |= MODE_DAEMON;
79 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010080 else if (strcmp(args[0], "master-worker") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010081 if (alertif_too_many_args(1, file, linenum, args, &err_code))
82 goto out;
83 if (*args[1]) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010084 if (strcmp(args[1], "no-exit-on-failure") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010085 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
86 } else {
87 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
88 err_code |= ERR_ALERT | ERR_FATAL;
89 goto out;
90 }
91 }
92 global.mode |= MODE_MWORKER;
93 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010094 else if (strcmp(args[0], "noepoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010095 if (alertif_too_many_args(0, file, linenum, args, &err_code))
96 goto out;
97 global.tune.options &= ~GTUNE_USE_EPOLL;
98 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010099 else if (strcmp(args[0], "nokqueue") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100100 if (alertif_too_many_args(0, file, linenum, args, &err_code))
101 goto out;
102 global.tune.options &= ~GTUNE_USE_KQUEUE;
103 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100104 else if (strcmp(args[0], "noevports") == 0) {
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +0000105 if (alertif_too_many_args(0, file, linenum, args, &err_code))
106 goto out;
107 global.tune.options &= ~GTUNE_USE_EVPORTS;
108 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100109 else if (strcmp(args[0], "nopoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100110 if (alertif_too_many_args(0, file, linenum, args, &err_code))
111 goto out;
112 global.tune.options &= ~GTUNE_USE_POLL;
113 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100114 else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100115 if (alertif_too_many_args(0, file, linenum, args, &err_code))
116 goto out;
117 if (kwm == KWM_NO)
118 global.tune.options &= ~GTUNE_BUSY_POLLING;
119 else
120 global.tune.options |= GTUNE_BUSY_POLLING;
121 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100122 else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */
Willy Tarreau636848a2019-04-15 19:38:50 +0200123 if (alertif_too_many_args(0, file, linenum, args, &err_code))
124 goto out;
125 if (kwm == KWM_NO)
126 global.tune.options &= ~GTUNE_SET_DUMPABLE;
127 else
128 global.tune.options |= GTUNE_SET_DUMPABLE;
129 }
Amaury Denoyellebefeae82021-07-09 17:14:30 +0200130 else if (strcmp(args[0], "h2-workaround-bogus-websocket-clients") == 0) { /* "no h2-workaround-bogus-websocket-clients" or "h2-workaround-bogus-websocket-clients" */
131 if (alertif_too_many_args(0, file, linenum, args, &err_code))
132 goto out;
133 if (kwm == KWM_NO)
134 global.tune.options &= ~GTUNE_DISABLE_H2_WEBSOCKET;
135 else
136 global.tune.options |= GTUNE_DISABLE_H2_WEBSOCKET;
137 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100138 else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
Willy Tarreaud96f1122019-12-03 07:07:36 +0100139 if (alertif_too_many_args(0, file, linenum, args, &err_code))
140 goto out;
141 if (kwm == KWM_NO)
142 global.tune.options &= ~GTUNE_INSECURE_FORK;
143 else
144 global.tune.options |= GTUNE_INSECURE_FORK;
145 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100146 else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100147 if (alertif_too_many_args(0, file, linenum, args, &err_code))
148 goto out;
149 if (kwm == KWM_NO)
150 global.tune.options &= ~GTUNE_INSECURE_SETUID;
151 else
152 global.tune.options |= GTUNE_INSECURE_SETUID;
153 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100154 else if (strcmp(args[0], "nosplice") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100155 if (alertif_too_many_args(0, file, linenum, args, &err_code))
156 goto out;
157 global.tune.options &= ~GTUNE_USE_SPLICE;
158 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100159 else if (strcmp(args[0], "nogetaddrinfo") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100160 if (alertif_too_many_args(0, file, linenum, args, &err_code))
161 goto out;
162 global.tune.options &= ~GTUNE_USE_GAI;
163 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100164 else if (strcmp(args[0], "noreuseport") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100165 if (alertif_too_many_args(0, file, linenum, args, &err_code))
166 goto out;
167 global.tune.options &= ~GTUNE_USE_REUSEPORT;
168 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100169 else if (strcmp(args[0], "quiet") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100170 if (alertif_too_many_args(0, file, linenum, args, &err_code))
171 goto out;
172 global.mode |= MODE_QUIET;
173 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100174 else if (strcmp(args[0], "zero-warning") == 0) {
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200175 if (alertif_too_many_args(0, file, linenum, args, &err_code))
176 goto out;
177 global.mode |= MODE_ZERO_WARNING;
178 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100179 else if (strcmp(args[0], "tune.runqueue-depth") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100180 if (alertif_too_many_args(1, file, linenum, args, &err_code))
181 goto out;
182 if (global.tune.runqueue_depth != 0) {
183 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
184 err_code |= ERR_ALERT;
185 goto out;
186 }
187 if (*(args[1]) == 0) {
188 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
189 err_code |= ERR_ALERT | ERR_FATAL;
190 goto out;
191 }
192 global.tune.runqueue_depth = atol(args[1]);
193
194 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100195 else if (strcmp(args[0], "tune.maxpollevents") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100196 if (alertif_too_many_args(1, file, linenum, args, &err_code))
197 goto out;
198 if (global.tune.maxpollevents != 0) {
199 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
200 err_code |= ERR_ALERT;
201 goto out;
202 }
203 if (*(args[1]) == 0) {
204 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
205 err_code |= ERR_ALERT | ERR_FATAL;
206 goto out;
207 }
208 global.tune.maxpollevents = atol(args[1]);
209 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100210 else if (strcmp(args[0], "tune.maxaccept") == 0) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200211 long max;
212
Willy Tarreau36b9e222018-11-11 15:19:52 +0100213 if (alertif_too_many_args(1, file, linenum, args, &err_code))
214 goto out;
215 if (global.tune.maxaccept != 0) {
216 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
217 err_code |= ERR_ALERT;
218 goto out;
219 }
220 if (*(args[1]) == 0) {
221 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
222 err_code |= ERR_ALERT | ERR_FATAL;
223 goto out;
224 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200225 max = atol(args[1]);
226 if (/*max < -1 || */max > INT_MAX) {
227 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
228 err_code |= ERR_ALERT | ERR_FATAL;
229 goto out;
230 }
231 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100232 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100233 else if (strcmp(args[0], "tune.chksize") == 0) {
Willy Tarreaueb9d90a2021-06-11 15:29:31 +0200234 ha_alert("parsing [%s:%d]: option '%s' is not supported any more (tune.bufsize is used instead).\n", file, linenum, args[0]);
235 err_code |= ERR_ALERT | ERR_FATAL;
236 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100237 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100238 else if (strcmp(args[0], "tune.recv_enough") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100239 if (alertif_too_many_args(1, file, linenum, args, &err_code))
240 goto out;
241 if (*(args[1]) == 0) {
242 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
243 err_code |= ERR_ALERT | ERR_FATAL;
244 goto out;
245 }
246 global.tune.recv_enough = atol(args[1]);
247 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100248 else if (strcmp(args[0], "tune.buffers.limit") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100249 if (alertif_too_many_args(1, file, linenum, args, &err_code))
250 goto out;
251 if (*(args[1]) == 0) {
252 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
253 err_code |= ERR_ALERT | ERR_FATAL;
254 goto out;
255 }
256 global.tune.buf_limit = atol(args[1]);
257 if (global.tune.buf_limit) {
258 if (global.tune.buf_limit < 3)
259 global.tune.buf_limit = 3;
260 if (global.tune.buf_limit <= global.tune.reserved_bufs)
261 global.tune.buf_limit = global.tune.reserved_bufs + 1;
262 }
263 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100264 else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100265 if (alertif_too_many_args(1, file, linenum, args, &err_code))
266 goto out;
267 if (*(args[1]) == 0) {
268 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
269 err_code |= ERR_ALERT | ERR_FATAL;
270 goto out;
271 }
272 global.tune.reserved_bufs = atol(args[1]);
273 if (global.tune.reserved_bufs < 2)
274 global.tune.reserved_bufs = 2;
275 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
276 global.tune.buf_limit = global.tune.reserved_bufs + 1;
277 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100278 else if (strcmp(args[0], "tune.bufsize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100279 if (alertif_too_many_args(1, file, linenum, args, &err_code))
280 goto out;
281 if (*(args[1]) == 0) {
282 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
283 err_code |= ERR_ALERT | ERR_FATAL;
284 goto out;
285 }
286 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100287 /* round it up to support a two-pointer alignment at the end */
288 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100289 if (global.tune.bufsize <= 0) {
290 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
291 err_code |= ERR_ALERT | ERR_FATAL;
292 goto out;
293 }
294 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100295 else if (strcmp(args[0], "tune.maxrewrite") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100296 if (alertif_too_many_args(1, file, linenum, args, &err_code))
297 goto out;
298 if (*(args[1]) == 0) {
299 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
300 err_code |= ERR_ALERT | ERR_FATAL;
301 goto out;
302 }
303 global.tune.maxrewrite = atol(args[1]);
304 if (global.tune.maxrewrite < 0) {
305 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
306 err_code |= ERR_ALERT | ERR_FATAL;
307 goto out;
308 }
309 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100310 else if (strcmp(args[0], "tune.idletimer") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100311 unsigned int idle;
312 const char *res;
313
314 if (alertif_too_many_args(1, file, linenum, args, &err_code))
315 goto out;
316 if (*(args[1]) == 0) {
317 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
318 err_code |= ERR_ALERT | ERR_FATAL;
319 goto out;
320 }
321
322 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200323 if (res == PARSE_TIME_OVER) {
324 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
325 file, linenum, args[1], args[0]);
326 err_code |= ERR_ALERT | ERR_FATAL;
327 goto out;
328 }
329 else if (res == PARSE_TIME_UNDER) {
330 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
331 file, linenum, args[1], args[0]);
332 err_code |= ERR_ALERT | ERR_FATAL;
333 goto out;
334 }
335 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100336 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200337 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100338 err_code |= ERR_ALERT | ERR_FATAL;
339 goto out;
340 }
341
342 if (idle > 65535) {
343 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
344 err_code |= ERR_ALERT | ERR_FATAL;
345 goto out;
346 }
347 global.tune.idle_timer = idle;
348 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100349 else if (strcmp(args[0], "tune.rcvbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100350 if (alertif_too_many_args(1, file, linenum, args, &err_code))
351 goto out;
352 if (global.tune.client_rcvbuf != 0) {
353 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
354 err_code |= ERR_ALERT;
355 goto out;
356 }
357 if (*(args[1]) == 0) {
358 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
359 err_code |= ERR_ALERT | ERR_FATAL;
360 goto out;
361 }
362 global.tune.client_rcvbuf = atol(args[1]);
363 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100364 else if (strcmp(args[0], "tune.rcvbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100365 if (alertif_too_many_args(1, file, linenum, args, &err_code))
366 goto out;
367 if (global.tune.server_rcvbuf != 0) {
368 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
369 err_code |= ERR_ALERT;
370 goto out;
371 }
372 if (*(args[1]) == 0) {
373 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
374 err_code |= ERR_ALERT | ERR_FATAL;
375 goto out;
376 }
377 global.tune.server_rcvbuf = atol(args[1]);
378 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100379 else if (strcmp(args[0], "tune.sndbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100380 if (alertif_too_many_args(1, file, linenum, args, &err_code))
381 goto out;
382 if (global.tune.client_sndbuf != 0) {
383 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
384 err_code |= ERR_ALERT;
385 goto out;
386 }
387 if (*(args[1]) == 0) {
388 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
389 err_code |= ERR_ALERT | ERR_FATAL;
390 goto out;
391 }
392 global.tune.client_sndbuf = atol(args[1]);
393 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100394 else if (strcmp(args[0], "tune.sndbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100395 if (alertif_too_many_args(1, file, linenum, args, &err_code))
396 goto out;
397 if (global.tune.server_sndbuf != 0) {
398 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
399 err_code |= ERR_ALERT;
400 goto out;
401 }
402 if (*(args[1]) == 0) {
403 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
404 err_code |= ERR_ALERT | ERR_FATAL;
405 goto out;
406 }
407 global.tune.server_sndbuf = atol(args[1]);
408 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100409 else if (strcmp(args[0], "tune.pipesize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100410 if (alertif_too_many_args(1, file, linenum, args, &err_code))
411 goto out;
412 if (*(args[1]) == 0) {
413 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
414 err_code |= ERR_ALERT | ERR_FATAL;
415 goto out;
416 }
417 global.tune.pipesize = atol(args[1]);
418 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100419 else if (strcmp(args[0], "tune.http.cookielen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100420 if (alertif_too_many_args(1, file, linenum, args, &err_code))
421 goto out;
422 if (*(args[1]) == 0) {
423 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
424 err_code |= ERR_ALERT | ERR_FATAL;
425 goto out;
426 }
427 global.tune.cookie_len = atol(args[1]) + 1;
428 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100429 else if (strcmp(args[0], "tune.http.logurilen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100430 if (alertif_too_many_args(1, file, linenum, args, &err_code))
431 goto out;
432 if (*(args[1]) == 0) {
433 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
434 err_code |= ERR_ALERT | ERR_FATAL;
435 goto out;
436 }
437 global.tune.requri_len = atol(args[1]) + 1;
438 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100439 else if (strcmp(args[0], "tune.http.maxhdr") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100440 if (alertif_too_many_args(1, file, linenum, args, &err_code))
441 goto out;
442 if (*(args[1]) == 0) {
443 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
444 err_code |= ERR_ALERT | ERR_FATAL;
445 goto out;
446 }
447 global.tune.max_http_hdr = atoi(args[1]);
448 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
449 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
450 file, linenum, args[0]);
451 err_code |= ERR_ALERT | ERR_FATAL;
452 goto out;
453 }
454 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100455 else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100456 if (alertif_too_many_args(1, file, linenum, args, &err_code))
457 goto out;
458 if (*args[1]) {
459 global.tune.comp_maxlevel = atoi(args[1]);
460 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
461 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
462 file, linenum, args[0]);
463 err_code |= ERR_ALERT | ERR_FATAL;
464 goto out;
465 }
466 } else {
467 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
468 file, linenum, args[0]);
469 err_code |= ERR_ALERT | ERR_FATAL;
470 goto out;
471 }
472 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100473 else if (strcmp(args[0], "tune.pattern.cache-size") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100474 if (*args[1]) {
475 global.tune.pattern_cache = atoi(args[1]);
476 if (global.tune.pattern_cache < 0) {
477 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
478 file, linenum, args[0]);
479 err_code |= ERR_ALERT | ERR_FATAL;
480 goto out;
481 }
482 } else {
483 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
484 file, linenum, args[0]);
485 err_code |= ERR_ALERT | ERR_FATAL;
486 goto out;
487 }
488 }
Frédéric Lécaille372508c2022-05-06 08:53:16 +0200489 else if (strcmp(args[0], "cluster-secret") == 0) {
490 if (alertif_too_many_args(1, file, linenum, args, &err_code))
491 goto out;
492 if (*args[1] == 0) {
493 ha_alert("parsing [%s:%d] : expects an ASCII string argument.\n", file, linenum);
494 err_code |= ERR_ALERT | ERR_FATAL;
495 goto out;
496 }
497 if (global.cluster_secret != NULL) {
498 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
499 err_code |= ERR_ALERT;
500 goto out;
501 }
502 ha_free(&global.cluster_secret);
503 global.cluster_secret = strdup(args[1]);
504 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100505 else if (strcmp(args[0], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100506 if (alertif_too_many_args(1, file, linenum, args, &err_code))
507 goto out;
508 if (global.uid != 0) {
509 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
510 err_code |= ERR_ALERT;
511 goto out;
512 }
513 if (*(args[1]) == 0) {
514 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
515 err_code |= ERR_ALERT | ERR_FATAL;
516 goto out;
517 }
518 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
519 ha_warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]);
520 err_code |= ERR_WARN;
521 goto out;
522 }
523
524 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100525 else if (strcmp(args[0], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100526 if (alertif_too_many_args(1, file, linenum, args, &err_code))
527 goto out;
528 if (global.gid != 0) {
529 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
530 err_code |= ERR_ALERT;
531 goto out;
532 }
533 if (*(args[1]) == 0) {
534 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
535 err_code |= ERR_ALERT | ERR_FATAL;
536 goto out;
537 }
538 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
539 ha_warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]);
540 err_code |= ERR_WARN;
541 goto out;
542 }
543 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100544 else if (strcmp(args[0], "external-check") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100545 if (alertif_too_many_args(0, file, linenum, args, &err_code))
546 goto out;
547 global.external_check = 1;
548 }
549 /* user/group name handling */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100550 else if (strcmp(args[0], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100551 struct passwd *ha_user;
552 if (alertif_too_many_args(1, file, linenum, args, &err_code))
553 goto out;
554 if (global.uid != 0) {
555 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
556 err_code |= ERR_ALERT;
557 goto out;
558 }
559 errno = 0;
560 ha_user = getpwnam(args[1]);
561 if (ha_user != NULL) {
562 global.uid = (int)ha_user->pw_uid;
563 }
564 else {
565 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
566 err_code |= ERR_ALERT | ERR_FATAL;
567 }
568 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100569 else if (strcmp(args[0], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100570 struct group *ha_group;
571 if (alertif_too_many_args(1, file, linenum, args, &err_code))
572 goto out;
573 if (global.gid != 0) {
574 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
575 err_code |= ERR_ALERT;
576 goto out;
577 }
578 errno = 0;
579 ha_group = getgrnam(args[1]);
580 if (ha_group != NULL) {
581 global.gid = (int)ha_group->gr_gid;
582 }
583 else {
584 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
585 err_code |= ERR_ALERT | ERR_FATAL;
586 }
587 }
588 /* end of user/group name handling*/
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100589 else if (strcmp(args[0], "nbproc") == 0) {
Willy Tarreaub63dbb72021-06-11 16:50:29 +0200590 ha_alert("parsing [%s:%d] : nbproc is not supported any more since HAProxy 2.5. Threads will automatically be used on multi-processor machines if available.\n", file, linenum);
591 err_code |= ERR_ALERT | ERR_FATAL;
592 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100593 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100594 else if (strcmp(args[0], "maxconn") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100595 if (alertif_too_many_args(1, file, linenum, args, &err_code))
596 goto out;
597 if (global.maxconn != 0) {
598 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
599 err_code |= ERR_ALERT;
600 goto out;
601 }
602 if (*(args[1]) == 0) {
603 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
604 err_code |= ERR_ALERT | ERR_FATAL;
605 goto out;
606 }
607 global.maxconn = atol(args[1]);
608#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100609 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
610 ha_alert("parsing [%s:%d] : maxconn value %d too high for this system.\nLimiting to %d. Please use '-n' to force the value.\n", file, linenum, global.maxconn, SYSTEM_MAXCONN);
611 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100612 err_code |= ERR_ALERT;
613 }
614#endif /* SYSTEM_MAXCONN */
615 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100616 else if (strcmp(args[0], "ssl-server-verify") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100617 if (alertif_too_many_args(1, file, linenum, args, &err_code))
618 goto out;
619 if (*(args[1]) == 0) {
620 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
621 err_code |= ERR_ALERT | ERR_FATAL;
622 goto out;
623 }
624 if (strcmp(args[1],"none") == 0)
625 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
626 else if (strcmp(args[1],"required") == 0)
627 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
628 else {
629 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
630 err_code |= ERR_ALERT | ERR_FATAL;
631 goto out;
632 }
633 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100634 else if (strcmp(args[0], "maxconnrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100635 if (alertif_too_many_args(1, file, linenum, args, &err_code))
636 goto out;
637 if (global.cps_lim != 0) {
638 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
639 err_code |= ERR_ALERT;
640 goto out;
641 }
642 if (*(args[1]) == 0) {
643 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
644 err_code |= ERR_ALERT | ERR_FATAL;
645 goto out;
646 }
647 global.cps_lim = atol(args[1]);
648 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100649 else if (strcmp(args[0], "maxsessrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100650 if (alertif_too_many_args(1, file, linenum, args, &err_code))
651 goto out;
652 if (global.sps_lim != 0) {
653 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
654 err_code |= ERR_ALERT;
655 goto out;
656 }
657 if (*(args[1]) == 0) {
658 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
659 err_code |= ERR_ALERT | ERR_FATAL;
660 goto out;
661 }
662 global.sps_lim = atol(args[1]);
663 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100664 else if (strcmp(args[0], "maxsslrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100665 if (alertif_too_many_args(1, file, linenum, args, &err_code))
666 goto out;
667 if (global.ssl_lim != 0) {
668 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
669 err_code |= ERR_ALERT;
670 goto out;
671 }
672 if (*(args[1]) == 0) {
673 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
674 err_code |= ERR_ALERT | ERR_FATAL;
675 goto out;
676 }
677 global.ssl_lim = atol(args[1]);
678 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100679 else if (strcmp(args[0], "maxcomprate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100680 if (alertif_too_many_args(1, file, linenum, args, &err_code))
681 goto out;
682 if (*(args[1]) == 0) {
683 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
684 err_code |= ERR_ALERT | ERR_FATAL;
685 goto out;
686 }
687 global.comp_rate_lim = atoi(args[1]) * 1024;
688 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100689 else if (strcmp(args[0], "maxpipes") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100690 if (alertif_too_many_args(1, file, linenum, args, &err_code))
691 goto out;
692 if (global.maxpipes != 0) {
693 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
694 err_code |= ERR_ALERT;
695 goto out;
696 }
697 if (*(args[1]) == 0) {
698 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
699 err_code |= ERR_ALERT | ERR_FATAL;
700 goto out;
701 }
702 global.maxpipes = atol(args[1]);
703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100704 else if (strcmp(args[0], "maxzlibmem") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100705 if (alertif_too_many_args(1, file, linenum, args, &err_code))
706 goto out;
707 if (*(args[1]) == 0) {
708 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
709 err_code |= ERR_ALERT | ERR_FATAL;
710 goto out;
711 }
712 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
713 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100714 else if (strcmp(args[0], "maxcompcpuusage") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100715 if (alertif_too_many_args(1, file, linenum, args, &err_code))
716 goto out;
717 if (*(args[1]) == 0) {
718 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
719 err_code |= ERR_ALERT | ERR_FATAL;
720 goto out;
721 }
722 compress_min_idle = 100 - atoi(args[1]);
723 if (compress_min_idle > 100) {
724 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
725 err_code |= ERR_ALERT | ERR_FATAL;
726 goto out;
727 }
728 }
Willy Tarreau2df1fbf2022-04-25 18:02:03 +0200729 else if (strcmp(args[0], "fd-hard-limit") == 0) {
730 if (alertif_too_many_args(1, file, linenum, args, &err_code))
731 goto out;
732 if (global.fd_hard_limit != 0) {
733 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
734 err_code |= ERR_ALERT;
735 goto out;
736 }
737 if (*(args[1]) == 0) {
738 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
739 err_code |= ERR_ALERT | ERR_FATAL;
740 goto out;
741 }
742 global.fd_hard_limit = atol(args[1]);
743 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100744 else if (strcmp(args[0], "ulimit-n") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100745 if (alertif_too_many_args(1, file, linenum, args, &err_code))
746 goto out;
747 if (global.rlimit_nofile != 0) {
748 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
749 err_code |= ERR_ALERT;
750 goto out;
751 }
752 if (*(args[1]) == 0) {
753 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
754 err_code |= ERR_ALERT | ERR_FATAL;
755 goto out;
756 }
757 global.rlimit_nofile = atol(args[1]);
758 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100759 else if (strcmp(args[0], "chroot") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100760 if (alertif_too_many_args(1, file, linenum, args, &err_code))
761 goto out;
762 if (global.chroot != NULL) {
763 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
764 err_code |= ERR_ALERT;
765 goto out;
766 }
767 if (*(args[1]) == 0) {
768 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
769 err_code |= ERR_ALERT | ERR_FATAL;
770 goto out;
771 }
772 global.chroot = strdup(args[1]);
773 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100774 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100775 int i, len=0;
776 char *d;
777
778 if (!*args[1]) {
779 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
780 file, linenum, args[0]);
781 err_code |= ERR_ALERT | ERR_FATAL;
782 goto out;
783 }
784
785 for (i = 1; *args[i]; i++)
786 len += strlen(args[i]) + 1;
787
788 if (global.desc)
789 free(global.desc);
790
791 global.desc = d = calloc(1, len);
792
793 d += snprintf(d, global.desc + len - d, "%s", args[1]);
794 for (i = 2; *args[i]; i++)
795 d += snprintf(d, global.desc + len - d, " %s", args[i]);
796 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100797 else if (strcmp(args[0], "node") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100798 int i;
799 char c;
800
801 if (alertif_too_many_args(1, file, linenum, args, &err_code))
802 goto out;
803
804 for (i=0; args[1][i]; i++) {
805 c = args[1][i];
806 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
807 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
808 break;
809 }
810
811 if (!i || args[1][i]) {
812 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
813 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
814 file, linenum, args[0]);
815 err_code |= ERR_ALERT | ERR_FATAL;
816 goto out;
817 }
818
819 if (global.node)
820 free(global.node);
821
822 global.node = strdup(args[1]);
823 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100824 else if (strcmp(args[0], "pidfile") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100825 if (alertif_too_many_args(1, file, linenum, args, &err_code))
826 goto out;
827 if (global.pidfile != NULL) {
828 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
829 err_code |= ERR_ALERT;
830 goto out;
831 }
832 if (*(args[1]) == 0) {
833 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
834 err_code |= ERR_ALERT | ERR_FATAL;
835 goto out;
836 }
837 global.pidfile = strdup(args[1]);
838 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100839 else if (strcmp(args[0], "unix-bind") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100840 int cur_arg = 1;
841 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100842 if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100843 if (global.unix_bind.prefix != NULL) {
844 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
845 err_code |= ERR_ALERT;
846 cur_arg += 2;
847 continue;
848 }
849
850 if (*(args[cur_arg+1]) == 0) {
851 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
852 err_code |= ERR_ALERT | ERR_FATAL;
853 goto out;
854 }
855 global.unix_bind.prefix = strdup(args[cur_arg+1]);
856 cur_arg += 2;
857 continue;
858 }
859
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100860 if (strcmp(args[cur_arg], "mode") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100861
862 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
863 cur_arg += 2;
864 continue;
865 }
866
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100867 if (strcmp(args[cur_arg], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100868
869 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
870 cur_arg += 2;
871 continue;
872 }
873
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100874 if (strcmp(args[cur_arg], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100875
876 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
877 cur_arg += 2;
878 continue;
879 }
880
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100881 if (strcmp(args[cur_arg], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100882 struct passwd *user;
883
884 user = getpwnam(args[cur_arg + 1]);
885 if (!user) {
886 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
887 file, linenum, args[0], args[cur_arg + 1 ]);
888 err_code |= ERR_ALERT | ERR_FATAL;
889 goto out;
890 }
891
892 global.unix_bind.ux.uid = user->pw_uid;
893 cur_arg += 2;
894 continue;
895 }
896
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100897 if (strcmp(args[cur_arg], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100898 struct group *group;
899
900 group = getgrnam(args[cur_arg + 1]);
901 if (!group) {
902 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
903 file, linenum, args[0], args[cur_arg + 1 ]);
904 err_code |= ERR_ALERT | ERR_FATAL;
905 goto out;
906 }
907
908 global.unix_bind.ux.gid = group->gr_gid;
909 cur_arg += 2;
910 continue;
911 }
912
913 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
914 file, linenum, args[0]);
915 err_code |= ERR_ALERT | ERR_FATAL;
916 goto out;
917 }
918 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100919 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +0200920 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100921 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
922 err_code |= ERR_ALERT | ERR_FATAL;
923 goto out;
924 }
925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100926 else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100927 char *name;
928
929 if (global.log_send_hostname != NULL) {
930 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
931 err_code |= ERR_ALERT;
932 goto out;
933 }
934
935 if (*(args[1]))
936 name = args[1];
937 else
938 name = hostname;
939
940 free(global.log_send_hostname);
941 global.log_send_hostname = strdup(name);
942 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100943 else if (strcmp(args[0], "server-state-base") == 0) { /* path base where HAProxy can find server state files */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100944 if (global.server_state_base != NULL) {
945 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
946 err_code |= ERR_ALERT;
947 goto out;
948 }
949
950 if (!*(args[1])) {
951 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
952 err_code |= ERR_FATAL;
953 goto out;
954 }
955
956 global.server_state_base = strdup(args[1]);
957 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100958 else if (strcmp(args[0], "server-state-file") == 0) { /* path to the file where HAProxy can load the server states */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100959 if (global.server_state_file != NULL) {
960 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
961 err_code |= ERR_ALERT;
962 goto out;
963 }
964
965 if (!*(args[1])) {
966 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
967 err_code |= ERR_FATAL;
968 goto out;
969 }
970
971 global.server_state_file = strdup(args[1]);
972 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100973 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100974 if (alertif_too_many_args(1, file, linenum, args, &err_code))
975 goto out;
976 if (*(args[1]) == 0) {
977 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
978 err_code |= ERR_ALERT | ERR_FATAL;
979 goto out;
980 }
981 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +0200982 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
983 if (b_orig(&global.log_tag) == NULL) {
984 chunk_destroy(&global.log_tag);
985 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
986 err_code |= ERR_ALERT | ERR_FATAL;
987 goto out;
988 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100989 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100990 else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100991 if (alertif_too_many_args(1, file, linenum, args, &err_code))
992 goto out;
993 if (global.spread_checks != 0) {
994 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
995 err_code |= ERR_ALERT;
996 goto out;
997 }
998 if (*(args[1]) == 0) {
999 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1000 err_code |= ERR_ALERT | ERR_FATAL;
1001 goto out;
1002 }
1003 global.spread_checks = atol(args[1]);
1004 if (global.spread_checks < 0 || global.spread_checks > 50) {
1005 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
1006 err_code |= ERR_ALERT | ERR_FATAL;
1007 }
1008 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001009 else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001010 const char *err;
1011 unsigned int val;
1012
1013 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1014 goto out;
1015 if (*(args[1]) == 0) {
1016 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1017 err_code |= ERR_ALERT | ERR_FATAL;
1018 goto out;
1019 }
1020
1021 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001022 if (err == PARSE_TIME_OVER) {
1023 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1024 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001025 err_code |= ERR_ALERT | ERR_FATAL;
1026 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001027 else if (err == PARSE_TIME_UNDER) {
1028 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1029 file, linenum, args[1], args[0]);
1030 err_code |= ERR_ALERT | ERR_FATAL;
1031 }
1032 else if (err) {
1033 ha_alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001034 err_code |= ERR_ALERT | ERR_FATAL;
1035 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001036 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001037 }
1038 else if (strcmp(args[0], "cpu-map") == 0) {
1039 /* map a process list to a CPU set */
1040#ifdef USE_CPU_AFFINITY
1041 char *slash;
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001042 unsigned long proc = 0, thread = 0;
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001043 int j, n, autoinc;
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001044 struct hap_cpuset cpus, cpus_copy;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001045
1046 if (!*args[1] || !*args[2]) {
1047 ha_alert("parsing [%s:%d] : %s expects a process number "
1048 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1049 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001050 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001051 err_code |= ERR_ALERT | ERR_FATAL;
1052 goto out;
1053 }
1054
1055 if ((slash = strchr(args[1], '/')) != NULL)
1056 *slash = 0;
1057
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001058 /* note: we silently ignore processes over MAX_PROCS and
1059 * threads over MAX_THREADS so as not to make configurations a
1060 * pain to maintain.
1061 */
1062 if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001063 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1064 err_code |= ERR_ALERT | ERR_FATAL;
1065 goto out;
1066 }
1067
1068 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001069 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001070 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1071 err_code |= ERR_ALERT | ERR_FATAL;
1072 goto out;
1073 }
1074 *slash = '/';
Willy Tarreau36b9e222018-11-11 15:19:52 +01001075 }
1076
Amaury Denoyellea8082352021-04-06 16:46:15 +02001077 if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001078 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1079 err_code |= ERR_ALERT | ERR_FATAL;
1080 goto out;
1081 }
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001082
Willy Tarreau36b9e222018-11-11 15:19:52 +01001083 if (autoinc &&
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001084 my_popcountl(proc) != ha_cpuset_count(&cpus) &&
1085 my_popcountl(thread) != ha_cpuset_count(&cpus)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001086 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1087 "must have the same size to be automatically bound\n",
1088 file, linenum, args[0]);
1089 err_code |= ERR_ALERT | ERR_FATAL;
1090 goto out;
1091 }
1092
Willy Tarreau7764a572019-07-16 15:10:34 +02001093 /* we now have to deal with 3 real cases :
1094 * cpu-map P-Q => mapping for whole processes, numbers P to Q
1095 * cpu-map P-Q/1 => mapping of first thread of processes P to Q
1096 * cpu-map 1/T-U => mapping of threads T to U of process 1
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001097 * (note: P=Q=1 since 2.5).
Willy Tarreau7764a572019-07-16 15:10:34 +02001098 * Otherwise other combinations are silently ignored since nbthread
1099 * and nbproc cannot both be >1 :
1100 * cpu-map P-Q/T => mapping for thread T for processes P to Q.
1101 * Only one of T,Q may be > 1, others ignored.
1102 * cpu-map P/T-U => mapping for threads T to U of process P. Only
1103 * one of P,U may be > 1, others ignored.
1104 */
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001105 if (!thread || thread == 0x1) {
1106 /* mapping for whole process. E.g. cpu-map 1 0-3 or cpu-map 1/1 0-3 */
1107 ha_cpuset_assign(&cpus_copy, &cpus);
1108
1109 if (!autoinc)
Willy Tarreau44ea6312021-06-15 08:57:56 +02001110 ha_cpuset_assign(&cpu_map.proc, &cpus);
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001111 else {
Willy Tarreau44ea6312021-06-15 08:57:56 +02001112 ha_cpuset_zero(&cpu_map.proc);
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001113 n = ha_cpuset_ffs(&cpus_copy) - 1;
1114 ha_cpuset_clr(&cpus_copy, n);
Willy Tarreau44ea6312021-06-15 08:57:56 +02001115 ha_cpuset_set(&cpu_map.proc, n);
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001116 }
1117 } else {
1118 /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001119 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001120 for (j = n = 0; j < MAX_THREADS; j++) {
1121 /* No mapping for this thread */
1122 if (!(thread & (1UL << j)))
Willy Tarreau81492c92019-05-03 09:41:23 +02001123 continue;
1124
Willy Tarreau36b9e222018-11-11 15:19:52 +01001125 if (!autoinc)
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001126 ha_cpuset_assign(&cpu_map.thread[j], &cpus);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001127 else {
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001128 ha_cpuset_zero(&cpu_map.thread[j]);
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001129 n = ha_cpuset_ffs(&cpus_copy) - 1;
1130 ha_cpuset_clr(&cpus_copy, n);
Willy Tarreaubda7c1d2021-06-15 08:49:05 +02001131 ha_cpuset_set(&cpu_map.thread[j], n);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001132 }
1133 }
Amaury Denoyellea2944ec2021-04-15 18:07:07 +02001134
1135 HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1,
1136 "parsing [%s:%d] : cpu-map statement is considered invalid and thus ignored as it addresses multiple processes and threads at the same time. At least one of them should be 1 and only 1.", file, linenum);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001137 }
1138#else
1139 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1140 file, linenum, args[0]);
1141 err_code |= ERR_ALERT | ERR_FATAL;
1142 goto out;
1143#endif /* ! USE_CPU_AFFINITY */
1144 }
1145 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1146 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1147 goto out;
1148
1149 if (*(args[2]) == 0) {
1150 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1151 err_code |= ERR_ALERT | ERR_FATAL;
1152 goto out;
1153 }
1154
1155 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1156 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1157 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1158 err_code |= ERR_ALERT | ERR_FATAL;
1159 goto out;
1160 }
1161 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001162 else if (strcmp(args[0], "unsetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001163 int arg;
1164
1165 if (*(args[1]) == 0) {
1166 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1167 err_code |= ERR_ALERT | ERR_FATAL;
1168 goto out;
1169 }
1170
1171 for (arg = 1; *args[arg]; arg++) {
1172 if (unsetenv(args[arg]) != 0) {
1173 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1174 err_code |= ERR_ALERT | ERR_FATAL;
1175 goto out;
1176 }
1177 }
1178 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001179 else if (strcmp(args[0], "resetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001180 extern char **environ;
1181 char **env = environ;
1182
1183 /* args contain variable names to keep, one per argument */
1184 while (*env) {
1185 int arg;
1186
1187 /* look for current variable in among all those we want to keep */
1188 for (arg = 1; *args[arg]; arg++) {
1189 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1190 (*env)[strlen(args[arg])] == '=')
1191 break;
1192 }
1193
1194 /* delete this variable */
1195 if (!*args[arg]) {
1196 char *delim = strchr(*env, '=');
1197
1198 if (!delim || delim - *env >= trash.size) {
1199 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1200 err_code |= ERR_ALERT | ERR_FATAL;
1201 goto out;
1202 }
1203
1204 memcpy(trash.area, *env, delim - *env);
1205 trash.area[delim - *env] = 0;
1206
1207 if (unsetenv(trash.area) != 0) {
1208 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1209 err_code |= ERR_ALERT | ERR_FATAL;
1210 goto out;
1211 }
1212 }
1213 else
1214 env++;
1215 }
1216 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001217 else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */
William Dauchy0fec3ab2019-10-27 20:08:11 +01001218 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1219 goto out;
1220 if (kwm == KWM_NO)
1221 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001222 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001223 else if (strcmp(args[0], "localpeer") == 0) {
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001224 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1225 goto out;
1226
1227 if (*(args[1]) == 0) {
1228 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1229 file, linenum, args[0]);
1230 err_code |= ERR_ALERT | ERR_FATAL;
1231 goto out;
1232 }
1233
1234 if (global.localpeer_cmdline != 0) {
1235 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1236 "command line argument.\n", file, linenum, args[0]);
1237 err_code |= ERR_WARN;
1238 goto out;
1239 }
1240
1241 if (cfg_peers) {
1242 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1243 file, linenum, args[0]);
1244 err_code |= ERR_WARN;
1245 goto out;
1246 }
1247
1248 free(localpeer);
1249 if ((localpeer = strdup(args[1])) == NULL) {
1250 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1251 file, linenum, args[0]);
1252 err_code |= ERR_ALERT | ERR_FATAL;
1253 goto out;
1254 }
1255 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1256 }
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +01001257 else if (strcmp(args[0], "numa-cpu-mapping") == 0) {
1258 global.numa_cpu_mapping = (kwm == KWM_NO) ? 0 : 1;
1259 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001260 else {
1261 struct cfg_kw_list *kwl;
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001262 const char *best;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001263 int index;
1264 int rc;
1265
1266 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1267 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1268 if (kwl->kw[index].section != CFG_GLOBAL)
1269 continue;
1270 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001271 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02001272 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001273 err_code |= ERR_ALERT | ERR_FATAL;
1274 goto out;
1275 }
1276
Willy Tarreau36b9e222018-11-11 15:19:52 +01001277 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1278 if (rc < 0) {
1279 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1280 err_code |= ERR_ALERT | ERR_FATAL;
1281 }
1282 else if (rc > 0) {
1283 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1284 err_code |= ERR_WARN;
1285 goto out;
1286 }
1287 goto out;
1288 }
1289 }
1290 }
1291
Willy Tarreau101df312021-03-15 09:12:41 +01001292 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list);
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001293 if (best)
1294 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
1295 else
1296 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau36b9e222018-11-11 15:19:52 +01001297 err_code |= ERR_ALERT | ERR_FATAL;
1298 }
1299
1300 out:
1301 free(errmsg);
1302 return err_code;
1303}
1304