blob: 49a6d14d4c683488ffd4e52dd7f6fa6086fa37cc [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 Tarreauc0ff6792021-03-12 09:14:19 +010036/* some keywords that are still being parsed using strcmp() and are not
37 * registered anywhere. They are used as suggestions for mistyped words.
38 */
39static const char *common_kw_list[] = {
40 "listen", "frontend", "backend", "defaults", "server",
41 "default-server", "server-template", "bind", "monitor-net",
42 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
43 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
44 "persist", "appsession", "load-server-state-from-file",
45 "server-state-file-name", "max-session-srv-conns", "capture",
46 "retries", "http-request", "http-response", "http-after-response",
47 "http-send-name-header", "block", "redirect", "use_backend",
48 "use-server", "force-persist", "ignore-persist", "force-persist",
49 "stick-table", "stick", "stats", "option", "default_backend",
50 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
51 "fullconn", "grace", "dispatch", "balance", "hash-type",
52 "hash-balance-factor", "unique-id-format", "unique-id-header",
53 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
54 NULL /* must be last */
55};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010056
Willy Tarreau31a3cea2021-03-15 11:11:55 +010057static const char *common_options[] = {
58 "httpclose", "forceclose", "http-server-close", "http-keep-alive",
59 "http-tunnel", "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
60 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
61 "mysql-check", "ldap-check", "spop-check", "tcp-check",
62 "external-check", "forwardfor", "original-to",
63 NULL /* must be last */
64};
65
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010066/* Report a warning if a rule is placed after a 'tcp-request session' rule.
67 * Return 1 if the warning has been emitted, otherwise 0.
68 */
69int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
70{
71 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
72 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
73 file, line, arg);
74 return 1;
75 }
76 return 0;
77}
78
79/* Report a warning if a rule is placed after a 'tcp-request content' rule.
80 * Return 1 if the warning has been emitted, otherwise 0.
81 */
82int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
83{
84 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
85 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
86 file, line, arg);
87 return 1;
88 }
89 return 0;
90}
91
92/* Report a warning if a rule is placed after a 'monitor fail' rule.
93 * Return 1 if the warning has been emitted, otherwise 0.
94 */
95int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
96{
97 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
98 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
99 file, line, arg);
100 return 1;
101 }
102 return 0;
103}
104
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100105/* Report a warning if a rule is placed after an 'http_request' rule.
106 * Return 1 if the warning has been emitted, otherwise 0.
107 */
108int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
109{
110 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
111 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
112 file, line, arg);
113 return 1;
114 }
115 return 0;
116}
117
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100118/* Report a warning if a rule is placed after a redirect rule.
119 * Return 1 if the warning has been emitted, otherwise 0.
120 */
121int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
122{
123 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
124 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
125 file, line, arg);
126 return 1;
127 }
128 return 0;
129}
130
131/* Report a warning if a rule is placed after a 'use_backend' rule.
132 * Return 1 if the warning has been emitted, otherwise 0.
133 */
134int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
135{
136 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
137 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
138 file, line, arg);
139 return 1;
140 }
141 return 0;
142}
143
144/* Report a warning if a rule is placed after a 'use-server' rule.
145 * Return 1 if the warning has been emitted, otherwise 0.
146 */
147int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
148{
149 if (!LIST_ISEMPTY(&proxy->server_rules)) {
150 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
151 file, line, arg);
152 return 1;
153 }
154 return 0;
155}
156
157/* report a warning if a redirect rule is dangerously placed */
158int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
159{
160 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
161 warnif_rule_after_use_server(proxy, file, line, arg);
162}
163
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100164/* report a warning if an http-request rule is dangerously placed */
165int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
166{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200167 return warnif_rule_after_redirect(proxy, file, line, arg) ||
168 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100169}
170
171/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200172int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100173{
174 return warnif_rule_after_http_req(proxy, file, line, arg) ||
175 warnif_misplaced_http_req(proxy, file, line, arg);
176}
177
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100178/* report a warning if a "tcp request content" rule is dangerously placed */
179int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
180{
181 return warnif_rule_after_monitor(proxy, file, line, arg) ||
182 warnif_misplaced_monitor(proxy, file, line, arg);
183}
184
185/* report a warning if a "tcp request session" rule is dangerously placed */
186int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
187{
188 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
189 warnif_misplaced_tcp_cont(proxy, file, line, arg);
190}
191
192/* report a warning if a "tcp request connection" rule is dangerously placed */
193int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
194{
195 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
196 warnif_misplaced_tcp_sess(proxy, file, line, arg);
197}
198
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100199int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
200{
201 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100202 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100203 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100204 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100205 int rc;
206 unsigned val;
207 int err_code = 0;
208 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100209 char *errmsg = NULL;
210 struct bind_conf *bind_conf;
211
Willy Tarreaue90904d2021-02-12 14:08:31 +0100212 if (!last_defproxy) {
213 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100214 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
215 proxy_preset_defaults(last_defproxy);
216
Willy Tarreaue90904d2021-02-12 14:08:31 +0100217 curr_defproxy = last_defproxy;
218 if (!last_defproxy) {
219 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
220 err_code |= ERR_ALERT | ERR_ABORT;
221 goto out;
222 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100223 }
224
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100225 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100226 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100228 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100229 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100230 rc = PR_CAP_BE;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100231 else if (strcmp(args[0], "defaults") == 0) {
232 /* "defaults" must first delete the last no-name defaults if any */
233 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
234 curr_defproxy = NULL;
235 rc = PR_CAP_DEF | PR_CAP_LISTEN;
236 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100237 else
238 rc = PR_CAP_NONE;
239
Willy Tarreaue90904d2021-02-12 14:08:31 +0100240 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100241 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100242 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100243 file, linenum, args[0]);
244 err_code |= ERR_ALERT | ERR_ABORT;
245 goto out;
246 }
247
248 err = invalid_char(args[1]);
249 if (err) {
250 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
251 file, linenum, *err, args[0], args[1]);
252 err_code |= ERR_ALERT | ERR_FATAL;
253 }
254
255 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
256 if (curproxy) {
257 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
258 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
259 curproxy->id, curproxy->conf.file, curproxy->conf.line);
260 err_code |= ERR_ALERT | ERR_FATAL;
261 }
262
Emeric Brunb0c331f2020-10-07 17:05:59 +0200263 curproxy = log_forward_by_name(args[1]);
264 if (curproxy) {
265 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
266 file, linenum, proxy_cap_str(rc), args[1],
267 curproxy->id, curproxy->conf.file, curproxy->conf.line);
268 err_code |= ERR_ALERT | ERR_FATAL;
269 }
270
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100271 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
272 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100273 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100274 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
275 goto out;
276 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100277 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100278
Willy Tarreaue90904d2021-02-12 14:08:31 +0100279 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100280 const char *name = args[1];
281 int arg = 2;
282
283 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
284 // also support "defaults from blah" (no name then)
285 arg = 1;
286 name = "";
287 }
288
289 /* only regular proxies inherit from the previous defaults section */
290 if (!(rc & PR_CAP_DEF))
291 curr_defproxy = last_defproxy;
292
293 if (strcmp(args[arg], "from") == 0) {
294 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
295
296 if (!curr_defproxy) {
297 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
298 err_code |= ERR_ALERT | ERR_ABORT;
299 goto out;
300 }
301
302 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
303 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
304
305 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
306 file, linenum, args[arg+1], proxy_cap_str(rc), name,
307 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
308 err_code |= ERR_ALERT | ERR_FATAL;
309 }
310
311 err = invalid_char(args[arg+1]);
312 if (err) {
313 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",
314 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
315 err_code |= ERR_ALERT | ERR_FATAL;
316 }
317 }
318
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100319 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100320 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100321 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100322 goto out;
323 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100324
Willy Tarreaue90904d2021-02-12 14:08:31 +0100325 if (rc & PR_CAP_DEF) {
326 /* last and current proxies must be updated to this one */
327 curr_defproxy = last_defproxy = curproxy;
328 } else {
329 /* regular proxies are in a list */
330 curproxy->next = proxies_list;
331 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100332 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100333 goto out;
334 }
335 else if (curproxy == NULL) {
336 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
337 err_code |= ERR_ALERT | ERR_FATAL;
338 goto out;
339 }
340
341 /* update the current file and line being parsed */
342 curproxy->conf.args.file = curproxy->conf.file;
343 curproxy->conf.args.line = linenum;
344
345 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100346 if ((strcmp(args[0], "server") == 0)) {
347 err_code |= parse_server(file, linenum, args,
348 curproxy, curr_defproxy,
349 SRV_PARSE_PARSE_ADDR);
350
351 if (err_code & ERR_FATAL)
352 goto out;
353 }
354 else if (strcmp(args[0], "default-server") == 0) {
355 err_code |= parse_server(file, linenum, args,
356 curproxy, curr_defproxy,
357 SRV_PARSE_DEFAULT_SERVER);
358
359 if (err_code & ERR_FATAL)
360 goto out;
361 }
362 else if (strcmp(args[0], "server-template") == 0) {
363 err_code |= parse_server(file, linenum, args,
364 curproxy, curr_defproxy,
365 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
366
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100367 if (err_code & ERR_FATAL)
368 goto out;
369 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100370 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100371 struct listener *l;
372 int cur_arg;
373
Willy Tarreau5d095c22021-02-12 10:15:59 +0100374 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100375 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
376 err_code |= ERR_ALERT | ERR_FATAL;
377 goto out;
378 }
379 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
380 err_code |= ERR_WARN;
381
382 if (!*(args[1])) {
383 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
384 file, linenum, args[0]);
385 err_code |= ERR_ALERT | ERR_FATAL;
386 goto out;
387 }
388
389 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
390
391 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200392 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
393 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
394 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100395
396 /* NOTE: the following line might create several listeners if there
397 * are comma-separated IPs or port ranges. So all further processing
398 * will have to be applied to all listeners created after last_listen.
399 */
400 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
401 if (errmsg && *errmsg) {
402 indent_msg(&errmsg, 2);
403 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
404 }
405 else
406 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
407 file, linenum, args[0], args[1]);
408 err_code |= ERR_ALERT | ERR_FATAL;
409 goto out;
410 }
411
412 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
413 /* Set default global rights and owner for unix bind */
414 global.maxsock++;
415 }
416
417 cur_arg = 2;
418 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100419 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100420 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100421
422 kw = bind_find_kw(args[cur_arg]);
423 if (kw) {
424 char *err = NULL;
425 int code;
426
427 if (!kw->parse) {
428 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
429 file, linenum, args[0], args[1], args[cur_arg]);
430 cur_arg += 1 + kw->skip ;
431 err_code |= ERR_ALERT | ERR_FATAL;
432 goto out;
433 }
434
435 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
436 err_code |= code;
437
438 if (code) {
439 if (err && *err) {
440 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200441 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
442 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
443 else
444 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100445 }
446 else
447 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
448 file, linenum, args[0], args[1], args[cur_arg]);
449 if (code & ERR_FATAL) {
450 free(err);
451 cur_arg += 1 + kw->skip;
452 goto out;
453 }
454 }
455 free(err);
456 cur_arg += 1 + kw->skip;
457 continue;
458 }
459
Willy Tarreau433b05f2021-03-12 10:14:07 +0100460 best = bind_find_best_kw(args[cur_arg]);
461 if (best)
462 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
463 file, linenum, args[0], args[1], args[cur_arg], best);
464 else
465 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
466 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100467
468 err_code |= ERR_ALERT | ERR_FATAL;
469 goto out;
470 }
471 goto out;
472 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100473 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200474 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]);
475 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100476 goto out;
477 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100478 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100479 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
480 err_code |= ERR_WARN;
481
482 if (alertif_too_many_args(1, file, linenum, args, &err_code))
483 goto out;
484
485 if (!*args[1]) {
486 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
487 file, linenum, args[0]);
488 err_code |= ERR_ALERT | ERR_FATAL;
489 goto out;
490 }
491
492 free(curproxy->monitor_uri);
493 curproxy->monitor_uri_len = strlen(args[1]);
494 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
495 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
496 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
497
498 goto out;
499 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100500 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100501 if (alertif_too_many_args(1, file, linenum, args, &err_code))
502 goto out;
503
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100504 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
505 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
506 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200507 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
508 err_code |= ERR_ALERT | ERR_FATAL;
509 goto out;
510 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100511 else {
512 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
513 err_code |= ERR_ALERT | ERR_FATAL;
514 goto out;
515 }
516 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100517 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100518 struct eb32_node *node;
519
Willy Tarreau5d095c22021-02-12 10:15:59 +0100520 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100521 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
522 file, linenum, args[0]);
523 err_code |= ERR_ALERT | ERR_FATAL;
524 goto out;
525 }
526
527 if (alertif_too_many_args(1, file, linenum, args, &err_code))
528 goto out;
529
530 if (!*args[1]) {
531 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
532 file, linenum, args[0]);
533 err_code |= ERR_ALERT | ERR_FATAL;
534 goto out;
535 }
536
537 curproxy->uuid = atol(args[1]);
538 curproxy->conf.id.key = curproxy->uuid;
539 curproxy->options |= PR_O_FORCED_ID;
540
541 if (curproxy->uuid <= 0) {
542 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
543 file, linenum);
544 err_code |= ERR_ALERT | ERR_FATAL;
545 goto out;
546 }
547
548 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
549 if (node) {
550 struct proxy *target = container_of(node, struct proxy, conf.id);
551 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
552 file, linenum, proxy_type_str(curproxy), curproxy->id,
553 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
554 err_code |= ERR_ALERT | ERR_FATAL;
555 goto out;
556 }
557 eb32_insert(&used_proxy_id, &curproxy->conf.id);
558 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100559 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100560 int i, len=0;
561 char *d;
562
Willy Tarreau5d095c22021-02-12 10:15:59 +0100563 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100564 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
565 file, linenum, args[0]);
566 err_code |= ERR_ALERT | ERR_FATAL;
567 goto out;
568 }
569
570 if (!*args[1]) {
571 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
572 file, linenum, args[0]);
573 return -1;
574 }
575
576 for (i = 1; *args[i]; i++)
577 len += strlen(args[i]) + 1;
578
579 d = calloc(1, len);
580 curproxy->desc = d;
581
582 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
583 for (i = 2; *args[i]; i++)
584 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
585
586 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100587 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100588 if (alertif_too_many_args(0, file, linenum, args, &err_code))
589 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200590 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100591 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100592 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100593 if (alertif_too_many_args(0, file, linenum, args, &err_code))
594 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200595 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100596 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100597 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100598 int cur_arg = 1;
599 unsigned long set = 0;
600
601 while (*args[cur_arg]) {
602 if (strcmp(args[cur_arg], "all") == 0) {
603 set = 0;
604 break;
605 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100606 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100607 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
608 err_code |= ERR_ALERT | ERR_FATAL;
609 goto out;
610 }
611 cur_arg++;
612 }
613 curproxy->bind_proc = set;
614 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100615 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100616 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100617 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
618 err_code |= ERR_ALERT | ERR_FATAL;
619 goto out;
620 }
621
622 err = invalid_char(args[1]);
623 if (err) {
624 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
625 file, linenum, *err, args[1]);
626 err_code |= ERR_ALERT | ERR_FATAL;
627 goto out;
628 }
629
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100630 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100631 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100632 "logical disjunction within a condition.\n",
633 file, linenum, args[1]);
634 err_code |= ERR_ALERT | ERR_FATAL;
635 goto out;
636 }
637
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100638 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
639 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
640 file, linenum, args[1], errmsg);
641 err_code |= ERR_ALERT | ERR_FATAL;
642 goto out;
643 }
644 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100645 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100646
647 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
648 err_code |= ERR_WARN;
649
650 if (*(args[1]) == 0) {
651 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
652 file, linenum, args[0]);
653 err_code |= ERR_ALERT | ERR_FATAL;
654 goto out;
655 }
656 free(curproxy->dyncookie_key);
657 curproxy->dyncookie_key = strdup(args[1]);
658 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100659 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100660 int cur_arg;
661
662 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
663 err_code |= ERR_WARN;
664
665 if (*(args[1]) == 0) {
666 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
667 file, linenum, args[0]);
668 err_code |= ERR_ALERT | ERR_FATAL;
669 goto out;
670 }
671
672 curproxy->ck_opts = 0;
673 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100674 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100675 free(curproxy->cookie_name);
676 curproxy->cookie_name = strdup(args[1]);
677 curproxy->cookie_len = strlen(curproxy->cookie_name);
678
679 cur_arg = 2;
680 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100681 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100682 curproxy->ck_opts |= PR_CK_RW;
683 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100684 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100685 curproxy->ck_opts |= PR_CK_IND;
686 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100687 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100688 curproxy->ck_opts |= PR_CK_INS;
689 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100690 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100691 curproxy->ck_opts |= PR_CK_NOC;
692 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100693 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100694 curproxy->ck_opts |= PR_CK_POST;
695 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100696 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100697 curproxy->ck_opts |= PR_CK_PSV;
698 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100699 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100700 curproxy->ck_opts |= PR_CK_PFX;
701 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100702 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100703 curproxy->ck_opts |= PR_CK_HTTPONLY;
704 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100705 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100706 curproxy->ck_opts |= PR_CK_SECURE;
707 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100708 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100709 if (!*args[cur_arg + 1]) {
710 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
711 file, linenum, args[cur_arg]);
712 err_code |= ERR_ALERT | ERR_FATAL;
713 goto out;
714 }
715
Joao Moraise1583752019-10-30 21:04:00 -0300716 if (!strchr(args[cur_arg + 1], '.')) {
717 /* rfc6265, 5.2.3 The Domain Attribute */
718 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
719 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100720 file, linenum, args[cur_arg + 1]);
721 err_code |= ERR_WARN;
722 }
723
724 err = invalid_domainchar(args[cur_arg + 1]);
725 if (err) {
726 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
727 file, linenum, *err, args[cur_arg + 1]);
728 err_code |= ERR_ALERT | ERR_FATAL;
729 goto out;
730 }
731
732 if (!curproxy->cookie_domain) {
733 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
734 } else {
735 /* one domain was already specified, add another one by
736 * building the string which will be returned along with
737 * the cookie.
738 */
739 char *new_ptr;
740 int new_len = strlen(curproxy->cookie_domain) +
741 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
742 new_ptr = malloc(new_len);
743 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
744 free(curproxy->cookie_domain);
745 curproxy->cookie_domain = new_ptr;
746 }
747 cur_arg++;
748 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100749 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100750 unsigned int maxidle;
751 const char *res;
752
753 if (!*args[cur_arg + 1]) {
754 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
755 file, linenum, args[cur_arg]);
756 err_code |= ERR_ALERT | ERR_FATAL;
757 goto out;
758 }
759
760 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200761 if (res == PARSE_TIME_OVER) {
762 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
763 file, linenum, args[cur_arg+1], args[cur_arg]);
764 err_code |= ERR_ALERT | ERR_FATAL;
765 goto out;
766 }
767 else if (res == PARSE_TIME_UNDER) {
768 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
769 file, linenum, args[cur_arg+1], args[cur_arg]);
770 err_code |= ERR_ALERT | ERR_FATAL;
771 goto out;
772 }
773 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100774 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
775 file, linenum, *res, args[cur_arg]);
776 err_code |= ERR_ALERT | ERR_FATAL;
777 goto out;
778 }
779 curproxy->cookie_maxidle = maxidle;
780 cur_arg++;
781 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100782 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100783 unsigned int maxlife;
784 const char *res;
785
786 if (!*args[cur_arg + 1]) {
787 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
788 file, linenum, args[cur_arg]);
789 err_code |= ERR_ALERT | ERR_FATAL;
790 goto out;
791 }
792
Willy Tarreau9faebe32019-06-07 19:00:37 +0200793
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100794 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200795 if (res == PARSE_TIME_OVER) {
796 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
797 file, linenum, args[cur_arg+1], args[cur_arg]);
798 err_code |= ERR_ALERT | ERR_FATAL;
799 goto out;
800 }
801 else if (res == PARSE_TIME_UNDER) {
802 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
803 file, linenum, args[cur_arg+1], args[cur_arg]);
804 err_code |= ERR_ALERT | ERR_FATAL;
805 goto out;
806 }
807 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100808 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
809 file, linenum, *res, args[cur_arg]);
810 err_code |= ERR_ALERT | ERR_FATAL;
811 goto out;
812 }
813 curproxy->cookie_maxlife = maxlife;
814 cur_arg++;
815 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100816 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100817
818 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
819 err_code |= ERR_WARN;
820 curproxy->ck_opts |= PR_CK_DYNAMIC;
821 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100822 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100823 char *val;
824 if (!*args[cur_arg + 1]) {
825 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
826 file, linenum, args[cur_arg]);
827 err_code |= ERR_ALERT | ERR_FATAL;
828 goto out;
829 }
830 val = args[cur_arg + 1];
831 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100832 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100833 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
834 file, linenum, *val);
835 err_code |= ERR_ALERT | ERR_FATAL;
836 goto out;
837 }
838 val++;
839 }
840 /* don't add ';' for the first attribute */
841 if (!curproxy->cookie_attrs)
842 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
843 else
844 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
845 cur_arg++;
846 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100847
848 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100849 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 +0100850 file, linenum, args[0]);
851 err_code |= ERR_ALERT | ERR_FATAL;
852 goto out;
853 }
854 cur_arg++;
855 }
856 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
857 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
858 file, linenum);
859 err_code |= ERR_ALERT | ERR_FATAL;
860 }
861
862 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
863 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
864 file, linenum);
865 err_code |= ERR_ALERT | ERR_FATAL;
866 }
867
868 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
869 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
870 file, linenum);
871 err_code |= ERR_ALERT | ERR_FATAL;
872 }
873 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100874 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100875 if (*(args[1]) == 0) {
876 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
877 file, linenum, args[0]);
878 err_code |= ERR_ALERT | ERR_FATAL;
879 goto out;
880 }
881
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100882 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100883 if (*(args[1]) == 0) {
884 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
885 file, linenum, args[1]);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto out;
888 }
889 free(curproxy->email_alert.from);
890 curproxy->email_alert.from = strdup(args[2]);
891 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100892 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100893 if (*(args[1]) == 0) {
894 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
895 file, linenum, args[1]);
896 err_code |= ERR_ALERT | ERR_FATAL;
897 goto out;
898 }
899 free(curproxy->email_alert.mailers.name);
900 curproxy->email_alert.mailers.name = strdup(args[2]);
901 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100902 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100903 if (*(args[1]) == 0) {
904 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
905 file, linenum, args[1]);
906 err_code |= ERR_ALERT | ERR_FATAL;
907 goto out;
908 }
909 free(curproxy->email_alert.myhostname);
910 curproxy->email_alert.myhostname = strdup(args[2]);
911 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100912 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100913 curproxy->email_alert.level = get_log_level(args[2]);
914 if (curproxy->email_alert.level < 0) {
915 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
916 file, linenum, args[1], args[2]);
917 err_code |= ERR_ALERT | ERR_FATAL;
918 goto out;
919 }
920 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100921 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100922 if (*(args[1]) == 0) {
923 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
924 file, linenum, args[1]);
925 err_code |= ERR_ALERT | ERR_FATAL;
926 goto out;
927 }
928 free(curproxy->email_alert.to);
929 curproxy->email_alert.to = strdup(args[2]);
930 }
931 else {
932 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
933 file, linenum, args[1]);
934 err_code |= ERR_ALERT | ERR_FATAL;
935 goto out;
936 }
937 /* Indicate that the email_alert is at least partially configured */
938 curproxy->email_alert.set = 1;
939 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100940 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100941 if (*(args[1]) == 0) {
942 ha_alert("parsing [%s:%d] : missing persist method.\n",
943 file, linenum);
944 err_code |= ERR_ALERT | ERR_FATAL;
945 goto out;
946 }
947
948 if (!strncmp(args[1], "rdp-cookie", 10)) {
949 curproxy->options2 |= PR_O2_RDPC_PRST;
950
951 if (*(args[1] + 10) == '(') { /* cookie name */
952 const char *beg, *end;
953
954 beg = args[1] + 11;
955 end = strchr(beg, ')');
956
957 if (alertif_too_many_args(1, file, linenum, args, &err_code))
958 goto out;
959
960 if (!end || end == beg) {
961 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
962 file, linenum);
963 err_code |= ERR_ALERT | ERR_FATAL;
964 goto out;
965 }
966
967 free(curproxy->rdp_cookie_name);
968 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
969 curproxy->rdp_cookie_len = end-beg;
970 }
971 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
972 free(curproxy->rdp_cookie_name);
973 curproxy->rdp_cookie_name = strdup("msts");
974 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
975 }
976 else { /* syntax */
977 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
978 file, linenum);
979 err_code |= ERR_ALERT | ERR_FATAL;
980 goto out;
981 }
982 }
983 else {
984 ha_alert("parsing [%s:%d] : unknown persist method.\n",
985 file, linenum);
986 err_code |= ERR_ALERT | ERR_FATAL;
987 goto out;
988 }
989 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100990 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +0200991 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 +0100992 err_code |= ERR_ALERT | ERR_FATAL;
993 goto out;
994 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100995 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100996 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
997 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100998 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100999 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1000 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001001 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 +01001002 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1003 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001004 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001005 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1006 }
1007 else {
1008 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1009 file, linenum, args[0], args[1]);
1010 err_code |= ERR_ALERT | ERR_FATAL;
1011 goto out;
1012 }
1013 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001014 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001015 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1016 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001017 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001018 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001019
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001020 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001021
1022 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001023 curproxy->server_state_file_name = strdup(curproxy->id);
1024 else
1025 curproxy->server_state_file_name = strdup(args[1]);
1026 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001027 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001028 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1029 err_code |= ERR_WARN;
1030 if (*(args[1]) == 0) {
1031 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1032 file, linenum, args[0]);
1033 err_code |= ERR_ALERT | ERR_FATAL;
1034 goto out;
1035 }
1036 curproxy->max_out_conns = atoi(args[1]);
1037 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001038 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001039 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1040 err_code |= ERR_WARN;
1041
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001042 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001043 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001044 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1045 err_code |= ERR_ALERT | ERR_FATAL;
1046 goto out;
1047 }
1048
1049 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1050 goto out;
1051
1052 if (*(args[4]) == 0) {
1053 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1054 file, linenum, args[0]);
1055 err_code |= ERR_ALERT | ERR_FATAL;
1056 goto out;
1057 }
1058 free(curproxy->capture_name);
1059 curproxy->capture_name = strdup(args[2]);
1060 curproxy->capture_namelen = strlen(curproxy->capture_name);
1061 curproxy->capture_len = atol(args[4]);
1062 curproxy->to_log |= LW_COOKIE;
1063 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001064 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001065 struct cap_hdr *hdr;
1066
Willy Tarreau5d095c22021-02-12 10:15:59 +01001067 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001068 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1069 err_code |= ERR_ALERT | ERR_FATAL;
1070 goto out;
1071 }
1072
1073 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1074 goto out;
1075
1076 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1077 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1078 file, linenum, args[0], args[1]);
1079 err_code |= ERR_ALERT | ERR_FATAL;
1080 goto out;
1081 }
1082
1083 hdr = calloc(1, sizeof(*hdr));
1084 hdr->next = curproxy->req_cap;
1085 hdr->name = strdup(args[3]);
1086 hdr->namelen = strlen(args[3]);
1087 hdr->len = atol(args[5]);
1088 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1089 hdr->index = curproxy->nb_req_cap++;
1090 curproxy->req_cap = hdr;
1091 curproxy->to_log |= LW_REQHDR;
1092 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001093 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001094 struct cap_hdr *hdr;
1095
Willy Tarreau5d095c22021-02-12 10:15:59 +01001096 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001097 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1098 err_code |= ERR_ALERT | ERR_FATAL;
1099 goto out;
1100 }
1101
1102 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1103 goto out;
1104
1105 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1106 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1107 file, linenum, args[0], args[1]);
1108 err_code |= ERR_ALERT | ERR_FATAL;
1109 goto out;
1110 }
1111 hdr = calloc(1, sizeof(*hdr));
1112 hdr->next = curproxy->rsp_cap;
1113 hdr->name = strdup(args[3]);
1114 hdr->namelen = strlen(args[3]);
1115 hdr->len = atol(args[5]);
1116 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1117 hdr->index = curproxy->nb_rsp_cap++;
1118 curproxy->rsp_cap = hdr;
1119 curproxy->to_log |= LW_RSPHDR;
1120 }
1121 else {
1122 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1123 file, linenum, args[0]);
1124 err_code |= ERR_ALERT | ERR_FATAL;
1125 goto out;
1126 }
1127 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001128 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001129 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1130 err_code |= ERR_WARN;
1131
1132 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1133 goto out;
1134
1135 if (*(args[1]) == 0) {
1136 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1137 file, linenum, args[0]);
1138 err_code |= ERR_ALERT | ERR_FATAL;
1139 goto out;
1140 }
1141 curproxy->conn_retries = atol(args[1]);
1142 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001143 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001144 struct act_rule *rule;
1145
Willy Tarreau5d095c22021-02-12 10:15:59 +01001146 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001147 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1148 err_code |= ERR_ALERT | ERR_FATAL;
1149 goto out;
1150 }
1151
1152 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1153 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001154 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001155 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1156 file, linenum, args[0]);
1157 err_code |= ERR_WARN;
1158 }
1159
1160 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1161
1162 if (!rule) {
1163 err_code |= ERR_ALERT | ERR_ABORT;
1164 goto out;
1165 }
1166
1167 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1168 err_code |= warnif_cond_conflicts(rule->cond,
1169 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1170 file, linenum);
1171
1172 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1173 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001174 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001175 struct act_rule *rule;
1176
Willy Tarreau5d095c22021-02-12 10:15:59 +01001177 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001178 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1179 err_code |= ERR_ALERT | ERR_FATAL;
1180 goto out;
1181 }
1182
1183 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1184 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001185 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001186 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1187 file, linenum, args[0]);
1188 err_code |= ERR_WARN;
1189 }
1190
1191 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1192
1193 if (!rule) {
1194 err_code |= ERR_ALERT | ERR_ABORT;
1195 goto out;
1196 }
1197
1198 err_code |= warnif_cond_conflicts(rule->cond,
1199 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1200 file, linenum);
1201
1202 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1203 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001204 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001205 struct act_rule *rule;
1206
Willy Tarreau5d095c22021-02-12 10:15:59 +01001207 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001208 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1209 err_code |= ERR_ALERT | ERR_FATAL;
1210 goto out;
1211 }
1212
1213 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1214 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1215 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1216 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1217 file, linenum, args[0]);
1218 err_code |= ERR_WARN;
1219 }
1220
1221 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1222
1223 if (!rule) {
1224 err_code |= ERR_ALERT | ERR_ABORT;
1225 goto out;
1226 }
1227
1228 err_code |= warnif_cond_conflicts(rule->cond,
1229 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1230 file, linenum);
1231
1232 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1233 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001234 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001235 /* set the header name and length into the proxy structure */
1236 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1237 err_code |= ERR_WARN;
1238
1239 if (!*args[1]) {
1240 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1241 file, linenum, args[0]);
1242 err_code |= ERR_ALERT | ERR_FATAL;
1243 goto out;
1244 }
1245
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001246 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001247 free(curproxy->server_id_hdr_name);
1248 curproxy->server_id_hdr_name = strdup(args[1]);
1249 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001250 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 +01001251 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001252 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001253 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 +01001254
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001255 err_code |= ERR_ALERT | ERR_FATAL;
1256 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001257 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001258 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001259 struct redirect_rule *rule;
1260
Willy Tarreau5d095c22021-02-12 10:15:59 +01001261 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001262 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1263 err_code |= ERR_ALERT | ERR_FATAL;
1264 goto out;
1265 }
1266
1267 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1268 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1269 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1270 err_code |= ERR_ALERT | ERR_FATAL;
1271 goto out;
1272 }
1273
1274 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1275 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1276 err_code |= warnif_cond_conflicts(rule->cond,
1277 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1278 file, linenum);
1279 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001280 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001281 struct switching_rule *rule;
1282
Willy Tarreau5d095c22021-02-12 10:15:59 +01001283 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001284 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1285 err_code |= ERR_ALERT | ERR_FATAL;
1286 goto out;
1287 }
1288
1289 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1290 err_code |= ERR_WARN;
1291
1292 if (*(args[1]) == 0) {
1293 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1294 err_code |= ERR_ALERT | ERR_FATAL;
1295 goto out;
1296 }
1297
1298 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1299 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1300 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1301 file, linenum, errmsg);
1302 err_code |= ERR_ALERT | ERR_FATAL;
1303 goto out;
1304 }
1305
1306 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1307 }
1308 else if (*args[2]) {
1309 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1310 file, linenum, args[2]);
1311 err_code |= ERR_ALERT | ERR_FATAL;
1312 goto out;
1313 }
1314
1315 rule = calloc(1, sizeof(*rule));
1316 if (!rule) {
1317 ha_alert("Out of memory error.\n");
1318 goto out;
1319 }
1320 rule->cond = cond;
1321 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001322 if (!rule->be.name) {
1323 ha_alert("Out of memory error.\n");
1324 goto out;
1325 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001326 rule->line = linenum;
1327 rule->file = strdup(file);
1328 if (!rule->file) {
1329 ha_alert("Out of memory error.\n");
1330 goto out;
1331 }
1332 LIST_INIT(&rule->list);
1333 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1334 }
1335 else if (strcmp(args[0], "use-server") == 0) {
1336 struct server_rule *rule;
1337
Willy Tarreau5d095c22021-02-12 10:15:59 +01001338 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001339 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1340 err_code |= ERR_ALERT | ERR_FATAL;
1341 goto out;
1342 }
1343
1344 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1345 err_code |= ERR_WARN;
1346
1347 if (*(args[1]) == 0) {
1348 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1349 err_code |= ERR_ALERT | ERR_FATAL;
1350 goto out;
1351 }
1352
1353 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1354 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1355 file, linenum, args[0]);
1356 err_code |= ERR_ALERT | ERR_FATAL;
1357 goto out;
1358 }
1359
1360 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1361 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1362 file, linenum, errmsg);
1363 err_code |= ERR_ALERT | ERR_FATAL;
1364 goto out;
1365 }
1366
1367 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1368
1369 rule = calloc(1, sizeof(*rule));
1370 rule->cond = cond;
1371 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001372 rule->line = linenum;
1373 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001374 LIST_INIT(&rule->list);
1375 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1376 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1377 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001378 else if ((strcmp(args[0], "force-persist") == 0) ||
1379 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001380 struct persist_rule *rule;
1381
Willy Tarreau5d095c22021-02-12 10:15:59 +01001382 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001383 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1384 err_code |= ERR_ALERT | ERR_FATAL;
1385 goto out;
1386 }
1387
1388 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1389 err_code |= ERR_WARN;
1390
1391 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1392 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1393 file, linenum, args[0]);
1394 err_code |= ERR_ALERT | ERR_FATAL;
1395 goto out;
1396 }
1397
1398 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1399 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1400 file, linenum, args[0], errmsg);
1401 err_code |= ERR_ALERT | ERR_FATAL;
1402 goto out;
1403 }
1404
1405 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1406 * where force-persist is applied.
1407 */
1408 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1409
1410 rule = calloc(1, sizeof(*rule));
1411 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001412 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001413 rule->type = PERSIST_TYPE_FORCE;
1414 } else {
1415 rule->type = PERSIST_TYPE_IGNORE;
1416 }
1417 LIST_INIT(&rule->list);
1418 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1419 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001420 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001421 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001422
Willy Tarreau5d095c22021-02-12 10:15:59 +01001423 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001424 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1425 file, linenum);
1426 err_code |= ERR_ALERT | ERR_FATAL;
1427 goto out;
1428 }
1429
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001430 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001431 if (other) {
1432 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 +01001433 file, linenum, curproxy->id,
1434 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1435 other->proxy ? other->id : other->peers.p->id,
1436 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001437 err_code |= ERR_ALERT | ERR_FATAL;
1438 goto out;
1439 }
1440
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001441 curproxy->table = calloc(1, sizeof *curproxy->table);
1442 if (!curproxy->table) {
1443 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1444 file, linenum, args[0], args[1]);
1445 err_code |= ERR_ALERT | ERR_FATAL;
1446 goto out;
1447 }
1448
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001449 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1450 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001451 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001452 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001453
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001454 /* Store the proxy in the stick-table. */
1455 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001456
1457 stktable_store_name(curproxy->table);
1458 curproxy->table->next = stktables_list;
1459 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001460
1461 /* Add this proxy to the list of proxies which refer to its stick-table. */
1462 if (curproxy->table->proxies_list != curproxy) {
1463 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1464 curproxy->table->proxies_list = curproxy;
1465 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001466 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001467 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001468 struct sticking_rule *rule;
1469 struct sample_expr *expr;
1470 int myidx = 0;
1471 const char *name = NULL;
1472 int flags;
1473
Willy Tarreau5d095c22021-02-12 10:15:59 +01001474 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001475 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1476 err_code |= ERR_ALERT | ERR_FATAL;
1477 goto out;
1478 }
1479
1480 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1481 err_code |= ERR_WARN;
1482 goto out;
1483 }
1484
1485 myidx++;
1486 if ((strcmp(args[myidx], "store") == 0) ||
1487 (strcmp(args[myidx], "store-request") == 0)) {
1488 myidx++;
1489 flags = STK_IS_STORE;
1490 }
1491 else if (strcmp(args[myidx], "store-response") == 0) {
1492 myidx++;
1493 flags = STK_IS_STORE | STK_ON_RSP;
1494 }
1495 else if (strcmp(args[myidx], "match") == 0) {
1496 myidx++;
1497 flags = STK_IS_MATCH;
1498 }
1499 else if (strcmp(args[myidx], "on") == 0) {
1500 myidx++;
1501 flags = STK_IS_MATCH | STK_IS_STORE;
1502 }
1503 else {
1504 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1505 err_code |= ERR_ALERT | ERR_FATAL;
1506 goto out;
1507 }
1508
1509 if (*(args[myidx]) == 0) {
1510 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1511 err_code |= ERR_ALERT | ERR_FATAL;
1512 goto out;
1513 }
1514
1515 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001516 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001517 if (!expr) {
1518 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1519 err_code |= ERR_ALERT | ERR_FATAL;
1520 goto out;
1521 }
1522
1523 if (flags & STK_ON_RSP) {
1524 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1525 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1526 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1527 err_code |= ERR_ALERT | ERR_FATAL;
1528 free(expr);
1529 goto out;
1530 }
1531 } else {
1532 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1533 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1534 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1535 err_code |= ERR_ALERT | ERR_FATAL;
1536 free(expr);
1537 goto out;
1538 }
1539 }
1540
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001541 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001542 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1543
1544 if (strcmp(args[myidx], "table") == 0) {
1545 myidx++;
1546 name = args[myidx++];
1547 }
1548
1549 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1550 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1551 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1552 file, linenum, args[0], errmsg);
1553 err_code |= ERR_ALERT | ERR_FATAL;
1554 free(expr);
1555 goto out;
1556 }
1557 }
1558 else if (*(args[myidx])) {
1559 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1560 file, linenum, args[0], args[myidx]);
1561 err_code |= ERR_ALERT | ERR_FATAL;
1562 free(expr);
1563 goto out;
1564 }
1565 if (flags & STK_ON_RSP)
1566 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1567 else
1568 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1569
1570 rule = calloc(1, sizeof(*rule));
1571 rule->cond = cond;
1572 rule->expr = expr;
1573 rule->flags = flags;
1574 rule->table.name = name ? strdup(name) : NULL;
1575 LIST_INIT(&rule->list);
1576 if (flags & STK_ON_RSP)
1577 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1578 else
1579 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1580 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001581 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001582 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001583 curproxy->uri_auth = NULL; /* we must detach from the default config */
1584
1585 if (!*args[1]) {
1586 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001587 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001588 struct stats_admin_rule *rule;
1589
Willy Tarreau5d095c22021-02-12 10:15:59 +01001590 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001591 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1592 err_code |= ERR_ALERT | ERR_FATAL;
1593 goto out;
1594 }
1595
1596 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1597 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1598 err_code |= ERR_ALERT | ERR_ABORT;
1599 goto out;
1600 }
1601
1602 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1603 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1604 file, linenum, args[0], args[1]);
1605 err_code |= ERR_ALERT | ERR_FATAL;
1606 goto out;
1607 }
1608 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1609 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1610 file, linenum, args[0], args[1], errmsg);
1611 err_code |= ERR_ALERT | ERR_FATAL;
1612 goto out;
1613 }
1614
1615 err_code |= warnif_cond_conflicts(cond,
1616 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1617 file, linenum);
1618
1619 rule = calloc(1, sizeof(*rule));
1620 rule->cond = cond;
1621 LIST_INIT(&rule->list);
1622 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001623 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001624 if (*(args[2]) == 0) {
1625 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1626 err_code |= ERR_ALERT | ERR_FATAL;
1627 goto out;
1628 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1629 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1630 err_code |= ERR_ALERT | ERR_ABORT;
1631 goto out;
1632 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001633 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001634 if (*(args[2]) == 0) {
1635 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1636 err_code |= ERR_ALERT | ERR_FATAL;
1637 goto out;
1638 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1639 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1640 err_code |= ERR_ALERT | ERR_ABORT;
1641 goto out;
1642 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001643 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001644 unsigned interval;
1645
1646 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001647 if (err == PARSE_TIME_OVER) {
1648 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1649 file, linenum, args[2]);
1650 err_code |= ERR_ALERT | ERR_FATAL;
1651 goto out;
1652 }
1653 else if (err == PARSE_TIME_UNDER) {
1654 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1655 file, linenum, args[2]);
1656 err_code |= ERR_ALERT | ERR_FATAL;
1657 goto out;
1658 }
1659 else if (err) {
1660 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001661 file, linenum, *err);
1662 err_code |= ERR_ALERT | ERR_FATAL;
1663 goto out;
1664 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1665 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1666 err_code |= ERR_ALERT | ERR_ABORT;
1667 goto out;
1668 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001669 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001670 struct act_rule *rule;
1671
Willy Tarreau5d095c22021-02-12 10:15:59 +01001672 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001673 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1674 err_code |= ERR_ALERT | ERR_FATAL;
1675 goto out;
1676 }
1677
1678 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1679 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1680 err_code |= ERR_ALERT | ERR_ABORT;
1681 goto out;
1682 }
1683
1684 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1685 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1686 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1687 file, linenum, args[0]);
1688 err_code |= ERR_WARN;
1689 }
1690
1691 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1692
1693 if (!rule) {
1694 err_code |= ERR_ALERT | ERR_ABORT;
1695 goto out;
1696 }
1697
1698 err_code |= warnif_cond_conflicts(rule->cond,
1699 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1700 file, linenum);
1701 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1702
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001703 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001704 if (*(args[2]) == 0) {
1705 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1706 err_code |= ERR_ALERT | ERR_FATAL;
1707 goto out;
1708 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1709 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1710 err_code |= ERR_ALERT | ERR_ABORT;
1711 goto out;
1712 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001713 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001714 if (*(args[2]) == 0) {
1715 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1716 err_code |= ERR_ALERT | ERR_FATAL;
1717 goto out;
1718 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1719 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1720 err_code |= ERR_ALERT | ERR_ABORT;
1721 goto out;
1722 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001723 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001724 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1725 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1726 err_code |= ERR_ALERT | ERR_ABORT;
1727 goto out;
1728 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001729 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001730 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001731 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1732 err_code |= ERR_ALERT | ERR_ABORT;
1733 goto out;
1734 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001735 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001736 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001737 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1738 err_code |= ERR_ALERT | ERR_ABORT;
1739 goto out;
1740 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001741 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001742 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1743 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1744 err_code |= ERR_ALERT | ERR_ABORT;
1745 goto out;
1746 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001747 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001748
1749 if (*args[2]) {
1750 int i;
1751 char c;
1752
1753 for (i=0; args[2][i]; i++) {
1754 c = args[2][i];
1755 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1756 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1757 break;
1758 }
1759
1760 if (!i || args[2][i]) {
1761 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1762 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1763 file, linenum, args[0], args[1]);
1764 err_code |= ERR_ALERT | ERR_FATAL;
1765 goto out;
1766 }
1767 }
1768
1769 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1770 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1771 err_code |= ERR_ALERT | ERR_ABORT;
1772 goto out;
1773 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001774 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001775 char *desc = NULL;
1776
1777 if (*args[2]) {
1778 int i, len=0;
1779 char *d;
1780
1781 for (i = 2; *args[i]; i++)
1782 len += strlen(args[i]) + 1;
1783
1784 desc = d = calloc(1, len);
1785
1786 d += snprintf(d, desc + len - d, "%s", args[2]);
1787 for (i = 3; *args[i]; i++)
1788 d += snprintf(d, desc + len - d, " %s", args[i]);
1789 }
1790
1791 if (!*args[2] && !global.desc)
1792 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1793 file, linenum, args[1]);
1794 else {
1795 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1796 free(desc);
1797 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1798 err_code |= ERR_ALERT | ERR_ABORT;
1799 goto out;
1800 }
1801 free(desc);
1802 }
1803 } else {
1804stats_error_parsing:
1805 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1806 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1807 err_code |= ERR_ALERT | ERR_FATAL;
1808 goto out;
1809 }
1810 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001811 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001812 int optnum;
1813
1814 if (*(args[1]) == '\0') {
1815 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1816 file, linenum, args[0]);
1817 err_code |= ERR_ALERT | ERR_FATAL;
1818 goto out;
1819 }
1820
1821 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001822 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001823 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1824 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1825 file, linenum, cfg_opts[optnum].name);
1826 err_code |= ERR_ALERT | ERR_FATAL;
1827 goto out;
1828 }
1829 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1830 goto out;
1831
1832 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1833 err_code |= ERR_WARN;
1834 goto out;
1835 }
1836
1837 curproxy->no_options &= ~cfg_opts[optnum].val;
1838 curproxy->options &= ~cfg_opts[optnum].val;
1839
1840 switch (kwm) {
1841 case KWM_STD:
1842 curproxy->options |= cfg_opts[optnum].val;
1843 break;
1844 case KWM_NO:
1845 curproxy->no_options |= cfg_opts[optnum].val;
1846 break;
1847 case KWM_DEF: /* already cleared */
1848 break;
1849 }
1850
1851 goto out;
1852 }
1853 }
1854
1855 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001856 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001857 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1858 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1859 file, linenum, cfg_opts2[optnum].name);
1860 err_code |= ERR_ALERT | ERR_FATAL;
1861 goto out;
1862 }
1863 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1864 goto out;
1865 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1866 err_code |= ERR_WARN;
1867 goto out;
1868 }
1869
Christopher Faulet31930372019-07-15 10:16:58 +02001870 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001871 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001872 if (kwm ==KWM_NO) {
1873 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1874 " The HTX mode is now the only supported mode.\n",
1875 file, linenum, cfg_opts2[optnum].name);
1876 err_code |= ERR_WARN;
1877 }
Christopher Faulet31930372019-07-15 10:16:58 +02001878 goto out;
1879 }
1880
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001881 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1882 curproxy->options2 &= ~cfg_opts2[optnum].val;
1883
1884 switch (kwm) {
1885 case KWM_STD:
1886 curproxy->options2 |= cfg_opts2[optnum].val;
1887 break;
1888 case KWM_NO:
1889 curproxy->no_options2 |= cfg_opts2[optnum].val;
1890 break;
1891 case KWM_DEF: /* already cleared */
1892 break;
1893 }
1894 goto out;
1895 }
1896 }
1897
1898 /* HTTP options override each other. They can be cancelled using
1899 * "no option xxx" which only switches to default mode if the mode
1900 * was this one (useful for cancelling options set in defaults
1901 * sections).
1902 */
1903 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001904 if (strcmp(args[1], "forceclose") == 0) {
1905 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1906 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1907 file, linenum, args[1]);
1908 err_code |= ERR_WARN;
1909 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001910 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1911 goto out;
1912 if (kwm == KWM_STD) {
1913 curproxy->options &= ~PR_O_HTTP_MODE;
1914 curproxy->options |= PR_O_HTTP_CLO;
1915 goto out;
1916 }
1917 else if (kwm == KWM_NO) {
1918 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1919 curproxy->options &= ~PR_O_HTTP_MODE;
1920 goto out;
1921 }
1922 }
1923 else if (strcmp(args[1], "http-server-close") == 0) {
1924 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1925 goto out;
1926 if (kwm == KWM_STD) {
1927 curproxy->options &= ~PR_O_HTTP_MODE;
1928 curproxy->options |= PR_O_HTTP_SCL;
1929 goto out;
1930 }
1931 else if (kwm == KWM_NO) {
1932 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1933 curproxy->options &= ~PR_O_HTTP_MODE;
1934 goto out;
1935 }
1936 }
1937 else if (strcmp(args[1], "http-keep-alive") == 0) {
1938 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1939 goto out;
1940 if (kwm == KWM_STD) {
1941 curproxy->options &= ~PR_O_HTTP_MODE;
1942 curproxy->options |= PR_O_HTTP_KAL;
1943 goto out;
1944 }
1945 else if (kwm == KWM_NO) {
1946 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1947 curproxy->options &= ~PR_O_HTTP_MODE;
1948 goto out;
1949 }
1950 }
1951 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001952 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
1953 file, linenum, args[1]);
1954 err_code |= ERR_WARN;
1955 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001956 }
1957
1958 /* Redispatch can take an integer argument that control when the
1959 * resispatch occurs. All values are relative to the retries option.
1960 * This can be cancelled using "no option xxx".
1961 */
1962 if (strcmp(args[1], "redispatch") == 0) {
1963 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
1964 err_code |= ERR_WARN;
1965 goto out;
1966 }
1967
1968 curproxy->no_options &= ~PR_O_REDISP;
1969 curproxy->options &= ~PR_O_REDISP;
1970
1971 switch (kwm) {
1972 case KWM_STD:
1973 curproxy->options |= PR_O_REDISP;
1974 curproxy->redispatch_after = -1;
1975 if(*args[2]) {
1976 curproxy->redispatch_after = atol(args[2]);
1977 }
1978 break;
1979 case KWM_NO:
1980 curproxy->no_options |= PR_O_REDISP;
1981 curproxy->redispatch_after = 0;
1982 break;
1983 case KWM_DEF: /* already cleared */
1984 break;
1985 }
1986 goto out;
1987 }
1988
1989 if (kwm != KWM_STD) {
1990 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
1991 file, linenum, args[1]);
1992 err_code |= ERR_ALERT | ERR_FATAL;
1993 goto out;
1994 }
1995
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001996 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001997 char *logformat;
1998 /* generate a complete HTTP log */
1999 logformat = default_http_log_format;
2000 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002001 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002002 curproxy->options2 |= PR_O2_CLFLOG;
2003 logformat = clf_http_log_format;
2004 } else {
2005 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2006 err_code |= ERR_ALERT | ERR_FATAL;
2007 goto out;
2008 }
2009 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2010 goto out;
2011 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002012 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002013 char *oldlogformat = "log-format";
2014 char *clflogformat = "";
2015
2016 if (curproxy->conf.logformat_string == default_http_log_format)
2017 oldlogformat = "option httplog";
2018 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2019 oldlogformat = "option tcplog";
2020 else if (curproxy->conf.logformat_string == clf_http_log_format)
2021 oldlogformat = "option httplog clf";
2022 if (logformat == clf_http_log_format)
2023 clflogformat = " clf";
2024 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2025 file, linenum, clflogformat, oldlogformat);
2026 }
2027 if (curproxy->conf.logformat_string != default_http_log_format &&
2028 curproxy->conf.logformat_string != default_tcp_log_format &&
2029 curproxy->conf.logformat_string != clf_http_log_format)
2030 free(curproxy->conf.logformat_string);
2031 curproxy->conf.logformat_string = logformat;
2032
2033 free(curproxy->conf.lfs_file);
2034 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2035 curproxy->conf.lfs_line = curproxy->conf.args.line;
2036
Willy Tarreau5d095c22021-02-12 10:15:59 +01002037 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002038 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2039 file, linenum, curproxy->id);
2040 err_code |= ERR_WARN;
2041 }
2042 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002043 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002044 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002045 char *oldlogformat = "log-format";
2046
2047 if (curproxy->conf.logformat_string == default_http_log_format)
2048 oldlogformat = "option httplog";
2049 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2050 oldlogformat = "option tcplog";
2051 else if (curproxy->conf.logformat_string == clf_http_log_format)
2052 oldlogformat = "option httplog clf";
2053 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2054 file, linenum, oldlogformat);
2055 }
2056 /* generate a detailed TCP log */
2057 if (curproxy->conf.logformat_string != default_http_log_format &&
2058 curproxy->conf.logformat_string != default_tcp_log_format &&
2059 curproxy->conf.logformat_string != clf_http_log_format)
2060 free(curproxy->conf.logformat_string);
2061 curproxy->conf.logformat_string = default_tcp_log_format;
2062
2063 free(curproxy->conf.lfs_file);
2064 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2065 curproxy->conf.lfs_line = curproxy->conf.args.line;
2066
2067 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2068 goto out;
2069
Willy Tarreau5d095c22021-02-12 10:15:59 +01002070 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002071 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2072 file, linenum, curproxy->id);
2073 err_code |= ERR_WARN;
2074 }
2075 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002076 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002077 /* enable TCP keep-alives on client and server streams */
2078 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2079 err_code |= ERR_WARN;
2080
2081 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2082 goto out;
2083
2084 if (curproxy->cap & PR_CAP_FE)
2085 curproxy->options |= PR_O_TCP_CLI_KA;
2086 if (curproxy->cap & PR_CAP_BE)
2087 curproxy->options |= PR_O_TCP_SRV_KA;
2088 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002089 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002090 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002091 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002092 goto out;
2093 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002094 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002095 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002096 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002097 goto out;
2098 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002099 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002100 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002101 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002102 goto out;
2103 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002104 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002105 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002106 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002107 goto out;
2108 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002109 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002110 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002111 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002112 goto out;
2113 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002114 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002115 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002116 if (err_code & ERR_FATAL)
2117 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002118 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002119 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002120 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002121 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002122 goto out;
2123 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002124 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002125 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002126 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002127 goto out;
2128 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002129 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002130 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002131 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002132 goto out;
2133 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002134 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002135 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002136 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002137 goto out;
2138 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002139 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002140 int cur_arg;
2141
2142 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002143 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002144 */
2145
2146 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2147
2148 free(curproxy->fwdfor_hdr_name);
2149 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2150 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002151 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002152
2153 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2154 cur_arg = 2;
2155 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002156 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002157 unsigned char mask;
2158 int i;
2159
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002160 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002161 if (*(args[cur_arg+1]) &&
2162 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2163 curproxy->except_xff_net.family = AF_INET;
2164 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2165 }
2166 else if (*(args[cur_arg+1]) &&
2167 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2168 curproxy->except_xff_net.family = AF_INET6;
2169 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2170 for (i = 0; i < 16; i++)
2171 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2172 }
2173 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002174 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2175 file, linenum, args[0], args[1], args[cur_arg]);
2176 err_code |= ERR_ALERT | ERR_FATAL;
2177 goto out;
2178 }
2179 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002180 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002181 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002182 /* suboption header - needs additional argument for it */
2183 if (*(args[cur_arg+1]) == 0) {
2184 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2185 file, linenum, args[0], args[1], args[cur_arg]);
2186 err_code |= ERR_ALERT | ERR_FATAL;
2187 goto out;
2188 }
2189 free(curproxy->fwdfor_hdr_name);
2190 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2191 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2192 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002193 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002194 curproxy->options &= ~PR_O_FF_ALWAYS;
2195 cur_arg += 1;
2196 } else {
2197 /* unknown suboption - catchall */
2198 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2199 file, linenum, args[0], args[1]);
2200 err_code |= ERR_ALERT | ERR_FATAL;
2201 goto out;
2202 }
2203 } /* end while loop */
2204 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002205 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002206 int cur_arg;
2207
2208 /* insert x-original-to field, but not for the IP address listed as an except.
2209 * set default options (ie: bitfield, header name, etc)
2210 */
2211
2212 curproxy->options |= PR_O_ORGTO;
2213
2214 free(curproxy->orgto_hdr_name);
2215 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2216 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002217 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002218
2219 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2220 cur_arg = 2;
2221 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002222 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002223 unsigned char mask;
2224 int i;
2225
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002226 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002227 if (*(args[cur_arg+1]) &&
2228 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2229 curproxy->except_xot_net.family = AF_INET;
2230 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2231 }
2232 else if (*(args[cur_arg+1]) &&
2233 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2234 curproxy->except_xot_net.family = AF_INET6;
2235 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2236 for (i = 0; i < 16; i++)
2237 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2238 }
2239 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002240 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2241 file, linenum, args[0], args[1], args[cur_arg]);
2242 err_code |= ERR_ALERT | ERR_FATAL;
2243 goto out;
2244 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002245 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002246 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002247 /* suboption header - needs additional argument for it */
2248 if (*(args[cur_arg+1]) == 0) {
2249 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2250 file, linenum, args[0], args[1], args[cur_arg]);
2251 err_code |= ERR_ALERT | ERR_FATAL;
2252 goto out;
2253 }
2254 free(curproxy->orgto_hdr_name);
2255 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2256 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2257 cur_arg += 2;
2258 } else {
2259 /* unknown suboption - catchall */
2260 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2261 file, linenum, args[0], args[1]);
2262 err_code |= ERR_ALERT | ERR_FATAL;
2263 goto out;
2264 }
2265 } /* end while loop */
2266 }
2267 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002268 const char *best = proxy_find_best_option(args[1], common_options);
2269
2270 if (best)
2271 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2272 else
2273 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2274
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002275 err_code |= ERR_ALERT | ERR_FATAL;
2276 goto out;
2277 }
2278 goto out;
2279 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002280 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002281 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2282 err_code |= ERR_WARN;
2283
2284 if (*(args[1]) == 0) {
2285 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2286 err_code |= ERR_ALERT | ERR_FATAL;
2287 goto out;
2288 }
2289 free(curproxy->defbe.name);
2290 curproxy->defbe.name = strdup(args[1]);
2291
2292 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2293 goto out;
2294 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002295 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002296 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 +01002297
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002298 err_code |= ERR_ALERT | ERR_FATAL;
2299 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002300 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002301 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002302 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2303 err_code |= ERR_WARN;
2304
2305 if (strcmp(args[1], "never") == 0) {
2306 /* enable a graceful server shutdown on an HTTP 404 response */
2307 curproxy->options &= ~PR_O_REUSE_MASK;
2308 curproxy->options |= PR_O_REUSE_NEVR;
2309 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2310 goto out;
2311 }
2312 else if (strcmp(args[1], "safe") == 0) {
2313 /* enable a graceful server shutdown on an HTTP 404 response */
2314 curproxy->options &= ~PR_O_REUSE_MASK;
2315 curproxy->options |= PR_O_REUSE_SAFE;
2316 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2317 goto out;
2318 }
2319 else if (strcmp(args[1], "aggressive") == 0) {
2320 curproxy->options &= ~PR_O_REUSE_MASK;
2321 curproxy->options |= PR_O_REUSE_AGGR;
2322 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2323 goto out;
2324 }
2325 else if (strcmp(args[1], "always") == 0) {
2326 /* enable a graceful server shutdown on an HTTP 404 response */
2327 curproxy->options &= ~PR_O_REUSE_MASK;
2328 curproxy->options |= PR_O_REUSE_ALWS;
2329 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2330 goto out;
2331 }
2332 else {
2333 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2334 err_code |= ERR_ALERT | ERR_FATAL;
2335 goto out;
2336 }
2337 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002338 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002339 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002340 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2341 err_code |= ERR_ALERT | ERR_FATAL;
2342 goto out;
2343 }
2344
2345 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2346 err_code |= ERR_WARN;
2347
2348 if (strcmp(args[1], "fail") == 0) {
2349 /* add a condition to fail monitor requests */
2350 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2351 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2352 file, linenum, args[0], args[1]);
2353 err_code |= ERR_ALERT | ERR_FATAL;
2354 goto out;
2355 }
2356
2357 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2358 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2359 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2360 file, linenum, args[0], args[1], errmsg);
2361 err_code |= ERR_ALERT | ERR_FATAL;
2362 goto out;
2363 }
2364 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2365 }
2366 else {
2367 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2368 err_code |= ERR_ALERT | ERR_FATAL;
2369 goto out;
2370 }
2371 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002372#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002373 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002374 /* enable transparent proxy connections */
2375 curproxy->options |= PR_O_TRANSP;
2376 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2377 goto out;
2378 }
2379#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002380 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002381 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2382 err_code |= ERR_WARN;
2383
2384 if (*(args[1]) == 0) {
2385 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2386 err_code |= ERR_ALERT | ERR_FATAL;
2387 goto out;
2388 }
2389 curproxy->maxconn = atol(args[1]);
2390 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2391 goto out;
2392 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002393 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002394 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2395 err_code |= ERR_WARN;
2396
2397 if (*(args[1]) == 0) {
2398 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2399 err_code |= ERR_ALERT | ERR_FATAL;
2400 goto out;
2401 }
2402 curproxy->backlog = atol(args[1]);
2403 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2404 goto out;
2405 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002406 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002407 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2408 err_code |= ERR_WARN;
2409
2410 if (*(args[1]) == 0) {
2411 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2412 err_code |= ERR_ALERT | ERR_FATAL;
2413 goto out;
2414 }
2415 curproxy->fullconn = atol(args[1]);
2416 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2417 goto out;
2418 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002419 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002420 if (*(args[1]) == 0) {
2421 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2422 err_code |= ERR_ALERT | ERR_FATAL;
2423 goto out;
2424 }
2425 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002426 if (err == PARSE_TIME_OVER) {
2427 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2428 file, linenum, args[1]);
2429 err_code |= ERR_ALERT | ERR_FATAL;
2430 goto out;
2431 }
2432 else if (err == PARSE_TIME_UNDER) {
2433 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2434 file, linenum, args[1]);
2435 err_code |= ERR_ALERT | ERR_FATAL;
2436 goto out;
2437 }
2438 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002439 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2440 file, linenum, *err);
2441 err_code |= ERR_ALERT | ERR_FATAL;
2442 goto out;
2443 }
2444 curproxy->grace = val;
2445 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2446 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002447
2448 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2449 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002450 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002451 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002452 struct sockaddr_storage *sk;
2453 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002454
Willy Tarreau5d095c22021-02-12 10:15:59 +01002455 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002456 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2457 err_code |= ERR_ALERT | ERR_FATAL;
2458 goto out;
2459 }
2460 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2461 err_code |= ERR_WARN;
2462
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002463 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2464 &errmsg, NULL, NULL,
2465 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 +01002466 if (!sk) {
2467 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2468 err_code |= ERR_ALERT | ERR_FATAL;
2469 goto out;
2470 }
2471
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002472 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2473 goto out;
2474
2475 curproxy->dispatch_addr = *sk;
2476 curproxy->options |= PR_O_DISPATCH;
2477 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002478 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002479 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2480 err_code |= ERR_WARN;
2481
2482 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2483 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2484 err_code |= ERR_ALERT | ERR_FATAL;
2485 goto out;
2486 }
2487 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002488 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002489 /**
2490 * The syntax for hash-type config element is
2491 * hash-type {map-based|consistent} [[<algo>] avalanche]
2492 *
2493 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2494 */
2495 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2496
2497 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2498 err_code |= ERR_WARN;
2499
2500 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2501 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2502 }
2503 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2504 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2505 }
2506 else if (strcmp(args[1], "avalanche") == 0) {
2507 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]);
2508 err_code |= ERR_ALERT | ERR_FATAL;
2509 goto out;
2510 }
2511 else {
2512 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2513 err_code |= ERR_ALERT | ERR_FATAL;
2514 goto out;
2515 }
2516
2517 /* set the hash function to use */
2518 if (!*args[2]) {
2519 /* the default algo is sdbm */
2520 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2521
2522 /* if consistent with no argument, then avalanche modifier is also applied */
2523 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2524 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2525 } else {
2526 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002527 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002528 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2529 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002530 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002531 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2532 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002533 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002534 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2535 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002536 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002537 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2538 }
2539 else {
2540 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2541 err_code |= ERR_ALERT | ERR_FATAL;
2542 goto out;
2543 }
2544
2545 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002546 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002547 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2548 }
2549 else if (*args[3]) {
2550 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2551 err_code |= ERR_ALERT | ERR_FATAL;
2552 goto out;
2553 }
2554 }
2555 }
2556 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2557 if (*(args[1]) == 0) {
2558 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2559 err_code |= ERR_ALERT | ERR_FATAL;
2560 goto out;
2561 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002562 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2563 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002564 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2565 err_code |= ERR_ALERT | ERR_FATAL;
2566 goto out;
2567 }
2568 }
2569 else if (strcmp(args[0], "unique-id-format") == 0) {
2570 if (!*(args[1])) {
2571 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2572 err_code |= ERR_ALERT | ERR_FATAL;
2573 goto out;
2574 }
2575 if (*(args[2])) {
2576 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2577 err_code |= ERR_ALERT | ERR_FATAL;
2578 goto out;
2579 }
2580 free(curproxy->conf.uniqueid_format_string);
2581 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2582
2583 free(curproxy->conf.uif_file);
2584 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2585 curproxy->conf.uif_line = curproxy->conf.args.line;
2586 }
2587
2588 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002589 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002590 if (!*(args[1])) {
2591 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2592 err_code |= ERR_ALERT | ERR_FATAL;
2593 goto out;
2594 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002595 copy = strdup(args[1]);
2596 if (copy == NULL) {
2597 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2598 err_code |= ERR_ALERT | ERR_FATAL;
2599 goto out;
2600 }
2601
2602 istfree(&curproxy->header_unique_id);
2603 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604 }
2605
2606 else if (strcmp(args[0], "log-format") == 0) {
2607 if (!*(args[1])) {
2608 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2609 err_code |= ERR_ALERT | ERR_FATAL;
2610 goto out;
2611 }
2612 if (*(args[2])) {
2613 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2614 err_code |= ERR_ALERT | ERR_FATAL;
2615 goto out;
2616 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002617 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002618 char *oldlogformat = "log-format";
2619
2620 if (curproxy->conf.logformat_string == default_http_log_format)
2621 oldlogformat = "option httplog";
2622 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2623 oldlogformat = "option tcplog";
2624 else if (curproxy->conf.logformat_string == clf_http_log_format)
2625 oldlogformat = "option httplog clf";
2626 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2627 file, linenum, oldlogformat);
2628 }
2629 if (curproxy->conf.logformat_string != default_http_log_format &&
2630 curproxy->conf.logformat_string != default_tcp_log_format &&
2631 curproxy->conf.logformat_string != clf_http_log_format)
2632 free(curproxy->conf.logformat_string);
2633 curproxy->conf.logformat_string = strdup(args[1]);
2634
2635 free(curproxy->conf.lfs_file);
2636 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2637 curproxy->conf.lfs_line = curproxy->conf.args.line;
2638
2639 /* get a chance to improve log-format error reporting by
2640 * reporting the correct line-number when possible.
2641 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002642 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002643 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2644 file, linenum, curproxy->id);
2645 err_code |= ERR_WARN;
2646 }
2647 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002648 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002649 if (!*(args[1])) {
2650 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2651 err_code |= ERR_ALERT | ERR_FATAL;
2652 goto out;
2653 }
2654 if (*(args[2])) {
2655 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2656 err_code |= ERR_ALERT | ERR_FATAL;
2657 goto out;
2658 }
2659
2660 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2661 free(curproxy->conf.logformat_sd_string);
2662 curproxy->conf.logformat_sd_string = strdup(args[1]);
2663
2664 free(curproxy->conf.lfsd_file);
2665 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2666 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2667
2668 /* get a chance to improve log-format-sd error reporting by
2669 * reporting the correct line-number when possible.
2670 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002671 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002672 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2673 file, linenum, curproxy->id);
2674 err_code |= ERR_WARN;
2675 }
2676 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002677 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002678 if (*(args[1]) == 0) {
2679 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2680 err_code |= ERR_ALERT | ERR_FATAL;
2681 goto out;
2682 }
2683 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002684 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2685 if (b_orig(&curproxy->log_tag) == NULL) {
2686 chunk_destroy(&curproxy->log_tag);
2687 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2688 err_code |= ERR_ALERT | ERR_FATAL;
2689 goto out;
2690 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002691 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002692 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002693 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002694 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2695 err_code |= ERR_ALERT | ERR_FATAL;
2696 goto out;
2697 }
2698 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002699 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002700 int cur_arg;
2701 int port1, port2;
2702 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002703
2704 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2705 err_code |= ERR_WARN;
2706
2707 if (!*args[1]) {
2708 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2709 file, linenum, "source", "usesrc", "interface");
2710 err_code |= ERR_ALERT | ERR_FATAL;
2711 goto out;
2712 }
2713
Christopher Faulet31930372019-07-15 10:16:58 +02002714 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002715 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002716 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002717 curproxy->conn_src.iface_len = 0;
2718
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002719 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2720 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002721 if (!sk) {
2722 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2723 file, linenum, args[0], args[1], errmsg);
2724 err_code |= ERR_ALERT | ERR_FATAL;
2725 goto out;
2726 }
2727
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002728 curproxy->conn_src.source_addr = *sk;
2729 curproxy->conn_src.opts |= CO_SRC_BIND;
2730
2731 cur_arg = 2;
2732 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002733 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002734#if defined(CONFIG_HAP_TRANSPARENT)
2735 if (!*args[cur_arg + 1]) {
2736 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2737 file, linenum, "usesrc");
2738 err_code |= ERR_ALERT | ERR_FATAL;
2739 goto out;
2740 }
2741
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002742 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002743 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2744 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002745 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002746 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2747 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2748 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2749 char *name, *end;
2750
2751 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002752 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002753 name++;
2754
2755 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002756 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002757 end++;
2758
2759 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2760 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002761 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002762 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2763 curproxy->conn_src.bind_hdr_len = end - name;
2764 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2765 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2766 curproxy->conn_src.bind_hdr_occ = -1;
2767
2768 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002769 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002770 end++;
2771 if (*end == ',') {
2772 end++;
2773 name = end;
2774 if (*end == '-')
2775 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002776 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002777 end++;
2778 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2779 }
2780
2781 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2782 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2783 " occurrences values smaller than %d.\n",
2784 file, linenum, MAX_HDR_HISTORY);
2785 err_code |= ERR_ALERT | ERR_FATAL;
2786 goto out;
2787 }
2788 } else {
2789 struct sockaddr_storage *sk;
2790
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002791 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2792 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002793 if (!sk) {
2794 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2795 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2796 err_code |= ERR_ALERT | ERR_FATAL;
2797 goto out;
2798 }
2799
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002800 curproxy->conn_src.tproxy_addr = *sk;
2801 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2802 }
2803 global.last_checks |= LSTCHK_NETADM;
2804#else /* no TPROXY support */
2805 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2806 file, linenum, "usesrc");
2807 err_code |= ERR_ALERT | ERR_FATAL;
2808 goto out;
2809#endif
2810 cur_arg += 2;
2811 continue;
2812 }
2813
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002814 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002815#ifdef SO_BINDTODEVICE
2816 if (!*args[cur_arg + 1]) {
2817 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2818 file, linenum, args[0]);
2819 err_code |= ERR_ALERT | ERR_FATAL;
2820 goto out;
2821 }
2822 free(curproxy->conn_src.iface_name);
2823 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2824 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2825 global.last_checks |= LSTCHK_NETADM;
2826#else
2827 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2828 file, linenum, args[0], args[cur_arg]);
2829 err_code |= ERR_ALERT | ERR_FATAL;
2830 goto out;
2831#endif
2832 cur_arg += 2;
2833 continue;
2834 }
2835 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2836 file, linenum, args[0], "interface", "usesrc");
2837 err_code |= ERR_ALERT | ERR_FATAL;
2838 goto out;
2839 }
2840 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002841 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002842 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2843 file, linenum, "usesrc", "source");
2844 err_code |= ERR_ALERT | ERR_FATAL;
2845 goto out;
2846 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002847 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 +02002848 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002849 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002850 file, linenum, args[0]);
2851 err_code |= ERR_ALERT | ERR_FATAL;
2852 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002853 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002854 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002855 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2856 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2857 err_code |= ERR_ALERT | ERR_FATAL;
2858 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002859 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002860 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002861 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2862 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2863 err_code |= ERR_ALERT | ERR_FATAL;
2864 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002865 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002866 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002867 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2868 err_code |= ERR_ALERT | ERR_FATAL;
2869 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002870 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002871 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002872 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2873 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2874 err_code |= ERR_ALERT | ERR_FATAL;
2875 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002876 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002877 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002878 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2879 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2880 err_code |= ERR_ALERT | ERR_FATAL;
2881 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002882 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002883 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002884 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2885 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2886 err_code |= ERR_ALERT | ERR_FATAL;
2887 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002888 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002889 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002890 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2891 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2892 err_code |= ERR_ALERT | ERR_FATAL;
2893 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002894 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002895 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 +02002896 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2897 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2898 err_code |= ERR_ALERT | ERR_FATAL;
2899 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002900 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002901 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002902 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\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], "reqiallow") == 0) { /* allow a request if a header matches this 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-request allow' 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], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
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-request tarpit' instead.\n", file, linenum, args[0]);
2915 err_code |= ERR_ALERT | ERR_FATAL;
2916 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002917 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002918 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002919 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2920 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2921 err_code |= ERR_ALERT | ERR_FATAL;
2922 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002923 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002924 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 +02002925 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2926 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2927 err_code |= ERR_ALERT | ERR_FATAL;
2928 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002929 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002930 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002931 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2932 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2933 err_code |= ERR_ALERT | ERR_FATAL;
2934 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002935 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002936 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002937 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2938 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2939 err_code |= ERR_ALERT | ERR_FATAL;
2940 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002941 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002942 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302943 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002944 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2945 err_code |= ERR_ALERT | ERR_FATAL;
2946 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002947 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002948 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002949 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2950 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2951 err_code |= ERR_ALERT | ERR_FATAL;
2952 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002953 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002954 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002955 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2956 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2957 err_code |= ERR_ALERT | ERR_FATAL;
2958 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002959 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002960 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002961 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2962 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2963 err_code |= ERR_ALERT | ERR_FATAL;
2964 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002965 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002966 else {
2967 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002968 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002969 int index;
2970
2971 list_for_each_entry(kwl, &cfg_keywords.list, list) {
2972 for (index = 0; kwl->kw[index].kw != NULL; index++) {
2973 if (kwl->kw[index].section != CFG_LISTEN)
2974 continue;
2975 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
2976 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01002977 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002978 if (rc < 0) {
2979 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2980 err_code |= ERR_ALERT | ERR_FATAL;
2981 goto out;
2982 }
2983 else if (rc > 0) {
2984 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2985 err_code |= ERR_WARN;
2986 goto out;
2987 }
2988 goto out;
2989 }
2990 }
2991 }
2992
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002993 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
2994 if (best)
2995 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
2996 else
2997 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002998 err_code |= ERR_ALERT | ERR_FATAL;
2999 goto out;
3000 }
3001 out:
3002 free(errmsg);
3003 return err_code;
3004}