blob: 1a39c2f7501732d681c97d66716448891d9c85f1 [file] [log] [blame]
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13
Willy Tarreaudcc048a2020-06-04 19:11:43 +020014#include <haproxy/acl.h>
Eric Salama7cea6062020-10-02 11:58:19 +020015#include <haproxy/buf.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020016#include <haproxy/capture-t.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020017#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020018#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020019#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020020#include <haproxy/connection.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020021#include <haproxy/extcheck.h>
Willy Tarreau87735332020-06-04 09:08:41 +020022#include <haproxy/http_htx.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020023#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020024#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020025#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020026#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020027#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020028#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020029#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020030#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020031#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020032#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/tcpcheck.h>
34#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010035
Willy Tarreau7d0c1432021-02-12 12:29:28 +010036
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010037/* Report a warning if a rule is placed after a 'tcp-request session' rule.
38 * Return 1 if the warning has been emitted, otherwise 0.
39 */
40int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
41{
42 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
43 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
44 file, line, arg);
45 return 1;
46 }
47 return 0;
48}
49
50/* Report a warning if a rule is placed after a 'tcp-request content' rule.
51 * Return 1 if the warning has been emitted, otherwise 0.
52 */
53int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
54{
55 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
56 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
57 file, line, arg);
58 return 1;
59 }
60 return 0;
61}
62
63/* Report a warning if a rule is placed after a 'monitor fail' rule.
64 * Return 1 if the warning has been emitted, otherwise 0.
65 */
66int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
67{
68 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
69 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
70 file, line, arg);
71 return 1;
72 }
73 return 0;
74}
75
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010076/* Report a warning if a rule is placed after an 'http_request' rule.
77 * Return 1 if the warning has been emitted, otherwise 0.
78 */
79int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
80{
81 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
82 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
83 file, line, arg);
84 return 1;
85 }
86 return 0;
87}
88
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010089/* Report a warning if a rule is placed after a redirect rule.
90 * Return 1 if the warning has been emitted, otherwise 0.
91 */
92int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
93{
94 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
95 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
96 file, line, arg);
97 return 1;
98 }
99 return 0;
100}
101
102/* Report a warning if a rule is placed after a 'use_backend' rule.
103 * Return 1 if the warning has been emitted, otherwise 0.
104 */
105int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
106{
107 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
108 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
109 file, line, arg);
110 return 1;
111 }
112 return 0;
113}
114
115/* Report a warning if a rule is placed after a 'use-server' rule.
116 * Return 1 if the warning has been emitted, otherwise 0.
117 */
118int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
119{
120 if (!LIST_ISEMPTY(&proxy->server_rules)) {
121 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
122 file, line, arg);
123 return 1;
124 }
125 return 0;
126}
127
128/* report a warning if a redirect rule is dangerously placed */
129int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
130{
131 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
132 warnif_rule_after_use_server(proxy, file, line, arg);
133}
134
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100135/* report a warning if an http-request rule is dangerously placed */
136int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
137{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200138 return warnif_rule_after_redirect(proxy, file, line, arg) ||
139 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100140}
141
142/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200143int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100144{
145 return warnif_rule_after_http_req(proxy, file, line, arg) ||
146 warnif_misplaced_http_req(proxy, file, line, arg);
147}
148
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100149/* report a warning if a "tcp request content" rule is dangerously placed */
150int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
151{
152 return warnif_rule_after_monitor(proxy, file, line, arg) ||
153 warnif_misplaced_monitor(proxy, file, line, arg);
154}
155
156/* report a warning if a "tcp request session" rule is dangerously placed */
157int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
158{
159 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
160 warnif_misplaced_tcp_cont(proxy, file, line, arg);
161}
162
163/* report a warning if a "tcp request connection" rule is dangerously placed */
164int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
165{
166 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
167 warnif_misplaced_tcp_sess(proxy, file, line, arg);
168}
169
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100170int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
171{
172 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100173 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100174 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100175 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100176 int rc;
177 unsigned val;
178 int err_code = 0;
179 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100180 char *errmsg = NULL;
181 struct bind_conf *bind_conf;
182
Willy Tarreaue90904d2021-02-12 14:08:31 +0100183 if (!last_defproxy) {
184 /* we need a default proxy and none was created yet */
185 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, "INIT", 0, NULL, &errmsg);
186 curr_defproxy = last_defproxy;
187 if (!last_defproxy) {
188 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
189 err_code |= ERR_ALERT | ERR_ABORT;
190 goto out;
191 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100192 }
193
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100194 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100195 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100196 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100197 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100198 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100199 rc = PR_CAP_BE;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100200 else if (strcmp(args[0], "defaults") == 0) {
201 /* "defaults" must first delete the last no-name defaults if any */
202 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
203 curr_defproxy = NULL;
204 rc = PR_CAP_DEF | PR_CAP_LISTEN;
205 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100206 else
207 rc = PR_CAP_NONE;
208
Willy Tarreaue90904d2021-02-12 14:08:31 +0100209 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100210 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100211 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100212 file, linenum, args[0]);
213 err_code |= ERR_ALERT | ERR_ABORT;
214 goto out;
215 }
216
217 err = invalid_char(args[1]);
218 if (err) {
219 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
220 file, linenum, *err, args[0], args[1]);
221 err_code |= ERR_ALERT | ERR_FATAL;
222 }
223
224 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
225 if (curproxy) {
226 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
227 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
228 curproxy->id, curproxy->conf.file, curproxy->conf.line);
229 err_code |= ERR_ALERT | ERR_FATAL;
230 }
231
Emeric Brunb0c331f2020-10-07 17:05:59 +0200232 curproxy = log_forward_by_name(args[1]);
233 if (curproxy) {
234 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
235 file, linenum, proxy_cap_str(rc), args[1],
236 curproxy->id, curproxy->conf.file, curproxy->conf.line);
237 err_code |= ERR_ALERT | ERR_FATAL;
238 }
239
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100240 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
241 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100242 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100243 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
244 goto out;
245 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100246 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100247
Willy Tarreaue90904d2021-02-12 14:08:31 +0100248 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100249 const char *name = args[1];
250 int arg = 2;
251
252 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
253 // also support "defaults from blah" (no name then)
254 arg = 1;
255 name = "";
256 }
257
258 /* only regular proxies inherit from the previous defaults section */
259 if (!(rc & PR_CAP_DEF))
260 curr_defproxy = last_defproxy;
261
262 if (strcmp(args[arg], "from") == 0) {
263 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
264
265 if (!curr_defproxy) {
266 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
267 err_code |= ERR_ALERT | ERR_ABORT;
268 goto out;
269 }
270
271 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
272 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
273
274 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
275 file, linenum, args[arg+1], proxy_cap_str(rc), name,
276 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
277 err_code |= ERR_ALERT | ERR_FATAL;
278 }
279
280 err = invalid_char(args[arg+1]);
281 if (err) {
282 ha_alert("parsing [%s:%d] : character '%c' is not permitted in defaults section name '%s' when designated by its name (section found at %s:%d).\n",
283 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
284 err_code |= ERR_ALERT | ERR_FATAL;
285 }
286 }
287
288 curproxy = alloc_new_proxy(name, rc, file, linenum, curr_defproxy, &errmsg);
Willy Tarreau76838932021-02-12 08:49:47 +0100289 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100290 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
291 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100292 goto out;
293 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100294
Willy Tarreaue90904d2021-02-12 14:08:31 +0100295 if (rc & PR_CAP_DEF) {
296 /* last and current proxies must be updated to this one */
297 curr_defproxy = last_defproxy = curproxy;
298 } else {
299 /* regular proxies are in a list */
300 curproxy->next = proxies_list;
301 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100302 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100303 goto out;
304 }
305 else if (curproxy == NULL) {
306 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
307 err_code |= ERR_ALERT | ERR_FATAL;
308 goto out;
309 }
310
311 /* update the current file and line being parsed */
312 curproxy->conf.args.file = curproxy->conf.file;
313 curproxy->conf.args.line = linenum;
314
315 /* Now let's parse the proxy-specific keywords */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100316 if (strcmp(args[0], "server") == 0 ||
317 strcmp(args[0], "default-server") == 0 ||
318 strcmp(args[0], "server-template") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +0100319 err_code |= parse_server(file, linenum, args, curproxy, curr_defproxy, 1, 0, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100320 if (err_code & ERR_FATAL)
321 goto out;
322 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100323 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100324 struct listener *l;
325 int cur_arg;
326
Willy Tarreau5d095c22021-02-12 10:15:59 +0100327 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100328 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
329 err_code |= ERR_ALERT | ERR_FATAL;
330 goto out;
331 }
332 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
333 err_code |= ERR_WARN;
334
335 if (!*(args[1])) {
336 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
337 file, linenum, args[0]);
338 err_code |= ERR_ALERT | ERR_FATAL;
339 goto out;
340 }
341
342 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
343
344 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200345 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
346 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
347 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100348
349 /* NOTE: the following line might create several listeners if there
350 * are comma-separated IPs or port ranges. So all further processing
351 * will have to be applied to all listeners created after last_listen.
352 */
353 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
354 if (errmsg && *errmsg) {
355 indent_msg(&errmsg, 2);
356 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
357 }
358 else
359 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
360 file, linenum, args[0], args[1]);
361 err_code |= ERR_ALERT | ERR_FATAL;
362 goto out;
363 }
364
365 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
366 /* Set default global rights and owner for unix bind */
367 global.maxsock++;
368 }
369
370 cur_arg = 2;
371 while (*(args[cur_arg])) {
372 static int bind_dumped;
373 struct bind_kw *kw;
374 char *err;
375
376 kw = bind_find_kw(args[cur_arg]);
377 if (kw) {
378 char *err = NULL;
379 int code;
380
381 if (!kw->parse) {
382 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
383 file, linenum, args[0], args[1], args[cur_arg]);
384 cur_arg += 1 + kw->skip ;
385 err_code |= ERR_ALERT | ERR_FATAL;
386 goto out;
387 }
388
389 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
390 err_code |= code;
391
392 if (code) {
393 if (err && *err) {
394 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200395 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
396 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
397 else
398 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100399 }
400 else
401 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
402 file, linenum, args[0], args[1], args[cur_arg]);
403 if (code & ERR_FATAL) {
404 free(err);
405 cur_arg += 1 + kw->skip;
406 goto out;
407 }
408 }
409 free(err);
410 cur_arg += 1 + kw->skip;
411 continue;
412 }
413
414 err = NULL;
415 if (!bind_dumped) {
416 bind_dump_kws(&err);
417 indent_msg(&err, 4);
418 bind_dumped = 1;
419 }
420
421 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
422 file, linenum, args[0], args[1], args[cur_arg],
423 err ? " Registered keywords :" : "", err ? err : "");
424 free(err);
425
426 err_code |= ERR_ALERT | ERR_FATAL;
427 goto out;
428 }
429 goto out;
430 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100431 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200432 ha_alert("parsing [%s:%d] : 'monitor-net' doesn't exist anymore. Please use 'http-request return status 200 if { src %s }' instead.\n", file, linenum, args[1]);
433 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100434 goto out;
435 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100436 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100437 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
438 err_code |= ERR_WARN;
439
440 if (alertif_too_many_args(1, file, linenum, args, &err_code))
441 goto out;
442
443 if (!*args[1]) {
444 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
445 file, linenum, args[0]);
446 err_code |= ERR_ALERT | ERR_FATAL;
447 goto out;
448 }
449
450 free(curproxy->monitor_uri);
451 curproxy->monitor_uri_len = strlen(args[1]);
452 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
453 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
454 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
455
456 goto out;
457 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100458 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100459 if (alertif_too_many_args(1, file, linenum, args, &err_code))
460 goto out;
461
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100462 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
463 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
464 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200465 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
466 err_code |= ERR_ALERT | ERR_FATAL;
467 goto out;
468 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100469 else {
470 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
471 err_code |= ERR_ALERT | ERR_FATAL;
472 goto out;
473 }
474 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100475 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100476 struct eb32_node *node;
477
Willy Tarreau5d095c22021-02-12 10:15:59 +0100478 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100479 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
480 file, linenum, args[0]);
481 err_code |= ERR_ALERT | ERR_FATAL;
482 goto out;
483 }
484
485 if (alertif_too_many_args(1, file, linenum, args, &err_code))
486 goto out;
487
488 if (!*args[1]) {
489 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
490 file, linenum, args[0]);
491 err_code |= ERR_ALERT | ERR_FATAL;
492 goto out;
493 }
494
495 curproxy->uuid = atol(args[1]);
496 curproxy->conf.id.key = curproxy->uuid;
497 curproxy->options |= PR_O_FORCED_ID;
498
499 if (curproxy->uuid <= 0) {
500 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
501 file, linenum);
502 err_code |= ERR_ALERT | ERR_FATAL;
503 goto out;
504 }
505
506 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
507 if (node) {
508 struct proxy *target = container_of(node, struct proxy, conf.id);
509 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
510 file, linenum, proxy_type_str(curproxy), curproxy->id,
511 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
512 err_code |= ERR_ALERT | ERR_FATAL;
513 goto out;
514 }
515 eb32_insert(&used_proxy_id, &curproxy->conf.id);
516 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100517 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100518 int i, len=0;
519 char *d;
520
Willy Tarreau5d095c22021-02-12 10:15:59 +0100521 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100522 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
523 file, linenum, args[0]);
524 err_code |= ERR_ALERT | ERR_FATAL;
525 goto out;
526 }
527
528 if (!*args[1]) {
529 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
530 file, linenum, args[0]);
531 return -1;
532 }
533
534 for (i = 1; *args[i]; i++)
535 len += strlen(args[i]) + 1;
536
537 d = calloc(1, len);
538 curproxy->desc = d;
539
540 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
541 for (i = 2; *args[i]; i++)
542 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
543
544 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100545 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100546 if (alertif_too_many_args(0, file, linenum, args, &err_code))
547 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200548 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100549 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100550 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100551 if (alertif_too_many_args(0, file, linenum, args, &err_code))
552 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200553 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100554 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100555 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100556 int cur_arg = 1;
557 unsigned long set = 0;
558
559 while (*args[cur_arg]) {
560 if (strcmp(args[cur_arg], "all") == 0) {
561 set = 0;
562 break;
563 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100564 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100565 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
566 err_code |= ERR_ALERT | ERR_FATAL;
567 goto out;
568 }
569 cur_arg++;
570 }
571 curproxy->bind_proc = set;
572 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100573 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100574 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100575 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
576 err_code |= ERR_ALERT | ERR_FATAL;
577 goto out;
578 }
579
580 err = invalid_char(args[1]);
581 if (err) {
582 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
583 file, linenum, *err, args[1]);
584 err_code |= ERR_ALERT | ERR_FATAL;
585 goto out;
586 }
587
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100588 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100589 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100590 "logical disjunction within a condition.\n",
591 file, linenum, args[1]);
592 err_code |= ERR_ALERT | ERR_FATAL;
593 goto out;
594 }
595
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100596 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
597 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
598 file, linenum, args[1], errmsg);
599 err_code |= ERR_ALERT | ERR_FATAL;
600 goto out;
601 }
602 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100603 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100604
605 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
606 err_code |= ERR_WARN;
607
608 if (*(args[1]) == 0) {
609 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
610 file, linenum, args[0]);
611 err_code |= ERR_ALERT | ERR_FATAL;
612 goto out;
613 }
614 free(curproxy->dyncookie_key);
615 curproxy->dyncookie_key = strdup(args[1]);
616 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100617 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100618 int cur_arg;
619
620 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
621 err_code |= ERR_WARN;
622
623 if (*(args[1]) == 0) {
624 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
625 file, linenum, args[0]);
626 err_code |= ERR_ALERT | ERR_FATAL;
627 goto out;
628 }
629
630 curproxy->ck_opts = 0;
631 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100632 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100633 free(curproxy->cookie_name);
634 curproxy->cookie_name = strdup(args[1]);
635 curproxy->cookie_len = strlen(curproxy->cookie_name);
636
637 cur_arg = 2;
638 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100639 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100640 curproxy->ck_opts |= PR_CK_RW;
641 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100642 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100643 curproxy->ck_opts |= PR_CK_IND;
644 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100645 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100646 curproxy->ck_opts |= PR_CK_INS;
647 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100648 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100649 curproxy->ck_opts |= PR_CK_NOC;
650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100651 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100652 curproxy->ck_opts |= PR_CK_POST;
653 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100654 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100655 curproxy->ck_opts |= PR_CK_PSV;
656 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100657 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100658 curproxy->ck_opts |= PR_CK_PFX;
659 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100660 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100661 curproxy->ck_opts |= PR_CK_HTTPONLY;
662 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100663 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100664 curproxy->ck_opts |= PR_CK_SECURE;
665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100666 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100667 if (!*args[cur_arg + 1]) {
668 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
669 file, linenum, args[cur_arg]);
670 err_code |= ERR_ALERT | ERR_FATAL;
671 goto out;
672 }
673
Joao Moraise1583752019-10-30 21:04:00 -0300674 if (!strchr(args[cur_arg + 1], '.')) {
675 /* rfc6265, 5.2.3 The Domain Attribute */
676 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
677 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100678 file, linenum, args[cur_arg + 1]);
679 err_code |= ERR_WARN;
680 }
681
682 err = invalid_domainchar(args[cur_arg + 1]);
683 if (err) {
684 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
685 file, linenum, *err, args[cur_arg + 1]);
686 err_code |= ERR_ALERT | ERR_FATAL;
687 goto out;
688 }
689
690 if (!curproxy->cookie_domain) {
691 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
692 } else {
693 /* one domain was already specified, add another one by
694 * building the string which will be returned along with
695 * the cookie.
696 */
697 char *new_ptr;
698 int new_len = strlen(curproxy->cookie_domain) +
699 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
700 new_ptr = malloc(new_len);
701 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
702 free(curproxy->cookie_domain);
703 curproxy->cookie_domain = new_ptr;
704 }
705 cur_arg++;
706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100708 unsigned int maxidle;
709 const char *res;
710
711 if (!*args[cur_arg + 1]) {
712 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
713 file, linenum, args[cur_arg]);
714 err_code |= ERR_ALERT | ERR_FATAL;
715 goto out;
716 }
717
718 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200719 if (res == PARSE_TIME_OVER) {
720 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
721 file, linenum, args[cur_arg+1], args[cur_arg]);
722 err_code |= ERR_ALERT | ERR_FATAL;
723 goto out;
724 }
725 else if (res == PARSE_TIME_UNDER) {
726 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
727 file, linenum, args[cur_arg+1], args[cur_arg]);
728 err_code |= ERR_ALERT | ERR_FATAL;
729 goto out;
730 }
731 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100732 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
733 file, linenum, *res, args[cur_arg]);
734 err_code |= ERR_ALERT | ERR_FATAL;
735 goto out;
736 }
737 curproxy->cookie_maxidle = maxidle;
738 cur_arg++;
739 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100740 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100741 unsigned int maxlife;
742 const char *res;
743
744 if (!*args[cur_arg + 1]) {
745 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
746 file, linenum, args[cur_arg]);
747 err_code |= ERR_ALERT | ERR_FATAL;
748 goto out;
749 }
750
Willy Tarreau9faebe32019-06-07 19:00:37 +0200751
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100752 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200753 if (res == PARSE_TIME_OVER) {
754 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
755 file, linenum, args[cur_arg+1], args[cur_arg]);
756 err_code |= ERR_ALERT | ERR_FATAL;
757 goto out;
758 }
759 else if (res == PARSE_TIME_UNDER) {
760 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
761 file, linenum, args[cur_arg+1], args[cur_arg]);
762 err_code |= ERR_ALERT | ERR_FATAL;
763 goto out;
764 }
765 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100766 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
767 file, linenum, *res, args[cur_arg]);
768 err_code |= ERR_ALERT | ERR_FATAL;
769 goto out;
770 }
771 curproxy->cookie_maxlife = maxlife;
772 cur_arg++;
773 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100774 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100775
776 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
777 err_code |= ERR_WARN;
778 curproxy->ck_opts |= PR_CK_DYNAMIC;
779 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100780 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100781 char *val;
782 if (!*args[cur_arg + 1]) {
783 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
784 file, linenum, args[cur_arg]);
785 err_code |= ERR_ALERT | ERR_FATAL;
786 goto out;
787 }
788 val = args[cur_arg + 1];
789 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100790 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100791 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
792 file, linenum, *val);
793 err_code |= ERR_ALERT | ERR_FATAL;
794 goto out;
795 }
796 val++;
797 }
798 /* don't add ';' for the first attribute */
799 if (!curproxy->cookie_attrs)
800 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
801 else
802 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
803 cur_arg++;
804 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100805
806 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100807 ha_alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic', 'maxlife' and 'attr' options.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100808 file, linenum, args[0]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812 cur_arg++;
813 }
814 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
815 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
816 file, linenum);
817 err_code |= ERR_ALERT | ERR_FATAL;
818 }
819
820 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
821 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
822 file, linenum);
823 err_code |= ERR_ALERT | ERR_FATAL;
824 }
825
826 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
827 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
828 file, linenum);
829 err_code |= ERR_ALERT | ERR_FATAL;
830 }
831 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100832 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100833 if (*(args[1]) == 0) {
834 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
835 file, linenum, args[0]);
836 err_code |= ERR_ALERT | ERR_FATAL;
837 goto out;
838 }
839
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100840 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100841 if (*(args[1]) == 0) {
842 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
843 file, linenum, args[1]);
844 err_code |= ERR_ALERT | ERR_FATAL;
845 goto out;
846 }
847 free(curproxy->email_alert.from);
848 curproxy->email_alert.from = strdup(args[2]);
849 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100850 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100851 if (*(args[1]) == 0) {
852 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
853 file, linenum, args[1]);
854 err_code |= ERR_ALERT | ERR_FATAL;
855 goto out;
856 }
857 free(curproxy->email_alert.mailers.name);
858 curproxy->email_alert.mailers.name = strdup(args[2]);
859 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100860 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100861 if (*(args[1]) == 0) {
862 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
863 file, linenum, args[1]);
864 err_code |= ERR_ALERT | ERR_FATAL;
865 goto out;
866 }
867 free(curproxy->email_alert.myhostname);
868 curproxy->email_alert.myhostname = strdup(args[2]);
869 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100870 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100871 curproxy->email_alert.level = get_log_level(args[2]);
872 if (curproxy->email_alert.level < 0) {
873 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
874 file, linenum, args[1], args[2]);
875 err_code |= ERR_ALERT | ERR_FATAL;
876 goto out;
877 }
878 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100879 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100880 if (*(args[1]) == 0) {
881 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
882 file, linenum, args[1]);
883 err_code |= ERR_ALERT | ERR_FATAL;
884 goto out;
885 }
886 free(curproxy->email_alert.to);
887 curproxy->email_alert.to = strdup(args[2]);
888 }
889 else {
890 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
891 file, linenum, args[1]);
892 err_code |= ERR_ALERT | ERR_FATAL;
893 goto out;
894 }
895 /* Indicate that the email_alert is at least partially configured */
896 curproxy->email_alert.set = 1;
897 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100898 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100899 if (*(args[1]) == 0) {
900 ha_alert("parsing [%s:%d] : missing persist method.\n",
901 file, linenum);
902 err_code |= ERR_ALERT | ERR_FATAL;
903 goto out;
904 }
905
906 if (!strncmp(args[1], "rdp-cookie", 10)) {
907 curproxy->options2 |= PR_O2_RDPC_PRST;
908
909 if (*(args[1] + 10) == '(') { /* cookie name */
910 const char *beg, *end;
911
912 beg = args[1] + 11;
913 end = strchr(beg, ')');
914
915 if (alertif_too_many_args(1, file, linenum, args, &err_code))
916 goto out;
917
918 if (!end || end == beg) {
919 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
920 file, linenum);
921 err_code |= ERR_ALERT | ERR_FATAL;
922 goto out;
923 }
924
925 free(curproxy->rdp_cookie_name);
926 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
927 curproxy->rdp_cookie_len = end-beg;
928 }
929 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
930 free(curproxy->rdp_cookie_name);
931 curproxy->rdp_cookie_name = strdup("msts");
932 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
933 }
934 else { /* syntax */
935 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
936 file, linenum);
937 err_code |= ERR_ALERT | ERR_FATAL;
938 goto out;
939 }
940 }
941 else {
942 ha_alert("parsing [%s:%d] : unknown persist method.\n",
943 file, linenum);
944 err_code |= ERR_ALERT | ERR_FATAL;
945 goto out;
946 }
947 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100948 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +0200949 ha_alert("parsing [%s:%d] : '%s' is not supported anymore since HAProxy 1.6.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100950 err_code |= ERR_ALERT | ERR_FATAL;
951 goto out;
952 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100953 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100954 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
955 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100956 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100957 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
958 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100959 else if (strcmp(args[1], "local") == 0) { /* use the server-state-file-name variable to locate the server-state file */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100960 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
961 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100962 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100963 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
964 }
965 else {
966 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
967 file, linenum, args[0], args[1]);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 goto out;
970 }
971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100972 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100973 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
974 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100975 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100976 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100977
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100978 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +0100979
980 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100981 curproxy->server_state_file_name = strdup(curproxy->id);
982 else
983 curproxy->server_state_file_name = strdup(args[1]);
984 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100985 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100986 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
987 err_code |= ERR_WARN;
988 if (*(args[1]) == 0) {
989 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
990 file, linenum, args[0]);
991 err_code |= ERR_ALERT | ERR_FATAL;
992 goto out;
993 }
994 curproxy->max_out_conns = atoi(args[1]);
995 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100996 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100997 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
998 err_code |= ERR_WARN;
999
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001000 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001001 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001002 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1003 err_code |= ERR_ALERT | ERR_FATAL;
1004 goto out;
1005 }
1006
1007 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1008 goto out;
1009
1010 if (*(args[4]) == 0) {
1011 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1012 file, linenum, args[0]);
1013 err_code |= ERR_ALERT | ERR_FATAL;
1014 goto out;
1015 }
1016 free(curproxy->capture_name);
1017 curproxy->capture_name = strdup(args[2]);
1018 curproxy->capture_namelen = strlen(curproxy->capture_name);
1019 curproxy->capture_len = atol(args[4]);
1020 curproxy->to_log |= LW_COOKIE;
1021 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001022 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001023 struct cap_hdr *hdr;
1024
Willy Tarreau5d095c22021-02-12 10:15:59 +01001025 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001026 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1027 err_code |= ERR_ALERT | ERR_FATAL;
1028 goto out;
1029 }
1030
1031 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1032 goto out;
1033
1034 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1035 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1036 file, linenum, args[0], args[1]);
1037 err_code |= ERR_ALERT | ERR_FATAL;
1038 goto out;
1039 }
1040
1041 hdr = calloc(1, sizeof(*hdr));
1042 hdr->next = curproxy->req_cap;
1043 hdr->name = strdup(args[3]);
1044 hdr->namelen = strlen(args[3]);
1045 hdr->len = atol(args[5]);
1046 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1047 hdr->index = curproxy->nb_req_cap++;
1048 curproxy->req_cap = hdr;
1049 curproxy->to_log |= LW_REQHDR;
1050 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001051 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001052 struct cap_hdr *hdr;
1053
Willy Tarreau5d095c22021-02-12 10:15:59 +01001054 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001055 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1056 err_code |= ERR_ALERT | ERR_FATAL;
1057 goto out;
1058 }
1059
1060 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1061 goto out;
1062
1063 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1064 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1065 file, linenum, args[0], args[1]);
1066 err_code |= ERR_ALERT | ERR_FATAL;
1067 goto out;
1068 }
1069 hdr = calloc(1, sizeof(*hdr));
1070 hdr->next = curproxy->rsp_cap;
1071 hdr->name = strdup(args[3]);
1072 hdr->namelen = strlen(args[3]);
1073 hdr->len = atol(args[5]);
1074 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1075 hdr->index = curproxy->nb_rsp_cap++;
1076 curproxy->rsp_cap = hdr;
1077 curproxy->to_log |= LW_RSPHDR;
1078 }
1079 else {
1080 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1081 file, linenum, args[0]);
1082 err_code |= ERR_ALERT | ERR_FATAL;
1083 goto out;
1084 }
1085 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001086 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001087 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1088 err_code |= ERR_WARN;
1089
1090 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1091 goto out;
1092
1093 if (*(args[1]) == 0) {
1094 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1095 file, linenum, args[0]);
1096 err_code |= ERR_ALERT | ERR_FATAL;
1097 goto out;
1098 }
1099 curproxy->conn_retries = atol(args[1]);
1100 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001101 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001102 struct act_rule *rule;
1103
Willy Tarreau5d095c22021-02-12 10:15:59 +01001104 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001105 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1106 err_code |= ERR_ALERT | ERR_FATAL;
1107 goto out;
1108 }
1109
1110 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1111 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001112 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001113 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1114 file, linenum, args[0]);
1115 err_code |= ERR_WARN;
1116 }
1117
1118 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1119
1120 if (!rule) {
1121 err_code |= ERR_ALERT | ERR_ABORT;
1122 goto out;
1123 }
1124
1125 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1126 err_code |= warnif_cond_conflicts(rule->cond,
1127 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1128 file, linenum);
1129
1130 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1131 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001132 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001133 struct act_rule *rule;
1134
Willy Tarreau5d095c22021-02-12 10:15:59 +01001135 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001136 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1137 err_code |= ERR_ALERT | ERR_FATAL;
1138 goto out;
1139 }
1140
1141 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1142 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001143 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001144 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1145 file, linenum, args[0]);
1146 err_code |= ERR_WARN;
1147 }
1148
1149 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1150
1151 if (!rule) {
1152 err_code |= ERR_ALERT | ERR_ABORT;
1153 goto out;
1154 }
1155
1156 err_code |= warnif_cond_conflicts(rule->cond,
1157 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1158 file, linenum);
1159
1160 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1161 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001162 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001163 struct act_rule *rule;
1164
Willy Tarreau5d095c22021-02-12 10:15:59 +01001165 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001166 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1167 err_code |= ERR_ALERT | ERR_FATAL;
1168 goto out;
1169 }
1170
1171 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1172 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1173 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1174 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1175 file, linenum, args[0]);
1176 err_code |= ERR_WARN;
1177 }
1178
1179 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1180
1181 if (!rule) {
1182 err_code |= ERR_ALERT | ERR_ABORT;
1183 goto out;
1184 }
1185
1186 err_code |= warnif_cond_conflicts(rule->cond,
1187 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1188 file, linenum);
1189
1190 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1191 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001192 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001193 /* set the header name and length into the proxy structure */
1194 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1195 err_code |= ERR_WARN;
1196
1197 if (!*args[1]) {
1198 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1199 file, linenum, args[0]);
1200 err_code |= ERR_ALERT | ERR_FATAL;
1201 goto out;
1202 }
1203
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001204 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001205 free(curproxy->server_id_hdr_name);
1206 curproxy->server_id_hdr_name = strdup(args[1]);
1207 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001208 ist2bin_lc(curproxy->server_id_hdr_name, ist2(curproxy->server_id_hdr_name, curproxy->server_id_hdr_len));
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001209 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001210 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001211 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. Use 'http-request deny' which uses the exact same syntax.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001212
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001213 err_code |= ERR_ALERT | ERR_FATAL;
1214 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001215 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001216 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001217 struct redirect_rule *rule;
1218
Willy Tarreau5d095c22021-02-12 10:15:59 +01001219 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001220 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1221 err_code |= ERR_ALERT | ERR_FATAL;
1222 goto out;
1223 }
1224
1225 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1226 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1227 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1228 err_code |= ERR_ALERT | ERR_FATAL;
1229 goto out;
1230 }
1231
1232 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1233 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1234 err_code |= warnif_cond_conflicts(rule->cond,
1235 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1236 file, linenum);
1237 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001238 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001239 struct switching_rule *rule;
1240
Willy Tarreau5d095c22021-02-12 10:15:59 +01001241 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001242 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1243 err_code |= ERR_ALERT | ERR_FATAL;
1244 goto out;
1245 }
1246
1247 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1248 err_code |= ERR_WARN;
1249
1250 if (*(args[1]) == 0) {
1251 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1252 err_code |= ERR_ALERT | ERR_FATAL;
1253 goto out;
1254 }
1255
1256 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1257 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1258 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1259 file, linenum, errmsg);
1260 err_code |= ERR_ALERT | ERR_FATAL;
1261 goto out;
1262 }
1263
1264 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1265 }
1266 else if (*args[2]) {
1267 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1268 file, linenum, args[2]);
1269 err_code |= ERR_ALERT | ERR_FATAL;
1270 goto out;
1271 }
1272
1273 rule = calloc(1, sizeof(*rule));
1274 if (!rule) {
1275 ha_alert("Out of memory error.\n");
1276 goto out;
1277 }
1278 rule->cond = cond;
1279 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001280 if (!rule->be.name) {
1281 ha_alert("Out of memory error.\n");
1282 goto out;
1283 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001284 rule->line = linenum;
1285 rule->file = strdup(file);
1286 if (!rule->file) {
1287 ha_alert("Out of memory error.\n");
1288 goto out;
1289 }
1290 LIST_INIT(&rule->list);
1291 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1292 }
1293 else if (strcmp(args[0], "use-server") == 0) {
1294 struct server_rule *rule;
1295
Willy Tarreau5d095c22021-02-12 10:15:59 +01001296 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001297 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1298 err_code |= ERR_ALERT | ERR_FATAL;
1299 goto out;
1300 }
1301
1302 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1303 err_code |= ERR_WARN;
1304
1305 if (*(args[1]) == 0) {
1306 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1307 err_code |= ERR_ALERT | ERR_FATAL;
1308 goto out;
1309 }
1310
1311 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1312 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1313 file, linenum, args[0]);
1314 err_code |= ERR_ALERT | ERR_FATAL;
1315 goto out;
1316 }
1317
1318 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1319 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1320 file, linenum, errmsg);
1321 err_code |= ERR_ALERT | ERR_FATAL;
1322 goto out;
1323 }
1324
1325 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1326
1327 rule = calloc(1, sizeof(*rule));
1328 rule->cond = cond;
1329 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001330 rule->line = linenum;
1331 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001332 LIST_INIT(&rule->list);
1333 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1334 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1335 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001336 else if ((strcmp(args[0], "force-persist") == 0) ||
1337 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001338 struct persist_rule *rule;
1339
Willy Tarreau5d095c22021-02-12 10:15:59 +01001340 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001341 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1342 err_code |= ERR_ALERT | ERR_FATAL;
1343 goto out;
1344 }
1345
1346 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1347 err_code |= ERR_WARN;
1348
1349 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1350 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1351 file, linenum, args[0]);
1352 err_code |= ERR_ALERT | ERR_FATAL;
1353 goto out;
1354 }
1355
1356 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1357 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1358 file, linenum, args[0], errmsg);
1359 err_code |= ERR_ALERT | ERR_FATAL;
1360 goto out;
1361 }
1362
1363 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1364 * where force-persist is applied.
1365 */
1366 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1367
1368 rule = calloc(1, sizeof(*rule));
1369 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001370 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001371 rule->type = PERSIST_TYPE_FORCE;
1372 } else {
1373 rule->type = PERSIST_TYPE_IGNORE;
1374 }
1375 LIST_INIT(&rule->list);
1376 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1377 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001378 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001379 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001380
Willy Tarreau5d095c22021-02-12 10:15:59 +01001381 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001382 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1383 file, linenum);
1384 err_code |= ERR_ALERT | ERR_FATAL;
1385 goto out;
1386 }
1387
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001388 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001389 if (other) {
1390 ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001391 file, linenum, curproxy->id,
1392 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1393 other->proxy ? other->id : other->peers.p->id,
1394 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001395 err_code |= ERR_ALERT | ERR_FATAL;
1396 goto out;
1397 }
1398
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001399 curproxy->table = calloc(1, sizeof *curproxy->table);
1400 if (!curproxy->table) {
1401 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1402 file, linenum, args[0], args[1]);
1403 err_code |= ERR_ALERT | ERR_FATAL;
1404 goto out;
1405 }
1406
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001407 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1408 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001409 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001410 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001411
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001412 /* Store the proxy in the stick-table. */
1413 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001414
1415 stktable_store_name(curproxy->table);
1416 curproxy->table->next = stktables_list;
1417 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001418
1419 /* Add this proxy to the list of proxies which refer to its stick-table. */
1420 if (curproxy->table->proxies_list != curproxy) {
1421 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1422 curproxy->table->proxies_list = curproxy;
1423 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001424 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001425 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001426 struct sticking_rule *rule;
1427 struct sample_expr *expr;
1428 int myidx = 0;
1429 const char *name = NULL;
1430 int flags;
1431
Willy Tarreau5d095c22021-02-12 10:15:59 +01001432 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001433 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1434 err_code |= ERR_ALERT | ERR_FATAL;
1435 goto out;
1436 }
1437
1438 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1439 err_code |= ERR_WARN;
1440 goto out;
1441 }
1442
1443 myidx++;
1444 if ((strcmp(args[myidx], "store") == 0) ||
1445 (strcmp(args[myidx], "store-request") == 0)) {
1446 myidx++;
1447 flags = STK_IS_STORE;
1448 }
1449 else if (strcmp(args[myidx], "store-response") == 0) {
1450 myidx++;
1451 flags = STK_IS_STORE | STK_ON_RSP;
1452 }
1453 else if (strcmp(args[myidx], "match") == 0) {
1454 myidx++;
1455 flags = STK_IS_MATCH;
1456 }
1457 else if (strcmp(args[myidx], "on") == 0) {
1458 myidx++;
1459 flags = STK_IS_MATCH | STK_IS_STORE;
1460 }
1461 else {
1462 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1463 err_code |= ERR_ALERT | ERR_FATAL;
1464 goto out;
1465 }
1466
1467 if (*(args[myidx]) == 0) {
1468 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1469 err_code |= ERR_ALERT | ERR_FATAL;
1470 goto out;
1471 }
1472
1473 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001474 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001475 if (!expr) {
1476 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1477 err_code |= ERR_ALERT | ERR_FATAL;
1478 goto out;
1479 }
1480
1481 if (flags & STK_ON_RSP) {
1482 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1483 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1484 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1485 err_code |= ERR_ALERT | ERR_FATAL;
1486 free(expr);
1487 goto out;
1488 }
1489 } else {
1490 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1491 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1492 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1493 err_code |= ERR_ALERT | ERR_FATAL;
1494 free(expr);
1495 goto out;
1496 }
1497 }
1498
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001499 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001500 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1501
1502 if (strcmp(args[myidx], "table") == 0) {
1503 myidx++;
1504 name = args[myidx++];
1505 }
1506
1507 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1508 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1509 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1510 file, linenum, args[0], errmsg);
1511 err_code |= ERR_ALERT | ERR_FATAL;
1512 free(expr);
1513 goto out;
1514 }
1515 }
1516 else if (*(args[myidx])) {
1517 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1518 file, linenum, args[0], args[myidx]);
1519 err_code |= ERR_ALERT | ERR_FATAL;
1520 free(expr);
1521 goto out;
1522 }
1523 if (flags & STK_ON_RSP)
1524 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1525 else
1526 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1527
1528 rule = calloc(1, sizeof(*rule));
1529 rule->cond = cond;
1530 rule->expr = expr;
1531 rule->flags = flags;
1532 rule->table.name = name ? strdup(name) : NULL;
1533 LIST_INIT(&rule->list);
1534 if (flags & STK_ON_RSP)
1535 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1536 else
1537 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1538 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001539 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001540 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001541 curproxy->uri_auth = NULL; /* we must detach from the default config */
1542
1543 if (!*args[1]) {
1544 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001545 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001546 struct stats_admin_rule *rule;
1547
Willy Tarreau5d095c22021-02-12 10:15:59 +01001548 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001549 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1550 err_code |= ERR_ALERT | ERR_FATAL;
1551 goto out;
1552 }
1553
1554 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1555 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1556 err_code |= ERR_ALERT | ERR_ABORT;
1557 goto out;
1558 }
1559
1560 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1561 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1562 file, linenum, args[0], args[1]);
1563 err_code |= ERR_ALERT | ERR_FATAL;
1564 goto out;
1565 }
1566 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1567 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1568 file, linenum, args[0], args[1], errmsg);
1569 err_code |= ERR_ALERT | ERR_FATAL;
1570 goto out;
1571 }
1572
1573 err_code |= warnif_cond_conflicts(cond,
1574 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1575 file, linenum);
1576
1577 rule = calloc(1, sizeof(*rule));
1578 rule->cond = cond;
1579 LIST_INIT(&rule->list);
1580 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001581 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001582 if (*(args[2]) == 0) {
1583 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1584 err_code |= ERR_ALERT | ERR_FATAL;
1585 goto out;
1586 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1587 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1588 err_code |= ERR_ALERT | ERR_ABORT;
1589 goto out;
1590 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001591 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001592 if (*(args[2]) == 0) {
1593 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1594 err_code |= ERR_ALERT | ERR_FATAL;
1595 goto out;
1596 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1597 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1598 err_code |= ERR_ALERT | ERR_ABORT;
1599 goto out;
1600 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001601 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001602 unsigned interval;
1603
1604 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001605 if (err == PARSE_TIME_OVER) {
1606 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1607 file, linenum, args[2]);
1608 err_code |= ERR_ALERT | ERR_FATAL;
1609 goto out;
1610 }
1611 else if (err == PARSE_TIME_UNDER) {
1612 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1613 file, linenum, args[2]);
1614 err_code |= ERR_ALERT | ERR_FATAL;
1615 goto out;
1616 }
1617 else if (err) {
1618 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001619 file, linenum, *err);
1620 err_code |= ERR_ALERT | ERR_FATAL;
1621 goto out;
1622 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1623 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1624 err_code |= ERR_ALERT | ERR_ABORT;
1625 goto out;
1626 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001627 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001628 struct act_rule *rule;
1629
Willy Tarreau5d095c22021-02-12 10:15:59 +01001630 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001631 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1632 err_code |= ERR_ALERT | ERR_FATAL;
1633 goto out;
1634 }
1635
1636 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1637 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1638 err_code |= ERR_ALERT | ERR_ABORT;
1639 goto out;
1640 }
1641
1642 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1643 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1644 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1645 file, linenum, args[0]);
1646 err_code |= ERR_WARN;
1647 }
1648
1649 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1650
1651 if (!rule) {
1652 err_code |= ERR_ALERT | ERR_ABORT;
1653 goto out;
1654 }
1655
1656 err_code |= warnif_cond_conflicts(rule->cond,
1657 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1658 file, linenum);
1659 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1660
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001661 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001662 if (*(args[2]) == 0) {
1663 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1664 err_code |= ERR_ALERT | ERR_FATAL;
1665 goto out;
1666 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1667 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1668 err_code |= ERR_ALERT | ERR_ABORT;
1669 goto out;
1670 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001671 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001672 if (*(args[2]) == 0) {
1673 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1674 err_code |= ERR_ALERT | ERR_FATAL;
1675 goto out;
1676 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1677 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1678 err_code |= ERR_ALERT | ERR_ABORT;
1679 goto out;
1680 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001681 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001682 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1683 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1684 err_code |= ERR_ALERT | ERR_ABORT;
1685 goto out;
1686 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001687 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001688 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001689 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1690 err_code |= ERR_ALERT | ERR_ABORT;
1691 goto out;
1692 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001693 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001694 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001695 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1696 err_code |= ERR_ALERT | ERR_ABORT;
1697 goto out;
1698 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001699 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001700 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1701 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1702 err_code |= ERR_ALERT | ERR_ABORT;
1703 goto out;
1704 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001705 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706
1707 if (*args[2]) {
1708 int i;
1709 char c;
1710
1711 for (i=0; args[2][i]; i++) {
1712 c = args[2][i];
1713 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1714 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1715 break;
1716 }
1717
1718 if (!i || args[2][i]) {
1719 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1720 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1721 file, linenum, args[0], args[1]);
1722 err_code |= ERR_ALERT | ERR_FATAL;
1723 goto out;
1724 }
1725 }
1726
1727 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1728 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1729 err_code |= ERR_ALERT | ERR_ABORT;
1730 goto out;
1731 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001732 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001733 char *desc = NULL;
1734
1735 if (*args[2]) {
1736 int i, len=0;
1737 char *d;
1738
1739 for (i = 2; *args[i]; i++)
1740 len += strlen(args[i]) + 1;
1741
1742 desc = d = calloc(1, len);
1743
1744 d += snprintf(d, desc + len - d, "%s", args[2]);
1745 for (i = 3; *args[i]; i++)
1746 d += snprintf(d, desc + len - d, " %s", args[i]);
1747 }
1748
1749 if (!*args[2] && !global.desc)
1750 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1751 file, linenum, args[1]);
1752 else {
1753 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1754 free(desc);
1755 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1756 err_code |= ERR_ALERT | ERR_ABORT;
1757 goto out;
1758 }
1759 free(desc);
1760 }
1761 } else {
1762stats_error_parsing:
1763 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1764 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1765 err_code |= ERR_ALERT | ERR_FATAL;
1766 goto out;
1767 }
1768 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001769 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001770 int optnum;
1771
1772 if (*(args[1]) == '\0') {
1773 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1774 file, linenum, args[0]);
1775 err_code |= ERR_ALERT | ERR_FATAL;
1776 goto out;
1777 }
1778
1779 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001780 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001781 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1782 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1783 file, linenum, cfg_opts[optnum].name);
1784 err_code |= ERR_ALERT | ERR_FATAL;
1785 goto out;
1786 }
1787 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1788 goto out;
1789
1790 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1791 err_code |= ERR_WARN;
1792 goto out;
1793 }
1794
1795 curproxy->no_options &= ~cfg_opts[optnum].val;
1796 curproxy->options &= ~cfg_opts[optnum].val;
1797
1798 switch (kwm) {
1799 case KWM_STD:
1800 curproxy->options |= cfg_opts[optnum].val;
1801 break;
1802 case KWM_NO:
1803 curproxy->no_options |= cfg_opts[optnum].val;
1804 break;
1805 case KWM_DEF: /* already cleared */
1806 break;
1807 }
1808
1809 goto out;
1810 }
1811 }
1812
1813 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001814 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001815 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1816 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1817 file, linenum, cfg_opts2[optnum].name);
1818 err_code |= ERR_ALERT | ERR_FATAL;
1819 goto out;
1820 }
1821 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1822 goto out;
1823 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1824 err_code |= ERR_WARN;
1825 goto out;
1826 }
1827
Christopher Faulet31930372019-07-15 10:16:58 +02001828 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001829 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001830 if (kwm ==KWM_NO) {
1831 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1832 " The HTX mode is now the only supported mode.\n",
1833 file, linenum, cfg_opts2[optnum].name);
1834 err_code |= ERR_WARN;
1835 }
Christopher Faulet31930372019-07-15 10:16:58 +02001836 goto out;
1837 }
1838
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001839 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1840 curproxy->options2 &= ~cfg_opts2[optnum].val;
1841
1842 switch (kwm) {
1843 case KWM_STD:
1844 curproxy->options2 |= cfg_opts2[optnum].val;
1845 break;
1846 case KWM_NO:
1847 curproxy->no_options2 |= cfg_opts2[optnum].val;
1848 break;
1849 case KWM_DEF: /* already cleared */
1850 break;
1851 }
1852 goto out;
1853 }
1854 }
1855
1856 /* HTTP options override each other. They can be cancelled using
1857 * "no option xxx" which only switches to default mode if the mode
1858 * was this one (useful for cancelling options set in defaults
1859 * sections).
1860 */
1861 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001862 if (strcmp(args[1], "forceclose") == 0) {
1863 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1864 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1865 file, linenum, args[1]);
1866 err_code |= ERR_WARN;
1867 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001868 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1869 goto out;
1870 if (kwm == KWM_STD) {
1871 curproxy->options &= ~PR_O_HTTP_MODE;
1872 curproxy->options |= PR_O_HTTP_CLO;
1873 goto out;
1874 }
1875 else if (kwm == KWM_NO) {
1876 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1877 curproxy->options &= ~PR_O_HTTP_MODE;
1878 goto out;
1879 }
1880 }
1881 else if (strcmp(args[1], "http-server-close") == 0) {
1882 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1883 goto out;
1884 if (kwm == KWM_STD) {
1885 curproxy->options &= ~PR_O_HTTP_MODE;
1886 curproxy->options |= PR_O_HTTP_SCL;
1887 goto out;
1888 }
1889 else if (kwm == KWM_NO) {
1890 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1891 curproxy->options &= ~PR_O_HTTP_MODE;
1892 goto out;
1893 }
1894 }
1895 else if (strcmp(args[1], "http-keep-alive") == 0) {
1896 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1897 goto out;
1898 if (kwm == KWM_STD) {
1899 curproxy->options &= ~PR_O_HTTP_MODE;
1900 curproxy->options |= PR_O_HTTP_KAL;
1901 goto out;
1902 }
1903 else if (kwm == KWM_NO) {
1904 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1905 curproxy->options &= ~PR_O_HTTP_MODE;
1906 goto out;
1907 }
1908 }
1909 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001910 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
1911 file, linenum, args[1]);
1912 err_code |= ERR_WARN;
1913 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001914 }
1915
1916 /* Redispatch can take an integer argument that control when the
1917 * resispatch occurs. All values are relative to the retries option.
1918 * This can be cancelled using "no option xxx".
1919 */
1920 if (strcmp(args[1], "redispatch") == 0) {
1921 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
1922 err_code |= ERR_WARN;
1923 goto out;
1924 }
1925
1926 curproxy->no_options &= ~PR_O_REDISP;
1927 curproxy->options &= ~PR_O_REDISP;
1928
1929 switch (kwm) {
1930 case KWM_STD:
1931 curproxy->options |= PR_O_REDISP;
1932 curproxy->redispatch_after = -1;
1933 if(*args[2]) {
1934 curproxy->redispatch_after = atol(args[2]);
1935 }
1936 break;
1937 case KWM_NO:
1938 curproxy->no_options |= PR_O_REDISP;
1939 curproxy->redispatch_after = 0;
1940 break;
1941 case KWM_DEF: /* already cleared */
1942 break;
1943 }
1944 goto out;
1945 }
1946
1947 if (kwm != KWM_STD) {
1948 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
1949 file, linenum, args[1]);
1950 err_code |= ERR_ALERT | ERR_FATAL;
1951 goto out;
1952 }
1953
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001954 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001955 char *logformat;
1956 /* generate a complete HTTP log */
1957 logformat = default_http_log_format;
1958 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001959 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001960 curproxy->options2 |= PR_O2_CLFLOG;
1961 logformat = clf_http_log_format;
1962 } else {
1963 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
1964 err_code |= ERR_ALERT | ERR_FATAL;
1965 goto out;
1966 }
1967 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
1968 goto out;
1969 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01001970 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001971 char *oldlogformat = "log-format";
1972 char *clflogformat = "";
1973
1974 if (curproxy->conf.logformat_string == default_http_log_format)
1975 oldlogformat = "option httplog";
1976 else if (curproxy->conf.logformat_string == default_tcp_log_format)
1977 oldlogformat = "option tcplog";
1978 else if (curproxy->conf.logformat_string == clf_http_log_format)
1979 oldlogformat = "option httplog clf";
1980 if (logformat == clf_http_log_format)
1981 clflogformat = " clf";
1982 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
1983 file, linenum, clflogformat, oldlogformat);
1984 }
1985 if (curproxy->conf.logformat_string != default_http_log_format &&
1986 curproxy->conf.logformat_string != default_tcp_log_format &&
1987 curproxy->conf.logformat_string != clf_http_log_format)
1988 free(curproxy->conf.logformat_string);
1989 curproxy->conf.logformat_string = logformat;
1990
1991 free(curproxy->conf.lfs_file);
1992 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
1993 curproxy->conf.lfs_line = curproxy->conf.args.line;
1994
Willy Tarreau5d095c22021-02-12 10:15:59 +01001995 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001996 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
1997 file, linenum, curproxy->id);
1998 err_code |= ERR_WARN;
1999 }
2000 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002001 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002002 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002003 char *oldlogformat = "log-format";
2004
2005 if (curproxy->conf.logformat_string == default_http_log_format)
2006 oldlogformat = "option httplog";
2007 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2008 oldlogformat = "option tcplog";
2009 else if (curproxy->conf.logformat_string == clf_http_log_format)
2010 oldlogformat = "option httplog clf";
2011 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2012 file, linenum, oldlogformat);
2013 }
2014 /* generate a detailed TCP log */
2015 if (curproxy->conf.logformat_string != default_http_log_format &&
2016 curproxy->conf.logformat_string != default_tcp_log_format &&
2017 curproxy->conf.logformat_string != clf_http_log_format)
2018 free(curproxy->conf.logformat_string);
2019 curproxy->conf.logformat_string = default_tcp_log_format;
2020
2021 free(curproxy->conf.lfs_file);
2022 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2023 curproxy->conf.lfs_line = curproxy->conf.args.line;
2024
2025 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2026 goto out;
2027
Willy Tarreau5d095c22021-02-12 10:15:59 +01002028 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002029 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2030 file, linenum, curproxy->id);
2031 err_code |= ERR_WARN;
2032 }
2033 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002034 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002035 /* enable TCP keep-alives on client and server streams */
2036 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2037 err_code |= ERR_WARN;
2038
2039 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2040 goto out;
2041
2042 if (curproxy->cap & PR_CAP_FE)
2043 curproxy->options |= PR_O_TCP_CLI_KA;
2044 if (curproxy->cap & PR_CAP_BE)
2045 curproxy->options |= PR_O_TCP_SRV_KA;
2046 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002047 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002048 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002049 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002050 goto out;
2051 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002052 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002053 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002054 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002055 goto out;
2056 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002057 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002058 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002059 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002060 goto out;
2061 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002062 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002063 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002064 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002065 goto out;
2066 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002067 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002068 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002069 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002070 goto out;
2071 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002072 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002073 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002074 if (err_code & ERR_FATAL)
2075 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002076 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002077 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002078 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002079 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002080 goto out;
2081 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002082 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002083 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002084 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002085 goto out;
2086 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002087 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002088 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002089 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002090 goto out;
2091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002092 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002093 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002094 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002095 goto out;
2096 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002097 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002098 int cur_arg;
2099
2100 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002101 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002102 */
2103
2104 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2105
2106 free(curproxy->fwdfor_hdr_name);
2107 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2108 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002109 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002110
2111 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2112 cur_arg = 2;
2113 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002114 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002115 unsigned char mask;
2116 int i;
2117
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002118 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002119 if (*(args[cur_arg+1]) &&
2120 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2121 curproxy->except_xff_net.family = AF_INET;
2122 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2123 }
2124 else if (*(args[cur_arg+1]) &&
2125 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2126 curproxy->except_xff_net.family = AF_INET6;
2127 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2128 for (i = 0; i < 16; i++)
2129 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2130 }
2131 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002132 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2133 file, linenum, args[0], args[1], args[cur_arg]);
2134 err_code |= ERR_ALERT | ERR_FATAL;
2135 goto out;
2136 }
2137 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002138 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002139 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002140 /* suboption header - needs additional argument for it */
2141 if (*(args[cur_arg+1]) == 0) {
2142 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2143 file, linenum, args[0], args[1], args[cur_arg]);
2144 err_code |= ERR_ALERT | ERR_FATAL;
2145 goto out;
2146 }
2147 free(curproxy->fwdfor_hdr_name);
2148 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2149 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2150 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002151 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002152 curproxy->options &= ~PR_O_FF_ALWAYS;
2153 cur_arg += 1;
2154 } else {
2155 /* unknown suboption - catchall */
2156 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2157 file, linenum, args[0], args[1]);
2158 err_code |= ERR_ALERT | ERR_FATAL;
2159 goto out;
2160 }
2161 } /* end while loop */
2162 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002163 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002164 int cur_arg;
2165
2166 /* insert x-original-to field, but not for the IP address listed as an except.
2167 * set default options (ie: bitfield, header name, etc)
2168 */
2169
2170 curproxy->options |= PR_O_ORGTO;
2171
2172 free(curproxy->orgto_hdr_name);
2173 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2174 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002175 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002176
2177 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2178 cur_arg = 2;
2179 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002180 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002181 unsigned char mask;
2182 int i;
2183
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002184 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002185 if (*(args[cur_arg+1]) &&
2186 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2187 curproxy->except_xot_net.family = AF_INET;
2188 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2189 }
2190 else if (*(args[cur_arg+1]) &&
2191 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2192 curproxy->except_xot_net.family = AF_INET6;
2193 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2194 for (i = 0; i < 16; i++)
2195 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2196 }
2197 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002198 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2199 file, linenum, args[0], args[1], args[cur_arg]);
2200 err_code |= ERR_ALERT | ERR_FATAL;
2201 goto out;
2202 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002203 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002204 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002205 /* suboption header - needs additional argument for it */
2206 if (*(args[cur_arg+1]) == 0) {
2207 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2208 file, linenum, args[0], args[1], args[cur_arg]);
2209 err_code |= ERR_ALERT | ERR_FATAL;
2210 goto out;
2211 }
2212 free(curproxy->orgto_hdr_name);
2213 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2214 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2215 cur_arg += 2;
2216 } else {
2217 /* unknown suboption - catchall */
2218 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2219 file, linenum, args[0], args[1]);
2220 err_code |= ERR_ALERT | ERR_FATAL;
2221 goto out;
2222 }
2223 } /* end while loop */
2224 }
2225 else {
2226 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2227 err_code |= ERR_ALERT | ERR_FATAL;
2228 goto out;
2229 }
2230 goto out;
2231 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002232 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002233 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2234 err_code |= ERR_WARN;
2235
2236 if (*(args[1]) == 0) {
2237 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2238 err_code |= ERR_ALERT | ERR_FATAL;
2239 goto out;
2240 }
2241 free(curproxy->defbe.name);
2242 curproxy->defbe.name = strdup(args[1]);
2243
2244 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2245 goto out;
2246 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002247 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002248 ha_alert("parsing [%s:%d] : keyword '%s' directive is not supported anymore since HAProxy 2.1. Use 'option redispatch'.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002249
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002250 err_code |= ERR_ALERT | ERR_FATAL;
2251 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002252 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002253 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002254 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2255 err_code |= ERR_WARN;
2256
2257 if (strcmp(args[1], "never") == 0) {
2258 /* enable a graceful server shutdown on an HTTP 404 response */
2259 curproxy->options &= ~PR_O_REUSE_MASK;
2260 curproxy->options |= PR_O_REUSE_NEVR;
2261 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2262 goto out;
2263 }
2264 else if (strcmp(args[1], "safe") == 0) {
2265 /* enable a graceful server shutdown on an HTTP 404 response */
2266 curproxy->options &= ~PR_O_REUSE_MASK;
2267 curproxy->options |= PR_O_REUSE_SAFE;
2268 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2269 goto out;
2270 }
2271 else if (strcmp(args[1], "aggressive") == 0) {
2272 curproxy->options &= ~PR_O_REUSE_MASK;
2273 curproxy->options |= PR_O_REUSE_AGGR;
2274 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2275 goto out;
2276 }
2277 else if (strcmp(args[1], "always") == 0) {
2278 /* enable a graceful server shutdown on an HTTP 404 response */
2279 curproxy->options &= ~PR_O_REUSE_MASK;
2280 curproxy->options |= PR_O_REUSE_ALWS;
2281 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2282 goto out;
2283 }
2284 else {
2285 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2286 err_code |= ERR_ALERT | ERR_FATAL;
2287 goto out;
2288 }
2289 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002290 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002291 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002292 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2293 err_code |= ERR_ALERT | ERR_FATAL;
2294 goto out;
2295 }
2296
2297 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2298 err_code |= ERR_WARN;
2299
2300 if (strcmp(args[1], "fail") == 0) {
2301 /* add a condition to fail monitor requests */
2302 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2303 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2304 file, linenum, args[0], args[1]);
2305 err_code |= ERR_ALERT | ERR_FATAL;
2306 goto out;
2307 }
2308
2309 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2310 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2311 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2312 file, linenum, args[0], args[1], errmsg);
2313 err_code |= ERR_ALERT | ERR_FATAL;
2314 goto out;
2315 }
2316 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2317 }
2318 else {
2319 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2320 err_code |= ERR_ALERT | ERR_FATAL;
2321 goto out;
2322 }
2323 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002324#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002325 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002326 /* enable transparent proxy connections */
2327 curproxy->options |= PR_O_TRANSP;
2328 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2329 goto out;
2330 }
2331#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002332 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002333 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2334 err_code |= ERR_WARN;
2335
2336 if (*(args[1]) == 0) {
2337 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2338 err_code |= ERR_ALERT | ERR_FATAL;
2339 goto out;
2340 }
2341 curproxy->maxconn = atol(args[1]);
2342 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2343 goto out;
2344 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002345 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002346 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2347 err_code |= ERR_WARN;
2348
2349 if (*(args[1]) == 0) {
2350 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2351 err_code |= ERR_ALERT | ERR_FATAL;
2352 goto out;
2353 }
2354 curproxy->backlog = atol(args[1]);
2355 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2356 goto out;
2357 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002358 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002359 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2360 err_code |= ERR_WARN;
2361
2362 if (*(args[1]) == 0) {
2363 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2364 err_code |= ERR_ALERT | ERR_FATAL;
2365 goto out;
2366 }
2367 curproxy->fullconn = atol(args[1]);
2368 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2369 goto out;
2370 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002371 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002372 if (*(args[1]) == 0) {
2373 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2374 err_code |= ERR_ALERT | ERR_FATAL;
2375 goto out;
2376 }
2377 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002378 if (err == PARSE_TIME_OVER) {
2379 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2380 file, linenum, args[1]);
2381 err_code |= ERR_ALERT | ERR_FATAL;
2382 goto out;
2383 }
2384 else if (err == PARSE_TIME_UNDER) {
2385 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2386 file, linenum, args[1]);
2387 err_code |= ERR_ALERT | ERR_FATAL;
2388 goto out;
2389 }
2390 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002391 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2392 file, linenum, *err);
2393 err_code |= ERR_ALERT | ERR_FATAL;
2394 goto out;
2395 }
2396 curproxy->grace = val;
2397 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2398 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002399
2400 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2401 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002402 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002403 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002404 struct sockaddr_storage *sk;
2405 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002406
Willy Tarreau5d095c22021-02-12 10:15:59 +01002407 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002408 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2409 err_code |= ERR_ALERT | ERR_FATAL;
2410 goto out;
2411 }
2412 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2413 err_code |= ERR_WARN;
2414
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002415 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2416 &errmsg, NULL, NULL,
2417 PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002418 if (!sk) {
2419 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2420 err_code |= ERR_ALERT | ERR_FATAL;
2421 goto out;
2422 }
2423
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002424 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2425 goto out;
2426
2427 curproxy->dispatch_addr = *sk;
2428 curproxy->options |= PR_O_DISPATCH;
2429 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002430 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002431 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2432 err_code |= ERR_WARN;
2433
2434 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2435 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2436 err_code |= ERR_ALERT | ERR_FATAL;
2437 goto out;
2438 }
2439 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002440 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002441 /**
2442 * The syntax for hash-type config element is
2443 * hash-type {map-based|consistent} [[<algo>] avalanche]
2444 *
2445 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2446 */
2447 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2448
2449 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2450 err_code |= ERR_WARN;
2451
2452 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2453 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2454 }
2455 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2456 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2457 }
2458 else if (strcmp(args[1], "avalanche") == 0) {
2459 ha_alert("parsing [%s:%d] : experimental feature '%s %s' is not supported anymore, please use '%s map-based sdbm avalanche' instead.\n", file, linenum, args[0], args[1], args[0]);
2460 err_code |= ERR_ALERT | ERR_FATAL;
2461 goto out;
2462 }
2463 else {
2464 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2465 err_code |= ERR_ALERT | ERR_FATAL;
2466 goto out;
2467 }
2468
2469 /* set the hash function to use */
2470 if (!*args[2]) {
2471 /* the default algo is sdbm */
2472 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2473
2474 /* if consistent with no argument, then avalanche modifier is also applied */
2475 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2476 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2477 } else {
2478 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002479 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002480 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2481 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002482 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002483 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2484 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002485 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002486 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2487 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002488 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002489 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2490 }
2491 else {
2492 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2493 err_code |= ERR_ALERT | ERR_FATAL;
2494 goto out;
2495 }
2496
2497 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002498 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002499 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2500 }
2501 else if (*args[3]) {
2502 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2503 err_code |= ERR_ALERT | ERR_FATAL;
2504 goto out;
2505 }
2506 }
2507 }
2508 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2509 if (*(args[1]) == 0) {
2510 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2511 err_code |= ERR_ALERT | ERR_FATAL;
2512 goto out;
2513 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002514 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2515 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002516 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2517 err_code |= ERR_ALERT | ERR_FATAL;
2518 goto out;
2519 }
2520 }
2521 else if (strcmp(args[0], "unique-id-format") == 0) {
2522 if (!*(args[1])) {
2523 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2524 err_code |= ERR_ALERT | ERR_FATAL;
2525 goto out;
2526 }
2527 if (*(args[2])) {
2528 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2529 err_code |= ERR_ALERT | ERR_FATAL;
2530 goto out;
2531 }
2532 free(curproxy->conf.uniqueid_format_string);
2533 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2534
2535 free(curproxy->conf.uif_file);
2536 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2537 curproxy->conf.uif_line = curproxy->conf.args.line;
2538 }
2539
2540 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002541 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002542 if (!*(args[1])) {
2543 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2544 err_code |= ERR_ALERT | ERR_FATAL;
2545 goto out;
2546 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002547 copy = strdup(args[1]);
2548 if (copy == NULL) {
2549 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2550 err_code |= ERR_ALERT | ERR_FATAL;
2551 goto out;
2552 }
2553
2554 istfree(&curproxy->header_unique_id);
2555 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002556 }
2557
2558 else if (strcmp(args[0], "log-format") == 0) {
2559 if (!*(args[1])) {
2560 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2561 err_code |= ERR_ALERT | ERR_FATAL;
2562 goto out;
2563 }
2564 if (*(args[2])) {
2565 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2566 err_code |= ERR_ALERT | ERR_FATAL;
2567 goto out;
2568 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002569 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002570 char *oldlogformat = "log-format";
2571
2572 if (curproxy->conf.logformat_string == default_http_log_format)
2573 oldlogformat = "option httplog";
2574 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2575 oldlogformat = "option tcplog";
2576 else if (curproxy->conf.logformat_string == clf_http_log_format)
2577 oldlogformat = "option httplog clf";
2578 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2579 file, linenum, oldlogformat);
2580 }
2581 if (curproxy->conf.logformat_string != default_http_log_format &&
2582 curproxy->conf.logformat_string != default_tcp_log_format &&
2583 curproxy->conf.logformat_string != clf_http_log_format)
2584 free(curproxy->conf.logformat_string);
2585 curproxy->conf.logformat_string = strdup(args[1]);
2586
2587 free(curproxy->conf.lfs_file);
2588 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2589 curproxy->conf.lfs_line = curproxy->conf.args.line;
2590
2591 /* get a chance to improve log-format error reporting by
2592 * reporting the correct line-number when possible.
2593 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002594 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002595 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2596 file, linenum, curproxy->id);
2597 err_code |= ERR_WARN;
2598 }
2599 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002600 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002601 if (!*(args[1])) {
2602 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2603 err_code |= ERR_ALERT | ERR_FATAL;
2604 goto out;
2605 }
2606 if (*(args[2])) {
2607 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2608 err_code |= ERR_ALERT | ERR_FATAL;
2609 goto out;
2610 }
2611
2612 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2613 free(curproxy->conf.logformat_sd_string);
2614 curproxy->conf.logformat_sd_string = strdup(args[1]);
2615
2616 free(curproxy->conf.lfsd_file);
2617 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2618 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2619
2620 /* get a chance to improve log-format-sd error reporting by
2621 * reporting the correct line-number when possible.
2622 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002623 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002624 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2625 file, linenum, curproxy->id);
2626 err_code |= ERR_WARN;
2627 }
2628 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002629 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002630 if (*(args[1]) == 0) {
2631 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2632 err_code |= ERR_ALERT | ERR_FATAL;
2633 goto out;
2634 }
2635 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002636 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2637 if (b_orig(&curproxy->log_tag) == NULL) {
2638 chunk_destroy(&curproxy->log_tag);
2639 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2640 err_code |= ERR_ALERT | ERR_FATAL;
2641 goto out;
2642 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002644 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002645 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2646 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2647 err_code |= ERR_ALERT | ERR_FATAL;
2648 goto out;
2649 }
2650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002651 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002652 int cur_arg;
2653 int port1, port2;
2654 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002655
2656 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2657 err_code |= ERR_WARN;
2658
2659 if (!*args[1]) {
2660 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2661 file, linenum, "source", "usesrc", "interface");
2662 err_code |= ERR_ALERT | ERR_FATAL;
2663 goto out;
2664 }
2665
Christopher Faulet31930372019-07-15 10:16:58 +02002666 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002667 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002668 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002669 curproxy->conn_src.iface_len = 0;
2670
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002671 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2672 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002673 if (!sk) {
2674 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2675 file, linenum, args[0], args[1], errmsg);
2676 err_code |= ERR_ALERT | ERR_FATAL;
2677 goto out;
2678 }
2679
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002680 curproxy->conn_src.source_addr = *sk;
2681 curproxy->conn_src.opts |= CO_SRC_BIND;
2682
2683 cur_arg = 2;
2684 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002685 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002686#if defined(CONFIG_HAP_TRANSPARENT)
2687 if (!*args[cur_arg + 1]) {
2688 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2689 file, linenum, "usesrc");
2690 err_code |= ERR_ALERT | ERR_FATAL;
2691 goto out;
2692 }
2693
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002694 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002695 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2696 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002697 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002698 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2699 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2700 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2701 char *name, *end;
2702
2703 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002704 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002705 name++;
2706
2707 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002708 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002709 end++;
2710
2711 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2712 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002713 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002714 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2715 curproxy->conn_src.bind_hdr_len = end - name;
2716 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2717 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2718 curproxy->conn_src.bind_hdr_occ = -1;
2719
2720 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002721 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002722 end++;
2723 if (*end == ',') {
2724 end++;
2725 name = end;
2726 if (*end == '-')
2727 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002728 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002729 end++;
2730 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2731 }
2732
2733 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2734 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2735 " occurrences values smaller than %d.\n",
2736 file, linenum, MAX_HDR_HISTORY);
2737 err_code |= ERR_ALERT | ERR_FATAL;
2738 goto out;
2739 }
2740 } else {
2741 struct sockaddr_storage *sk;
2742
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002743 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2744 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002745 if (!sk) {
2746 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2747 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2748 err_code |= ERR_ALERT | ERR_FATAL;
2749 goto out;
2750 }
2751
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002752 curproxy->conn_src.tproxy_addr = *sk;
2753 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2754 }
2755 global.last_checks |= LSTCHK_NETADM;
2756#else /* no TPROXY support */
2757 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2758 file, linenum, "usesrc");
2759 err_code |= ERR_ALERT | ERR_FATAL;
2760 goto out;
2761#endif
2762 cur_arg += 2;
2763 continue;
2764 }
2765
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002766 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002767#ifdef SO_BINDTODEVICE
2768 if (!*args[cur_arg + 1]) {
2769 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2770 file, linenum, args[0]);
2771 err_code |= ERR_ALERT | ERR_FATAL;
2772 goto out;
2773 }
2774 free(curproxy->conn_src.iface_name);
2775 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2776 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2777 global.last_checks |= LSTCHK_NETADM;
2778#else
2779 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2780 file, linenum, args[0], args[cur_arg]);
2781 err_code |= ERR_ALERT | ERR_FATAL;
2782 goto out;
2783#endif
2784 cur_arg += 2;
2785 continue;
2786 }
2787 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2788 file, linenum, args[0], "interface", "usesrc");
2789 err_code |= ERR_ALERT | ERR_FATAL;
2790 goto out;
2791 }
2792 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002793 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002794 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2795 file, linenum, "usesrc", "source");
2796 err_code |= ERR_ALERT | ERR_FATAL;
2797 goto out;
2798 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002799 else if (strcmp(args[0], "cliexp") == 0 || strcmp(args[0], "reqrep") == 0) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002800 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002801 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002802 file, linenum, args[0]);
2803 err_code |= ERR_ALERT | ERR_FATAL;
2804 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002805 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002806 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002807 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2808 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2809 err_code |= ERR_ALERT | ERR_FATAL;
2810 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002811 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002812 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002813 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2814 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2815 err_code |= ERR_ALERT | ERR_FATAL;
2816 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002817 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002818 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002819 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2820 err_code |= ERR_ALERT | ERR_FATAL;
2821 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002822 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002823 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002824 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2825 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2826 err_code |= ERR_ALERT | ERR_FATAL;
2827 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002828 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002829 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002830 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2831 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2832 err_code |= ERR_ALERT | ERR_FATAL;
2833 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002834 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002835 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002836 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2837 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2838 err_code |= ERR_ALERT | ERR_FATAL;
2839 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002840 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002841 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002842 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2843 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2844 err_code |= ERR_ALERT | ERR_FATAL;
2845 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002846 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002847 else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002848 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2849 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2850 err_code |= ERR_ALERT | ERR_FATAL;
2851 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002852 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002853 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002854 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2855 err_code |= ERR_ALERT | ERR_FATAL;
2856 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002857 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002858 else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002859 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2860 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2861 err_code |= ERR_ALERT | ERR_FATAL;
2862 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002863 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002864 else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002865 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2866 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2867 err_code |= ERR_ALERT | ERR_FATAL;
2868 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002869 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002870 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002871 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2872 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2873 err_code |= ERR_ALERT | ERR_FATAL;
2874 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002875 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002876 else if (strcmp(args[0], "srvexp") == 0 || strcmp(args[0], "rsprep") == 0) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002877 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2878 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2879 err_code |= ERR_ALERT | ERR_FATAL;
2880 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002881 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002882 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002883 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2884 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2885 err_code |= ERR_ALERT | ERR_FATAL;
2886 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002887 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002888 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002889 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2890 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2891 err_code |= ERR_ALERT | ERR_FATAL;
2892 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002893 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002894 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302895 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002896 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2897 err_code |= ERR_ALERT | ERR_FATAL;
2898 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002899 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002900 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002901 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2902 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2903 err_code |= ERR_ALERT | ERR_FATAL;
2904 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002905 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002906 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002907 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2908 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2909 err_code |= ERR_ALERT | ERR_FATAL;
2910 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002911 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002912 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002913 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2914 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2915 err_code |= ERR_ALERT | ERR_FATAL;
2916 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002917 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002918 else {
2919 struct cfg_kw_list *kwl;
2920 int index;
2921
2922 list_for_each_entry(kwl, &cfg_keywords.list, list) {
2923 for (index = 0; kwl->kw[index].kw != NULL; index++) {
2924 if (kwl->kw[index].section != CFG_LISTEN)
2925 continue;
2926 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
2927 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01002928 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002929 if (rc < 0) {
2930 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2931 err_code |= ERR_ALERT | ERR_FATAL;
2932 goto out;
2933 }
2934 else if (rc > 0) {
2935 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2936 err_code |= ERR_WARN;
2937 goto out;
2938 }
2939 goto out;
2940 }
2941 }
2942 }
2943
2944 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
2945 err_code |= ERR_ALERT | ERR_FATAL;
2946 goto out;
2947 }
2948 out:
2949 free(errmsg);
2950 return err_code;
2951}