blob: 76d1769043c935d23c1260b99bc90b4f400a0ab3 [file] [log] [blame]
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001#define _GNU_SOURCE /* for cpu_set_t from haproxy/cpuset.h */
Willy Tarreau36b9e222018-11-11 15:19:52 +01002#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <ctype.h>
7#include <pwd.h>
8#include <grp.h>
9#include <errno.h>
10#include <sys/types.h>
11#include <sys/stat.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010012#include <unistd.h>
13
Eric Salama7cea6062020-10-02 11:58:19 +020014#include <haproxy/buf.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020015#include <haproxy/cfgparse.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020016#ifdef USE_CPU_AFFINITY
Amaury Denoyellec90932b2021-04-14 16:16:03 +020017#include <haproxy/cpuset.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020018#endif
Willy Tarreau0a3bd392020-06-04 08:52:38 +020019#include <haproxy/compression.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020020#include <haproxy/global.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020021#include <haproxy/log.h>
Dragan Dosen13cd54c2020-06-18 18:24:05 +020022#include <haproxy/peers.h>
Willy Tarreau785b89f2023-04-22 15:09:07 +020023#include <haproxy/protocol.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",
Christopher Fauletd4eaa8a2023-02-14 15:37:14 +010040 "tune.comp.maxlevel", "tune.pattern.cache-size",
41 "tune.fast-forward", "uid", "gid",
Willy Tarreau51ec03a2021-09-22 11:55:22 +020042 "external-check", "user", "group", "nbproc", "maxconn",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010043 "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate",
44 "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n",
45 "chroot", "description", "node", "pidfile", "unix-bind", "log",
46 "log-send-hostname", "server-state-base", "server-state-file",
47 "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv",
48 "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +010049 "numa-cpu-mapping", "defaults", "listen", "frontend", "backend",
Frédéric Lécaille12a03172023-01-12 15:23:54 +010050 "peers", "resolvers", "cluster-secret", "no-quic",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010051 NULL /* must be last */
52};
53
Willy Tarreau36b9e222018-11-11 15:19:52 +010054/*
55 * parse a line in a <global> section. Returns the error code, 0 if OK, or
56 * any combination of :
57 * - ERR_ABORT: must abort ASAP
58 * - ERR_FATAL: we can continue parsing but not start the service
59 * - ERR_WARN: a warning has been emitted
60 * - ERR_ALERT: an alert has been emitted
61 * Only the two first ones can stop processing, the two others are just
62 * indicators.
63 */
64int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
65{
66 int err_code = 0;
67 char *errmsg = NULL;
68
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010069 if (strcmp(args[0], "global") == 0) { /* new section */
Willy Tarreau36b9e222018-11-11 15:19:52 +010070 /* no option, nothing special to do */
71 alertif_too_many_args(0, file, linenum, args, &err_code);
72 goto out;
73 }
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +020074 else if (strcmp(args[0], "expose-experimental-directives") == 0) {
75 experimental_directives_allowed = 1;
76 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010077 else if (strcmp(args[0], "daemon") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010078 if (alertif_too_many_args(0, file, linenum, args, &err_code))
79 goto out;
80 global.mode |= MODE_DAEMON;
81 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010082 else if (strcmp(args[0], "master-worker") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010083 if (alertif_too_many_args(1, file, linenum, args, &err_code))
84 goto out;
85 if (*args[1]) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010086 if (strcmp(args[1], "no-exit-on-failure") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010087 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
88 } else {
89 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
90 err_code |= ERR_ALERT | ERR_FATAL;
91 goto out;
92 }
93 }
94 global.mode |= MODE_MWORKER;
95 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010096 else if (strcmp(args[0], "noepoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010097 if (alertif_too_many_args(0, file, linenum, args, &err_code))
98 goto out;
99 global.tune.options &= ~GTUNE_USE_EPOLL;
100 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100101 else if (strcmp(args[0], "nokqueue") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100102 if (alertif_too_many_args(0, file, linenum, args, &err_code))
103 goto out;
104 global.tune.options &= ~GTUNE_USE_KQUEUE;
105 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100106 else if (strcmp(args[0], "noevports") == 0) {
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +0000107 if (alertif_too_many_args(0, file, linenum, args, &err_code))
108 goto out;
109 global.tune.options &= ~GTUNE_USE_EVPORTS;
110 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100111 else if (strcmp(args[0], "nopoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100112 if (alertif_too_many_args(0, file, linenum, args, &err_code))
113 goto out;
114 global.tune.options &= ~GTUNE_USE_POLL;
115 }
Frédéric Lécaille12a03172023-01-12 15:23:54 +0100116 else if (strcmp(args[0], "no-quic") == 0) {
117 if (alertif_too_many_args(0, file, linenum, args, &err_code))
118 goto out;
119
120 global.tune.options |= GTUNE_NO_QUIC;
121 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100122 else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100123 if (alertif_too_many_args(0, file, linenum, args, &err_code))
124 goto out;
125 if (kwm == KWM_NO)
126 global.tune.options &= ~GTUNE_BUSY_POLLING;
127 else
128 global.tune.options |= GTUNE_BUSY_POLLING;
129 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100130 else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */
Willy Tarreau636848a2019-04-15 19:38:50 +0200131 if (alertif_too_many_args(0, file, linenum, args, &err_code))
132 goto out;
133 if (kwm == KWM_NO)
134 global.tune.options &= ~GTUNE_SET_DUMPABLE;
135 else
136 global.tune.options |= GTUNE_SET_DUMPABLE;
137 }
Amaury Denoyellebefeae82021-07-09 17:14:30 +0200138 else if (strcmp(args[0], "h2-workaround-bogus-websocket-clients") == 0) { /* "no h2-workaround-bogus-websocket-clients" or "h2-workaround-bogus-websocket-clients" */
139 if (alertif_too_many_args(0, file, linenum, args, &err_code))
140 goto out;
141 if (kwm == KWM_NO)
142 global.tune.options &= ~GTUNE_DISABLE_H2_WEBSOCKET;
143 else
144 global.tune.options |= GTUNE_DISABLE_H2_WEBSOCKET;
145 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100146 else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
Willy Tarreaud96f1122019-12-03 07:07:36 +0100147 if (alertif_too_many_args(0, file, linenum, args, &err_code))
148 goto out;
149 if (kwm == KWM_NO)
150 global.tune.options &= ~GTUNE_INSECURE_FORK;
151 else
152 global.tune.options |= GTUNE_INSECURE_FORK;
153 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100154 else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100155 if (alertif_too_many_args(0, file, linenum, args, &err_code))
156 goto out;
157 if (kwm == KWM_NO)
158 global.tune.options &= ~GTUNE_INSECURE_SETUID;
159 else
160 global.tune.options |= GTUNE_INSECURE_SETUID;
161 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100162 else if (strcmp(args[0], "nosplice") == 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.tune.options &= ~GTUNE_USE_SPLICE;
166 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100167 else if (strcmp(args[0], "nogetaddrinfo") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100168 if (alertif_too_many_args(0, file, linenum, args, &err_code))
169 goto out;
170 global.tune.options &= ~GTUNE_USE_GAI;
171 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100172 else if (strcmp(args[0], "noreuseport") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100173 if (alertif_too_many_args(0, file, linenum, args, &err_code))
174 goto out;
Willy Tarreau785b89f2023-04-22 15:09:07 +0200175 protocol_clrf_all(PROTO_F_REUSEPORT_SUPPORTED);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100176 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100177 else if (strcmp(args[0], "quiet") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100178 if (alertif_too_many_args(0, file, linenum, args, &err_code))
179 goto out;
180 global.mode |= MODE_QUIET;
181 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100182 else if (strcmp(args[0], "zero-warning") == 0) {
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200183 if (alertif_too_many_args(0, file, linenum, args, &err_code))
184 goto out;
185 global.mode |= MODE_ZERO_WARNING;
186 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100187 else if (strcmp(args[0], "tune.runqueue-depth") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100188 if (alertif_too_many_args(1, file, linenum, args, &err_code))
189 goto out;
190 if (global.tune.runqueue_depth != 0) {
191 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
192 err_code |= ERR_ALERT;
193 goto out;
194 }
195 if (*(args[1]) == 0) {
196 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
197 err_code |= ERR_ALERT | ERR_FATAL;
198 goto out;
199 }
200 global.tune.runqueue_depth = atol(args[1]);
201
202 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100203 else if (strcmp(args[0], "tune.maxpollevents") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100204 if (alertif_too_many_args(1, file, linenum, args, &err_code))
205 goto out;
206 if (global.tune.maxpollevents != 0) {
207 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
208 err_code |= ERR_ALERT;
209 goto out;
210 }
211 if (*(args[1]) == 0) {
212 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
213 err_code |= ERR_ALERT | ERR_FATAL;
214 goto out;
215 }
216 global.tune.maxpollevents = atol(args[1]);
217 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100218 else if (strcmp(args[0], "tune.maxaccept") == 0) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200219 long max;
220
Willy Tarreau36b9e222018-11-11 15:19:52 +0100221 if (alertif_too_many_args(1, file, linenum, args, &err_code))
222 goto out;
223 if (global.tune.maxaccept != 0) {
224 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
225 err_code |= ERR_ALERT;
226 goto out;
227 }
228 if (*(args[1]) == 0) {
229 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
230 err_code |= ERR_ALERT | ERR_FATAL;
231 goto out;
232 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200233 max = atol(args[1]);
234 if (/*max < -1 || */max > INT_MAX) {
235 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
236 err_code |= ERR_ALERT | ERR_FATAL;
237 goto out;
238 }
239 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100240 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100241 else if (strcmp(args[0], "tune.chksize") == 0) {
Willy Tarreaueb9d90a2021-06-11 15:29:31 +0200242 ha_alert("parsing [%s:%d]: option '%s' is not supported any more (tune.bufsize is used instead).\n", file, linenum, args[0]);
243 err_code |= ERR_ALERT | ERR_FATAL;
244 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100245 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100246 else if (strcmp(args[0], "tune.recv_enough") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100247 if (alertif_too_many_args(1, file, linenum, args, &err_code))
248 goto out;
249 if (*(args[1]) == 0) {
250 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
251 err_code |= ERR_ALERT | ERR_FATAL;
252 goto out;
253 }
254 global.tune.recv_enough = atol(args[1]);
255 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100256 else if (strcmp(args[0], "tune.buffers.limit") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100257 if (alertif_too_many_args(1, file, linenum, args, &err_code))
258 goto out;
259 if (*(args[1]) == 0) {
260 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
261 err_code |= ERR_ALERT | ERR_FATAL;
262 goto out;
263 }
264 global.tune.buf_limit = atol(args[1]);
265 if (global.tune.buf_limit) {
266 if (global.tune.buf_limit < 3)
267 global.tune.buf_limit = 3;
268 if (global.tune.buf_limit <= global.tune.reserved_bufs)
269 global.tune.buf_limit = global.tune.reserved_bufs + 1;
270 }
271 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100272 else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100273 if (alertif_too_many_args(1, file, linenum, args, &err_code))
274 goto out;
275 if (*(args[1]) == 0) {
276 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
277 err_code |= ERR_ALERT | ERR_FATAL;
278 goto out;
279 }
280 global.tune.reserved_bufs = atol(args[1]);
281 if (global.tune.reserved_bufs < 2)
282 global.tune.reserved_bufs = 2;
283 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
284 global.tune.buf_limit = global.tune.reserved_bufs + 1;
285 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100286 else if (strcmp(args[0], "tune.bufsize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100287 if (alertif_too_many_args(1, file, linenum, args, &err_code))
288 goto out;
289 if (*(args[1]) == 0) {
290 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
291 err_code |= ERR_ALERT | ERR_FATAL;
292 goto out;
293 }
294 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100295 /* round it up to support a two-pointer alignment at the end */
296 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100297 if (global.tune.bufsize <= 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.maxrewrite") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100304 if (alertif_too_many_args(1, file, linenum, args, &err_code))
305 goto out;
306 if (*(args[1]) == 0) {
307 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
308 err_code |= ERR_ALERT | ERR_FATAL;
309 goto out;
310 }
311 global.tune.maxrewrite = atol(args[1]);
312 if (global.tune.maxrewrite < 0) {
313 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
314 err_code |= ERR_ALERT | ERR_FATAL;
315 goto out;
316 }
317 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100318 else if (strcmp(args[0], "tune.idletimer") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100319 unsigned int idle;
320 const char *res;
321
322 if (alertif_too_many_args(1, file, linenum, args, &err_code))
323 goto out;
324 if (*(args[1]) == 0) {
325 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
326 err_code |= ERR_ALERT | ERR_FATAL;
327 goto out;
328 }
329
330 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200331 if (res == PARSE_TIME_OVER) {
332 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
333 file, linenum, args[1], args[0]);
334 err_code |= ERR_ALERT | ERR_FATAL;
335 goto out;
336 }
337 else if (res == PARSE_TIME_UNDER) {
338 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
339 file, linenum, args[1], args[0]);
340 err_code |= ERR_ALERT | ERR_FATAL;
341 goto out;
342 }
343 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100344 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200345 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100346 err_code |= ERR_ALERT | ERR_FATAL;
347 goto out;
348 }
349
350 if (idle > 65535) {
351 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
352 err_code |= ERR_ALERT | ERR_FATAL;
353 goto out;
354 }
355 global.tune.idle_timer = idle;
356 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100357 else if (strcmp(args[0], "tune.rcvbuf.client") == 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.client_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.client_rcvbuf = atol(args[1]);
371 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100372 else if (strcmp(args[0], "tune.rcvbuf.server") == 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.server_rcvbuf != 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.server_rcvbuf = atol(args[1]);
386 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100387 else if (strcmp(args[0], "tune.sndbuf.client") == 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.client_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.client_sndbuf = atol(args[1]);
401 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100402 else if (strcmp(args[0], "tune.sndbuf.server") == 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 (global.tune.server_sndbuf != 0) {
406 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
407 err_code |= ERR_ALERT;
408 goto out;
409 }
410 if (*(args[1]) == 0) {
411 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
412 err_code |= ERR_ALERT | ERR_FATAL;
413 goto out;
414 }
415 global.tune.server_sndbuf = atol(args[1]);
416 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100417 else if (strcmp(args[0], "tune.pipesize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100418 if (alertif_too_many_args(1, file, linenum, args, &err_code))
419 goto out;
420 if (*(args[1]) == 0) {
421 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
422 err_code |= ERR_ALERT | ERR_FATAL;
423 goto out;
424 }
425 global.tune.pipesize = atol(args[1]);
426 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100427 else if (strcmp(args[0], "tune.http.cookielen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100428 if (alertif_too_many_args(1, file, linenum, args, &err_code))
429 goto out;
430 if (*(args[1]) == 0) {
431 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
432 err_code |= ERR_ALERT | ERR_FATAL;
433 goto out;
434 }
435 global.tune.cookie_len = atol(args[1]) + 1;
436 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100437 else if (strcmp(args[0], "tune.http.logurilen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100438 if (alertif_too_many_args(1, file, linenum, args, &err_code))
439 goto out;
440 if (*(args[1]) == 0) {
441 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
442 err_code |= ERR_ALERT | ERR_FATAL;
443 goto out;
444 }
445 global.tune.requri_len = atol(args[1]) + 1;
446 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100447 else if (strcmp(args[0], "tune.http.maxhdr") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100448 if (alertif_too_many_args(1, file, linenum, args, &err_code))
449 goto out;
450 if (*(args[1]) == 0) {
451 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
452 err_code |= ERR_ALERT | ERR_FATAL;
453 goto out;
454 }
455 global.tune.max_http_hdr = atoi(args[1]);
456 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
457 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
458 file, linenum, args[0]);
459 err_code |= ERR_ALERT | ERR_FATAL;
460 goto out;
461 }
462 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100463 else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100464 if (alertif_too_many_args(1, file, linenum, args, &err_code))
465 goto out;
466 if (*args[1]) {
467 global.tune.comp_maxlevel = atoi(args[1]);
468 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
469 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
470 file, linenum, args[0]);
471 err_code |= ERR_ALERT | ERR_FATAL;
472 goto out;
473 }
474 } else {
475 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
476 file, linenum, args[0]);
477 err_code |= ERR_ALERT | ERR_FATAL;
478 goto out;
479 }
480 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100481 else if (strcmp(args[0], "tune.pattern.cache-size") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100482 if (*args[1]) {
483 global.tune.pattern_cache = atoi(args[1]);
484 if (global.tune.pattern_cache < 0) {
485 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
486 file, linenum, args[0]);
487 err_code |= ERR_ALERT | ERR_FATAL;
488 goto out;
489 }
490 } else {
491 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
492 file, linenum, args[0]);
493 err_code |= ERR_ALERT | ERR_FATAL;
494 goto out;
495 }
496 }
Christopher Faulet2f7c82b2023-02-20 14:06:52 +0100497 else if (strcmp(args[0], "tune.disable-fast-forward") == 0) {
Christopher Fauletd4eaa8a2023-02-14 15:37:14 +0100498 if (!experimental_directives_allowed) {
499 ha_alert("parsing [%s:%d] : '%s' directive is experimental, must be allowed via a global 'expose-experimental-directives'",
500 file, linenum, args[0]);
501 err_code |= ERR_ALERT | ERR_FATAL;
502 goto out;
503 }
504 mark_tainted(TAINTED_CONFIG_EXP_KW_DECLARED);
505
Christopher Faulet2f7c82b2023-02-20 14:06:52 +0100506 if (alertif_too_many_args(0, file, linenum, args, &err_code))
Christopher Fauletd4eaa8a2023-02-14 15:37:14 +0100507 goto out;
Christopher Faulet2f7c82b2023-02-20 14:06:52 +0100508 global.tune.options &= GTUNE_USE_FAST_FWD;
Christopher Fauletd4eaa8a2023-02-14 15:37:14 +0100509 }
Frédéric Lécaille372508c2022-05-06 08:53:16 +0200510 else if (strcmp(args[0], "cluster-secret") == 0) {
511 if (alertif_too_many_args(1, file, linenum, args, &err_code))
512 goto out;
513 if (*args[1] == 0) {
514 ha_alert("parsing [%s:%d] : expects an ASCII string argument.\n", file, linenum);
515 err_code |= ERR_ALERT | ERR_FATAL;
516 goto out;
517 }
518 if (global.cluster_secret != NULL) {
519 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
520 err_code |= ERR_ALERT;
521 goto out;
522 }
523 ha_free(&global.cluster_secret);
524 global.cluster_secret = strdup(args[1]);
525 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100526 else if (strcmp(args[0], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100527 if (alertif_too_many_args(1, file, linenum, args, &err_code))
528 goto out;
529 if (global.uid != 0) {
530 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
531 err_code |= ERR_ALERT;
532 goto out;
533 }
534 if (*(args[1]) == 0) {
535 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
536 err_code |= ERR_ALERT | ERR_FATAL;
537 goto out;
538 }
539 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
540 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]);
541 err_code |= ERR_WARN;
542 goto out;
543 }
544
545 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100546 else if (strcmp(args[0], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100547 if (alertif_too_many_args(1, file, linenum, args, &err_code))
548 goto out;
549 if (global.gid != 0) {
550 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
551 err_code |= ERR_ALERT;
552 goto out;
553 }
554 if (*(args[1]) == 0) {
555 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
556 err_code |= ERR_ALERT | ERR_FATAL;
557 goto out;
558 }
559 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
560 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]);
561 err_code |= ERR_WARN;
562 goto out;
563 }
564 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100565 else if (strcmp(args[0], "external-check") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100566 if (alertif_too_many_args(0, file, linenum, args, &err_code))
567 goto out;
568 global.external_check = 1;
569 }
570 /* user/group name handling */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100571 else if (strcmp(args[0], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100572 struct passwd *ha_user;
573 if (alertif_too_many_args(1, file, linenum, args, &err_code))
574 goto out;
575 if (global.uid != 0) {
576 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
577 err_code |= ERR_ALERT;
578 goto out;
579 }
580 errno = 0;
581 ha_user = getpwnam(args[1]);
582 if (ha_user != NULL) {
583 global.uid = (int)ha_user->pw_uid;
584 }
585 else {
586 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
587 err_code |= ERR_ALERT | ERR_FATAL;
588 }
589 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100590 else if (strcmp(args[0], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100591 struct group *ha_group;
592 if (alertif_too_many_args(1, file, linenum, args, &err_code))
593 goto out;
594 if (global.gid != 0) {
595 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
596 err_code |= ERR_ALERT;
597 goto out;
598 }
599 errno = 0;
600 ha_group = getgrnam(args[1]);
601 if (ha_group != NULL) {
602 global.gid = (int)ha_group->gr_gid;
603 }
604 else {
605 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
606 err_code |= ERR_ALERT | ERR_FATAL;
607 }
608 }
609 /* end of user/group name handling*/
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100610 else if (strcmp(args[0], "nbproc") == 0) {
Willy Tarreaub63dbb72021-06-11 16:50:29 +0200611 ha_alert("parsing [%s:%d] : nbproc is not supported any more since HAProxy 2.5. Threads will automatically be used on multi-processor machines if available.\n", file, linenum);
612 err_code |= ERR_ALERT | ERR_FATAL;
613 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100614 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100615 else if (strcmp(args[0], "maxconn") == 0) {
Thierry Fournier3d1c3342022-10-01 10:06:59 +0200616 char *stop;
617
Willy Tarreau36b9e222018-11-11 15:19:52 +0100618 if (alertif_too_many_args(1, file, linenum, args, &err_code))
619 goto out;
620 if (global.maxconn != 0) {
621 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
622 err_code |= ERR_ALERT;
623 goto out;
624 }
625 if (*(args[1]) == 0) {
626 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
627 err_code |= ERR_ALERT | ERR_FATAL;
628 goto out;
629 }
Thierry Fournier3d1c3342022-10-01 10:06:59 +0200630 global.maxconn = strtol(args[1], &stop, 10);
631 if (*stop != '\0') {
632 ha_alert("parsing [%s:%d] : cannot parse '%s' value '%s', an integer is expected.\n", file, linenum, args[0], args[1]);
633 err_code |= ERR_ALERT | ERR_FATAL;
634 goto out;
635 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100636#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100637 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
638 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);
639 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100640 err_code |= ERR_ALERT;
641 }
642#endif /* SYSTEM_MAXCONN */
643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100644 else if (strcmp(args[0], "ssl-server-verify") == 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 (*(args[1]) == 0) {
648 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
649 err_code |= ERR_ALERT | ERR_FATAL;
650 goto out;
651 }
652 if (strcmp(args[1],"none") == 0)
653 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
654 else if (strcmp(args[1],"required") == 0)
655 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
656 else {
657 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
658 err_code |= ERR_ALERT | ERR_FATAL;
659 goto out;
660 }
661 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100662 else if (strcmp(args[0], "maxconnrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100663 if (alertif_too_many_args(1, file, linenum, args, &err_code))
664 goto out;
665 if (global.cps_lim != 0) {
666 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
667 err_code |= ERR_ALERT;
668 goto out;
669 }
670 if (*(args[1]) == 0) {
671 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
672 err_code |= ERR_ALERT | ERR_FATAL;
673 goto out;
674 }
675 global.cps_lim = atol(args[1]);
676 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100677 else if (strcmp(args[0], "maxsessrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100678 if (alertif_too_many_args(1, file, linenum, args, &err_code))
679 goto out;
680 if (global.sps_lim != 0) {
681 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
682 err_code |= ERR_ALERT;
683 goto out;
684 }
685 if (*(args[1]) == 0) {
686 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
687 err_code |= ERR_ALERT | ERR_FATAL;
688 goto out;
689 }
690 global.sps_lim = atol(args[1]);
691 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100692 else if (strcmp(args[0], "maxsslrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100693 if (alertif_too_many_args(1, file, linenum, args, &err_code))
694 goto out;
695 if (global.ssl_lim != 0) {
696 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
697 err_code |= ERR_ALERT;
698 goto out;
699 }
700 if (*(args[1]) == 0) {
701 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
702 err_code |= ERR_ALERT | ERR_FATAL;
703 goto out;
704 }
705 global.ssl_lim = atol(args[1]);
706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[0], "maxcomprate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100708 if (alertif_too_many_args(1, file, linenum, args, &err_code))
709 goto out;
710 if (*(args[1]) == 0) {
711 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
712 err_code |= ERR_ALERT | ERR_FATAL;
713 goto out;
714 }
715 global.comp_rate_lim = atoi(args[1]) * 1024;
716 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100717 else if (strcmp(args[0], "maxpipes") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100718 if (alertif_too_many_args(1, file, linenum, args, &err_code))
719 goto out;
720 if (global.maxpipes != 0) {
721 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
722 err_code |= ERR_ALERT;
723 goto out;
724 }
725 if (*(args[1]) == 0) {
726 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
727 err_code |= ERR_ALERT | ERR_FATAL;
728 goto out;
729 }
730 global.maxpipes = atol(args[1]);
731 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100732 else if (strcmp(args[0], "maxzlibmem") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100733 if (alertif_too_many_args(1, file, linenum, args, &err_code))
734 goto out;
735 if (*(args[1]) == 0) {
736 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
737 err_code |= ERR_ALERT | ERR_FATAL;
738 goto out;
739 }
740 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
741 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100742 else if (strcmp(args[0], "maxcompcpuusage") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100743 if (alertif_too_many_args(1, file, linenum, args, &err_code))
744 goto out;
745 if (*(args[1]) == 0) {
746 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
747 err_code |= ERR_ALERT | ERR_FATAL;
748 goto out;
749 }
750 compress_min_idle = 100 - atoi(args[1]);
751 if (compress_min_idle > 100) {
752 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
753 err_code |= ERR_ALERT | ERR_FATAL;
754 goto out;
755 }
756 }
Willy Tarreau2df1fbf2022-04-25 18:02:03 +0200757 else if (strcmp(args[0], "fd-hard-limit") == 0) {
758 if (alertif_too_many_args(1, file, linenum, args, &err_code))
759 goto out;
760 if (global.fd_hard_limit != 0) {
761 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
762 err_code |= ERR_ALERT;
763 goto out;
764 }
765 if (*(args[1]) == 0) {
766 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
767 err_code |= ERR_ALERT | ERR_FATAL;
768 goto out;
769 }
770 global.fd_hard_limit = atol(args[1]);
771 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100772 else if (strcmp(args[0], "ulimit-n") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100773 if (alertif_too_many_args(1, file, linenum, args, &err_code))
774 goto out;
775 if (global.rlimit_nofile != 0) {
776 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
777 err_code |= ERR_ALERT;
778 goto out;
779 }
780 if (*(args[1]) == 0) {
781 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
782 err_code |= ERR_ALERT | ERR_FATAL;
783 goto out;
784 }
785 global.rlimit_nofile = atol(args[1]);
786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[0], "chroot") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100788 if (alertif_too_many_args(1, file, linenum, args, &err_code))
789 goto out;
790 if (global.chroot != NULL) {
791 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
792 err_code |= ERR_ALERT;
793 goto out;
794 }
795 if (*(args[1]) == 0) {
796 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
797 err_code |= ERR_ALERT | ERR_FATAL;
798 goto out;
799 }
800 global.chroot = strdup(args[1]);
801 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100802 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100803 int i, len=0;
804 char *d;
805
806 if (!*args[1]) {
807 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
808 file, linenum, args[0]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812
813 for (i = 1; *args[i]; i++)
814 len += strlen(args[i]) + 1;
815
816 if (global.desc)
817 free(global.desc);
818
819 global.desc = d = calloc(1, len);
820
821 d += snprintf(d, global.desc + len - d, "%s", args[1]);
822 for (i = 2; *args[i]; i++)
823 d += snprintf(d, global.desc + len - d, " %s", args[i]);
824 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100825 else if (strcmp(args[0], "node") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100826 int i;
827 char c;
828
829 if (alertif_too_many_args(1, file, linenum, args, &err_code))
830 goto out;
831
832 for (i=0; args[1][i]; i++) {
833 c = args[1][i];
834 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
835 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
836 break;
837 }
838
839 if (!i || args[1][i]) {
840 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
841 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
842 file, linenum, args[0]);
843 err_code |= ERR_ALERT | ERR_FATAL;
844 goto out;
845 }
846
847 if (global.node)
848 free(global.node);
849
850 global.node = strdup(args[1]);
851 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100852 else if (strcmp(args[0], "pidfile") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100853 if (alertif_too_many_args(1, file, linenum, args, &err_code))
854 goto out;
855 if (global.pidfile != NULL) {
856 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
857 err_code |= ERR_ALERT;
858 goto out;
859 }
860 if (*(args[1]) == 0) {
861 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
862 err_code |= ERR_ALERT | ERR_FATAL;
863 goto out;
864 }
865 global.pidfile = strdup(args[1]);
866 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100867 else if (strcmp(args[0], "unix-bind") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100868 int cur_arg = 1;
869 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100870 if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100871 if (global.unix_bind.prefix != NULL) {
872 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
873 err_code |= ERR_ALERT;
874 cur_arg += 2;
875 continue;
876 }
877
878 if (*(args[cur_arg+1]) == 0) {
879 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
880 err_code |= ERR_ALERT | ERR_FATAL;
881 goto out;
882 }
883 global.unix_bind.prefix = strdup(args[cur_arg+1]);
884 cur_arg += 2;
885 continue;
886 }
887
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100888 if (strcmp(args[cur_arg], "mode") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100889
890 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
891 cur_arg += 2;
892 continue;
893 }
894
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100895 if (strcmp(args[cur_arg], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100896
897 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
898 cur_arg += 2;
899 continue;
900 }
901
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100902 if (strcmp(args[cur_arg], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100903
904 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
905 cur_arg += 2;
906 continue;
907 }
908
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100909 if (strcmp(args[cur_arg], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100910 struct passwd *user;
911
912 user = getpwnam(args[cur_arg + 1]);
913 if (!user) {
914 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
915 file, linenum, args[0], args[cur_arg + 1 ]);
916 err_code |= ERR_ALERT | ERR_FATAL;
917 goto out;
918 }
919
920 global.unix_bind.ux.uid = user->pw_uid;
921 cur_arg += 2;
922 continue;
923 }
924
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100925 if (strcmp(args[cur_arg], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100926 struct group *group;
927
928 group = getgrnam(args[cur_arg + 1]);
929 if (!group) {
930 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
931 file, linenum, args[0], args[cur_arg + 1 ]);
932 err_code |= ERR_ALERT | ERR_FATAL;
933 goto out;
934 }
935
936 global.unix_bind.ux.gid = group->gr_gid;
937 cur_arg += 2;
938 continue;
939 }
940
941 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
942 file, linenum, args[0]);
943 err_code |= ERR_ALERT | ERR_FATAL;
944 goto out;
945 }
946 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100947 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +0200948 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100949 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
950 err_code |= ERR_ALERT | ERR_FATAL;
951 goto out;
952 }
953 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100954 else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100955 char *name;
956
957 if (global.log_send_hostname != NULL) {
958 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
959 err_code |= ERR_ALERT;
960 goto out;
961 }
962
963 if (*(args[1]))
964 name = args[1];
965 else
966 name = hostname;
967
968 free(global.log_send_hostname);
969 global.log_send_hostname = strdup(name);
970 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100971 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 +0100972 if (global.server_state_base != NULL) {
973 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
974 err_code |= ERR_ALERT;
975 goto out;
976 }
977
978 if (!*(args[1])) {
979 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
980 err_code |= ERR_FATAL;
981 goto out;
982 }
983
984 global.server_state_base = strdup(args[1]);
985 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100986 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 +0100987 if (global.server_state_file != NULL) {
988 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
989 err_code |= ERR_ALERT;
990 goto out;
991 }
992
993 if (!*(args[1])) {
994 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
995 err_code |= ERR_FATAL;
996 goto out;
997 }
998
999 global.server_state_file = strdup(args[1]);
1000 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001001 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001002 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1003 goto out;
1004 if (*(args[1]) == 0) {
1005 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
1006 err_code |= ERR_ALERT | ERR_FATAL;
1007 goto out;
1008 }
1009 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02001010 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
1011 if (b_orig(&global.log_tag) == NULL) {
1012 chunk_destroy(&global.log_tag);
1013 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
1014 err_code |= ERR_ALERT | ERR_FATAL;
1015 goto out;
1016 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001017 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001018 else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001019 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1020 goto out;
1021 if (global.spread_checks != 0) {
1022 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
1023 err_code |= ERR_ALERT;
1024 goto out;
1025 }
1026 if (*(args[1]) == 0) {
1027 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1028 err_code |= ERR_ALERT | ERR_FATAL;
1029 goto out;
1030 }
1031 global.spread_checks = atol(args[1]);
1032 if (global.spread_checks < 0 || global.spread_checks > 50) {
1033 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
1034 err_code |= ERR_ALERT | ERR_FATAL;
1035 }
1036 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001037 else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001038 const char *err;
1039 unsigned int val;
1040
1041 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1042 goto out;
1043 if (*(args[1]) == 0) {
1044 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1045 err_code |= ERR_ALERT | ERR_FATAL;
1046 goto out;
1047 }
1048
1049 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001050 if (err == PARSE_TIME_OVER) {
1051 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1052 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001053 err_code |= ERR_ALERT | ERR_FATAL;
1054 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001055 else if (err == PARSE_TIME_UNDER) {
1056 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1057 file, linenum, args[1], args[0]);
1058 err_code |= ERR_ALERT | ERR_FATAL;
1059 }
1060 else if (err) {
1061 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 +01001062 err_code |= ERR_ALERT | ERR_FATAL;
1063 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001064 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001065 }
1066 else if (strcmp(args[0], "cpu-map") == 0) {
1067 /* map a process list to a CPU set */
1068#ifdef USE_CPU_AFFINITY
1069 char *slash;
Willy Tarreau5b093412022-07-08 09:38:30 +02001070 unsigned long tgroup = 0, thread = 0;
1071 int g, j, n, autoinc;
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001072 struct hap_cpuset cpus, cpus_copy;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001073
1074 if (!*args[1] || !*args[2]) {
Willy Tarreau5b093412022-07-08 09:38:30 +02001075 ha_alert("parsing [%s:%d] : %s expects a thread group number "
Willy Tarreau36b9e222018-11-11 15:19:52 +01001076 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1077 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001078 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001079 err_code |= ERR_ALERT | ERR_FATAL;
1080 goto out;
1081 }
1082
1083 if ((slash = strchr(args[1], '/')) != NULL)
1084 *slash = 0;
1085
Willy Tarreau5b093412022-07-08 09:38:30 +02001086 /* note: we silently ignore thread group numbers over MAX_TGROUPS
1087 * and threads over MAX_THREADS so as not to make configurations a
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001088 * pain to maintain.
1089 */
Willy Tarreau5b093412022-07-08 09:38:30 +02001090 if (parse_process_number(args[1], &tgroup, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001091 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1092 err_code |= ERR_ALERT | ERR_FATAL;
1093 goto out;
1094 }
1095
1096 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001097 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001098 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1099 err_code |= ERR_ALERT | ERR_FATAL;
1100 goto out;
1101 }
1102 *slash = '/';
Willy Tarreau36b9e222018-11-11 15:19:52 +01001103 }
1104
Amaury Denoyellea8082352021-04-06 16:46:15 +02001105 if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001106 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1107 err_code |= ERR_ALERT | ERR_FATAL;
1108 goto out;
1109 }
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001110
Willy Tarreau36b9e222018-11-11 15:19:52 +01001111 if (autoinc &&
Willy Tarreau5b093412022-07-08 09:38:30 +02001112 my_popcountl(tgroup) != ha_cpuset_count(&cpus) &&
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001113 my_popcountl(thread) != ha_cpuset_count(&cpus)) {
Willy Tarreau5b093412022-07-08 09:38:30 +02001114 ha_alert("parsing [%s:%d] : %s : TGROUP/THREAD range and CPU sets "
Willy Tarreau36b9e222018-11-11 15:19:52 +01001115 "must have the same size to be automatically bound\n",
1116 file, linenum, args[0]);
1117 err_code |= ERR_ALERT | ERR_FATAL;
1118 goto out;
1119 }
1120
Willy Tarreau7764a572019-07-16 15:10:34 +02001121 /* we now have to deal with 3 real cases :
Willy Tarreau5b093412022-07-08 09:38:30 +02001122 * cpu-map P-Q => mapping for whole tgroups, numbers P to Q
1123 * cpu-map P-Q/1 => mapping of first thread of groups P to Q
1124 * cpu-map P/T-U => mapping of threads T to U of tgroup P
Willy Tarreau7764a572019-07-16 15:10:34 +02001125 */
Willy Tarreau3cd71ac2022-08-22 10:38:00 +02001126 /* first tgroup, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
1127 for (g = 0; g < MAX_TGROUPS; g++) {
1128 /* No mapping for this tgroup */
1129 if (!(tgroup & (1UL << g)))
1130 continue;
Willy Tarreau81492c92019-05-03 09:41:23 +02001131
Willy Tarreau3cd71ac2022-08-22 10:38:00 +02001132 ha_cpuset_assign(&cpus_copy, &cpus);
1133
1134 if (!thread) {
1135 /* no thread set was specified, apply
1136 * the CPU set to the whole group.
1137 */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001138 if (!autoinc)
Willy Tarreau5b093412022-07-08 09:38:30 +02001139 ha_cpuset_assign(&cpu_map[g].proc, &cpus);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001140 else {
Willy Tarreau5b093412022-07-08 09:38:30 +02001141 ha_cpuset_zero(&cpu_map[g].proc);
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001142 n = ha_cpuset_ffs(&cpus_copy) - 1;
1143 ha_cpuset_clr(&cpus_copy, n);
Willy Tarreau5b093412022-07-08 09:38:30 +02001144 ha_cpuset_set(&cpu_map[g].proc, n);
1145 }
Willy Tarreau3cd71ac2022-08-22 10:38:00 +02001146 } else {
1147 /* a thread set is specified, apply the
1148 * CPU set to these threads.
1149 */
Willy Tarreau5b093412022-07-08 09:38:30 +02001150 for (j = n = 0; j < MAX_THREADS_PER_GROUP; j++) {
1151 /* No mapping for this thread */
1152 if (!(thread & (1UL << j)))
1153 continue;
1154
1155 if (!autoinc)
1156 ha_cpuset_assign(&cpu_map[g].thread[j], &cpus);
1157 else {
1158 ha_cpuset_zero(&cpu_map[g].thread[j]);
1159 n = ha_cpuset_ffs(&cpus_copy) - 1;
1160 ha_cpuset_clr(&cpus_copy, n);
1161 ha_cpuset_set(&cpu_map[g].thread[j], n);
1162 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001163 }
1164 }
1165 }
1166#else
1167 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1168 file, linenum, args[0]);
1169 err_code |= ERR_ALERT | ERR_FATAL;
1170 goto out;
1171#endif /* ! USE_CPU_AFFINITY */
1172 }
1173 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1174 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1175 goto out;
1176
1177 if (*(args[2]) == 0) {
1178 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1179 err_code |= ERR_ALERT | ERR_FATAL;
1180 goto out;
1181 }
1182
1183 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1184 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1185 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1186 err_code |= ERR_ALERT | ERR_FATAL;
1187 goto out;
1188 }
1189 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001190 else if (strcmp(args[0], "unsetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001191 int arg;
1192
1193 if (*(args[1]) == 0) {
1194 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1195 err_code |= ERR_ALERT | ERR_FATAL;
1196 goto out;
1197 }
1198
1199 for (arg = 1; *args[arg]; arg++) {
1200 if (unsetenv(args[arg]) != 0) {
1201 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1202 err_code |= ERR_ALERT | ERR_FATAL;
1203 goto out;
1204 }
1205 }
1206 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001207 else if (strcmp(args[0], "resetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001208 extern char **environ;
1209 char **env = environ;
1210
1211 /* args contain variable names to keep, one per argument */
1212 while (*env) {
1213 int arg;
1214
1215 /* look for current variable in among all those we want to keep */
1216 for (arg = 1; *args[arg]; arg++) {
1217 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1218 (*env)[strlen(args[arg])] == '=')
1219 break;
1220 }
1221
1222 /* delete this variable */
1223 if (!*args[arg]) {
1224 char *delim = strchr(*env, '=');
1225
1226 if (!delim || delim - *env >= trash.size) {
1227 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1228 err_code |= ERR_ALERT | ERR_FATAL;
1229 goto out;
1230 }
1231
1232 memcpy(trash.area, *env, delim - *env);
1233 trash.area[delim - *env] = 0;
1234
1235 if (unsetenv(trash.area) != 0) {
1236 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1237 err_code |= ERR_ALERT | ERR_FATAL;
1238 goto out;
1239 }
1240 }
1241 else
1242 env++;
1243 }
1244 }
Willy Tarreaue98d3852022-11-15 09:34:07 +01001245 else if (strcmp(args[0], "quick-exit") == 0) {
1246 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1247 goto out;
1248 global.tune.options |= GTUNE_QUICK_EXIT;
1249 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001250 else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */
William Dauchy0fec3ab2019-10-27 20:08:11 +01001251 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1252 goto out;
1253 if (kwm == KWM_NO)
1254 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001255 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001256 else if (strcmp(args[0], "localpeer") == 0) {
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001257 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1258 goto out;
1259
1260 if (*(args[1]) == 0) {
1261 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1262 file, linenum, args[0]);
1263 err_code |= ERR_ALERT | ERR_FATAL;
1264 goto out;
1265 }
1266
1267 if (global.localpeer_cmdline != 0) {
1268 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1269 "command line argument.\n", file, linenum, args[0]);
1270 err_code |= ERR_WARN;
1271 goto out;
1272 }
1273
1274 if (cfg_peers) {
1275 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1276 file, linenum, args[0]);
1277 err_code |= ERR_WARN;
1278 goto out;
1279 }
1280
1281 free(localpeer);
1282 if ((localpeer = strdup(args[1])) == NULL) {
1283 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1284 file, linenum, args[0]);
1285 err_code |= ERR_ALERT | ERR_FATAL;
1286 goto out;
1287 }
1288 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1289 }
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +01001290 else if (strcmp(args[0], "numa-cpu-mapping") == 0) {
1291 global.numa_cpu_mapping = (kwm == KWM_NO) ? 0 : 1;
1292 }
Erwan Le Goasfad9da82022-09-14 17:24:22 +02001293 else if (strcmp(args[0], "anonkey") == 0) {
1294 long long tmp = 0;
1295
1296 if (*args[1] == 0) {
1297 ha_alert("parsing [%s:%d]: a key is expected after '%s'.\n",
1298 file, linenum, args[0]);
1299 err_code |= ERR_ALERT | ERR_FATAL;
1300 goto out;
1301 }
1302
1303 if (HA_ATOMIC_LOAD(&global.anon_key) == 0) {
1304 tmp = atoll(args[1]);
1305 if (tmp < 0 || tmp > UINT_MAX) {
1306 ha_alert("parsing [%s:%d]: '%s' value must be within range %u-%u (was '%s').\n",
1307 file, linenum, args[0], 0, UINT_MAX, args[1]);
1308 err_code |= ERR_ALERT | ERR_FATAL;
1309 goto out;
1310 }
1311
1312 HA_ATOMIC_STORE(&global.anon_key, tmp);
1313 }
1314 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001315 else {
1316 struct cfg_kw_list *kwl;
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001317 const char *best;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001318 int index;
1319 int rc;
1320
1321 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1322 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1323 if (kwl->kw[index].section != CFG_GLOBAL)
1324 continue;
1325 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001326 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02001327 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001328 err_code |= ERR_ALERT | ERR_FATAL;
1329 goto out;
1330 }
1331
Willy Tarreau36b9e222018-11-11 15:19:52 +01001332 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1333 if (rc < 0) {
1334 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1335 err_code |= ERR_ALERT | ERR_FATAL;
1336 }
1337 else if (rc > 0) {
1338 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1339 err_code |= ERR_WARN;
1340 goto out;
1341 }
1342 goto out;
1343 }
1344 }
1345 }
1346
Willy Tarreau101df312021-03-15 09:12:41 +01001347 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list);
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001348 if (best)
1349 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
1350 else
1351 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau36b9e222018-11-11 15:19:52 +01001352 err_code |= ERR_ALERT | ERR_FATAL;
1353 }
1354
1355 out:
1356 free(errmsg);
1357 return err_code;
1358}
1359