blob: fc56fbf4170da853beed85977527213ed1bd19bd [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
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010022/* some keywords that are still being parsed using strcmp() and are not
23 * registered anywhere. They are used as suggestions for mistyped words.
24 */
25static const char *common_kw_list[] = {
26 "global", "daemon", "master-worker", "noepoll", "nokqueue",
27 "noevports", "nopoll", "busy-polling", "set-dumpable",
28 "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice",
29 "nogetaddrinfo", "noreuseport", "quiet", "zero-warning",
30 "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept",
31 "tune.chksize", "tune.recv_enough", "tune.buffers.limit",
32 "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite",
33 "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server",
34 "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize",
35 "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr",
36 "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid",
37 "external-check", "user", "group", "nbproc", "nbthread", "maxconn",
38 "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate",
39 "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n",
40 "chroot", "description", "node", "pidfile", "unix-bind", "log",
41 "log-send-hostname", "server-state-base", "server-state-file",
42 "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv",
43 "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
44 "defaults", "listen", "frontend", "backend", "peers", "resolvers",
45 NULL /* must be last */
46};
47
Willy Tarreau36b9e222018-11-11 15:19:52 +010048/*
49 * parse a line in a <global> section. Returns the error code, 0 if OK, or
50 * any combination of :
51 * - ERR_ABORT: must abort ASAP
52 * - ERR_FATAL: we can continue parsing but not start the service
53 * - ERR_WARN: a warning has been emitted
54 * - ERR_ALERT: an alert has been emitted
55 * Only the two first ones can stop processing, the two others are just
56 * indicators.
57 */
58int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
59{
60 int err_code = 0;
61 char *errmsg = NULL;
62
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010063 if (strcmp(args[0], "global") == 0) { /* new section */
Willy Tarreau36b9e222018-11-11 15:19:52 +010064 /* no option, nothing special to do */
65 alertif_too_many_args(0, file, linenum, args, &err_code);
66 goto out;
67 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010068 else if (strcmp(args[0], "daemon") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010069 if (alertif_too_many_args(0, file, linenum, args, &err_code))
70 goto out;
71 global.mode |= MODE_DAEMON;
72 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010073 else if (strcmp(args[0], "master-worker") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010074 if (alertif_too_many_args(1, file, linenum, args, &err_code))
75 goto out;
76 if (*args[1]) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010077 if (strcmp(args[1], "no-exit-on-failure") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010078 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
79 } else {
80 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
81 err_code |= ERR_ALERT | ERR_FATAL;
82 goto out;
83 }
84 }
85 global.mode |= MODE_MWORKER;
86 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010087 else if (strcmp(args[0], "noepoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010088 if (alertif_too_many_args(0, file, linenum, args, &err_code))
89 goto out;
90 global.tune.options &= ~GTUNE_USE_EPOLL;
91 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010092 else if (strcmp(args[0], "nokqueue") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010093 if (alertif_too_many_args(0, file, linenum, args, &err_code))
94 goto out;
95 global.tune.options &= ~GTUNE_USE_KQUEUE;
96 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010097 else if (strcmp(args[0], "noevports") == 0) {
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +000098 if (alertif_too_many_args(0, file, linenum, args, &err_code))
99 goto out;
100 global.tune.options &= ~GTUNE_USE_EVPORTS;
101 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100102 else if (strcmp(args[0], "nopoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100103 if (alertif_too_many_args(0, file, linenum, args, &err_code))
104 goto out;
105 global.tune.options &= ~GTUNE_USE_POLL;
106 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100107 else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100108 if (alertif_too_many_args(0, file, linenum, args, &err_code))
109 goto out;
110 if (kwm == KWM_NO)
111 global.tune.options &= ~GTUNE_BUSY_POLLING;
112 else
113 global.tune.options |= GTUNE_BUSY_POLLING;
114 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100115 else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */
Willy Tarreau636848a2019-04-15 19:38:50 +0200116 if (alertif_too_many_args(0, file, linenum, args, &err_code))
117 goto out;
118 if (kwm == KWM_NO)
119 global.tune.options &= ~GTUNE_SET_DUMPABLE;
120 else
121 global.tune.options |= GTUNE_SET_DUMPABLE;
122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100123 else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
Willy Tarreaud96f1122019-12-03 07:07:36 +0100124 if (alertif_too_many_args(0, file, linenum, args, &err_code))
125 goto out;
126 if (kwm == KWM_NO)
127 global.tune.options &= ~GTUNE_INSECURE_FORK;
128 else
129 global.tune.options |= GTUNE_INSECURE_FORK;
130 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100131 else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100132 if (alertif_too_many_args(0, file, linenum, args, &err_code))
133 goto out;
134 if (kwm == KWM_NO)
135 global.tune.options &= ~GTUNE_INSECURE_SETUID;
136 else
137 global.tune.options |= GTUNE_INSECURE_SETUID;
138 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100139 else if (strcmp(args[0], "nosplice") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100140 if (alertif_too_many_args(0, file, linenum, args, &err_code))
141 goto out;
142 global.tune.options &= ~GTUNE_USE_SPLICE;
143 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100144 else if (strcmp(args[0], "nogetaddrinfo") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100145 if (alertif_too_many_args(0, file, linenum, args, &err_code))
146 goto out;
147 global.tune.options &= ~GTUNE_USE_GAI;
148 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100149 else if (strcmp(args[0], "noreuseport") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100150 if (alertif_too_many_args(0, file, linenum, args, &err_code))
151 goto out;
152 global.tune.options &= ~GTUNE_USE_REUSEPORT;
153 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100154 else if (strcmp(args[0], "quiet") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100155 if (alertif_too_many_args(0, file, linenum, args, &err_code))
156 goto out;
157 global.mode |= MODE_QUIET;
158 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100159 else if (strcmp(args[0], "zero-warning") == 0) {
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200160 if (alertif_too_many_args(0, file, linenum, args, &err_code))
161 goto out;
162 global.mode |= MODE_ZERO_WARNING;
163 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100164 else if (strcmp(args[0], "tune.runqueue-depth") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100165 if (alertif_too_many_args(1, file, linenum, args, &err_code))
166 goto out;
167 if (global.tune.runqueue_depth != 0) {
168 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
169 err_code |= ERR_ALERT;
170 goto out;
171 }
172 if (*(args[1]) == 0) {
173 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
174 err_code |= ERR_ALERT | ERR_FATAL;
175 goto out;
176 }
177 global.tune.runqueue_depth = atol(args[1]);
178
179 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100180 else if (strcmp(args[0], "tune.maxpollevents") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100181 if (alertif_too_many_args(1, file, linenum, args, &err_code))
182 goto out;
183 if (global.tune.maxpollevents != 0) {
184 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
185 err_code |= ERR_ALERT;
186 goto out;
187 }
188 if (*(args[1]) == 0) {
189 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
190 err_code |= ERR_ALERT | ERR_FATAL;
191 goto out;
192 }
193 global.tune.maxpollevents = atol(args[1]);
194 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100195 else if (strcmp(args[0], "tune.maxaccept") == 0) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200196 long max;
197
Willy Tarreau36b9e222018-11-11 15:19:52 +0100198 if (alertif_too_many_args(1, file, linenum, args, &err_code))
199 goto out;
200 if (global.tune.maxaccept != 0) {
201 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
202 err_code |= ERR_ALERT;
203 goto out;
204 }
205 if (*(args[1]) == 0) {
206 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
207 err_code |= ERR_ALERT | ERR_FATAL;
208 goto out;
209 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200210 max = atol(args[1]);
211 if (/*max < -1 || */max > INT_MAX) {
212 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
213 err_code |= ERR_ALERT | ERR_FATAL;
214 goto out;
215 }
216 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100217 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100218 else if (strcmp(args[0], "tune.chksize") == 0) {
Christopher Fauletf8c869b2020-11-25 17:33:03 +0100219 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
220 file, linenum, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100221 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100222 else if (strcmp(args[0], "tune.recv_enough") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100223 if (alertif_too_many_args(1, file, linenum, args, &err_code))
224 goto out;
225 if (*(args[1]) == 0) {
226 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
227 err_code |= ERR_ALERT | ERR_FATAL;
228 goto out;
229 }
230 global.tune.recv_enough = atol(args[1]);
231 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100232 else if (strcmp(args[0], "tune.buffers.limit") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100233 if (alertif_too_many_args(1, file, linenum, args, &err_code))
234 goto out;
235 if (*(args[1]) == 0) {
236 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
237 err_code |= ERR_ALERT | ERR_FATAL;
238 goto out;
239 }
240 global.tune.buf_limit = atol(args[1]);
241 if (global.tune.buf_limit) {
242 if (global.tune.buf_limit < 3)
243 global.tune.buf_limit = 3;
244 if (global.tune.buf_limit <= global.tune.reserved_bufs)
245 global.tune.buf_limit = global.tune.reserved_bufs + 1;
246 }
247 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100248 else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100249 if (alertif_too_many_args(1, file, linenum, args, &err_code))
250 goto out;
251 if (*(args[1]) == 0) {
252 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
253 err_code |= ERR_ALERT | ERR_FATAL;
254 goto out;
255 }
256 global.tune.reserved_bufs = atol(args[1]);
257 if (global.tune.reserved_bufs < 2)
258 global.tune.reserved_bufs = 2;
259 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
260 global.tune.buf_limit = global.tune.reserved_bufs + 1;
261 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100262 else if (strcmp(args[0], "tune.bufsize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100263 if (alertif_too_many_args(1, file, linenum, args, &err_code))
264 goto out;
265 if (*(args[1]) == 0) {
266 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
267 err_code |= ERR_ALERT | ERR_FATAL;
268 goto out;
269 }
270 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100271 /* round it up to support a two-pointer alignment at the end */
272 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100273 if (global.tune.bufsize <= 0) {
274 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
275 err_code |= ERR_ALERT | ERR_FATAL;
276 goto out;
277 }
278 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100279 else if (strcmp(args[0], "tune.maxrewrite") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100280 if (alertif_too_many_args(1, file, linenum, args, &err_code))
281 goto out;
282 if (*(args[1]) == 0) {
283 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
284 err_code |= ERR_ALERT | ERR_FATAL;
285 goto out;
286 }
287 global.tune.maxrewrite = atol(args[1]);
288 if (global.tune.maxrewrite < 0) {
289 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
290 err_code |= ERR_ALERT | ERR_FATAL;
291 goto out;
292 }
293 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100294 else if (strcmp(args[0], "tune.idletimer") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100295 unsigned int idle;
296 const char *res;
297
298 if (alertif_too_many_args(1, file, linenum, args, &err_code))
299 goto out;
300 if (*(args[1]) == 0) {
301 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
302 err_code |= ERR_ALERT | ERR_FATAL;
303 goto out;
304 }
305
306 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200307 if (res == PARSE_TIME_OVER) {
308 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
309 file, linenum, args[1], args[0]);
310 err_code |= ERR_ALERT | ERR_FATAL;
311 goto out;
312 }
313 else if (res == PARSE_TIME_UNDER) {
314 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
315 file, linenum, args[1], args[0]);
316 err_code |= ERR_ALERT | ERR_FATAL;
317 goto out;
318 }
319 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100320 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200321 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100322 err_code |= ERR_ALERT | ERR_FATAL;
323 goto out;
324 }
325
326 if (idle > 65535) {
327 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
328 err_code |= ERR_ALERT | ERR_FATAL;
329 goto out;
330 }
331 global.tune.idle_timer = idle;
332 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100333 else if (strcmp(args[0], "tune.rcvbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100334 if (alertif_too_many_args(1, file, linenum, args, &err_code))
335 goto out;
336 if (global.tune.client_rcvbuf != 0) {
337 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
338 err_code |= ERR_ALERT;
339 goto out;
340 }
341 if (*(args[1]) == 0) {
342 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
343 err_code |= ERR_ALERT | ERR_FATAL;
344 goto out;
345 }
346 global.tune.client_rcvbuf = atol(args[1]);
347 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100348 else if (strcmp(args[0], "tune.rcvbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100349 if (alertif_too_many_args(1, file, linenum, args, &err_code))
350 goto out;
351 if (global.tune.server_rcvbuf != 0) {
352 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
353 err_code |= ERR_ALERT;
354 goto out;
355 }
356 if (*(args[1]) == 0) {
357 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
358 err_code |= ERR_ALERT | ERR_FATAL;
359 goto out;
360 }
361 global.tune.server_rcvbuf = atol(args[1]);
362 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100363 else if (strcmp(args[0], "tune.sndbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100364 if (alertif_too_many_args(1, file, linenum, args, &err_code))
365 goto out;
366 if (global.tune.client_sndbuf != 0) {
367 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
368 err_code |= ERR_ALERT;
369 goto out;
370 }
371 if (*(args[1]) == 0) {
372 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
373 err_code |= ERR_ALERT | ERR_FATAL;
374 goto out;
375 }
376 global.tune.client_sndbuf = atol(args[1]);
377 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100378 else if (strcmp(args[0], "tune.sndbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100379 if (alertif_too_many_args(1, file, linenum, args, &err_code))
380 goto out;
381 if (global.tune.server_sndbuf != 0) {
382 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
383 err_code |= ERR_ALERT;
384 goto out;
385 }
386 if (*(args[1]) == 0) {
387 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
388 err_code |= ERR_ALERT | ERR_FATAL;
389 goto out;
390 }
391 global.tune.server_sndbuf = atol(args[1]);
392 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100393 else if (strcmp(args[0], "tune.pipesize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100394 if (alertif_too_many_args(1, file, linenum, args, &err_code))
395 goto out;
396 if (*(args[1]) == 0) {
397 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
398 err_code |= ERR_ALERT | ERR_FATAL;
399 goto out;
400 }
401 global.tune.pipesize = atol(args[1]);
402 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100403 else if (strcmp(args[0], "tune.http.cookielen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100404 if (alertif_too_many_args(1, file, linenum, args, &err_code))
405 goto out;
406 if (*(args[1]) == 0) {
407 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
408 err_code |= ERR_ALERT | ERR_FATAL;
409 goto out;
410 }
411 global.tune.cookie_len = atol(args[1]) + 1;
412 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100413 else if (strcmp(args[0], "tune.http.logurilen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100414 if (alertif_too_many_args(1, file, linenum, args, &err_code))
415 goto out;
416 if (*(args[1]) == 0) {
417 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
418 err_code |= ERR_ALERT | ERR_FATAL;
419 goto out;
420 }
421 global.tune.requri_len = atol(args[1]) + 1;
422 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100423 else if (strcmp(args[0], "tune.http.maxhdr") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100424 if (alertif_too_many_args(1, file, linenum, args, &err_code))
425 goto out;
426 if (*(args[1]) == 0) {
427 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
428 err_code |= ERR_ALERT | ERR_FATAL;
429 goto out;
430 }
431 global.tune.max_http_hdr = atoi(args[1]);
432 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
433 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
434 file, linenum, args[0]);
435 err_code |= ERR_ALERT | ERR_FATAL;
436 goto out;
437 }
438 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100439 else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100440 if (alertif_too_many_args(1, file, linenum, args, &err_code))
441 goto out;
442 if (*args[1]) {
443 global.tune.comp_maxlevel = atoi(args[1]);
444 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
445 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
446 file, linenum, args[0]);
447 err_code |= ERR_ALERT | ERR_FATAL;
448 goto out;
449 }
450 } else {
451 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
452 file, linenum, args[0]);
453 err_code |= ERR_ALERT | ERR_FATAL;
454 goto out;
455 }
456 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100457 else if (strcmp(args[0], "tune.pattern.cache-size") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100458 if (*args[1]) {
459 global.tune.pattern_cache = atoi(args[1]);
460 if (global.tune.pattern_cache < 0) {
461 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
462 file, linenum, args[0]);
463 err_code |= ERR_ALERT | ERR_FATAL;
464 goto out;
465 }
466 } else {
467 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
468 file, linenum, args[0]);
469 err_code |= ERR_ALERT | ERR_FATAL;
470 goto out;
471 }
472 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100473 else if (strcmp(args[0], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100474 if (alertif_too_many_args(1, file, linenum, args, &err_code))
475 goto out;
476 if (global.uid != 0) {
477 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
478 err_code |= ERR_ALERT;
479 goto out;
480 }
481 if (*(args[1]) == 0) {
482 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
483 err_code |= ERR_ALERT | ERR_FATAL;
484 goto out;
485 }
486 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
487 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]);
488 err_code |= ERR_WARN;
489 goto out;
490 }
491
492 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100493 else if (strcmp(args[0], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100494 if (alertif_too_many_args(1, file, linenum, args, &err_code))
495 goto out;
496 if (global.gid != 0) {
497 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
498 err_code |= ERR_ALERT;
499 goto out;
500 }
501 if (*(args[1]) == 0) {
502 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
503 err_code |= ERR_ALERT | ERR_FATAL;
504 goto out;
505 }
506 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
507 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]);
508 err_code |= ERR_WARN;
509 goto out;
510 }
511 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100512 else if (strcmp(args[0], "external-check") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100513 if (alertif_too_many_args(0, file, linenum, args, &err_code))
514 goto out;
515 global.external_check = 1;
516 }
517 /* user/group name handling */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100518 else if (strcmp(args[0], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100519 struct passwd *ha_user;
520 if (alertif_too_many_args(1, file, linenum, args, &err_code))
521 goto out;
522 if (global.uid != 0) {
523 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
524 err_code |= ERR_ALERT;
525 goto out;
526 }
527 errno = 0;
528 ha_user = getpwnam(args[1]);
529 if (ha_user != NULL) {
530 global.uid = (int)ha_user->pw_uid;
531 }
532 else {
533 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
534 err_code |= ERR_ALERT | ERR_FATAL;
535 }
536 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100537 else if (strcmp(args[0], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100538 struct group *ha_group;
539 if (alertif_too_many_args(1, file, linenum, args, &err_code))
540 goto out;
541 if (global.gid != 0) {
542 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
543 err_code |= ERR_ALERT;
544 goto out;
545 }
546 errno = 0;
547 ha_group = getgrnam(args[1]);
548 if (ha_group != NULL) {
549 global.gid = (int)ha_group->gr_gid;
550 }
551 else {
552 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
553 err_code |= ERR_ALERT | ERR_FATAL;
554 }
555 }
556 /* end of user/group name handling*/
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100557 else if (strcmp(args[0], "nbproc") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100558 if (alertif_too_many_args(1, file, linenum, args, &err_code))
559 goto out;
560 if (*(args[1]) == 0) {
561 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
562 err_code |= ERR_ALERT | ERR_FATAL;
563 goto out;
564 }
565 global.nbproc = atol(args[1]);
Willy Tarreaua38a7172019-02-02 17:11:28 +0100566 all_proc_mask = nbits(global.nbproc);
Willy Tarreauff9c9142019-02-07 10:39:36 +0100567 if (global.nbproc < 1 || global.nbproc > MAX_PROCS) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100568 ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
Willy Tarreauff9c9142019-02-07 10:39:36 +0100569 file, linenum, args[0], MAX_PROCS, global.nbproc);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100570 err_code |= ERR_ALERT | ERR_FATAL;
571 goto out;
572 }
573 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100574 else if (strcmp(args[0], "nbthread") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100575 if (alertif_too_many_args(1, file, linenum, args, &err_code))
576 goto out;
577 if (*(args[1]) == 0) {
578 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
579 err_code |= ERR_ALERT | ERR_FATAL;
580 goto out;
581 }
582 global.nbthread = parse_nbthread(args[1], &errmsg);
583 if (!global.nbthread) {
584 ha_alert("parsing [%s:%d] : '%s' %s.\n",
585 file, linenum, args[0], errmsg);
586 err_code |= ERR_ALERT | ERR_FATAL;
587 goto out;
588 }
589 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100590 else if (strcmp(args[0], "maxconn") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100591 if (alertif_too_many_args(1, file, linenum, args, &err_code))
592 goto out;
593 if (global.maxconn != 0) {
594 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
595 err_code |= ERR_ALERT;
596 goto out;
597 }
598 if (*(args[1]) == 0) {
599 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
600 err_code |= ERR_ALERT | ERR_FATAL;
601 goto out;
602 }
603 global.maxconn = atol(args[1]);
604#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100605 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
606 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);
607 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100608 err_code |= ERR_ALERT;
609 }
610#endif /* SYSTEM_MAXCONN */
611 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100612 else if (strcmp(args[0], "ssl-server-verify") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100613 if (alertif_too_many_args(1, file, linenum, args, &err_code))
614 goto out;
615 if (*(args[1]) == 0) {
616 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
617 err_code |= ERR_ALERT | ERR_FATAL;
618 goto out;
619 }
620 if (strcmp(args[1],"none") == 0)
621 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
622 else if (strcmp(args[1],"required") == 0)
623 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
624 else {
625 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
626 err_code |= ERR_ALERT | ERR_FATAL;
627 goto out;
628 }
629 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100630 else if (strcmp(args[0], "maxconnrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100631 if (alertif_too_many_args(1, file, linenum, args, &err_code))
632 goto out;
633 if (global.cps_lim != 0) {
634 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
635 err_code |= ERR_ALERT;
636 goto out;
637 }
638 if (*(args[1]) == 0) {
639 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
640 err_code |= ERR_ALERT | ERR_FATAL;
641 goto out;
642 }
643 global.cps_lim = atol(args[1]);
644 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100645 else if (strcmp(args[0], "maxsessrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100646 if (alertif_too_many_args(1, file, linenum, args, &err_code))
647 goto out;
648 if (global.sps_lim != 0) {
649 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
650 err_code |= ERR_ALERT;
651 goto out;
652 }
653 if (*(args[1]) == 0) {
654 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
655 err_code |= ERR_ALERT | ERR_FATAL;
656 goto out;
657 }
658 global.sps_lim = atol(args[1]);
659 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100660 else if (strcmp(args[0], "maxsslrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100661 if (alertif_too_many_args(1, file, linenum, args, &err_code))
662 goto out;
663 if (global.ssl_lim != 0) {
664 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
665 err_code |= ERR_ALERT;
666 goto out;
667 }
668 if (*(args[1]) == 0) {
669 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
670 err_code |= ERR_ALERT | ERR_FATAL;
671 goto out;
672 }
673 global.ssl_lim = atol(args[1]);
674 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100675 else if (strcmp(args[0], "maxcomprate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100676 if (alertif_too_many_args(1, file, linenum, args, &err_code))
677 goto out;
678 if (*(args[1]) == 0) {
679 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
680 err_code |= ERR_ALERT | ERR_FATAL;
681 goto out;
682 }
683 global.comp_rate_lim = atoi(args[1]) * 1024;
684 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100685 else if (strcmp(args[0], "maxpipes") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100686 if (alertif_too_many_args(1, file, linenum, args, &err_code))
687 goto out;
688 if (global.maxpipes != 0) {
689 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
690 err_code |= ERR_ALERT;
691 goto out;
692 }
693 if (*(args[1]) == 0) {
694 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
695 err_code |= ERR_ALERT | ERR_FATAL;
696 goto out;
697 }
698 global.maxpipes = atol(args[1]);
699 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100700 else if (strcmp(args[0], "maxzlibmem") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100701 if (alertif_too_many_args(1, file, linenum, args, &err_code))
702 goto out;
703 if (*(args[1]) == 0) {
704 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
705 err_code |= ERR_ALERT | ERR_FATAL;
706 goto out;
707 }
708 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
709 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100710 else if (strcmp(args[0], "maxcompcpuusage") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100711 if (alertif_too_many_args(1, file, linenum, args, &err_code))
712 goto out;
713 if (*(args[1]) == 0) {
714 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
715 err_code |= ERR_ALERT | ERR_FATAL;
716 goto out;
717 }
718 compress_min_idle = 100 - atoi(args[1]);
719 if (compress_min_idle > 100) {
720 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
721 err_code |= ERR_ALERT | ERR_FATAL;
722 goto out;
723 }
724 }
725
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100726 else if (strcmp(args[0], "ulimit-n") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100727 if (alertif_too_many_args(1, file, linenum, args, &err_code))
728 goto out;
729 if (global.rlimit_nofile != 0) {
730 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
731 err_code |= ERR_ALERT;
732 goto out;
733 }
734 if (*(args[1]) == 0) {
735 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
736 err_code |= ERR_ALERT | ERR_FATAL;
737 goto out;
738 }
739 global.rlimit_nofile = atol(args[1]);
740 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100741 else if (strcmp(args[0], "chroot") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100742 if (alertif_too_many_args(1, file, linenum, args, &err_code))
743 goto out;
744 if (global.chroot != NULL) {
745 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
746 err_code |= ERR_ALERT;
747 goto out;
748 }
749 if (*(args[1]) == 0) {
750 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
751 err_code |= ERR_ALERT | ERR_FATAL;
752 goto out;
753 }
754 global.chroot = strdup(args[1]);
755 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100756 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100757 int i, len=0;
758 char *d;
759
760 if (!*args[1]) {
761 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
762 file, linenum, args[0]);
763 err_code |= ERR_ALERT | ERR_FATAL;
764 goto out;
765 }
766
767 for (i = 1; *args[i]; i++)
768 len += strlen(args[i]) + 1;
769
770 if (global.desc)
771 free(global.desc);
772
773 global.desc = d = calloc(1, len);
774
775 d += snprintf(d, global.desc + len - d, "%s", args[1]);
776 for (i = 2; *args[i]; i++)
777 d += snprintf(d, global.desc + len - d, " %s", args[i]);
778 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100779 else if (strcmp(args[0], "node") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100780 int i;
781 char c;
782
783 if (alertif_too_many_args(1, file, linenum, args, &err_code))
784 goto out;
785
786 for (i=0; args[1][i]; i++) {
787 c = args[1][i];
788 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
789 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
790 break;
791 }
792
793 if (!i || args[1][i]) {
794 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
795 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
796 file, linenum, args[0]);
797 err_code |= ERR_ALERT | ERR_FATAL;
798 goto out;
799 }
800
801 if (global.node)
802 free(global.node);
803
804 global.node = strdup(args[1]);
805 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100806 else if (strcmp(args[0], "pidfile") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100807 if (alertif_too_many_args(1, file, linenum, args, &err_code))
808 goto out;
809 if (global.pidfile != NULL) {
810 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
811 err_code |= ERR_ALERT;
812 goto out;
813 }
814 if (*(args[1]) == 0) {
815 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
816 err_code |= ERR_ALERT | ERR_FATAL;
817 goto out;
818 }
819 global.pidfile = strdup(args[1]);
820 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100821 else if (strcmp(args[0], "unix-bind") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100822 int cur_arg = 1;
823 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100824 if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100825 if (global.unix_bind.prefix != NULL) {
826 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
827 err_code |= ERR_ALERT;
828 cur_arg += 2;
829 continue;
830 }
831
832 if (*(args[cur_arg+1]) == 0) {
833 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
834 err_code |= ERR_ALERT | ERR_FATAL;
835 goto out;
836 }
837 global.unix_bind.prefix = strdup(args[cur_arg+1]);
838 cur_arg += 2;
839 continue;
840 }
841
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100842 if (strcmp(args[cur_arg], "mode") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100843
844 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
845 cur_arg += 2;
846 continue;
847 }
848
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100849 if (strcmp(args[cur_arg], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100850
851 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
852 cur_arg += 2;
853 continue;
854 }
855
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100856 if (strcmp(args[cur_arg], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100857
858 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
859 cur_arg += 2;
860 continue;
861 }
862
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100863 if (strcmp(args[cur_arg], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100864 struct passwd *user;
865
866 user = getpwnam(args[cur_arg + 1]);
867 if (!user) {
868 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
869 file, linenum, args[0], args[cur_arg + 1 ]);
870 err_code |= ERR_ALERT | ERR_FATAL;
871 goto out;
872 }
873
874 global.unix_bind.ux.uid = user->pw_uid;
875 cur_arg += 2;
876 continue;
877 }
878
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100879 if (strcmp(args[cur_arg], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100880 struct group *group;
881
882 group = getgrnam(args[cur_arg + 1]);
883 if (!group) {
884 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
885 file, linenum, args[0], args[cur_arg + 1 ]);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto out;
888 }
889
890 global.unix_bind.ux.gid = group->gr_gid;
891 cur_arg += 2;
892 continue;
893 }
894
895 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
896 file, linenum, args[0]);
897 err_code |= ERR_ALERT | ERR_FATAL;
898 goto out;
899 }
900 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100901 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100902 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) {
903 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
904 err_code |= ERR_ALERT | ERR_FATAL;
905 goto out;
906 }
907 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100908 else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100909 char *name;
910
911 if (global.log_send_hostname != NULL) {
912 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
913 err_code |= ERR_ALERT;
914 goto out;
915 }
916
917 if (*(args[1]))
918 name = args[1];
919 else
920 name = hostname;
921
922 free(global.log_send_hostname);
923 global.log_send_hostname = strdup(name);
924 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100925 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 +0100926 if (global.server_state_base != NULL) {
927 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
928 err_code |= ERR_ALERT;
929 goto out;
930 }
931
932 if (!*(args[1])) {
933 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
934 err_code |= ERR_FATAL;
935 goto out;
936 }
937
938 global.server_state_base = strdup(args[1]);
939 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100940 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 +0100941 if (global.server_state_file != NULL) {
942 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
943 err_code |= ERR_ALERT;
944 goto out;
945 }
946
947 if (!*(args[1])) {
948 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
949 err_code |= ERR_FATAL;
950 goto out;
951 }
952
953 global.server_state_file = strdup(args[1]);
954 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100955 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100956 if (alertif_too_many_args(1, file, linenum, args, &err_code))
957 goto out;
958 if (*(args[1]) == 0) {
959 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
962 }
963 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +0200964 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
965 if (b_orig(&global.log_tag) == NULL) {
966 chunk_destroy(&global.log_tag);
967 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 goto out;
970 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100972 else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100973 if (alertif_too_many_args(1, file, linenum, args, &err_code))
974 goto out;
975 if (global.spread_checks != 0) {
976 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
977 err_code |= ERR_ALERT;
978 goto out;
979 }
980 if (*(args[1]) == 0) {
981 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
982 err_code |= ERR_ALERT | ERR_FATAL;
983 goto out;
984 }
985 global.spread_checks = atol(args[1]);
986 if (global.spread_checks < 0 || global.spread_checks > 50) {
987 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
988 err_code |= ERR_ALERT | ERR_FATAL;
989 }
990 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100991 else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100992 const char *err;
993 unsigned int val;
994
995 if (alertif_too_many_args(1, file, linenum, args, &err_code))
996 goto out;
997 if (*(args[1]) == 0) {
998 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
999 err_code |= ERR_ALERT | ERR_FATAL;
1000 goto out;
1001 }
1002
1003 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001004 if (err == PARSE_TIME_OVER) {
1005 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1006 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001007 err_code |= ERR_ALERT | ERR_FATAL;
1008 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001009 else if (err == PARSE_TIME_UNDER) {
1010 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1011 file, linenum, args[1], args[0]);
1012 err_code |= ERR_ALERT | ERR_FATAL;
1013 }
1014 else if (err) {
1015 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 +01001016 err_code |= ERR_ALERT | ERR_FATAL;
1017 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001018 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001019 }
1020 else if (strcmp(args[0], "cpu-map") == 0) {
1021 /* map a process list to a CPU set */
1022#ifdef USE_CPU_AFFINITY
1023 char *slash;
1024 unsigned long proc = 0, thread = 0, cpus;
1025 int i, j, n, autoinc;
1026
1027 if (!*args[1] || !*args[2]) {
1028 ha_alert("parsing [%s:%d] : %s expects a process number "
1029 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1030 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001031 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001032 err_code |= ERR_ALERT | ERR_FATAL;
1033 goto out;
1034 }
1035
1036 if ((slash = strchr(args[1], '/')) != NULL)
1037 *slash = 0;
1038
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001039 /* note: we silently ignore processes over MAX_PROCS and
1040 * threads over MAX_THREADS so as not to make configurations a
1041 * pain to maintain.
1042 */
1043 if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001044 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1045 err_code |= ERR_ALERT | ERR_FATAL;
1046 goto out;
1047 }
1048
1049 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001050 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001051 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1052 err_code |= ERR_ALERT | ERR_FATAL;
1053 goto out;
1054 }
1055 *slash = '/';
1056
1057 if (autoinc && atleast2(proc) && atleast2(thread)) {
1058 ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
1059 "a process range _AND_ a thread range\n",
1060 file, linenum, args[0], args[1]);
1061 err_code |= ERR_ALERT | ERR_FATAL;
1062 goto out;
1063 }
1064 }
1065
1066 if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) {
1067 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071
1072 if (autoinc &&
1073 my_popcountl(proc) != my_popcountl(cpus) &&
1074 my_popcountl(thread) != my_popcountl(cpus)) {
1075 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1076 "must have the same size to be automatically bound\n",
1077 file, linenum, args[0]);
1078 err_code |= ERR_ALERT | ERR_FATAL;
1079 goto out;
1080 }
1081
Willy Tarreau7764a572019-07-16 15:10:34 +02001082 /* we now have to deal with 3 real cases :
1083 * cpu-map P-Q => mapping for whole processes, numbers P to Q
1084 * cpu-map P-Q/1 => mapping of first thread of processes P to Q
1085 * cpu-map 1/T-U => mapping of threads T to U of process 1
1086 * Otherwise other combinations are silently ignored since nbthread
1087 * and nbproc cannot both be >1 :
1088 * cpu-map P-Q/T => mapping for thread T for processes P to Q.
1089 * Only one of T,Q may be > 1, others ignored.
1090 * cpu-map P/T-U => mapping for threads T to U of process P. Only
1091 * one of P,U may be > 1, others ignored.
1092 */
1093 if (!thread) {
1094 /* mapping for whole processes. E.g. cpu-map 1-4 0-3 */
Willy Tarreau81492c92019-05-03 09:41:23 +02001095 for (i = n = 0; i < MAX_PROCS; i++) {
1096 /* No mapping for this process */
1097 if (!(proc & (1UL << i)))
1098 continue;
1099
Willy Tarreau36b9e222018-11-11 15:19:52 +01001100 if (!autoinc)
1101 global.cpu_map.proc[i] = cpus;
1102 else {
1103 n += my_ffsl(cpus >> n);
1104 global.cpu_map.proc[i] = (1UL << (n-1));
1105 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001106 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001107 } else {
1108 /* Mapping at the thread level. All threads are retained
1109 * for process 1, and only thread 1 is retained for other
1110 * processes.
1111 */
1112 if (thread == 0x1) {
1113 /* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */
1114 for (i = n = 0; i < MAX_PROCS; i++) {
1115 /* No mapping for this process */
1116 if (!(proc & (1UL << i)))
1117 continue;
1118 if (!autoinc)
1119 global.cpu_map.proc_t1[i] = cpus;
1120 else {
1121 n += my_ffsl(cpus >> n);
1122 global.cpu_map.proc_t1[i] = (1UL << (n-1));
1123 }
1124 }
1125 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001126
Willy Tarreau7764a572019-07-16 15:10:34 +02001127 if (proc == 0x1) {
1128 /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
1129 for (j = n = 0; j < MAX_THREADS; j++) {
1130 /* No mapping for this thread */
1131 if (!(thread & (1UL << j)))
1132 continue;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001133
Willy Tarreau7764a572019-07-16 15:10:34 +02001134 if (!autoinc)
1135 global.cpu_map.thread[j] = cpus;
1136 else {
1137 n += my_ffsl(cpus >> n);
1138 global.cpu_map.thread[j] = (1UL << (n-1));
1139 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001140 }
1141 }
1142 }
1143#else
1144 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1145 file, linenum, args[0]);
1146 err_code |= ERR_ALERT | ERR_FATAL;
1147 goto out;
1148#endif /* ! USE_CPU_AFFINITY */
1149 }
1150 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1151 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1152 goto out;
1153
1154 if (*(args[2]) == 0) {
1155 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1156 err_code |= ERR_ALERT | ERR_FATAL;
1157 goto out;
1158 }
1159
1160 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1161 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1162 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1163 err_code |= ERR_ALERT | ERR_FATAL;
1164 goto out;
1165 }
1166 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001167 else if (strcmp(args[0], "unsetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001168 int arg;
1169
1170 if (*(args[1]) == 0) {
1171 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1172 err_code |= ERR_ALERT | ERR_FATAL;
1173 goto out;
1174 }
1175
1176 for (arg = 1; *args[arg]; arg++) {
1177 if (unsetenv(args[arg]) != 0) {
1178 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1179 err_code |= ERR_ALERT | ERR_FATAL;
1180 goto out;
1181 }
1182 }
1183 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001184 else if (strcmp(args[0], "resetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001185 extern char **environ;
1186 char **env = environ;
1187
1188 /* args contain variable names to keep, one per argument */
1189 while (*env) {
1190 int arg;
1191
1192 /* look for current variable in among all those we want to keep */
1193 for (arg = 1; *args[arg]; arg++) {
1194 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1195 (*env)[strlen(args[arg])] == '=')
1196 break;
1197 }
1198
1199 /* delete this variable */
1200 if (!*args[arg]) {
1201 char *delim = strchr(*env, '=');
1202
1203 if (!delim || delim - *env >= trash.size) {
1204 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1205 err_code |= ERR_ALERT | ERR_FATAL;
1206 goto out;
1207 }
1208
1209 memcpy(trash.area, *env, delim - *env);
1210 trash.area[delim - *env] = 0;
1211
1212 if (unsetenv(trash.area) != 0) {
1213 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1214 err_code |= ERR_ALERT | ERR_FATAL;
1215 goto out;
1216 }
1217 }
1218 else
1219 env++;
1220 }
1221 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001222 else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */
William Dauchy0fec3ab2019-10-27 20:08:11 +01001223 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1224 goto out;
1225 if (kwm == KWM_NO)
1226 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001227 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001228 else if (strcmp(args[0], "localpeer") == 0) {
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001229 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1230 goto out;
1231
1232 if (*(args[1]) == 0) {
1233 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1234 file, linenum, args[0]);
1235 err_code |= ERR_ALERT | ERR_FATAL;
1236 goto out;
1237 }
1238
1239 if (global.localpeer_cmdline != 0) {
1240 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1241 "command line argument.\n", file, linenum, args[0]);
1242 err_code |= ERR_WARN;
1243 goto out;
1244 }
1245
1246 if (cfg_peers) {
1247 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1248 file, linenum, args[0]);
1249 err_code |= ERR_WARN;
1250 goto out;
1251 }
1252
1253 free(localpeer);
1254 if ((localpeer = strdup(args[1])) == NULL) {
1255 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1256 file, linenum, args[0]);
1257 err_code |= ERR_ALERT | ERR_FATAL;
1258 goto out;
1259 }
1260 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1261 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001262 else {
1263 struct cfg_kw_list *kwl;
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001264 const char *best;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001265 int index;
1266 int rc;
1267
1268 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1269 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1270 if (kwl->kw[index].section != CFG_GLOBAL)
1271 continue;
1272 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
1273 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1274 if (rc < 0) {
1275 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1276 err_code |= ERR_ALERT | ERR_FATAL;
1277 }
1278 else if (rc > 0) {
1279 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1280 err_code |= ERR_WARN;
1281 goto out;
1282 }
1283 goto out;
1284 }
1285 }
1286 }
1287
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001288 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
1289 if (best)
1290 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
1291 else
1292 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau36b9e222018-11-11 15:19:52 +01001293 err_code |= ERR_ALERT | ERR_FATAL;
1294 }
1295
1296 out:
1297 free(errmsg);
1298 return err_code;
1299}
1300