blob: 84e44064dfbb02f584d726554167f8164419e414 [file] [log] [blame]
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001#define _GNU_SOURCE /* for cpu_set_t from haproxy/cpuset.h */
Willy Tarreau36b9e222018-11-11 15:19:52 +01002#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <ctype.h>
7#include <pwd.h>
8#include <grp.h>
9#include <errno.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13#include <unistd.h>
14
Eric Salama7cea6062020-10-02 11:58:19 +020015#include <haproxy/buf.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020016#include <haproxy/cfgparse.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020017#ifdef USE_CPU_AFFINITY
Amaury Denoyellec90932b2021-04-14 16:16:03 +020018#include <haproxy/cpuset.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020019#endif
Willy Tarreau0a3bd392020-06-04 08:52:38 +020020#include <haproxy/compression.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020021#include <haproxy/global.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020022#include <haproxy/log.h>
Dragan Dosen13cd54c2020-06-18 18:24:05 +020023#include <haproxy/peers.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020024#include <haproxy/tools.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010025
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010026/* some keywords that are still being parsed using strcmp() and are not
27 * registered anywhere. They are used as suggestions for mistyped words.
28 */
29static const char *common_kw_list[] = {
30 "global", "daemon", "master-worker", "noepoll", "nokqueue",
31 "noevports", "nopoll", "busy-polling", "set-dumpable",
32 "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice",
33 "nogetaddrinfo", "noreuseport", "quiet", "zero-warning",
34 "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept",
Willy Tarreaueb9d90a2021-06-11 15:29:31 +020035 "tune.recv_enough", "tune.buffers.limit",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010036 "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite",
37 "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server",
38 "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize",
39 "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr",
40 "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid",
41 "external-check", "user", "group", "nbproc", "nbthread", "maxconn",
42 "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate",
43 "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n",
44 "chroot", "description", "node", "pidfile", "unix-bind", "log",
45 "log-send-hostname", "server-state-base", "server-state-file",
46 "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv",
47 "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +010048 "numa-cpu-mapping", "defaults", "listen", "frontend", "backend",
49 "peers", "resolvers",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010050 NULL /* must be last */
51};
52
Willy Tarreau36b9e222018-11-11 15:19:52 +010053/*
54 * parse a line in a <global> section. Returns the error code, 0 if OK, or
55 * any combination of :
56 * - ERR_ABORT: must abort ASAP
57 * - ERR_FATAL: we can continue parsing but not start the service
58 * - ERR_WARN: a warning has been emitted
59 * - ERR_ALERT: an alert has been emitted
60 * Only the two first ones can stop processing, the two others are just
61 * indicators.
62 */
63int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
64{
65 int err_code = 0;
66 char *errmsg = NULL;
67
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010068 if (strcmp(args[0], "global") == 0) { /* new section */
Willy Tarreau36b9e222018-11-11 15:19:52 +010069 /* no option, nothing special to do */
70 alertif_too_many_args(0, file, linenum, args, &err_code);
71 goto out;
72 }
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +020073 else if (strcmp(args[0], "expose-experimental-directives") == 0) {
74 experimental_directives_allowed = 1;
75 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010076 else if (strcmp(args[0], "daemon") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010077 if (alertif_too_many_args(0, file, linenum, args, &err_code))
78 goto out;
79 global.mode |= MODE_DAEMON;
80 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010081 else if (strcmp(args[0], "master-worker") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010082 if (alertif_too_many_args(1, file, linenum, args, &err_code))
83 goto out;
84 if (*args[1]) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010085 if (strcmp(args[1], "no-exit-on-failure") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010086 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
87 } else {
88 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
89 err_code |= ERR_ALERT | ERR_FATAL;
90 goto out;
91 }
92 }
93 global.mode |= MODE_MWORKER;
94 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010095 else if (strcmp(args[0], "noepoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010096 if (alertif_too_many_args(0, file, linenum, args, &err_code))
97 goto out;
98 global.tune.options &= ~GTUNE_USE_EPOLL;
99 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100100 else if (strcmp(args[0], "nokqueue") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100101 if (alertif_too_many_args(0, file, linenum, args, &err_code))
102 goto out;
103 global.tune.options &= ~GTUNE_USE_KQUEUE;
104 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100105 else if (strcmp(args[0], "noevports") == 0) {
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +0000106 if (alertif_too_many_args(0, file, linenum, args, &err_code))
107 goto out;
108 global.tune.options &= ~GTUNE_USE_EVPORTS;
109 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100110 else if (strcmp(args[0], "nopoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100111 if (alertif_too_many_args(0, file, linenum, args, &err_code))
112 goto out;
113 global.tune.options &= ~GTUNE_USE_POLL;
114 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100115 else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100116 if (alertif_too_many_args(0, file, linenum, args, &err_code))
117 goto out;
118 if (kwm == KWM_NO)
119 global.tune.options &= ~GTUNE_BUSY_POLLING;
120 else
121 global.tune.options |= GTUNE_BUSY_POLLING;
122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100123 else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */
Willy Tarreau636848a2019-04-15 19:38:50 +0200124 if (alertif_too_many_args(0, file, linenum, args, &err_code))
125 goto out;
126 if (kwm == KWM_NO)
127 global.tune.options &= ~GTUNE_SET_DUMPABLE;
128 else
129 global.tune.options |= GTUNE_SET_DUMPABLE;
130 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100131 else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
Willy Tarreaud96f1122019-12-03 07:07:36 +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_FORK;
136 else
137 global.tune.options |= GTUNE_INSECURE_FORK;
138 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100139 else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100140 if (alertif_too_many_args(0, file, linenum, args, &err_code))
141 goto out;
142 if (kwm == KWM_NO)
143 global.tune.options &= ~GTUNE_INSECURE_SETUID;
144 else
145 global.tune.options |= GTUNE_INSECURE_SETUID;
146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100147 else if (strcmp(args[0], "nosplice") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100148 if (alertif_too_many_args(0, file, linenum, args, &err_code))
149 goto out;
150 global.tune.options &= ~GTUNE_USE_SPLICE;
151 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100152 else if (strcmp(args[0], "nogetaddrinfo") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100153 if (alertif_too_many_args(0, file, linenum, args, &err_code))
154 goto out;
155 global.tune.options &= ~GTUNE_USE_GAI;
156 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100157 else if (strcmp(args[0], "noreuseport") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100158 if (alertif_too_many_args(0, file, linenum, args, &err_code))
159 goto out;
160 global.tune.options &= ~GTUNE_USE_REUSEPORT;
161 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100162 else if (strcmp(args[0], "quiet") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100163 if (alertif_too_many_args(0, file, linenum, args, &err_code))
164 goto out;
165 global.mode |= MODE_QUIET;
166 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100167 else if (strcmp(args[0], "zero-warning") == 0) {
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200168 if (alertif_too_many_args(0, file, linenum, args, &err_code))
169 goto out;
170 global.mode |= MODE_ZERO_WARNING;
171 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100172 else if (strcmp(args[0], "tune.runqueue-depth") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100173 if (alertif_too_many_args(1, file, linenum, args, &err_code))
174 goto out;
175 if (global.tune.runqueue_depth != 0) {
176 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
177 err_code |= ERR_ALERT;
178 goto out;
179 }
180 if (*(args[1]) == 0) {
181 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
182 err_code |= ERR_ALERT | ERR_FATAL;
183 goto out;
184 }
185 global.tune.runqueue_depth = atol(args[1]);
186
187 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100188 else if (strcmp(args[0], "tune.maxpollevents") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100189 if (alertif_too_many_args(1, file, linenum, args, &err_code))
190 goto out;
191 if (global.tune.maxpollevents != 0) {
192 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
193 err_code |= ERR_ALERT;
194 goto out;
195 }
196 if (*(args[1]) == 0) {
197 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
198 err_code |= ERR_ALERT | ERR_FATAL;
199 goto out;
200 }
201 global.tune.maxpollevents = atol(args[1]);
202 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100203 else if (strcmp(args[0], "tune.maxaccept") == 0) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200204 long max;
205
Willy Tarreau36b9e222018-11-11 15:19:52 +0100206 if (alertif_too_many_args(1, file, linenum, args, &err_code))
207 goto out;
208 if (global.tune.maxaccept != 0) {
209 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
210 err_code |= ERR_ALERT;
211 goto out;
212 }
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 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200218 max = atol(args[1]);
219 if (/*max < -1 || */max > INT_MAX) {
220 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
221 err_code |= ERR_ALERT | ERR_FATAL;
222 goto out;
223 }
224 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100225 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100226 else if (strcmp(args[0], "tune.chksize") == 0) {
Willy Tarreaueb9d90a2021-06-11 15:29:31 +0200227 ha_alert("parsing [%s:%d]: option '%s' is not supported any more (tune.bufsize is used instead).\n", file, linenum, args[0]);
228 err_code |= ERR_ALERT | ERR_FATAL;
229 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100230 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100231 else if (strcmp(args[0], "tune.recv_enough") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100232 if (alertif_too_many_args(1, file, linenum, args, &err_code))
233 goto out;
234 if (*(args[1]) == 0) {
235 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
236 err_code |= ERR_ALERT | ERR_FATAL;
237 goto out;
238 }
239 global.tune.recv_enough = atol(args[1]);
240 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100241 else if (strcmp(args[0], "tune.buffers.limit") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100242 if (alertif_too_many_args(1, file, linenum, args, &err_code))
243 goto out;
244 if (*(args[1]) == 0) {
245 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
246 err_code |= ERR_ALERT | ERR_FATAL;
247 goto out;
248 }
249 global.tune.buf_limit = atol(args[1]);
250 if (global.tune.buf_limit) {
251 if (global.tune.buf_limit < 3)
252 global.tune.buf_limit = 3;
253 if (global.tune.buf_limit <= global.tune.reserved_bufs)
254 global.tune.buf_limit = global.tune.reserved_bufs + 1;
255 }
256 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100257 else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100258 if (alertif_too_many_args(1, file, linenum, args, &err_code))
259 goto out;
260 if (*(args[1]) == 0) {
261 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
262 err_code |= ERR_ALERT | ERR_FATAL;
263 goto out;
264 }
265 global.tune.reserved_bufs = atol(args[1]);
266 if (global.tune.reserved_bufs < 2)
267 global.tune.reserved_bufs = 2;
268 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
269 global.tune.buf_limit = global.tune.reserved_bufs + 1;
270 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100271 else if (strcmp(args[0], "tune.bufsize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100272 if (alertif_too_many_args(1, file, linenum, args, &err_code))
273 goto out;
274 if (*(args[1]) == 0) {
275 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
276 err_code |= ERR_ALERT | ERR_FATAL;
277 goto out;
278 }
279 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100280 /* round it up to support a two-pointer alignment at the end */
281 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100282 if (global.tune.bufsize <= 0) {
283 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
284 err_code |= ERR_ALERT | ERR_FATAL;
285 goto out;
286 }
287 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100288 else if (strcmp(args[0], "tune.maxrewrite") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100289 if (alertif_too_many_args(1, file, linenum, args, &err_code))
290 goto out;
291 if (*(args[1]) == 0) {
292 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
293 err_code |= ERR_ALERT | ERR_FATAL;
294 goto out;
295 }
296 global.tune.maxrewrite = atol(args[1]);
297 if (global.tune.maxrewrite < 0) {
298 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
299 err_code |= ERR_ALERT | ERR_FATAL;
300 goto out;
301 }
302 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100303 else if (strcmp(args[0], "tune.idletimer") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100304 unsigned int idle;
305 const char *res;
306
307 if (alertif_too_many_args(1, file, linenum, args, &err_code))
308 goto out;
309 if (*(args[1]) == 0) {
310 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
311 err_code |= ERR_ALERT | ERR_FATAL;
312 goto out;
313 }
314
315 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200316 if (res == PARSE_TIME_OVER) {
317 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
318 file, linenum, args[1], args[0]);
319 err_code |= ERR_ALERT | ERR_FATAL;
320 goto out;
321 }
322 else if (res == PARSE_TIME_UNDER) {
323 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
324 file, linenum, args[1], args[0]);
325 err_code |= ERR_ALERT | ERR_FATAL;
326 goto out;
327 }
328 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100329 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200330 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100331 err_code |= ERR_ALERT | ERR_FATAL;
332 goto out;
333 }
334
335 if (idle > 65535) {
336 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
337 err_code |= ERR_ALERT | ERR_FATAL;
338 goto out;
339 }
340 global.tune.idle_timer = idle;
341 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100342 else if (strcmp(args[0], "tune.rcvbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100343 if (alertif_too_many_args(1, file, linenum, args, &err_code))
344 goto out;
345 if (global.tune.client_rcvbuf != 0) {
346 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
347 err_code |= ERR_ALERT;
348 goto out;
349 }
350 if (*(args[1]) == 0) {
351 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
352 err_code |= ERR_ALERT | ERR_FATAL;
353 goto out;
354 }
355 global.tune.client_rcvbuf = atol(args[1]);
356 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100357 else if (strcmp(args[0], "tune.rcvbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100358 if (alertif_too_many_args(1, file, linenum, args, &err_code))
359 goto out;
360 if (global.tune.server_rcvbuf != 0) {
361 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
362 err_code |= ERR_ALERT;
363 goto out;
364 }
365 if (*(args[1]) == 0) {
366 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
367 err_code |= ERR_ALERT | ERR_FATAL;
368 goto out;
369 }
370 global.tune.server_rcvbuf = atol(args[1]);
371 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100372 else if (strcmp(args[0], "tune.sndbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100373 if (alertif_too_many_args(1, file, linenum, args, &err_code))
374 goto out;
375 if (global.tune.client_sndbuf != 0) {
376 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
377 err_code |= ERR_ALERT;
378 goto out;
379 }
380 if (*(args[1]) == 0) {
381 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
382 err_code |= ERR_ALERT | ERR_FATAL;
383 goto out;
384 }
385 global.tune.client_sndbuf = atol(args[1]);
386 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100387 else if (strcmp(args[0], "tune.sndbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100388 if (alertif_too_many_args(1, file, linenum, args, &err_code))
389 goto out;
390 if (global.tune.server_sndbuf != 0) {
391 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
392 err_code |= ERR_ALERT;
393 goto out;
394 }
395 if (*(args[1]) == 0) {
396 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
397 err_code |= ERR_ALERT | ERR_FATAL;
398 goto out;
399 }
400 global.tune.server_sndbuf = atol(args[1]);
401 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100402 else if (strcmp(args[0], "tune.pipesize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100403 if (alertif_too_many_args(1, file, linenum, args, &err_code))
404 goto out;
405 if (*(args[1]) == 0) {
406 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
407 err_code |= ERR_ALERT | ERR_FATAL;
408 goto out;
409 }
410 global.tune.pipesize = atol(args[1]);
411 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100412 else if (strcmp(args[0], "tune.http.cookielen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100413 if (alertif_too_many_args(1, file, linenum, args, &err_code))
414 goto out;
415 if (*(args[1]) == 0) {
416 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
417 err_code |= ERR_ALERT | ERR_FATAL;
418 goto out;
419 }
420 global.tune.cookie_len = atol(args[1]) + 1;
421 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100422 else if (strcmp(args[0], "tune.http.logurilen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100423 if (alertif_too_many_args(1, file, linenum, args, &err_code))
424 goto out;
425 if (*(args[1]) == 0) {
426 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
427 err_code |= ERR_ALERT | ERR_FATAL;
428 goto out;
429 }
430 global.tune.requri_len = atol(args[1]) + 1;
431 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100432 else if (strcmp(args[0], "tune.http.maxhdr") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100433 if (alertif_too_many_args(1, file, linenum, args, &err_code))
434 goto out;
435 if (*(args[1]) == 0) {
436 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
437 err_code |= ERR_ALERT | ERR_FATAL;
438 goto out;
439 }
440 global.tune.max_http_hdr = atoi(args[1]);
441 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
442 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
443 file, linenum, args[0]);
444 err_code |= ERR_ALERT | ERR_FATAL;
445 goto out;
446 }
447 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100448 else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100449 if (alertif_too_many_args(1, file, linenum, args, &err_code))
450 goto out;
451 if (*args[1]) {
452 global.tune.comp_maxlevel = atoi(args[1]);
453 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
454 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
455 file, linenum, args[0]);
456 err_code |= ERR_ALERT | ERR_FATAL;
457 goto out;
458 }
459 } else {
460 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
461 file, linenum, args[0]);
462 err_code |= ERR_ALERT | ERR_FATAL;
463 goto out;
464 }
465 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100466 else if (strcmp(args[0], "tune.pattern.cache-size") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100467 if (*args[1]) {
468 global.tune.pattern_cache = atoi(args[1]);
469 if (global.tune.pattern_cache < 0) {
470 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
471 file, linenum, args[0]);
472 err_code |= ERR_ALERT | ERR_FATAL;
473 goto out;
474 }
475 } else {
476 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
477 file, linenum, args[0]);
478 err_code |= ERR_ALERT | ERR_FATAL;
479 goto out;
480 }
481 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100482 else if (strcmp(args[0], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100483 if (alertif_too_many_args(1, file, linenum, args, &err_code))
484 goto out;
485 if (global.uid != 0) {
486 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
487 err_code |= ERR_ALERT;
488 goto out;
489 }
490 if (*(args[1]) == 0) {
491 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
492 err_code |= ERR_ALERT | ERR_FATAL;
493 goto out;
494 }
495 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
496 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]);
497 err_code |= ERR_WARN;
498 goto out;
499 }
500
501 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100502 else if (strcmp(args[0], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100503 if (alertif_too_many_args(1, file, linenum, args, &err_code))
504 goto out;
505 if (global.gid != 0) {
506 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
507 err_code |= ERR_ALERT;
508 goto out;
509 }
510 if (*(args[1]) == 0) {
511 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
512 err_code |= ERR_ALERT | ERR_FATAL;
513 goto out;
514 }
515 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
516 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]);
517 err_code |= ERR_WARN;
518 goto out;
519 }
520 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100521 else if (strcmp(args[0], "external-check") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100522 if (alertif_too_many_args(0, file, linenum, args, &err_code))
523 goto out;
524 global.external_check = 1;
525 }
526 /* user/group name handling */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100527 else if (strcmp(args[0], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100528 struct passwd *ha_user;
529 if (alertif_too_many_args(1, file, linenum, args, &err_code))
530 goto out;
531 if (global.uid != 0) {
532 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
533 err_code |= ERR_ALERT;
534 goto out;
535 }
536 errno = 0;
537 ha_user = getpwnam(args[1]);
538 if (ha_user != NULL) {
539 global.uid = (int)ha_user->pw_uid;
540 }
541 else {
542 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
543 err_code |= ERR_ALERT | ERR_FATAL;
544 }
545 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100546 else if (strcmp(args[0], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100547 struct group *ha_group;
548 if (alertif_too_many_args(1, file, linenum, args, &err_code))
549 goto out;
550 if (global.gid != 0) {
551 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
552 err_code |= ERR_ALERT;
553 goto out;
554 }
555 errno = 0;
556 ha_group = getgrnam(args[1]);
557 if (ha_group != NULL) {
558 global.gid = (int)ha_group->gr_gid;
559 }
560 else {
561 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
562 err_code |= ERR_ALERT | ERR_FATAL;
563 }
564 }
565 /* end of user/group name handling*/
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100566 else if (strcmp(args[0], "nbproc") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100567 if (alertif_too_many_args(1, file, linenum, args, &err_code))
568 goto out;
569 if (*(args[1]) == 0) {
570 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
571 err_code |= ERR_ALERT | ERR_FATAL;
572 goto out;
573 }
574 global.nbproc = atol(args[1]);
Willy Tarreaua38a7172019-02-02 17:11:28 +0100575 all_proc_mask = nbits(global.nbproc);
Willy Tarreauff9c9142019-02-07 10:39:36 +0100576 if (global.nbproc < 1 || global.nbproc > MAX_PROCS) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100577 ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
Willy Tarreauff9c9142019-02-07 10:39:36 +0100578 file, linenum, args[0], MAX_PROCS, global.nbproc);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100579 err_code |= ERR_ALERT | ERR_FATAL;
580 goto out;
581 }
582 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100583 else if (strcmp(args[0], "nbthread") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100584 if (alertif_too_many_args(1, file, linenum, args, &err_code))
585 goto out;
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 }
Amaury Denoyellec4d47d62021-03-29 10:41:15 +0200591
592 HA_DIAG_WARNING_COND(global.nbthread,
593 "parsing [%s:%d] : nbthread is already defined and will be overridden.\n",
594 file, linenum);
595
Willy Tarreau36b9e222018-11-11 15:19:52 +0100596 global.nbthread = parse_nbthread(args[1], &errmsg);
597 if (!global.nbthread) {
598 ha_alert("parsing [%s:%d] : '%s' %s.\n",
599 file, linenum, args[0], errmsg);
600 err_code |= ERR_ALERT | ERR_FATAL;
601 goto out;
602 }
603 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100604 else if (strcmp(args[0], "maxconn") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100605 if (alertif_too_many_args(1, file, linenum, args, &err_code))
606 goto out;
607 if (global.maxconn != 0) {
608 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
609 err_code |= ERR_ALERT;
610 goto out;
611 }
612 if (*(args[1]) == 0) {
613 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
614 err_code |= ERR_ALERT | ERR_FATAL;
615 goto out;
616 }
617 global.maxconn = atol(args[1]);
618#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100619 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
620 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);
621 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100622 err_code |= ERR_ALERT;
623 }
624#endif /* SYSTEM_MAXCONN */
625 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100626 else if (strcmp(args[0], "ssl-server-verify") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100627 if (alertif_too_many_args(1, file, linenum, args, &err_code))
628 goto out;
629 if (*(args[1]) == 0) {
630 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
631 err_code |= ERR_ALERT | ERR_FATAL;
632 goto out;
633 }
634 if (strcmp(args[1],"none") == 0)
635 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
636 else if (strcmp(args[1],"required") == 0)
637 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
638 else {
639 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
640 err_code |= ERR_ALERT | ERR_FATAL;
641 goto out;
642 }
643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100644 else if (strcmp(args[0], "maxconnrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100645 if (alertif_too_many_args(1, file, linenum, args, &err_code))
646 goto out;
647 if (global.cps_lim != 0) {
648 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
649 err_code |= ERR_ALERT;
650 goto out;
651 }
652 if (*(args[1]) == 0) {
653 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
654 err_code |= ERR_ALERT | ERR_FATAL;
655 goto out;
656 }
657 global.cps_lim = atol(args[1]);
658 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100659 else if (strcmp(args[0], "maxsessrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100660 if (alertif_too_many_args(1, file, linenum, args, &err_code))
661 goto out;
662 if (global.sps_lim != 0) {
663 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
664 err_code |= ERR_ALERT;
665 goto out;
666 }
667 if (*(args[1]) == 0) {
668 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
669 err_code |= ERR_ALERT | ERR_FATAL;
670 goto out;
671 }
672 global.sps_lim = atol(args[1]);
673 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100674 else if (strcmp(args[0], "maxsslrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100675 if (alertif_too_many_args(1, file, linenum, args, &err_code))
676 goto out;
677 if (global.ssl_lim != 0) {
678 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
679 err_code |= ERR_ALERT;
680 goto out;
681 }
682 if (*(args[1]) == 0) {
683 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
684 err_code |= ERR_ALERT | ERR_FATAL;
685 goto out;
686 }
687 global.ssl_lim = atol(args[1]);
688 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100689 else if (strcmp(args[0], "maxcomprate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100690 if (alertif_too_many_args(1, file, linenum, args, &err_code))
691 goto out;
692 if (*(args[1]) == 0) {
693 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
694 err_code |= ERR_ALERT | ERR_FATAL;
695 goto out;
696 }
697 global.comp_rate_lim = atoi(args[1]) * 1024;
698 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100699 else if (strcmp(args[0], "maxpipes") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100700 if (alertif_too_many_args(1, file, linenum, args, &err_code))
701 goto out;
702 if (global.maxpipes != 0) {
703 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
704 err_code |= ERR_ALERT;
705 goto out;
706 }
707 if (*(args[1]) == 0) {
708 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
709 err_code |= ERR_ALERT | ERR_FATAL;
710 goto out;
711 }
712 global.maxpipes = atol(args[1]);
713 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100714 else if (strcmp(args[0], "maxzlibmem") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100715 if (alertif_too_many_args(1, file, linenum, args, &err_code))
716 goto out;
717 if (*(args[1]) == 0) {
718 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
719 err_code |= ERR_ALERT | ERR_FATAL;
720 goto out;
721 }
722 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
723 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100724 else if (strcmp(args[0], "maxcompcpuusage") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100725 if (alertif_too_many_args(1, file, linenum, args, &err_code))
726 goto out;
727 if (*(args[1]) == 0) {
728 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
729 err_code |= ERR_ALERT | ERR_FATAL;
730 goto out;
731 }
732 compress_min_idle = 100 - atoi(args[1]);
733 if (compress_min_idle > 100) {
734 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
735 err_code |= ERR_ALERT | ERR_FATAL;
736 goto out;
737 }
738 }
739
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100740 else if (strcmp(args[0], "ulimit-n") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100741 if (alertif_too_many_args(1, file, linenum, args, &err_code))
742 goto out;
743 if (global.rlimit_nofile != 0) {
744 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
745 err_code |= ERR_ALERT;
746 goto out;
747 }
748 if (*(args[1]) == 0) {
749 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
750 err_code |= ERR_ALERT | ERR_FATAL;
751 goto out;
752 }
753 global.rlimit_nofile = atol(args[1]);
754 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100755 else if (strcmp(args[0], "chroot") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100756 if (alertif_too_many_args(1, file, linenum, args, &err_code))
757 goto out;
758 if (global.chroot != NULL) {
759 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
760 err_code |= ERR_ALERT;
761 goto out;
762 }
763 if (*(args[1]) == 0) {
764 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
765 err_code |= ERR_ALERT | ERR_FATAL;
766 goto out;
767 }
768 global.chroot = strdup(args[1]);
769 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100770 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100771 int i, len=0;
772 char *d;
773
774 if (!*args[1]) {
775 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
776 file, linenum, args[0]);
777 err_code |= ERR_ALERT | ERR_FATAL;
778 goto out;
779 }
780
781 for (i = 1; *args[i]; i++)
782 len += strlen(args[i]) + 1;
783
784 if (global.desc)
785 free(global.desc);
786
787 global.desc = d = calloc(1, len);
788
789 d += snprintf(d, global.desc + len - d, "%s", args[1]);
790 for (i = 2; *args[i]; i++)
791 d += snprintf(d, global.desc + len - d, " %s", args[i]);
792 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100793 else if (strcmp(args[0], "node") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100794 int i;
795 char c;
796
797 if (alertif_too_many_args(1, file, linenum, args, &err_code))
798 goto out;
799
800 for (i=0; args[1][i]; i++) {
801 c = args[1][i];
802 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
803 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
804 break;
805 }
806
807 if (!i || args[1][i]) {
808 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
809 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
810 file, linenum, args[0]);
811 err_code |= ERR_ALERT | ERR_FATAL;
812 goto out;
813 }
814
815 if (global.node)
816 free(global.node);
817
818 global.node = strdup(args[1]);
819 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100820 else if (strcmp(args[0], "pidfile") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100821 if (alertif_too_many_args(1, file, linenum, args, &err_code))
822 goto out;
823 if (global.pidfile != NULL) {
824 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
825 err_code |= ERR_ALERT;
826 goto out;
827 }
828 if (*(args[1]) == 0) {
829 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
830 err_code |= ERR_ALERT | ERR_FATAL;
831 goto out;
832 }
833 global.pidfile = strdup(args[1]);
834 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100835 else if (strcmp(args[0], "unix-bind") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100836 int cur_arg = 1;
837 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100838 if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100839 if (global.unix_bind.prefix != NULL) {
840 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
841 err_code |= ERR_ALERT;
842 cur_arg += 2;
843 continue;
844 }
845
846 if (*(args[cur_arg+1]) == 0) {
847 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
848 err_code |= ERR_ALERT | ERR_FATAL;
849 goto out;
850 }
851 global.unix_bind.prefix = strdup(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], "mode") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100857
858 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
859 cur_arg += 2;
860 continue;
861 }
862
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100863 if (strcmp(args[cur_arg], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100864
865 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
866 cur_arg += 2;
867 continue;
868 }
869
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100870 if (strcmp(args[cur_arg], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100871
872 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
873 cur_arg += 2;
874 continue;
875 }
876
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100877 if (strcmp(args[cur_arg], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100878 struct passwd *user;
879
880 user = getpwnam(args[cur_arg + 1]);
881 if (!user) {
882 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
883 file, linenum, args[0], args[cur_arg + 1 ]);
884 err_code |= ERR_ALERT | ERR_FATAL;
885 goto out;
886 }
887
888 global.unix_bind.ux.uid = user->pw_uid;
889 cur_arg += 2;
890 continue;
891 }
892
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100893 if (strcmp(args[cur_arg], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100894 struct group *group;
895
896 group = getgrnam(args[cur_arg + 1]);
897 if (!group) {
898 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
899 file, linenum, args[0], args[cur_arg + 1 ]);
900 err_code |= ERR_ALERT | ERR_FATAL;
901 goto out;
902 }
903
904 global.unix_bind.ux.gid = group->gr_gid;
905 cur_arg += 2;
906 continue;
907 }
908
909 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
910 file, linenum, args[0]);
911 err_code |= ERR_ALERT | ERR_FATAL;
912 goto out;
913 }
914 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100915 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +0200916 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100917 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100922 else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100923 char *name;
924
925 if (global.log_send_hostname != NULL) {
926 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
927 err_code |= ERR_ALERT;
928 goto out;
929 }
930
931 if (*(args[1]))
932 name = args[1];
933 else
934 name = hostname;
935
936 free(global.log_send_hostname);
937 global.log_send_hostname = strdup(name);
938 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100939 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 +0100940 if (global.server_state_base != NULL) {
941 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
942 err_code |= ERR_ALERT;
943 goto out;
944 }
945
946 if (!*(args[1])) {
947 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
948 err_code |= ERR_FATAL;
949 goto out;
950 }
951
952 global.server_state_base = strdup(args[1]);
953 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100954 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 +0100955 if (global.server_state_file != NULL) {
956 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
957 err_code |= ERR_ALERT;
958 goto out;
959 }
960
961 if (!*(args[1])) {
962 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
963 err_code |= ERR_FATAL;
964 goto out;
965 }
966
967 global.server_state_file = strdup(args[1]);
968 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100969 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100970 if (alertif_too_many_args(1, file, linenum, args, &err_code))
971 goto out;
972 if (*(args[1]) == 0) {
973 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
974 err_code |= ERR_ALERT | ERR_FATAL;
975 goto out;
976 }
977 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +0200978 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
979 if (b_orig(&global.log_tag) == NULL) {
980 chunk_destroy(&global.log_tag);
981 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
982 err_code |= ERR_ALERT | ERR_FATAL;
983 goto out;
984 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100985 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100986 else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100987 if (alertif_too_many_args(1, file, linenum, args, &err_code))
988 goto out;
989 if (global.spread_checks != 0) {
990 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
991 err_code |= ERR_ALERT;
992 goto out;
993 }
994 if (*(args[1]) == 0) {
995 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
996 err_code |= ERR_ALERT | ERR_FATAL;
997 goto out;
998 }
999 global.spread_checks = atol(args[1]);
1000 if (global.spread_checks < 0 || global.spread_checks > 50) {
1001 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
1002 err_code |= ERR_ALERT | ERR_FATAL;
1003 }
1004 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001005 else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001006 const char *err;
1007 unsigned int val;
1008
1009 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1010 goto out;
1011 if (*(args[1]) == 0) {
1012 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1013 err_code |= ERR_ALERT | ERR_FATAL;
1014 goto out;
1015 }
1016
1017 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001018 if (err == PARSE_TIME_OVER) {
1019 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1020 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001021 err_code |= ERR_ALERT | ERR_FATAL;
1022 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001023 else if (err == PARSE_TIME_UNDER) {
1024 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1025 file, linenum, args[1], args[0]);
1026 err_code |= ERR_ALERT | ERR_FATAL;
1027 }
1028 else if (err) {
1029 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 +01001030 err_code |= ERR_ALERT | ERR_FATAL;
1031 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001032 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001033 }
1034 else if (strcmp(args[0], "cpu-map") == 0) {
1035 /* map a process list to a CPU set */
1036#ifdef USE_CPU_AFFINITY
1037 char *slash;
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001038 unsigned long proc = 0, thread = 0;
1039 int i, j, n, autoinc;
1040 struct hap_cpuset cpus, cpus_copy;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001041
1042 if (!*args[1] || !*args[2]) {
1043 ha_alert("parsing [%s:%d] : %s expects a process number "
1044 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1045 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001046 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001047 err_code |= ERR_ALERT | ERR_FATAL;
1048 goto out;
1049 }
1050
1051 if ((slash = strchr(args[1], '/')) != NULL)
1052 *slash = 0;
1053
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001054 /* note: we silently ignore processes over MAX_PROCS and
1055 * threads over MAX_THREADS so as not to make configurations a
1056 * pain to maintain.
1057 */
1058 if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001059 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1060 err_code |= ERR_ALERT | ERR_FATAL;
1061 goto out;
1062 }
1063
1064 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001065 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001066 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1067 err_code |= ERR_ALERT | ERR_FATAL;
1068 goto out;
1069 }
1070 *slash = '/';
1071
1072 if (autoinc && atleast2(proc) && atleast2(thread)) {
1073 ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
1074 "a process range _AND_ a thread range\n",
1075 file, linenum, args[0], args[1]);
1076 err_code |= ERR_ALERT | ERR_FATAL;
1077 goto out;
1078 }
1079 }
1080
Amaury Denoyellea8082352021-04-06 16:46:15 +02001081 if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001082 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1083 err_code |= ERR_ALERT | ERR_FATAL;
1084 goto out;
1085 }
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001086
Willy Tarreau36b9e222018-11-11 15:19:52 +01001087 if (autoinc &&
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001088 my_popcountl(proc) != ha_cpuset_count(&cpus) &&
1089 my_popcountl(thread) != ha_cpuset_count(&cpus)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001090 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1091 "must have the same size to be automatically bound\n",
1092 file, linenum, args[0]);
1093 err_code |= ERR_ALERT | ERR_FATAL;
1094 goto out;
1095 }
1096
Willy Tarreau7764a572019-07-16 15:10:34 +02001097 /* we now have to deal with 3 real cases :
1098 * cpu-map P-Q => mapping for whole processes, numbers P to Q
1099 * cpu-map P-Q/1 => mapping of first thread of processes P to Q
1100 * cpu-map 1/T-U => mapping of threads T to U of process 1
1101 * Otherwise other combinations are silently ignored since nbthread
1102 * and nbproc cannot both be >1 :
1103 * cpu-map P-Q/T => mapping for thread T for processes P to Q.
1104 * Only one of T,Q may be > 1, others ignored.
1105 * cpu-map P/T-U => mapping for threads T to U of process P. Only
1106 * one of P,U may be > 1, others ignored.
1107 */
1108 if (!thread) {
1109 /* mapping for whole processes. E.g. cpu-map 1-4 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001110 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau81492c92019-05-03 09:41:23 +02001111 for (i = n = 0; i < MAX_PROCS; i++) {
1112 /* No mapping for this process */
1113 if (!(proc & (1UL << i)))
1114 continue;
1115
Willy Tarreau36b9e222018-11-11 15:19:52 +01001116 if (!autoinc)
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001117 ha_cpuset_assign(&cpu_map.proc[i], &cpus);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001118 else {
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001119 ha_cpuset_zero(&cpu_map.proc[i]);
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001120 n = ha_cpuset_ffs(&cpus_copy) - 1;
1121 ha_cpuset_clr(&cpus_copy, n);
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001122 ha_cpuset_set(&cpu_map.proc[i], n);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001123 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001124 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001125 } else {
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001126 /* Mapping at the thread level.
1127 * Either proc and/or thread must be 1 and only 1. All
1128 * other combinations are silently ignored.
Willy Tarreau7764a572019-07-16 15:10:34 +02001129 */
1130 if (thread == 0x1) {
1131 /* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001132 struct hap_cpuset *dst;
1133
1134 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001135 for (i = n = 0; i < MAX_PROCS; i++) {
1136 /* No mapping for this process */
1137 if (!(proc & (1UL << i)))
1138 continue;
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001139
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001140 /* For first process, thread[0] is used.
1141 * Use proc_t1[N] for all others
1142 */
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001143 dst = i ? &cpu_map.proc_t1[i] :
1144 &cpu_map.thread[0];
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001145
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001146 if (!autoinc) {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001147 ha_cpuset_assign(dst, &cpus);
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001148 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001149 else {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001150 ha_cpuset_zero(dst);
1151 n = ha_cpuset_ffs(&cpus_copy) - 1;
1152 ha_cpuset_clr(&cpus_copy, n);
1153 ha_cpuset_set(dst, n);
Willy Tarreau7764a572019-07-16 15:10:34 +02001154 }
1155 }
1156 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001157
Willy Tarreau7764a572019-07-16 15:10:34 +02001158 if (proc == 0x1) {
1159 /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001160 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001161 for (j = n = 0; j < MAX_THREADS; j++) {
1162 /* No mapping for this thread */
1163 if (!(thread & (1UL << j)))
1164 continue;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001165
Willy Tarreau7764a572019-07-16 15:10:34 +02001166 if (!autoinc)
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001167 ha_cpuset_assign(&cpu_map.thread[j], &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001168 else {
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001169 ha_cpuset_zero(&cpu_map.thread[j]);
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001170 n = ha_cpuset_ffs(&cpus_copy) - 1;
1171 ha_cpuset_clr(&cpus_copy, n);
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001172 ha_cpuset_set(&cpu_map.thread[j], n);
Willy Tarreau7764a572019-07-16 15:10:34 +02001173 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001174 }
1175 }
Amaury Denoyellea2944ec2021-04-15 18:07:07 +02001176
1177 HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1,
1178 "parsing [%s:%d] : cpu-map statement is considered invalid and thus ignored as it addresses multiple processes and threads at the same time. At least one of them should be 1 and only 1.", file, linenum);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001179 }
1180#else
1181 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1182 file, linenum, args[0]);
1183 err_code |= ERR_ALERT | ERR_FATAL;
1184 goto out;
1185#endif /* ! USE_CPU_AFFINITY */
1186 }
1187 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1188 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1189 goto out;
1190
1191 if (*(args[2]) == 0) {
1192 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1193 err_code |= ERR_ALERT | ERR_FATAL;
1194 goto out;
1195 }
1196
1197 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1198 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1199 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1200 err_code |= ERR_ALERT | ERR_FATAL;
1201 goto out;
1202 }
1203 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001204 else if (strcmp(args[0], "unsetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001205 int arg;
1206
1207 if (*(args[1]) == 0) {
1208 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1209 err_code |= ERR_ALERT | ERR_FATAL;
1210 goto out;
1211 }
1212
1213 for (arg = 1; *args[arg]; arg++) {
1214 if (unsetenv(args[arg]) != 0) {
1215 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1216 err_code |= ERR_ALERT | ERR_FATAL;
1217 goto out;
1218 }
1219 }
1220 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001221 else if (strcmp(args[0], "resetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001222 extern char **environ;
1223 char **env = environ;
1224
1225 /* args contain variable names to keep, one per argument */
1226 while (*env) {
1227 int arg;
1228
1229 /* look for current variable in among all those we want to keep */
1230 for (arg = 1; *args[arg]; arg++) {
1231 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1232 (*env)[strlen(args[arg])] == '=')
1233 break;
1234 }
1235
1236 /* delete this variable */
1237 if (!*args[arg]) {
1238 char *delim = strchr(*env, '=');
1239
1240 if (!delim || delim - *env >= trash.size) {
1241 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1242 err_code |= ERR_ALERT | ERR_FATAL;
1243 goto out;
1244 }
1245
1246 memcpy(trash.area, *env, delim - *env);
1247 trash.area[delim - *env] = 0;
1248
1249 if (unsetenv(trash.area) != 0) {
1250 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1251 err_code |= ERR_ALERT | ERR_FATAL;
1252 goto out;
1253 }
1254 }
1255 else
1256 env++;
1257 }
1258 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001259 else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */
William Dauchy0fec3ab2019-10-27 20:08:11 +01001260 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1261 goto out;
1262 if (kwm == KWM_NO)
1263 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001264 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001265 else if (strcmp(args[0], "localpeer") == 0) {
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001266 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1267 goto out;
1268
1269 if (*(args[1]) == 0) {
1270 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1271 file, linenum, args[0]);
1272 err_code |= ERR_ALERT | ERR_FATAL;
1273 goto out;
1274 }
1275
1276 if (global.localpeer_cmdline != 0) {
1277 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1278 "command line argument.\n", file, linenum, args[0]);
1279 err_code |= ERR_WARN;
1280 goto out;
1281 }
1282
1283 if (cfg_peers) {
1284 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1285 file, linenum, args[0]);
1286 err_code |= ERR_WARN;
1287 goto out;
1288 }
1289
1290 free(localpeer);
1291 if ((localpeer = strdup(args[1])) == NULL) {
1292 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1293 file, linenum, args[0]);
1294 err_code |= ERR_ALERT | ERR_FATAL;
1295 goto out;
1296 }
1297 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1298 }
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +01001299 else if (strcmp(args[0], "numa-cpu-mapping") == 0) {
1300 global.numa_cpu_mapping = (kwm == KWM_NO) ? 0 : 1;
1301 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001302 else {
1303 struct cfg_kw_list *kwl;
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001304 const char *best;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001305 int index;
1306 int rc;
1307
1308 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1309 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1310 if (kwl->kw[index].section != CFG_GLOBAL)
1311 continue;
1312 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001313 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02001314 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001315 err_code |= ERR_ALERT | ERR_FATAL;
1316 goto out;
1317 }
1318
Willy Tarreau36b9e222018-11-11 15:19:52 +01001319 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1320 if (rc < 0) {
1321 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1322 err_code |= ERR_ALERT | ERR_FATAL;
1323 }
1324 else if (rc > 0) {
1325 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1326 err_code |= ERR_WARN;
1327 goto out;
1328 }
1329 goto out;
1330 }
1331 }
1332 }
1333
Willy Tarreau101df312021-03-15 09:12:41 +01001334 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list);
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001335 if (best)
1336 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
1337 else
1338 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau36b9e222018-11-11 15:19:52 +01001339 err_code |= ERR_ALERT | ERR_FATAL;
1340 }
1341
1342 out:
1343 free(errmsg);
1344 return err_code;
1345}
1346