blob: 3f4c877e9ab54768270c43c5ba4de606469db8d3 [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écaille12a03172023-01-12 15:23:54 +010048 "peers", "resolvers", "cluster-secret", "no-quic",
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 }
Frédéric Lécaille12a03172023-01-12 15:23:54 +0100114 else if (strcmp(args[0], "no-quic") == 0) {
115 if (alertif_too_many_args(0, file, linenum, args, &err_code))
116 goto out;
117
118 global.tune.options |= GTUNE_NO_QUIC;
119 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100120 else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100121 if (alertif_too_many_args(0, file, linenum, args, &err_code))
122 goto out;
123 if (kwm == KWM_NO)
124 global.tune.options &= ~GTUNE_BUSY_POLLING;
125 else
126 global.tune.options |= GTUNE_BUSY_POLLING;
127 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100128 else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */
Willy Tarreau636848a2019-04-15 19:38:50 +0200129 if (alertif_too_many_args(0, file, linenum, args, &err_code))
130 goto out;
131 if (kwm == KWM_NO)
132 global.tune.options &= ~GTUNE_SET_DUMPABLE;
133 else
134 global.tune.options |= GTUNE_SET_DUMPABLE;
135 }
Amaury Denoyellebefeae82021-07-09 17:14:30 +0200136 else if (strcmp(args[0], "h2-workaround-bogus-websocket-clients") == 0) { /* "no h2-workaround-bogus-websocket-clients" or "h2-workaround-bogus-websocket-clients" */
137 if (alertif_too_many_args(0, file, linenum, args, &err_code))
138 goto out;
139 if (kwm == KWM_NO)
140 global.tune.options &= ~GTUNE_DISABLE_H2_WEBSOCKET;
141 else
142 global.tune.options |= GTUNE_DISABLE_H2_WEBSOCKET;
143 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100144 else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
Willy Tarreaud96f1122019-12-03 07:07:36 +0100145 if (alertif_too_many_args(0, file, linenum, args, &err_code))
146 goto out;
147 if (kwm == KWM_NO)
148 global.tune.options &= ~GTUNE_INSECURE_FORK;
149 else
150 global.tune.options |= GTUNE_INSECURE_FORK;
151 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100152 else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100153 if (alertif_too_many_args(0, file, linenum, args, &err_code))
154 goto out;
155 if (kwm == KWM_NO)
156 global.tune.options &= ~GTUNE_INSECURE_SETUID;
157 else
158 global.tune.options |= GTUNE_INSECURE_SETUID;
159 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100160 else if (strcmp(args[0], "nosplice") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100161 if (alertif_too_many_args(0, file, linenum, args, &err_code))
162 goto out;
163 global.tune.options &= ~GTUNE_USE_SPLICE;
164 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100165 else if (strcmp(args[0], "nogetaddrinfo") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100166 if (alertif_too_many_args(0, file, linenum, args, &err_code))
167 goto out;
168 global.tune.options &= ~GTUNE_USE_GAI;
169 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100170 else if (strcmp(args[0], "noreuseport") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100171 if (alertif_too_many_args(0, file, linenum, args, &err_code))
172 goto out;
173 global.tune.options &= ~GTUNE_USE_REUSEPORT;
174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100175 else if (strcmp(args[0], "quiet") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100176 if (alertif_too_many_args(0, file, linenum, args, &err_code))
177 goto out;
178 global.mode |= MODE_QUIET;
179 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100180 else if (strcmp(args[0], "zero-warning") == 0) {
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200181 if (alertif_too_many_args(0, file, linenum, args, &err_code))
182 goto out;
183 global.mode |= MODE_ZERO_WARNING;
184 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100185 else if (strcmp(args[0], "tune.runqueue-depth") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100186 if (alertif_too_many_args(1, file, linenum, args, &err_code))
187 goto out;
188 if (global.tune.runqueue_depth != 0) {
189 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
190 err_code |= ERR_ALERT;
191 goto out;
192 }
193 if (*(args[1]) == 0) {
194 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
195 err_code |= ERR_ALERT | ERR_FATAL;
196 goto out;
197 }
198 global.tune.runqueue_depth = atol(args[1]);
199
200 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100201 else if (strcmp(args[0], "tune.maxpollevents") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100202 if (alertif_too_many_args(1, file, linenum, args, &err_code))
203 goto out;
204 if (global.tune.maxpollevents != 0) {
205 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
206 err_code |= ERR_ALERT;
207 goto out;
208 }
209 if (*(args[1]) == 0) {
210 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
211 err_code |= ERR_ALERT | ERR_FATAL;
212 goto out;
213 }
214 global.tune.maxpollevents = atol(args[1]);
215 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100216 else if (strcmp(args[0], "tune.maxaccept") == 0) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200217 long max;
218
Willy Tarreau36b9e222018-11-11 15:19:52 +0100219 if (alertif_too_many_args(1, file, linenum, args, &err_code))
220 goto out;
221 if (global.tune.maxaccept != 0) {
222 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
223 err_code |= ERR_ALERT;
224 goto out;
225 }
226 if (*(args[1]) == 0) {
227 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
228 err_code |= ERR_ALERT | ERR_FATAL;
229 goto out;
230 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200231 max = atol(args[1]);
232 if (/*max < -1 || */max > INT_MAX) {
233 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
234 err_code |= ERR_ALERT | ERR_FATAL;
235 goto out;
236 }
237 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100238 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100239 else if (strcmp(args[0], "tune.chksize") == 0) {
Willy Tarreaueb9d90a2021-06-11 15:29:31 +0200240 ha_alert("parsing [%s:%d]: option '%s' is not supported any more (tune.bufsize is used instead).\n", file, linenum, args[0]);
241 err_code |= ERR_ALERT | ERR_FATAL;
242 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100243 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100244 else if (strcmp(args[0], "tune.recv_enough") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100245 if (alertif_too_many_args(1, file, linenum, args, &err_code))
246 goto out;
247 if (*(args[1]) == 0) {
248 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
249 err_code |= ERR_ALERT | ERR_FATAL;
250 goto out;
251 }
252 global.tune.recv_enough = atol(args[1]);
253 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100254 else if (strcmp(args[0], "tune.buffers.limit") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100255 if (alertif_too_many_args(1, file, linenum, args, &err_code))
256 goto out;
257 if (*(args[1]) == 0) {
258 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
259 err_code |= ERR_ALERT | ERR_FATAL;
260 goto out;
261 }
262 global.tune.buf_limit = atol(args[1]);
263 if (global.tune.buf_limit) {
264 if (global.tune.buf_limit < 3)
265 global.tune.buf_limit = 3;
266 if (global.tune.buf_limit <= global.tune.reserved_bufs)
267 global.tune.buf_limit = global.tune.reserved_bufs + 1;
268 }
269 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100270 else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100271 if (alertif_too_many_args(1, file, linenum, args, &err_code))
272 goto out;
273 if (*(args[1]) == 0) {
274 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
275 err_code |= ERR_ALERT | ERR_FATAL;
276 goto out;
277 }
278 global.tune.reserved_bufs = atol(args[1]);
279 if (global.tune.reserved_bufs < 2)
280 global.tune.reserved_bufs = 2;
281 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
282 global.tune.buf_limit = global.tune.reserved_bufs + 1;
283 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100284 else if (strcmp(args[0], "tune.bufsize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100285 if (alertif_too_many_args(1, file, linenum, args, &err_code))
286 goto out;
287 if (*(args[1]) == 0) {
288 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
289 err_code |= ERR_ALERT | ERR_FATAL;
290 goto out;
291 }
292 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100293 /* round it up to support a two-pointer alignment at the end */
294 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100295 if (global.tune.bufsize <= 0) {
296 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
297 err_code |= ERR_ALERT | ERR_FATAL;
298 goto out;
299 }
300 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100301 else if (strcmp(args[0], "tune.maxrewrite") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100302 if (alertif_too_many_args(1, file, linenum, args, &err_code))
303 goto out;
304 if (*(args[1]) == 0) {
305 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
306 err_code |= ERR_ALERT | ERR_FATAL;
307 goto out;
308 }
309 global.tune.maxrewrite = atol(args[1]);
310 if (global.tune.maxrewrite < 0) {
311 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
312 err_code |= ERR_ALERT | ERR_FATAL;
313 goto out;
314 }
315 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100316 else if (strcmp(args[0], "tune.idletimer") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100317 unsigned int idle;
318 const char *res;
319
320 if (alertif_too_many_args(1, file, linenum, args, &err_code))
321 goto out;
322 if (*(args[1]) == 0) {
323 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
324 err_code |= ERR_ALERT | ERR_FATAL;
325 goto out;
326 }
327
328 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200329 if (res == PARSE_TIME_OVER) {
330 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
331 file, linenum, args[1], args[0]);
332 err_code |= ERR_ALERT | ERR_FATAL;
333 goto out;
334 }
335 else if (res == PARSE_TIME_UNDER) {
336 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
337 file, linenum, args[1], args[0]);
338 err_code |= ERR_ALERT | ERR_FATAL;
339 goto out;
340 }
341 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100342 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200343 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100344 err_code |= ERR_ALERT | ERR_FATAL;
345 goto out;
346 }
347
348 if (idle > 65535) {
349 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
350 err_code |= ERR_ALERT | ERR_FATAL;
351 goto out;
352 }
353 global.tune.idle_timer = idle;
354 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100355 else if (strcmp(args[0], "tune.rcvbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100356 if (alertif_too_many_args(1, file, linenum, args, &err_code))
357 goto out;
358 if (global.tune.client_rcvbuf != 0) {
359 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
360 err_code |= ERR_ALERT;
361 goto out;
362 }
363 if (*(args[1]) == 0) {
364 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
365 err_code |= ERR_ALERT | ERR_FATAL;
366 goto out;
367 }
368 global.tune.client_rcvbuf = atol(args[1]);
369 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100370 else if (strcmp(args[0], "tune.rcvbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100371 if (alertif_too_many_args(1, file, linenum, args, &err_code))
372 goto out;
373 if (global.tune.server_rcvbuf != 0) {
374 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
375 err_code |= ERR_ALERT;
376 goto out;
377 }
378 if (*(args[1]) == 0) {
379 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
380 err_code |= ERR_ALERT | ERR_FATAL;
381 goto out;
382 }
383 global.tune.server_rcvbuf = atol(args[1]);
384 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100385 else if (strcmp(args[0], "tune.sndbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100386 if (alertif_too_many_args(1, file, linenum, args, &err_code))
387 goto out;
388 if (global.tune.client_sndbuf != 0) {
389 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
390 err_code |= ERR_ALERT;
391 goto out;
392 }
393 if (*(args[1]) == 0) {
394 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
395 err_code |= ERR_ALERT | ERR_FATAL;
396 goto out;
397 }
398 global.tune.client_sndbuf = atol(args[1]);
399 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100400 else if (strcmp(args[0], "tune.sndbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100401 if (alertif_too_many_args(1, file, linenum, args, &err_code))
402 goto out;
403 if (global.tune.server_sndbuf != 0) {
404 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
405 err_code |= ERR_ALERT;
406 goto out;
407 }
408 if (*(args[1]) == 0) {
409 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
410 err_code |= ERR_ALERT | ERR_FATAL;
411 goto out;
412 }
413 global.tune.server_sndbuf = atol(args[1]);
414 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100415 else if (strcmp(args[0], "tune.pipesize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100416 if (alertif_too_many_args(1, file, linenum, args, &err_code))
417 goto out;
418 if (*(args[1]) == 0) {
419 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
420 err_code |= ERR_ALERT | ERR_FATAL;
421 goto out;
422 }
423 global.tune.pipesize = atol(args[1]);
424 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100425 else if (strcmp(args[0], "tune.http.cookielen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100426 if (alertif_too_many_args(1, file, linenum, args, &err_code))
427 goto out;
428 if (*(args[1]) == 0) {
429 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
430 err_code |= ERR_ALERT | ERR_FATAL;
431 goto out;
432 }
433 global.tune.cookie_len = atol(args[1]) + 1;
434 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100435 else if (strcmp(args[0], "tune.http.logurilen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100436 if (alertif_too_many_args(1, file, linenum, args, &err_code))
437 goto out;
438 if (*(args[1]) == 0) {
439 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
440 err_code |= ERR_ALERT | ERR_FATAL;
441 goto out;
442 }
443 global.tune.requri_len = atol(args[1]) + 1;
444 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100445 else if (strcmp(args[0], "tune.http.maxhdr") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100446 if (alertif_too_many_args(1, file, linenum, args, &err_code))
447 goto out;
448 if (*(args[1]) == 0) {
449 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
450 err_code |= ERR_ALERT | ERR_FATAL;
451 goto out;
452 }
453 global.tune.max_http_hdr = atoi(args[1]);
454 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
455 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
456 file, linenum, args[0]);
457 err_code |= ERR_ALERT | ERR_FATAL;
458 goto out;
459 }
460 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100461 else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100462 if (alertif_too_many_args(1, file, linenum, args, &err_code))
463 goto out;
464 if (*args[1]) {
465 global.tune.comp_maxlevel = atoi(args[1]);
466 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
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 } else {
473 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
474 file, linenum, args[0]);
475 err_code |= ERR_ALERT | ERR_FATAL;
476 goto out;
477 }
478 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100479 else if (strcmp(args[0], "tune.pattern.cache-size") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100480 if (*args[1]) {
481 global.tune.pattern_cache = atoi(args[1]);
482 if (global.tune.pattern_cache < 0) {
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 } else {
489 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
490 file, linenum, args[0]);
491 err_code |= ERR_ALERT | ERR_FATAL;
492 goto out;
493 }
494 }
Frédéric Lécaille372508c2022-05-06 08:53:16 +0200495 else if (strcmp(args[0], "cluster-secret") == 0) {
496 if (alertif_too_many_args(1, file, linenum, args, &err_code))
497 goto out;
498 if (*args[1] == 0) {
499 ha_alert("parsing [%s:%d] : expects an ASCII string argument.\n", file, linenum);
500 err_code |= ERR_ALERT | ERR_FATAL;
501 goto out;
502 }
503 if (global.cluster_secret != NULL) {
504 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
505 err_code |= ERR_ALERT;
506 goto out;
507 }
508 ha_free(&global.cluster_secret);
509 global.cluster_secret = strdup(args[1]);
510 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100511 else if (strcmp(args[0], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100512 if (alertif_too_many_args(1, file, linenum, args, &err_code))
513 goto out;
514 if (global.uid != 0) {
515 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
516 err_code |= ERR_ALERT;
517 goto out;
518 }
519 if (*(args[1]) == 0) {
520 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
521 err_code |= ERR_ALERT | ERR_FATAL;
522 goto out;
523 }
524 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
525 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]);
526 err_code |= ERR_WARN;
527 goto out;
528 }
529
530 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100531 else if (strcmp(args[0], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100532 if (alertif_too_many_args(1, file, linenum, args, &err_code))
533 goto out;
534 if (global.gid != 0) {
535 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
536 err_code |= ERR_ALERT;
537 goto out;
538 }
539 if (*(args[1]) == 0) {
540 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
541 err_code |= ERR_ALERT | ERR_FATAL;
542 goto out;
543 }
544 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
545 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]);
546 err_code |= ERR_WARN;
547 goto out;
548 }
549 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100550 else if (strcmp(args[0], "external-check") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100551 if (alertif_too_many_args(0, file, linenum, args, &err_code))
552 goto out;
553 global.external_check = 1;
554 }
555 /* user/group name handling */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100556 else if (strcmp(args[0], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100557 struct passwd *ha_user;
558 if (alertif_too_many_args(1, file, linenum, args, &err_code))
559 goto out;
560 if (global.uid != 0) {
561 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
562 err_code |= ERR_ALERT;
563 goto out;
564 }
565 errno = 0;
566 ha_user = getpwnam(args[1]);
567 if (ha_user != NULL) {
568 global.uid = (int)ha_user->pw_uid;
569 }
570 else {
571 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
572 err_code |= ERR_ALERT | ERR_FATAL;
573 }
574 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100575 else if (strcmp(args[0], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100576 struct group *ha_group;
577 if (alertif_too_many_args(1, file, linenum, args, &err_code))
578 goto out;
579 if (global.gid != 0) {
580 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
581 err_code |= ERR_ALERT;
582 goto out;
583 }
584 errno = 0;
585 ha_group = getgrnam(args[1]);
586 if (ha_group != NULL) {
587 global.gid = (int)ha_group->gr_gid;
588 }
589 else {
590 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
591 err_code |= ERR_ALERT | ERR_FATAL;
592 }
593 }
594 /* end of user/group name handling*/
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100595 else if (strcmp(args[0], "nbproc") == 0) {
Willy Tarreaub63dbb72021-06-11 16:50:29 +0200596 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);
597 err_code |= ERR_ALERT | ERR_FATAL;
598 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100599 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100600 else if (strcmp(args[0], "maxconn") == 0) {
Thierry Fournier3d1c3342022-10-01 10:06:59 +0200601 char *stop;
602
Willy Tarreau36b9e222018-11-11 15:19:52 +0100603 if (alertif_too_many_args(1, file, linenum, args, &err_code))
604 goto out;
605 if (global.maxconn != 0) {
606 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
607 err_code |= ERR_ALERT;
608 goto out;
609 }
610 if (*(args[1]) == 0) {
611 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
612 err_code |= ERR_ALERT | ERR_FATAL;
613 goto out;
614 }
Thierry Fournier3d1c3342022-10-01 10:06:59 +0200615 global.maxconn = strtol(args[1], &stop, 10);
616 if (*stop != '\0') {
617 ha_alert("parsing [%s:%d] : cannot parse '%s' value '%s', an integer is expected.\n", file, linenum, args[0], args[1]);
618 err_code |= ERR_ALERT | ERR_FATAL;
619 goto out;
620 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100621#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100622 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
623 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);
624 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100625 err_code |= ERR_ALERT;
626 }
627#endif /* SYSTEM_MAXCONN */
628 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100629 else if (strcmp(args[0], "ssl-server-verify") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100630 if (alertif_too_many_args(1, file, linenum, args, &err_code))
631 goto out;
632 if (*(args[1]) == 0) {
633 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
634 err_code |= ERR_ALERT | ERR_FATAL;
635 goto out;
636 }
637 if (strcmp(args[1],"none") == 0)
638 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
639 else if (strcmp(args[1],"required") == 0)
640 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
641 else {
642 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
643 err_code |= ERR_ALERT | ERR_FATAL;
644 goto out;
645 }
646 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100647 else if (strcmp(args[0], "maxconnrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100648 if (alertif_too_many_args(1, file, linenum, args, &err_code))
649 goto out;
650 if (global.cps_lim != 0) {
651 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
652 err_code |= ERR_ALERT;
653 goto out;
654 }
655 if (*(args[1]) == 0) {
656 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
657 err_code |= ERR_ALERT | ERR_FATAL;
658 goto out;
659 }
660 global.cps_lim = atol(args[1]);
661 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100662 else if (strcmp(args[0], "maxsessrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100663 if (alertif_too_many_args(1, file, linenum, args, &err_code))
664 goto out;
665 if (global.sps_lim != 0) {
666 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
667 err_code |= ERR_ALERT;
668 goto out;
669 }
670 if (*(args[1]) == 0) {
671 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
672 err_code |= ERR_ALERT | ERR_FATAL;
673 goto out;
674 }
675 global.sps_lim = atol(args[1]);
676 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100677 else if (strcmp(args[0], "maxsslrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100678 if (alertif_too_many_args(1, file, linenum, args, &err_code))
679 goto out;
680 if (global.ssl_lim != 0) {
681 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
682 err_code |= ERR_ALERT;
683 goto out;
684 }
685 if (*(args[1]) == 0) {
686 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
687 err_code |= ERR_ALERT | ERR_FATAL;
688 goto out;
689 }
690 global.ssl_lim = atol(args[1]);
691 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100692 else if (strcmp(args[0], "maxcomprate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100693 if (alertif_too_many_args(1, file, linenum, args, &err_code))
694 goto out;
695 if (*(args[1]) == 0) {
696 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
697 err_code |= ERR_ALERT | ERR_FATAL;
698 goto out;
699 }
700 global.comp_rate_lim = atoi(args[1]) * 1024;
701 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100702 else if (strcmp(args[0], "maxpipes") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100703 if (alertif_too_many_args(1, file, linenum, args, &err_code))
704 goto out;
705 if (global.maxpipes != 0) {
706 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
707 err_code |= ERR_ALERT;
708 goto out;
709 }
710 if (*(args[1]) == 0) {
711 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
712 err_code |= ERR_ALERT | ERR_FATAL;
713 goto out;
714 }
715 global.maxpipes = atol(args[1]);
716 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100717 else if (strcmp(args[0], "maxzlibmem") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100718 if (alertif_too_many_args(1, file, linenum, args, &err_code))
719 goto out;
720 if (*(args[1]) == 0) {
721 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
722 err_code |= ERR_ALERT | ERR_FATAL;
723 goto out;
724 }
725 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
726 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100727 else if (strcmp(args[0], "maxcompcpuusage") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100728 if (alertif_too_many_args(1, file, linenum, args, &err_code))
729 goto out;
730 if (*(args[1]) == 0) {
731 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
732 err_code |= ERR_ALERT | ERR_FATAL;
733 goto out;
734 }
735 compress_min_idle = 100 - atoi(args[1]);
736 if (compress_min_idle > 100) {
737 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
738 err_code |= ERR_ALERT | ERR_FATAL;
739 goto out;
740 }
741 }
Willy Tarreau2df1fbf2022-04-25 18:02:03 +0200742 else if (strcmp(args[0], "fd-hard-limit") == 0) {
743 if (alertif_too_many_args(1, file, linenum, args, &err_code))
744 goto out;
745 if (global.fd_hard_limit != 0) {
746 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
747 err_code |= ERR_ALERT;
748 goto out;
749 }
750 if (*(args[1]) == 0) {
751 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
752 err_code |= ERR_ALERT | ERR_FATAL;
753 goto out;
754 }
755 global.fd_hard_limit = atol(args[1]);
756 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100757 else if (strcmp(args[0], "ulimit-n") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100758 if (alertif_too_many_args(1, file, linenum, args, &err_code))
759 goto out;
760 if (global.rlimit_nofile != 0) {
761 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
762 err_code |= ERR_ALERT;
763 goto out;
764 }
765 if (*(args[1]) == 0) {
766 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
767 err_code |= ERR_ALERT | ERR_FATAL;
768 goto out;
769 }
770 global.rlimit_nofile = atol(args[1]);
771 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100772 else if (strcmp(args[0], "chroot") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100773 if (alertif_too_many_args(1, file, linenum, args, &err_code))
774 goto out;
775 if (global.chroot != NULL) {
776 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
777 err_code |= ERR_ALERT;
778 goto out;
779 }
780 if (*(args[1]) == 0) {
781 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
782 err_code |= ERR_ALERT | ERR_FATAL;
783 goto out;
784 }
785 global.chroot = strdup(args[1]);
786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100788 int i, len=0;
789 char *d;
790
791 if (!*args[1]) {
792 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
793 file, linenum, args[0]);
794 err_code |= ERR_ALERT | ERR_FATAL;
795 goto out;
796 }
797
798 for (i = 1; *args[i]; i++)
799 len += strlen(args[i]) + 1;
800
801 if (global.desc)
802 free(global.desc);
803
804 global.desc = d = calloc(1, len);
805
806 d += snprintf(d, global.desc + len - d, "%s", args[1]);
807 for (i = 2; *args[i]; i++)
808 d += snprintf(d, global.desc + len - d, " %s", args[i]);
809 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100810 else if (strcmp(args[0], "node") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100811 int i;
812 char c;
813
814 if (alertif_too_many_args(1, file, linenum, args, &err_code))
815 goto out;
816
817 for (i=0; args[1][i]; i++) {
818 c = args[1][i];
819 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
820 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
821 break;
822 }
823
824 if (!i || args[1][i]) {
825 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
826 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
827 file, linenum, args[0]);
828 err_code |= ERR_ALERT | ERR_FATAL;
829 goto out;
830 }
831
832 if (global.node)
833 free(global.node);
834
835 global.node = strdup(args[1]);
836 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100837 else if (strcmp(args[0], "pidfile") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100838 if (alertif_too_many_args(1, file, linenum, args, &err_code))
839 goto out;
840 if (global.pidfile != NULL) {
841 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
842 err_code |= ERR_ALERT;
843 goto out;
844 }
845 if (*(args[1]) == 0) {
846 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
847 err_code |= ERR_ALERT | ERR_FATAL;
848 goto out;
849 }
850 global.pidfile = strdup(args[1]);
851 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100852 else if (strcmp(args[0], "unix-bind") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100853 int cur_arg = 1;
854 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100855 if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100856 if (global.unix_bind.prefix != NULL) {
857 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
858 err_code |= ERR_ALERT;
859 cur_arg += 2;
860 continue;
861 }
862
863 if (*(args[cur_arg+1]) == 0) {
864 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
865 err_code |= ERR_ALERT | ERR_FATAL;
866 goto out;
867 }
868 global.unix_bind.prefix = strdup(args[cur_arg+1]);
869 cur_arg += 2;
870 continue;
871 }
872
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100873 if (strcmp(args[cur_arg], "mode") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100874
875 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
876 cur_arg += 2;
877 continue;
878 }
879
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100880 if (strcmp(args[cur_arg], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100881
882 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
883 cur_arg += 2;
884 continue;
885 }
886
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100887 if (strcmp(args[cur_arg], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100888
889 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
890 cur_arg += 2;
891 continue;
892 }
893
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100894 if (strcmp(args[cur_arg], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100895 struct passwd *user;
896
897 user = getpwnam(args[cur_arg + 1]);
898 if (!user) {
899 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
900 file, linenum, args[0], args[cur_arg + 1 ]);
901 err_code |= ERR_ALERT | ERR_FATAL;
902 goto out;
903 }
904
905 global.unix_bind.ux.uid = user->pw_uid;
906 cur_arg += 2;
907 continue;
908 }
909
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100910 if (strcmp(args[cur_arg], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100911 struct group *group;
912
913 group = getgrnam(args[cur_arg + 1]);
914 if (!group) {
915 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
916 file, linenum, args[0], args[cur_arg + 1 ]);
917 err_code |= ERR_ALERT | ERR_FATAL;
918 goto out;
919 }
920
921 global.unix_bind.ux.gid = group->gr_gid;
922 cur_arg += 2;
923 continue;
924 }
925
926 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
927 file, linenum, args[0]);
928 err_code |= ERR_ALERT | ERR_FATAL;
929 goto out;
930 }
931 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100932 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +0200933 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100934 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
935 err_code |= ERR_ALERT | ERR_FATAL;
936 goto out;
937 }
938 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100939 else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100940 char *name;
941
942 if (global.log_send_hostname != NULL) {
943 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
944 err_code |= ERR_ALERT;
945 goto out;
946 }
947
948 if (*(args[1]))
949 name = args[1];
950 else
951 name = hostname;
952
953 free(global.log_send_hostname);
954 global.log_send_hostname = strdup(name);
955 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100956 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 +0100957 if (global.server_state_base != NULL) {
958 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
959 err_code |= ERR_ALERT;
960 goto out;
961 }
962
963 if (!*(args[1])) {
964 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
965 err_code |= ERR_FATAL;
966 goto out;
967 }
968
969 global.server_state_base = strdup(args[1]);
970 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100971 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 +0100972 if (global.server_state_file != NULL) {
973 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
974 err_code |= ERR_ALERT;
975 goto out;
976 }
977
978 if (!*(args[1])) {
979 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
980 err_code |= ERR_FATAL;
981 goto out;
982 }
983
984 global.server_state_file = strdup(args[1]);
985 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100986 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100987 if (alertif_too_many_args(1, file, linenum, args, &err_code))
988 goto out;
989 if (*(args[1]) == 0) {
990 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
991 err_code |= ERR_ALERT | ERR_FATAL;
992 goto out;
993 }
994 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +0200995 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
996 if (b_orig(&global.log_tag) == NULL) {
997 chunk_destroy(&global.log_tag);
998 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
999 err_code |= ERR_ALERT | ERR_FATAL;
1000 goto out;
1001 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001002 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001003 else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001004 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1005 goto out;
1006 if (global.spread_checks != 0) {
1007 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
1008 err_code |= ERR_ALERT;
1009 goto out;
1010 }
1011 if (*(args[1]) == 0) {
1012 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1013 err_code |= ERR_ALERT | ERR_FATAL;
1014 goto out;
1015 }
1016 global.spread_checks = atol(args[1]);
1017 if (global.spread_checks < 0 || global.spread_checks > 50) {
1018 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
1019 err_code |= ERR_ALERT | ERR_FATAL;
1020 }
1021 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001022 else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001023 const char *err;
1024 unsigned int val;
1025
1026 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1027 goto out;
1028 if (*(args[1]) == 0) {
1029 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1030 err_code |= ERR_ALERT | ERR_FATAL;
1031 goto out;
1032 }
1033
1034 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001035 if (err == PARSE_TIME_OVER) {
1036 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1037 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001038 err_code |= ERR_ALERT | ERR_FATAL;
1039 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001040 else if (err == PARSE_TIME_UNDER) {
1041 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1042 file, linenum, args[1], args[0]);
1043 err_code |= ERR_ALERT | ERR_FATAL;
1044 }
1045 else if (err) {
1046 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 +01001047 err_code |= ERR_ALERT | ERR_FATAL;
1048 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001049 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001050 }
1051 else if (strcmp(args[0], "cpu-map") == 0) {
1052 /* map a process list to a CPU set */
1053#ifdef USE_CPU_AFFINITY
1054 char *slash;
Willy Tarreau5b093412022-07-08 09:38:30 +02001055 unsigned long tgroup = 0, thread = 0;
1056 int g, j, n, autoinc;
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001057 struct hap_cpuset cpus, cpus_copy;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001058
1059 if (!*args[1] || !*args[2]) {
Willy Tarreau5b093412022-07-08 09:38:30 +02001060 ha_alert("parsing [%s:%d] : %s expects a thread group number "
Willy Tarreau36b9e222018-11-11 15:19:52 +01001061 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1062 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001063 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001064 err_code |= ERR_ALERT | ERR_FATAL;
1065 goto out;
1066 }
1067
1068 if ((slash = strchr(args[1], '/')) != NULL)
1069 *slash = 0;
1070
Willy Tarreau5b093412022-07-08 09:38:30 +02001071 /* note: we silently ignore thread group numbers over MAX_TGROUPS
1072 * and threads over MAX_THREADS so as not to make configurations a
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001073 * pain to maintain.
1074 */
Willy Tarreau5b093412022-07-08 09:38:30 +02001075 if (parse_process_number(args[1], &tgroup, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001076 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1077 err_code |= ERR_ALERT | ERR_FATAL;
1078 goto out;
1079 }
1080
1081 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001082 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001083 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1084 err_code |= ERR_ALERT | ERR_FATAL;
1085 goto out;
1086 }
1087 *slash = '/';
Willy Tarreau36b9e222018-11-11 15:19:52 +01001088 }
1089
Amaury Denoyellea8082352021-04-06 16:46:15 +02001090 if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001091 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1092 err_code |= ERR_ALERT | ERR_FATAL;
1093 goto out;
1094 }
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001095
Willy Tarreau36b9e222018-11-11 15:19:52 +01001096 if (autoinc &&
Willy Tarreau5b093412022-07-08 09:38:30 +02001097 my_popcountl(tgroup) != ha_cpuset_count(&cpus) &&
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001098 my_popcountl(thread) != ha_cpuset_count(&cpus)) {
Willy Tarreau5b093412022-07-08 09:38:30 +02001099 ha_alert("parsing [%s:%d] : %s : TGROUP/THREAD range and CPU sets "
Willy Tarreau36b9e222018-11-11 15:19:52 +01001100 "must have the same size to be automatically bound\n",
1101 file, linenum, args[0]);
1102 err_code |= ERR_ALERT | ERR_FATAL;
1103 goto out;
1104 }
1105
Willy Tarreau7764a572019-07-16 15:10:34 +02001106 /* we now have to deal with 3 real cases :
Willy Tarreau5b093412022-07-08 09:38:30 +02001107 * cpu-map P-Q => mapping for whole tgroups, numbers P to Q
1108 * cpu-map P-Q/1 => mapping of first thread of groups P to Q
1109 * cpu-map P/T-U => mapping of threads T to U of tgroup P
Willy Tarreau7764a572019-07-16 15:10:34 +02001110 */
Willy Tarreau3cd71ac2022-08-22 10:38:00 +02001111 /* first tgroup, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
1112 for (g = 0; g < MAX_TGROUPS; g++) {
1113 /* No mapping for this tgroup */
1114 if (!(tgroup & (1UL << g)))
1115 continue;
Willy Tarreau81492c92019-05-03 09:41:23 +02001116
Willy Tarreau3cd71ac2022-08-22 10:38:00 +02001117 ha_cpuset_assign(&cpus_copy, &cpus);
1118
1119 if (!thread) {
1120 /* no thread set was specified, apply
1121 * the CPU set to the whole group.
1122 */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001123 if (!autoinc)
Willy Tarreau5b093412022-07-08 09:38:30 +02001124 ha_cpuset_assign(&cpu_map[g].proc, &cpus);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001125 else {
Willy Tarreau5b093412022-07-08 09:38:30 +02001126 ha_cpuset_zero(&cpu_map[g].proc);
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001127 n = ha_cpuset_ffs(&cpus_copy) - 1;
1128 ha_cpuset_clr(&cpus_copy, n);
Willy Tarreau5b093412022-07-08 09:38:30 +02001129 ha_cpuset_set(&cpu_map[g].proc, n);
1130 }
Willy Tarreau3cd71ac2022-08-22 10:38:00 +02001131 } else {
1132 /* a thread set is specified, apply the
1133 * CPU set to these threads.
1134 */
Willy Tarreau5b093412022-07-08 09:38:30 +02001135 for (j = n = 0; j < MAX_THREADS_PER_GROUP; j++) {
1136 /* No mapping for this thread */
1137 if (!(thread & (1UL << j)))
1138 continue;
1139
1140 if (!autoinc)
1141 ha_cpuset_assign(&cpu_map[g].thread[j], &cpus);
1142 else {
1143 ha_cpuset_zero(&cpu_map[g].thread[j]);
1144 n = ha_cpuset_ffs(&cpus_copy) - 1;
1145 ha_cpuset_clr(&cpus_copy, n);
1146 ha_cpuset_set(&cpu_map[g].thread[j], n);
1147 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001148 }
1149 }
1150 }
1151#else
1152 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1153 file, linenum, args[0]);
1154 err_code |= ERR_ALERT | ERR_FATAL;
1155 goto out;
1156#endif /* ! USE_CPU_AFFINITY */
1157 }
1158 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1159 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1160 goto out;
1161
1162 if (*(args[2]) == 0) {
1163 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1164 err_code |= ERR_ALERT | ERR_FATAL;
1165 goto out;
1166 }
1167
1168 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1169 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1170 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1171 err_code |= ERR_ALERT | ERR_FATAL;
1172 goto out;
1173 }
1174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001175 else if (strcmp(args[0], "unsetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001176 int arg;
1177
1178 if (*(args[1]) == 0) {
1179 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1180 err_code |= ERR_ALERT | ERR_FATAL;
1181 goto out;
1182 }
1183
1184 for (arg = 1; *args[arg]; arg++) {
1185 if (unsetenv(args[arg]) != 0) {
1186 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1187 err_code |= ERR_ALERT | ERR_FATAL;
1188 goto out;
1189 }
1190 }
1191 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001192 else if (strcmp(args[0], "resetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001193 extern char **environ;
1194 char **env = environ;
1195
1196 /* args contain variable names to keep, one per argument */
1197 while (*env) {
1198 int arg;
1199
1200 /* look for current variable in among all those we want to keep */
1201 for (arg = 1; *args[arg]; arg++) {
1202 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1203 (*env)[strlen(args[arg])] == '=')
1204 break;
1205 }
1206
1207 /* delete this variable */
1208 if (!*args[arg]) {
1209 char *delim = strchr(*env, '=');
1210
1211 if (!delim || delim - *env >= trash.size) {
1212 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1213 err_code |= ERR_ALERT | ERR_FATAL;
1214 goto out;
1215 }
1216
1217 memcpy(trash.area, *env, delim - *env);
1218 trash.area[delim - *env] = 0;
1219
1220 if (unsetenv(trash.area) != 0) {
1221 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1222 err_code |= ERR_ALERT | ERR_FATAL;
1223 goto out;
1224 }
1225 }
1226 else
1227 env++;
1228 }
1229 }
Willy Tarreaue98d3852022-11-15 09:34:07 +01001230 else if (strcmp(args[0], "quick-exit") == 0) {
1231 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1232 goto out;
1233 global.tune.options |= GTUNE_QUICK_EXIT;
1234 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001235 else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */
William Dauchy0fec3ab2019-10-27 20:08:11 +01001236 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1237 goto out;
1238 if (kwm == KWM_NO)
1239 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001240 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001241 else if (strcmp(args[0], "localpeer") == 0) {
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001242 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1243 goto out;
1244
1245 if (*(args[1]) == 0) {
1246 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1247 file, linenum, args[0]);
1248 err_code |= ERR_ALERT | ERR_FATAL;
1249 goto out;
1250 }
1251
1252 if (global.localpeer_cmdline != 0) {
1253 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1254 "command line argument.\n", file, linenum, args[0]);
1255 err_code |= ERR_WARN;
1256 goto out;
1257 }
1258
1259 if (cfg_peers) {
1260 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1261 file, linenum, args[0]);
1262 err_code |= ERR_WARN;
1263 goto out;
1264 }
1265
1266 free(localpeer);
1267 if ((localpeer = strdup(args[1])) == NULL) {
1268 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1269 file, linenum, args[0]);
1270 err_code |= ERR_ALERT | ERR_FATAL;
1271 goto out;
1272 }
1273 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1274 }
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +01001275 else if (strcmp(args[0], "numa-cpu-mapping") == 0) {
1276 global.numa_cpu_mapping = (kwm == KWM_NO) ? 0 : 1;
1277 }
Erwan Le Goasfad9da82022-09-14 17:24:22 +02001278 else if (strcmp(args[0], "anonkey") == 0) {
1279 long long tmp = 0;
1280
1281 if (*args[1] == 0) {
1282 ha_alert("parsing [%s:%d]: a key is expected after '%s'.\n",
1283 file, linenum, args[0]);
1284 err_code |= ERR_ALERT | ERR_FATAL;
1285 goto out;
1286 }
1287
1288 if (HA_ATOMIC_LOAD(&global.anon_key) == 0) {
1289 tmp = atoll(args[1]);
1290 if (tmp < 0 || tmp > UINT_MAX) {
1291 ha_alert("parsing [%s:%d]: '%s' value must be within range %u-%u (was '%s').\n",
1292 file, linenum, args[0], 0, UINT_MAX, args[1]);
1293 err_code |= ERR_ALERT | ERR_FATAL;
1294 goto out;
1295 }
1296
1297 HA_ATOMIC_STORE(&global.anon_key, tmp);
1298 }
1299 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001300 else {
1301 struct cfg_kw_list *kwl;
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001302 const char *best;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001303 int index;
1304 int rc;
1305
1306 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1307 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1308 if (kwl->kw[index].section != CFG_GLOBAL)
1309 continue;
1310 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001311 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02001312 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001313 err_code |= ERR_ALERT | ERR_FATAL;
1314 goto out;
1315 }
1316
Willy Tarreau36b9e222018-11-11 15:19:52 +01001317 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1318 if (rc < 0) {
1319 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1320 err_code |= ERR_ALERT | ERR_FATAL;
1321 }
1322 else if (rc > 0) {
1323 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1324 err_code |= ERR_WARN;
1325 goto out;
1326 }
1327 goto out;
1328 }
1329 }
1330 }
1331
Willy Tarreau101df312021-03-15 09:12:41 +01001332 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list);
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001333 if (best)
1334 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
1335 else
1336 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau36b9e222018-11-11 15:19:52 +01001337 err_code |= ERR_ALERT | ERR_FATAL;
1338 }
1339
1340 out:
1341 free(errmsg);
1342 return err_code;
1343}
1344