blob: c9805a32ed6ce8185a63636450bd11d7063b8107 [file] [log] [blame]
Willy Tarreau36b9e222018-11-11 15:19:52 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#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>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020016#include <haproxy/compression.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020017#include <haproxy/global.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020018#include <haproxy/log.h>
Dragan Dosen13cd54c2020-06-18 18:24:05 +020019#include <haproxy/peers.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020020#include <haproxy/tools.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010021
22/*
23 * parse a line in a <global> section. Returns the error code, 0 if OK, or
24 * any combination of :
25 * - ERR_ABORT: must abort ASAP
26 * - ERR_FATAL: we can continue parsing but not start the service
27 * - ERR_WARN: a warning has been emitted
28 * - ERR_ALERT: an alert has been emitted
29 * Only the two first ones can stop processing, the two others are just
30 * indicators.
31 */
32int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
33{
34 int err_code = 0;
35 char *errmsg = NULL;
36
37 if (!strcmp(args[0], "global")) { /* new section */
38 /* no option, nothing special to do */
39 alertif_too_many_args(0, file, linenum, args, &err_code);
40 goto out;
41 }
42 else if (!strcmp(args[0], "daemon")) {
43 if (alertif_too_many_args(0, file, linenum, args, &err_code))
44 goto out;
45 global.mode |= MODE_DAEMON;
46 }
47 else if (!strcmp(args[0], "master-worker")) {
48 if (alertif_too_many_args(1, file, linenum, args, &err_code))
49 goto out;
50 if (*args[1]) {
51 if (!strcmp(args[1], "no-exit-on-failure")) {
52 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
53 } else {
54 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
55 err_code |= ERR_ALERT | ERR_FATAL;
56 goto out;
57 }
58 }
59 global.mode |= MODE_MWORKER;
60 }
61 else if (!strcmp(args[0], "debug")) {
62 if (alertif_too_many_args(0, file, linenum, args, &err_code))
63 goto out;
64 global.mode |= MODE_DEBUG;
Willy Tarreau1b857852020-02-25 11:27:22 +010065 ha_warning("parsing [%s:%d] : '%s' must never be used and will be removed in 2.3. If you need debug mode, please use '-d' on the command line.\n", file, linenum, args[0]);
66 err_code |= ERR_WARN;
67 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +010068 }
69 else if (!strcmp(args[0], "noepoll")) {
70 if (alertif_too_many_args(0, file, linenum, args, &err_code))
71 goto out;
72 global.tune.options &= ~GTUNE_USE_EPOLL;
73 }
74 else if (!strcmp(args[0], "nokqueue")) {
75 if (alertif_too_many_args(0, file, linenum, args, &err_code))
76 goto out;
77 global.tune.options &= ~GTUNE_USE_KQUEUE;
78 }
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +000079 else if (!strcmp(args[0], "noevports")) {
80 if (alertif_too_many_args(0, file, linenum, args, &err_code))
81 goto out;
82 global.tune.options &= ~GTUNE_USE_EVPORTS;
83 }
Willy Tarreau36b9e222018-11-11 15:19:52 +010084 else if (!strcmp(args[0], "nopoll")) {
85 if (alertif_too_many_args(0, file, linenum, args, &err_code))
86 goto out;
87 global.tune.options &= ~GTUNE_USE_POLL;
88 }
Willy Tarreaubeb859a2018-11-22 18:07:59 +010089 else if (!strcmp(args[0], "busy-polling")) { /* "no busy-polling" or "busy-polling" */
90 if (alertif_too_many_args(0, file, linenum, args, &err_code))
91 goto out;
92 if (kwm == KWM_NO)
93 global.tune.options &= ~GTUNE_BUSY_POLLING;
94 else
95 global.tune.options |= GTUNE_BUSY_POLLING;
96 }
Willy Tarreau636848a2019-04-15 19:38:50 +020097 else if (!strcmp(args[0], "set-dumpable")) { /* "no set-dumpable" or "set-dumpable" */
98 if (alertif_too_many_args(0, file, linenum, args, &err_code))
99 goto out;
100 if (kwm == KWM_NO)
101 global.tune.options &= ~GTUNE_SET_DUMPABLE;
102 else
103 global.tune.options |= GTUNE_SET_DUMPABLE;
104 }
Willy Tarreaud96f1122019-12-03 07:07:36 +0100105 else if (!strcmp(args[0], "insecure-fork-wanted")) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
106 if (alertif_too_many_args(0, file, linenum, args, &err_code))
107 goto out;
108 if (kwm == KWM_NO)
109 global.tune.options &= ~GTUNE_INSECURE_FORK;
110 else
111 global.tune.options |= GTUNE_INSECURE_FORK;
112 }
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100113 else if (!strcmp(args[0], "insecure-setuid-wanted")) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
114 if (alertif_too_many_args(0, file, linenum, args, &err_code))
115 goto out;
116 if (kwm == KWM_NO)
117 global.tune.options &= ~GTUNE_INSECURE_SETUID;
118 else
119 global.tune.options |= GTUNE_INSECURE_SETUID;
120 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100121 else if (!strcmp(args[0], "nosplice")) {
122 if (alertif_too_many_args(0, file, linenum, args, &err_code))
123 goto out;
124 global.tune.options &= ~GTUNE_USE_SPLICE;
125 }
126 else if (!strcmp(args[0], "nogetaddrinfo")) {
127 if (alertif_too_many_args(0, file, linenum, args, &err_code))
128 goto out;
129 global.tune.options &= ~GTUNE_USE_GAI;
130 }
131 else if (!strcmp(args[0], "noreuseport")) {
132 if (alertif_too_many_args(0, file, linenum, args, &err_code))
133 goto out;
134 global.tune.options &= ~GTUNE_USE_REUSEPORT;
135 }
136 else if (!strcmp(args[0], "quiet")) {
137 if (alertif_too_many_args(0, file, linenum, args, &err_code))
138 goto out;
139 global.mode |= MODE_QUIET;
140 }
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200141 else if (!strcmp(args[0], "zero-warning")) {
142 if (alertif_too_many_args(0, file, linenum, args, &err_code))
143 goto out;
144 global.mode |= MODE_ZERO_WARNING;
145 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100146 else if (!strcmp(args[0], "tune.runqueue-depth")) {
147 if (alertif_too_many_args(1, file, linenum, args, &err_code))
148 goto out;
149 if (global.tune.runqueue_depth != 0) {
150 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
151 err_code |= ERR_ALERT;
152 goto out;
153 }
154 if (*(args[1]) == 0) {
155 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
156 err_code |= ERR_ALERT | ERR_FATAL;
157 goto out;
158 }
159 global.tune.runqueue_depth = atol(args[1]);
160
161 }
162 else if (!strcmp(args[0], "tune.maxpollevents")) {
163 if (alertif_too_many_args(1, file, linenum, args, &err_code))
164 goto out;
165 if (global.tune.maxpollevents != 0) {
166 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
167 err_code |= ERR_ALERT;
168 goto out;
169 }
170 if (*(args[1]) == 0) {
171 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
172 err_code |= ERR_ALERT | ERR_FATAL;
173 goto out;
174 }
175 global.tune.maxpollevents = atol(args[1]);
176 }
177 else if (!strcmp(args[0], "tune.maxaccept")) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200178 long max;
179
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.maxaccept != 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 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200192 max = atol(args[1]);
193 if (/*max < -1 || */max > INT_MAX) {
194 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
195 err_code |= ERR_ALERT | ERR_FATAL;
196 goto out;
197 }
198 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100199 }
200 else if (!strcmp(args[0], "tune.chksize")) {
201 if (alertif_too_many_args(1, file, linenum, args, &err_code))
202 goto out;
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.chksize = atol(args[1]);
209 }
210 else if (!strcmp(args[0], "tune.recv_enough")) {
211 if (alertif_too_many_args(1, file, linenum, args, &err_code))
212 goto out;
213 if (*(args[1]) == 0) {
214 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
215 err_code |= ERR_ALERT | ERR_FATAL;
216 goto out;
217 }
218 global.tune.recv_enough = atol(args[1]);
219 }
220 else if (!strcmp(args[0], "tune.buffers.limit")) {
221 if (alertif_too_many_args(1, file, linenum, args, &err_code))
222 goto out;
223 if (*(args[1]) == 0) {
224 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
225 err_code |= ERR_ALERT | ERR_FATAL;
226 goto out;
227 }
228 global.tune.buf_limit = atol(args[1]);
229 if (global.tune.buf_limit) {
230 if (global.tune.buf_limit < 3)
231 global.tune.buf_limit = 3;
232 if (global.tune.buf_limit <= global.tune.reserved_bufs)
233 global.tune.buf_limit = global.tune.reserved_bufs + 1;
234 }
235 }
236 else if (!strcmp(args[0], "tune.buffers.reserve")) {
237 if (alertif_too_many_args(1, file, linenum, args, &err_code))
238 goto out;
239 if (*(args[1]) == 0) {
240 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
241 err_code |= ERR_ALERT | ERR_FATAL;
242 goto out;
243 }
244 global.tune.reserved_bufs = atol(args[1]);
245 if (global.tune.reserved_bufs < 2)
246 global.tune.reserved_bufs = 2;
247 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
248 global.tune.buf_limit = global.tune.reserved_bufs + 1;
249 }
250 else if (!strcmp(args[0], "tune.bufsize")) {
251 if (alertif_too_many_args(1, file, linenum, args, &err_code))
252 goto out;
253 if (*(args[1]) == 0) {
254 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
255 err_code |= ERR_ALERT | ERR_FATAL;
256 goto out;
257 }
258 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100259 /* round it up to support a two-pointer alignment at the end */
260 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100261 if (global.tune.bufsize <= 0) {
262 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
263 err_code |= ERR_ALERT | ERR_FATAL;
264 goto out;
265 }
266 }
267 else if (!strcmp(args[0], "tune.maxrewrite")) {
268 if (alertif_too_many_args(1, file, linenum, args, &err_code))
269 goto out;
270 if (*(args[1]) == 0) {
271 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
272 err_code |= ERR_ALERT | ERR_FATAL;
273 goto out;
274 }
275 global.tune.maxrewrite = atol(args[1]);
276 if (global.tune.maxrewrite < 0) {
277 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
278 err_code |= ERR_ALERT | ERR_FATAL;
279 goto out;
280 }
281 }
282 else if (!strcmp(args[0], "tune.idletimer")) {
283 unsigned int idle;
284 const char *res;
285
286 if (alertif_too_many_args(1, file, linenum, args, &err_code))
287 goto out;
288 if (*(args[1]) == 0) {
289 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
290 err_code |= ERR_ALERT | ERR_FATAL;
291 goto out;
292 }
293
294 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200295 if (res == PARSE_TIME_OVER) {
296 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
297 file, linenum, args[1], args[0]);
298 err_code |= ERR_ALERT | ERR_FATAL;
299 goto out;
300 }
301 else if (res == PARSE_TIME_UNDER) {
302 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
303 file, linenum, args[1], args[0]);
304 err_code |= ERR_ALERT | ERR_FATAL;
305 goto out;
306 }
307 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100308 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200309 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100310 err_code |= ERR_ALERT | ERR_FATAL;
311 goto out;
312 }
313
314 if (idle > 65535) {
315 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
316 err_code |= ERR_ALERT | ERR_FATAL;
317 goto out;
318 }
319 global.tune.idle_timer = idle;
320 }
321 else if (!strcmp(args[0], "tune.rcvbuf.client")) {
322 if (alertif_too_many_args(1, file, linenum, args, &err_code))
323 goto out;
324 if (global.tune.client_rcvbuf != 0) {
325 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
326 err_code |= ERR_ALERT;
327 goto out;
328 }
329 if (*(args[1]) == 0) {
330 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
331 err_code |= ERR_ALERT | ERR_FATAL;
332 goto out;
333 }
334 global.tune.client_rcvbuf = atol(args[1]);
335 }
336 else if (!strcmp(args[0], "tune.rcvbuf.server")) {
337 if (alertif_too_many_args(1, file, linenum, args, &err_code))
338 goto out;
339 if (global.tune.server_rcvbuf != 0) {
340 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
341 err_code |= ERR_ALERT;
342 goto out;
343 }
344 if (*(args[1]) == 0) {
345 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
346 err_code |= ERR_ALERT | ERR_FATAL;
347 goto out;
348 }
349 global.tune.server_rcvbuf = atol(args[1]);
350 }
351 else if (!strcmp(args[0], "tune.sndbuf.client")) {
352 if (alertif_too_many_args(1, file, linenum, args, &err_code))
353 goto out;
354 if (global.tune.client_sndbuf != 0) {
355 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
356 err_code |= ERR_ALERT;
357 goto out;
358 }
359 if (*(args[1]) == 0) {
360 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
361 err_code |= ERR_ALERT | ERR_FATAL;
362 goto out;
363 }
364 global.tune.client_sndbuf = atol(args[1]);
365 }
366 else if (!strcmp(args[0], "tune.sndbuf.server")) {
367 if (alertif_too_many_args(1, file, linenum, args, &err_code))
368 goto out;
369 if (global.tune.server_sndbuf != 0) {
370 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
371 err_code |= ERR_ALERT;
372 goto out;
373 }
374 if (*(args[1]) == 0) {
375 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
376 err_code |= ERR_ALERT | ERR_FATAL;
377 goto out;
378 }
379 global.tune.server_sndbuf = atol(args[1]);
380 }
381 else if (!strcmp(args[0], "tune.pipesize")) {
382 if (alertif_too_many_args(1, file, linenum, args, &err_code))
383 goto out;
384 if (*(args[1]) == 0) {
385 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
386 err_code |= ERR_ALERT | ERR_FATAL;
387 goto out;
388 }
389 global.tune.pipesize = atol(args[1]);
390 }
391 else if (!strcmp(args[0], "tune.http.cookielen")) {
392 if (alertif_too_many_args(1, file, linenum, args, &err_code))
393 goto out;
394 if (*(args[1]) == 0) {
395 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
396 err_code |= ERR_ALERT | ERR_FATAL;
397 goto out;
398 }
399 global.tune.cookie_len = atol(args[1]) + 1;
400 }
401 else if (!strcmp(args[0], "tune.http.logurilen")) {
402 if (alertif_too_many_args(1, file, linenum, args, &err_code))
403 goto out;
404 if (*(args[1]) == 0) {
405 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
406 err_code |= ERR_ALERT | ERR_FATAL;
407 goto out;
408 }
409 global.tune.requri_len = atol(args[1]) + 1;
410 }
411 else if (!strcmp(args[0], "tune.http.maxhdr")) {
412 if (alertif_too_many_args(1, file, linenum, args, &err_code))
413 goto out;
414 if (*(args[1]) == 0) {
415 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
416 err_code |= ERR_ALERT | ERR_FATAL;
417 goto out;
418 }
419 global.tune.max_http_hdr = atoi(args[1]);
420 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
421 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
422 file, linenum, args[0]);
423 err_code |= ERR_ALERT | ERR_FATAL;
424 goto out;
425 }
426 }
427 else if (!strcmp(args[0], "tune.comp.maxlevel")) {
428 if (alertif_too_many_args(1, file, linenum, args, &err_code))
429 goto out;
430 if (*args[1]) {
431 global.tune.comp_maxlevel = atoi(args[1]);
432 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
433 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
434 file, linenum, args[0]);
435 err_code |= ERR_ALERT | ERR_FATAL;
436 goto out;
437 }
438 } else {
439 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
440 file, linenum, args[0]);
441 err_code |= ERR_ALERT | ERR_FATAL;
442 goto out;
443 }
444 }
445 else if (!strcmp(args[0], "tune.pattern.cache-size")) {
446 if (*args[1]) {
447 global.tune.pattern_cache = atoi(args[1]);
448 if (global.tune.pattern_cache < 0) {
449 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
450 file, linenum, args[0]);
451 err_code |= ERR_ALERT | ERR_FATAL;
452 goto out;
453 }
454 } else {
455 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
456 file, linenum, args[0]);
457 err_code |= ERR_ALERT | ERR_FATAL;
458 goto out;
459 }
460 }
461 else if (!strcmp(args[0], "uid")) {
462 if (alertif_too_many_args(1, file, linenum, args, &err_code))
463 goto out;
464 if (global.uid != 0) {
465 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
466 err_code |= ERR_ALERT;
467 goto out;
468 }
469 if (*(args[1]) == 0) {
470 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
471 err_code |= ERR_ALERT | ERR_FATAL;
472 goto out;
473 }
474 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
475 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]);
476 err_code |= ERR_WARN;
477 goto out;
478 }
479
480 }
481 else if (!strcmp(args[0], "gid")) {
482 if (alertif_too_many_args(1, file, linenum, args, &err_code))
483 goto out;
484 if (global.gid != 0) {
485 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
486 err_code |= ERR_ALERT;
487 goto out;
488 }
489 if (*(args[1]) == 0) {
490 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
491 err_code |= ERR_ALERT | ERR_FATAL;
492 goto out;
493 }
494 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
495 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]);
496 err_code |= ERR_WARN;
497 goto out;
498 }
499 }
500 else if (!strcmp(args[0], "external-check")) {
501 if (alertif_too_many_args(0, file, linenum, args, &err_code))
502 goto out;
503 global.external_check = 1;
504 }
505 /* user/group name handling */
506 else if (!strcmp(args[0], "user")) {
507 struct passwd *ha_user;
508 if (alertif_too_many_args(1, file, linenum, args, &err_code))
509 goto out;
510 if (global.uid != 0) {
511 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
512 err_code |= ERR_ALERT;
513 goto out;
514 }
515 errno = 0;
516 ha_user = getpwnam(args[1]);
517 if (ha_user != NULL) {
518 global.uid = (int)ha_user->pw_uid;
519 }
520 else {
521 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
522 err_code |= ERR_ALERT | ERR_FATAL;
523 }
524 }
525 else if (!strcmp(args[0], "group")) {
526 struct group *ha_group;
527 if (alertif_too_many_args(1, file, linenum, args, &err_code))
528 goto out;
529 if (global.gid != 0) {
530 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
531 err_code |= ERR_ALERT;
532 goto out;
533 }
534 errno = 0;
535 ha_group = getgrnam(args[1]);
536 if (ha_group != NULL) {
537 global.gid = (int)ha_group->gr_gid;
538 }
539 else {
540 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
541 err_code |= ERR_ALERT | ERR_FATAL;
542 }
543 }
544 /* end of user/group name handling*/
545 else if (!strcmp(args[0], "nbproc")) {
546 if (alertif_too_many_args(1, file, linenum, args, &err_code))
547 goto out;
548 if (*(args[1]) == 0) {
549 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
550 err_code |= ERR_ALERT | ERR_FATAL;
551 goto out;
552 }
553 global.nbproc = atol(args[1]);
Willy Tarreaua38a7172019-02-02 17:11:28 +0100554 all_proc_mask = nbits(global.nbproc);
Willy Tarreauff9c9142019-02-07 10:39:36 +0100555 if (global.nbproc < 1 || global.nbproc > MAX_PROCS) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100556 ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
Willy Tarreauff9c9142019-02-07 10:39:36 +0100557 file, linenum, args[0], MAX_PROCS, global.nbproc);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100558 err_code |= ERR_ALERT | ERR_FATAL;
559 goto out;
560 }
561 }
562 else if (!strcmp(args[0], "nbthread")) {
563 if (alertif_too_many_args(1, file, linenum, args, &err_code))
564 goto out;
565 if (*(args[1]) == 0) {
566 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
567 err_code |= ERR_ALERT | ERR_FATAL;
568 goto out;
569 }
570 global.nbthread = parse_nbthread(args[1], &errmsg);
571 if (!global.nbthread) {
572 ha_alert("parsing [%s:%d] : '%s' %s.\n",
573 file, linenum, args[0], errmsg);
574 err_code |= ERR_ALERT | ERR_FATAL;
575 goto out;
576 }
577 }
578 else if (!strcmp(args[0], "maxconn")) {
579 if (alertif_too_many_args(1, file, linenum, args, &err_code))
580 goto out;
581 if (global.maxconn != 0) {
582 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
583 err_code |= ERR_ALERT;
584 goto out;
585 }
586 if (*(args[1]) == 0) {
587 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
588 err_code |= ERR_ALERT | ERR_FATAL;
589 goto out;
590 }
591 global.maxconn = atol(args[1]);
592#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100593 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
594 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);
595 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100596 err_code |= ERR_ALERT;
597 }
598#endif /* SYSTEM_MAXCONN */
599 }
600 else if (!strcmp(args[0], "ssl-server-verify")) {
601 if (alertif_too_many_args(1, file, linenum, args, &err_code))
602 goto out;
603 if (*(args[1]) == 0) {
604 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
605 err_code |= ERR_ALERT | ERR_FATAL;
606 goto out;
607 }
608 if (strcmp(args[1],"none") == 0)
609 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
610 else if (strcmp(args[1],"required") == 0)
611 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
612 else {
613 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
614 err_code |= ERR_ALERT | ERR_FATAL;
615 goto out;
616 }
617 }
618 else if (!strcmp(args[0], "maxconnrate")) {
619 if (alertif_too_many_args(1, file, linenum, args, &err_code))
620 goto out;
621 if (global.cps_lim != 0) {
622 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
623 err_code |= ERR_ALERT;
624 goto out;
625 }
626 if (*(args[1]) == 0) {
627 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
628 err_code |= ERR_ALERT | ERR_FATAL;
629 goto out;
630 }
631 global.cps_lim = atol(args[1]);
632 }
633 else if (!strcmp(args[0], "maxsessrate")) {
634 if (alertif_too_many_args(1, file, linenum, args, &err_code))
635 goto out;
636 if (global.sps_lim != 0) {
637 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
638 err_code |= ERR_ALERT;
639 goto out;
640 }
641 if (*(args[1]) == 0) {
642 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
643 err_code |= ERR_ALERT | ERR_FATAL;
644 goto out;
645 }
646 global.sps_lim = atol(args[1]);
647 }
648 else if (!strcmp(args[0], "maxsslrate")) {
649 if (alertif_too_many_args(1, file, linenum, args, &err_code))
650 goto out;
651 if (global.ssl_lim != 0) {
652 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
653 err_code |= ERR_ALERT;
654 goto out;
655 }
656 if (*(args[1]) == 0) {
657 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
658 err_code |= ERR_ALERT | ERR_FATAL;
659 goto out;
660 }
661 global.ssl_lim = atol(args[1]);
662 }
663 else if (!strcmp(args[0], "maxcomprate")) {
664 if (alertif_too_many_args(1, file, linenum, args, &err_code))
665 goto out;
666 if (*(args[1]) == 0) {
667 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
668 err_code |= ERR_ALERT | ERR_FATAL;
669 goto out;
670 }
671 global.comp_rate_lim = atoi(args[1]) * 1024;
672 }
673 else if (!strcmp(args[0], "maxpipes")) {
674 if (alertif_too_many_args(1, file, linenum, args, &err_code))
675 goto out;
676 if (global.maxpipes != 0) {
677 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
678 err_code |= ERR_ALERT;
679 goto out;
680 }
681 if (*(args[1]) == 0) {
682 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
683 err_code |= ERR_ALERT | ERR_FATAL;
684 goto out;
685 }
686 global.maxpipes = atol(args[1]);
687 }
688 else if (!strcmp(args[0], "maxzlibmem")) {
689 if (alertif_too_many_args(1, file, linenum, args, &err_code))
690 goto out;
691 if (*(args[1]) == 0) {
692 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
693 err_code |= ERR_ALERT | ERR_FATAL;
694 goto out;
695 }
696 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
697 }
698 else if (!strcmp(args[0], "maxcompcpuusage")) {
699 if (alertif_too_many_args(1, file, linenum, args, &err_code))
700 goto out;
701 if (*(args[1]) == 0) {
702 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
703 err_code |= ERR_ALERT | ERR_FATAL;
704 goto out;
705 }
706 compress_min_idle = 100 - atoi(args[1]);
707 if (compress_min_idle > 100) {
708 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
709 err_code |= ERR_ALERT | ERR_FATAL;
710 goto out;
711 }
712 }
713
714 else if (!strcmp(args[0], "ulimit-n")) {
715 if (alertif_too_many_args(1, file, linenum, args, &err_code))
716 goto out;
717 if (global.rlimit_nofile != 0) {
718 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
719 err_code |= ERR_ALERT;
720 goto out;
721 }
722 if (*(args[1]) == 0) {
723 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
724 err_code |= ERR_ALERT | ERR_FATAL;
725 goto out;
726 }
727 global.rlimit_nofile = atol(args[1]);
728 }
729 else if (!strcmp(args[0], "chroot")) {
730 if (alertif_too_many_args(1, file, linenum, args, &err_code))
731 goto out;
732 if (global.chroot != NULL) {
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 a directory as an argument.\n", file, linenum, args[0]);
739 err_code |= ERR_ALERT | ERR_FATAL;
740 goto out;
741 }
742 global.chroot = strdup(args[1]);
743 }
744 else if (!strcmp(args[0], "description")) {
745 int i, len=0;
746 char *d;
747
748 if (!*args[1]) {
749 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
750 file, linenum, args[0]);
751 err_code |= ERR_ALERT | ERR_FATAL;
752 goto out;
753 }
754
755 for (i = 1; *args[i]; i++)
756 len += strlen(args[i]) + 1;
757
758 if (global.desc)
759 free(global.desc);
760
761 global.desc = d = calloc(1, len);
762
763 d += snprintf(d, global.desc + len - d, "%s", args[1]);
764 for (i = 2; *args[i]; i++)
765 d += snprintf(d, global.desc + len - d, " %s", args[i]);
766 }
767 else if (!strcmp(args[0], "node")) {
768 int i;
769 char c;
770
771 if (alertif_too_many_args(1, file, linenum, args, &err_code))
772 goto out;
773
774 for (i=0; args[1][i]; i++) {
775 c = args[1][i];
776 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
777 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
778 break;
779 }
780
781 if (!i || args[1][i]) {
782 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
783 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
784 file, linenum, args[0]);
785 err_code |= ERR_ALERT | ERR_FATAL;
786 goto out;
787 }
788
789 if (global.node)
790 free(global.node);
791
792 global.node = strdup(args[1]);
793 }
794 else if (!strcmp(args[0], "pidfile")) {
795 if (alertif_too_many_args(1, file, linenum, args, &err_code))
796 goto out;
797 if (global.pidfile != NULL) {
798 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
799 err_code |= ERR_ALERT;
800 goto out;
801 }
802 if (*(args[1]) == 0) {
803 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
804 err_code |= ERR_ALERT | ERR_FATAL;
805 goto out;
806 }
807 global.pidfile = strdup(args[1]);
808 }
809 else if (!strcmp(args[0], "unix-bind")) {
810 int cur_arg = 1;
811 while (*(args[cur_arg])) {
812 if (!strcmp(args[cur_arg], "prefix")) {
813 if (global.unix_bind.prefix != NULL) {
814 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
815 err_code |= ERR_ALERT;
816 cur_arg += 2;
817 continue;
818 }
819
820 if (*(args[cur_arg+1]) == 0) {
821 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
822 err_code |= ERR_ALERT | ERR_FATAL;
823 goto out;
824 }
825 global.unix_bind.prefix = strdup(args[cur_arg+1]);
826 cur_arg += 2;
827 continue;
828 }
829
830 if (!strcmp(args[cur_arg], "mode")) {
831
832 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
833 cur_arg += 2;
834 continue;
835 }
836
837 if (!strcmp(args[cur_arg], "uid")) {
838
839 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
840 cur_arg += 2;
841 continue;
842 }
843
844 if (!strcmp(args[cur_arg], "gid")) {
845
846 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
847 cur_arg += 2;
848 continue;
849 }
850
851 if (!strcmp(args[cur_arg], "user")) {
852 struct passwd *user;
853
854 user = getpwnam(args[cur_arg + 1]);
855 if (!user) {
856 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
857 file, linenum, args[0], args[cur_arg + 1 ]);
858 err_code |= ERR_ALERT | ERR_FATAL;
859 goto out;
860 }
861
862 global.unix_bind.ux.uid = user->pw_uid;
863 cur_arg += 2;
864 continue;
865 }
866
867 if (!strcmp(args[cur_arg], "group")) {
868 struct group *group;
869
870 group = getgrnam(args[cur_arg + 1]);
871 if (!group) {
872 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
873 file, linenum, args[0], args[cur_arg + 1 ]);
874 err_code |= ERR_ALERT | ERR_FATAL;
875 goto out;
876 }
877
878 global.unix_bind.ux.gid = group->gr_gid;
879 cur_arg += 2;
880 continue;
881 }
882
883 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
884 file, linenum, args[0]);
885 err_code |= ERR_ALERT | ERR_FATAL;
886 goto out;
887 }
888 }
889 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
890 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) {
891 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
892 err_code |= ERR_ALERT | ERR_FATAL;
893 goto out;
894 }
895 }
896 else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */
897 char *name;
898
899 if (global.log_send_hostname != NULL) {
900 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
901 err_code |= ERR_ALERT;
902 goto out;
903 }
904
905 if (*(args[1]))
906 name = args[1];
907 else
908 name = hostname;
909
910 free(global.log_send_hostname);
911 global.log_send_hostname = strdup(name);
912 }
913 else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */
914 if (global.server_state_base != NULL) {
915 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
916 err_code |= ERR_ALERT;
917 goto out;
918 }
919
920 if (!*(args[1])) {
921 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
922 err_code |= ERR_FATAL;
923 goto out;
924 }
925
926 global.server_state_base = strdup(args[1]);
927 }
928 else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */
929 if (global.server_state_file != 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 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
937 err_code |= ERR_FATAL;
938 goto out;
939 }
940
941 global.server_state_file = strdup(args[1]);
942 }
943 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
944 if (alertif_too_many_args(1, file, linenum, args, &err_code))
945 goto out;
946 if (*(args[1]) == 0) {
947 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
948 err_code |= ERR_ALERT | ERR_FATAL;
949 goto out;
950 }
951 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +0200952 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
953 if (b_orig(&global.log_tag) == NULL) {
954 chunk_destroy(&global.log_tag);
955 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
956 err_code |= ERR_ALERT | ERR_FATAL;
957 goto out;
958 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100959 }
960 else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */
961 if (alertif_too_many_args(1, file, linenum, args, &err_code))
962 goto out;
963 if (global.spread_checks != 0) {
964 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
965 err_code |= ERR_ALERT;
966 goto out;
967 }
968 if (*(args[1]) == 0) {
969 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
970 err_code |= ERR_ALERT | ERR_FATAL;
971 goto out;
972 }
973 global.spread_checks = atol(args[1]);
974 if (global.spread_checks < 0 || global.spread_checks > 50) {
975 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
976 err_code |= ERR_ALERT | ERR_FATAL;
977 }
978 }
979 else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */
980 const char *err;
981 unsigned int val;
982
983 if (alertif_too_many_args(1, file, linenum, args, &err_code))
984 goto out;
985 if (*(args[1]) == 0) {
986 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
987 err_code |= ERR_ALERT | ERR_FATAL;
988 goto out;
989 }
990
991 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200992 if (err == PARSE_TIME_OVER) {
993 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
994 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100995 err_code |= ERR_ALERT | ERR_FATAL;
996 }
Willy Tarreau9faebe32019-06-07 19:00:37 +0200997 else if (err == PARSE_TIME_UNDER) {
998 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
999 file, linenum, args[1], args[0]);
1000 err_code |= ERR_ALERT | ERR_FATAL;
1001 }
1002 else if (err) {
1003 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 +01001004 err_code |= ERR_ALERT | ERR_FATAL;
1005 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001006 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001007 }
1008 else if (strcmp(args[0], "cpu-map") == 0) {
1009 /* map a process list to a CPU set */
1010#ifdef USE_CPU_AFFINITY
1011 char *slash;
1012 unsigned long proc = 0, thread = 0, cpus;
1013 int i, j, n, autoinc;
1014
1015 if (!*args[1] || !*args[2]) {
1016 ha_alert("parsing [%s:%d] : %s expects a process number "
1017 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1018 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001019 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001020 err_code |= ERR_ALERT | ERR_FATAL;
1021 goto out;
1022 }
1023
1024 if ((slash = strchr(args[1], '/')) != NULL)
1025 *slash = 0;
1026
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001027 /* note: we silently ignore processes over MAX_PROCS and
1028 * threads over MAX_THREADS so as not to make configurations a
1029 * pain to maintain.
1030 */
1031 if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001032 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1033 err_code |= ERR_ALERT | ERR_FATAL;
1034 goto out;
1035 }
1036
1037 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001038 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001039 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1040 err_code |= ERR_ALERT | ERR_FATAL;
1041 goto out;
1042 }
1043 *slash = '/';
1044
1045 if (autoinc && atleast2(proc) && atleast2(thread)) {
1046 ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
1047 "a process range _AND_ a thread range\n",
1048 file, linenum, args[0], args[1]);
1049 err_code |= ERR_ALERT | ERR_FATAL;
1050 goto out;
1051 }
1052 }
1053
1054 if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) {
1055 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1056 err_code |= ERR_ALERT | ERR_FATAL;
1057 goto out;
1058 }
1059
1060 if (autoinc &&
1061 my_popcountl(proc) != my_popcountl(cpus) &&
1062 my_popcountl(thread) != my_popcountl(cpus)) {
1063 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1064 "must have the same size to be automatically bound\n",
1065 file, linenum, args[0]);
1066 err_code |= ERR_ALERT | ERR_FATAL;
1067 goto out;
1068 }
1069
Willy Tarreau7764a572019-07-16 15:10:34 +02001070 /* we now have to deal with 3 real cases :
1071 * cpu-map P-Q => mapping for whole processes, numbers P to Q
1072 * cpu-map P-Q/1 => mapping of first thread of processes P to Q
1073 * cpu-map 1/T-U => mapping of threads T to U of process 1
1074 * Otherwise other combinations are silently ignored since nbthread
1075 * and nbproc cannot both be >1 :
1076 * cpu-map P-Q/T => mapping for thread T for processes P to Q.
1077 * Only one of T,Q may be > 1, others ignored.
1078 * cpu-map P/T-U => mapping for threads T to U of process P. Only
1079 * one of P,U may be > 1, others ignored.
1080 */
1081 if (!thread) {
1082 /* mapping for whole processes. E.g. cpu-map 1-4 0-3 */
Willy Tarreau81492c92019-05-03 09:41:23 +02001083 for (i = n = 0; i < MAX_PROCS; i++) {
1084 /* No mapping for this process */
1085 if (!(proc & (1UL << i)))
1086 continue;
1087
Willy Tarreau36b9e222018-11-11 15:19:52 +01001088 if (!autoinc)
1089 global.cpu_map.proc[i] = cpus;
1090 else {
1091 n += my_ffsl(cpus >> n);
1092 global.cpu_map.proc[i] = (1UL << (n-1));
1093 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001094 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001095 } else {
1096 /* Mapping at the thread level. All threads are retained
1097 * for process 1, and only thread 1 is retained for other
1098 * processes.
1099 */
1100 if (thread == 0x1) {
1101 /* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */
1102 for (i = n = 0; i < MAX_PROCS; i++) {
1103 /* No mapping for this process */
1104 if (!(proc & (1UL << i)))
1105 continue;
1106 if (!autoinc)
1107 global.cpu_map.proc_t1[i] = cpus;
1108 else {
1109 n += my_ffsl(cpus >> n);
1110 global.cpu_map.proc_t1[i] = (1UL << (n-1));
1111 }
1112 }
1113 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001114
Willy Tarreau7764a572019-07-16 15:10:34 +02001115 if (proc == 0x1) {
1116 /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
1117 for (j = n = 0; j < MAX_THREADS; j++) {
1118 /* No mapping for this thread */
1119 if (!(thread & (1UL << j)))
1120 continue;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001121
Willy Tarreau7764a572019-07-16 15:10:34 +02001122 if (!autoinc)
1123 global.cpu_map.thread[j] = cpus;
1124 else {
1125 n += my_ffsl(cpus >> n);
1126 global.cpu_map.thread[j] = (1UL << (n-1));
1127 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001128 }
1129 }
1130 }
1131#else
1132 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1133 file, linenum, args[0]);
1134 err_code |= ERR_ALERT | ERR_FATAL;
1135 goto out;
1136#endif /* ! USE_CPU_AFFINITY */
1137 }
1138 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1139 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1140 goto out;
1141
1142 if (*(args[2]) == 0) {
1143 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1144 err_code |= ERR_ALERT | ERR_FATAL;
1145 goto out;
1146 }
1147
1148 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1149 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1150 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1151 err_code |= ERR_ALERT | ERR_FATAL;
1152 goto out;
1153 }
1154 }
1155 else if (!strcmp(args[0], "unsetenv")) {
1156 int arg;
1157
1158 if (*(args[1]) == 0) {
1159 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1160 err_code |= ERR_ALERT | ERR_FATAL;
1161 goto out;
1162 }
1163
1164 for (arg = 1; *args[arg]; arg++) {
1165 if (unsetenv(args[arg]) != 0) {
1166 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1167 err_code |= ERR_ALERT | ERR_FATAL;
1168 goto out;
1169 }
1170 }
1171 }
1172 else if (!strcmp(args[0], "resetenv")) {
1173 extern char **environ;
1174 char **env = environ;
1175
1176 /* args contain variable names to keep, one per argument */
1177 while (*env) {
1178 int arg;
1179
1180 /* look for current variable in among all those we want to keep */
1181 for (arg = 1; *args[arg]; arg++) {
1182 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1183 (*env)[strlen(args[arg])] == '=')
1184 break;
1185 }
1186
1187 /* delete this variable */
1188 if (!*args[arg]) {
1189 char *delim = strchr(*env, '=');
1190
1191 if (!delim || delim - *env >= trash.size) {
1192 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1193 err_code |= ERR_ALERT | ERR_FATAL;
1194 goto out;
1195 }
1196
1197 memcpy(trash.area, *env, delim - *env);
1198 trash.area[delim - *env] = 0;
1199
1200 if (unsetenv(trash.area) != 0) {
1201 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1202 err_code |= ERR_ALERT | ERR_FATAL;
1203 goto out;
1204 }
1205 }
1206 else
1207 env++;
1208 }
1209 }
William Dauchy0fec3ab2019-10-27 20:08:11 +01001210 else if (!strcmp(args[0], "strict-limits")) { /* "no strict-limits" or "strict-limits" */
1211 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1212 goto out;
1213 if (kwm == KWM_NO)
1214 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001215 }
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001216 else if (!strcmp(args[0], "localpeer")) {
1217 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1218 goto out;
1219
1220 if (*(args[1]) == 0) {
1221 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1222 file, linenum, args[0]);
1223 err_code |= ERR_ALERT | ERR_FATAL;
1224 goto out;
1225 }
1226
1227 if (global.localpeer_cmdline != 0) {
1228 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1229 "command line argument.\n", file, linenum, args[0]);
1230 err_code |= ERR_WARN;
1231 goto out;
1232 }
1233
1234 if (cfg_peers) {
1235 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1236 file, linenum, args[0]);
1237 err_code |= ERR_WARN;
1238 goto out;
1239 }
1240
1241 free(localpeer);
1242 if ((localpeer = strdup(args[1])) == NULL) {
1243 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1244 file, linenum, args[0]);
1245 err_code |= ERR_ALERT | ERR_FATAL;
1246 goto out;
1247 }
1248 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1249 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001250 else {
1251 struct cfg_kw_list *kwl;
1252 int index;
1253 int rc;
1254
1255 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1256 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1257 if (kwl->kw[index].section != CFG_GLOBAL)
1258 continue;
1259 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
1260 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1261 if (rc < 0) {
1262 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1263 err_code |= ERR_ALERT | ERR_FATAL;
1264 }
1265 else if (rc > 0) {
1266 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1267 err_code |= ERR_WARN;
1268 goto out;
1269 }
1270 goto out;
1271 }
1272 }
1273 }
1274
1275 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
1276 err_code |= ERR_ALERT | ERR_FATAL;
1277 }
1278
1279 out:
1280 free(errmsg);
1281 return err_code;
1282}
1283