blob: aa2b5eb07726e515bd0e0819656a001acc527546 [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 */
214 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, "INIT", 0, NULL, &errmsg);
215 curr_defproxy = last_defproxy;
216 if (!last_defproxy) {
217 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
218 err_code |= ERR_ALERT | ERR_ABORT;
219 goto out;
220 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100221 }
222
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100223 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100224 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100225 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100226 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100228 rc = PR_CAP_BE;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100229 else if (strcmp(args[0], "defaults") == 0) {
230 /* "defaults" must first delete the last no-name defaults if any */
231 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
232 curr_defproxy = NULL;
233 rc = PR_CAP_DEF | PR_CAP_LISTEN;
234 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100235 else
236 rc = PR_CAP_NONE;
237
Willy Tarreaue90904d2021-02-12 14:08:31 +0100238 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100239 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100240 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100241 file, linenum, args[0]);
242 err_code |= ERR_ALERT | ERR_ABORT;
243 goto out;
244 }
245
246 err = invalid_char(args[1]);
247 if (err) {
248 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
249 file, linenum, *err, args[0], args[1]);
250 err_code |= ERR_ALERT | ERR_FATAL;
251 }
252
253 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
254 if (curproxy) {
255 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
256 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
257 curproxy->id, curproxy->conf.file, curproxy->conf.line);
258 err_code |= ERR_ALERT | ERR_FATAL;
259 }
260
Emeric Brunb0c331f2020-10-07 17:05:59 +0200261 curproxy = log_forward_by_name(args[1]);
262 if (curproxy) {
263 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
264 file, linenum, proxy_cap_str(rc), args[1],
265 curproxy->id, curproxy->conf.file, curproxy->conf.line);
266 err_code |= ERR_ALERT | ERR_FATAL;
267 }
268
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100269 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
270 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100271 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100272 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
273 goto out;
274 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100275 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100276
Willy Tarreaue90904d2021-02-12 14:08:31 +0100277 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100278 const char *name = args[1];
279 int arg = 2;
280
281 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
282 // also support "defaults from blah" (no name then)
283 arg = 1;
284 name = "";
285 }
286
287 /* only regular proxies inherit from the previous defaults section */
288 if (!(rc & PR_CAP_DEF))
289 curr_defproxy = last_defproxy;
290
291 if (strcmp(args[arg], "from") == 0) {
292 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
293
294 if (!curr_defproxy) {
295 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
296 err_code |= ERR_ALERT | ERR_ABORT;
297 goto out;
298 }
299
300 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
301 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
302
303 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
304 file, linenum, args[arg+1], proxy_cap_str(rc), name,
305 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
306 err_code |= ERR_ALERT | ERR_FATAL;
307 }
308
309 err = invalid_char(args[arg+1]);
310 if (err) {
311 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",
312 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
313 err_code |= ERR_ALERT | ERR_FATAL;
314 }
315 }
316
317 curproxy = alloc_new_proxy(name, rc, file, linenum, curr_defproxy, &errmsg);
Willy Tarreau76838932021-02-12 08:49:47 +0100318 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100319 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
320 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100321 goto out;
322 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100323
Willy Tarreaue90904d2021-02-12 14:08:31 +0100324 if (rc & PR_CAP_DEF) {
325 /* last and current proxies must be updated to this one */
326 curr_defproxy = last_defproxy = curproxy;
327 } else {
328 /* regular proxies are in a list */
329 curproxy->next = proxies_list;
330 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100331 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100332 goto out;
333 }
334 else if (curproxy == NULL) {
335 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
336 err_code |= ERR_ALERT | ERR_FATAL;
337 goto out;
338 }
339
340 /* update the current file and line being parsed */
341 curproxy->conf.args.file = curproxy->conf.file;
342 curproxy->conf.args.line = linenum;
343
344 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100345 if ((strcmp(args[0], "server") == 0)) {
346 err_code |= parse_server(file, linenum, args,
347 curproxy, curr_defproxy,
348 SRV_PARSE_PARSE_ADDR);
349
350 if (err_code & ERR_FATAL)
351 goto out;
352 }
353 else if (strcmp(args[0], "default-server") == 0) {
354 err_code |= parse_server(file, linenum, args,
355 curproxy, curr_defproxy,
356 SRV_PARSE_DEFAULT_SERVER);
357
358 if (err_code & ERR_FATAL)
359 goto out;
360 }
361 else if (strcmp(args[0], "server-template") == 0) {
362 err_code |= parse_server(file, linenum, args,
363 curproxy, curr_defproxy,
364 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
365
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100366 if (err_code & ERR_FATAL)
367 goto out;
368 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100369 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100370 struct listener *l;
371 int cur_arg;
372
Willy Tarreau5d095c22021-02-12 10:15:59 +0100373 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100374 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
375 err_code |= ERR_ALERT | ERR_FATAL;
376 goto out;
377 }
378 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
379 err_code |= ERR_WARN;
380
381 if (!*(args[1])) {
382 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
383 file, linenum, args[0]);
384 err_code |= ERR_ALERT | ERR_FATAL;
385 goto out;
386 }
387
388 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
389
390 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200391 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
392 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
393 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100394
395 /* NOTE: the following line might create several listeners if there
396 * are comma-separated IPs or port ranges. So all further processing
397 * will have to be applied to all listeners created after last_listen.
398 */
399 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
400 if (errmsg && *errmsg) {
401 indent_msg(&errmsg, 2);
402 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
403 }
404 else
405 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
406 file, linenum, args[0], args[1]);
407 err_code |= ERR_ALERT | ERR_FATAL;
408 goto out;
409 }
410
411 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
412 /* Set default global rights and owner for unix bind */
413 global.maxsock++;
414 }
415
416 cur_arg = 2;
417 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100418 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100419 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100420
421 kw = bind_find_kw(args[cur_arg]);
422 if (kw) {
423 char *err = NULL;
424 int code;
425
426 if (!kw->parse) {
427 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
428 file, linenum, args[0], args[1], args[cur_arg]);
429 cur_arg += 1 + kw->skip ;
430 err_code |= ERR_ALERT | ERR_FATAL;
431 goto out;
432 }
433
434 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
435 err_code |= code;
436
437 if (code) {
438 if (err && *err) {
439 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200440 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
441 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
442 else
443 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100444 }
445 else
446 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
447 file, linenum, args[0], args[1], args[cur_arg]);
448 if (code & ERR_FATAL) {
449 free(err);
450 cur_arg += 1 + kw->skip;
451 goto out;
452 }
453 }
454 free(err);
455 cur_arg += 1 + kw->skip;
456 continue;
457 }
458
Willy Tarreau433b05f2021-03-12 10:14:07 +0100459 best = bind_find_best_kw(args[cur_arg]);
460 if (best)
461 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
462 file, linenum, args[0], args[1], args[cur_arg], best);
463 else
464 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
465 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100466
467 err_code |= ERR_ALERT | ERR_FATAL;
468 goto out;
469 }
470 goto out;
471 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100472 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200473 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]);
474 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100475 goto out;
476 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100477 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100478 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
479 err_code |= ERR_WARN;
480
481 if (alertif_too_many_args(1, file, linenum, args, &err_code))
482 goto out;
483
484 if (!*args[1]) {
485 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
486 file, linenum, args[0]);
487 err_code |= ERR_ALERT | ERR_FATAL;
488 goto out;
489 }
490
491 free(curproxy->monitor_uri);
492 curproxy->monitor_uri_len = strlen(args[1]);
493 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
494 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
495 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
496
497 goto out;
498 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100499 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100500 if (alertif_too_many_args(1, file, linenum, args, &err_code))
501 goto out;
502
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100503 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
504 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
505 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200506 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
507 err_code |= ERR_ALERT | ERR_FATAL;
508 goto out;
509 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100510 else {
511 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
512 err_code |= ERR_ALERT | ERR_FATAL;
513 goto out;
514 }
515 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100516 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100517 struct eb32_node *node;
518
Willy Tarreau5d095c22021-02-12 10:15:59 +0100519 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100520 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
521 file, linenum, args[0]);
522 err_code |= ERR_ALERT | ERR_FATAL;
523 goto out;
524 }
525
526 if (alertif_too_many_args(1, file, linenum, args, &err_code))
527 goto out;
528
529 if (!*args[1]) {
530 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
531 file, linenum, args[0]);
532 err_code |= ERR_ALERT | ERR_FATAL;
533 goto out;
534 }
535
536 curproxy->uuid = atol(args[1]);
537 curproxy->conf.id.key = curproxy->uuid;
538 curproxy->options |= PR_O_FORCED_ID;
539
540 if (curproxy->uuid <= 0) {
541 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
542 file, linenum);
543 err_code |= ERR_ALERT | ERR_FATAL;
544 goto out;
545 }
546
547 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
548 if (node) {
549 struct proxy *target = container_of(node, struct proxy, conf.id);
550 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
551 file, linenum, proxy_type_str(curproxy), curproxy->id,
552 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
553 err_code |= ERR_ALERT | ERR_FATAL;
554 goto out;
555 }
556 eb32_insert(&used_proxy_id, &curproxy->conf.id);
557 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100558 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100559 int i, len=0;
560 char *d;
561
Willy Tarreau5d095c22021-02-12 10:15:59 +0100562 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100563 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
564 file, linenum, args[0]);
565 err_code |= ERR_ALERT | ERR_FATAL;
566 goto out;
567 }
568
569 if (!*args[1]) {
570 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
571 file, linenum, args[0]);
572 return -1;
573 }
574
575 for (i = 1; *args[i]; i++)
576 len += strlen(args[i]) + 1;
577
578 d = calloc(1, len);
579 curproxy->desc = d;
580
581 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
582 for (i = 2; *args[i]; i++)
583 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
584
585 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100586 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100587 if (alertif_too_many_args(0, file, linenum, args, &err_code))
588 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200589 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100590 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100591 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100592 if (alertif_too_many_args(0, file, linenum, args, &err_code))
593 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200594 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100595 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100596 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100597 int cur_arg = 1;
598 unsigned long set = 0;
599
600 while (*args[cur_arg]) {
601 if (strcmp(args[cur_arg], "all") == 0) {
602 set = 0;
603 break;
604 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100605 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100606 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
607 err_code |= ERR_ALERT | ERR_FATAL;
608 goto out;
609 }
610 cur_arg++;
611 }
612 curproxy->bind_proc = set;
613 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100614 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100615 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100616 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
617 err_code |= ERR_ALERT | ERR_FATAL;
618 goto out;
619 }
620
621 err = invalid_char(args[1]);
622 if (err) {
623 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
624 file, linenum, *err, args[1]);
625 err_code |= ERR_ALERT | ERR_FATAL;
626 goto out;
627 }
628
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100629 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100630 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100631 "logical disjunction within a condition.\n",
632 file, linenum, args[1]);
633 err_code |= ERR_ALERT | ERR_FATAL;
634 goto out;
635 }
636
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100637 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
638 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
639 file, linenum, args[1], errmsg);
640 err_code |= ERR_ALERT | ERR_FATAL;
641 goto out;
642 }
643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100644 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100645
646 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
647 err_code |= ERR_WARN;
648
649 if (*(args[1]) == 0) {
650 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
651 file, linenum, args[0]);
652 err_code |= ERR_ALERT | ERR_FATAL;
653 goto out;
654 }
655 free(curproxy->dyncookie_key);
656 curproxy->dyncookie_key = strdup(args[1]);
657 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100658 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100659 int cur_arg;
660
661 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
662 err_code |= ERR_WARN;
663
664 if (*(args[1]) == 0) {
665 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
666 file, linenum, args[0]);
667 err_code |= ERR_ALERT | ERR_FATAL;
668 goto out;
669 }
670
671 curproxy->ck_opts = 0;
672 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100673 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100674 free(curproxy->cookie_name);
675 curproxy->cookie_name = strdup(args[1]);
676 curproxy->cookie_len = strlen(curproxy->cookie_name);
677
678 cur_arg = 2;
679 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100680 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100681 curproxy->ck_opts |= PR_CK_RW;
682 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100683 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100684 curproxy->ck_opts |= PR_CK_IND;
685 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100686 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100687 curproxy->ck_opts |= PR_CK_INS;
688 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100689 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100690 curproxy->ck_opts |= PR_CK_NOC;
691 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100692 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100693 curproxy->ck_opts |= PR_CK_POST;
694 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100695 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100696 curproxy->ck_opts |= PR_CK_PSV;
697 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100698 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100699 curproxy->ck_opts |= PR_CK_PFX;
700 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100701 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100702 curproxy->ck_opts |= PR_CK_HTTPONLY;
703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100704 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100705 curproxy->ck_opts |= PR_CK_SECURE;
706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100708 if (!*args[cur_arg + 1]) {
709 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
710 file, linenum, args[cur_arg]);
711 err_code |= ERR_ALERT | ERR_FATAL;
712 goto out;
713 }
714
Joao Moraise1583752019-10-30 21:04:00 -0300715 if (!strchr(args[cur_arg + 1], '.')) {
716 /* rfc6265, 5.2.3 The Domain Attribute */
717 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
718 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100719 file, linenum, args[cur_arg + 1]);
720 err_code |= ERR_WARN;
721 }
722
723 err = invalid_domainchar(args[cur_arg + 1]);
724 if (err) {
725 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
726 file, linenum, *err, args[cur_arg + 1]);
727 err_code |= ERR_ALERT | ERR_FATAL;
728 goto out;
729 }
730
731 if (!curproxy->cookie_domain) {
732 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
733 } else {
734 /* one domain was already specified, add another one by
735 * building the string which will be returned along with
736 * the cookie.
737 */
738 char *new_ptr;
739 int new_len = strlen(curproxy->cookie_domain) +
740 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
741 new_ptr = malloc(new_len);
742 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
743 free(curproxy->cookie_domain);
744 curproxy->cookie_domain = new_ptr;
745 }
746 cur_arg++;
747 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100748 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100749 unsigned int maxidle;
750 const char *res;
751
752 if (!*args[cur_arg + 1]) {
753 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
754 file, linenum, args[cur_arg]);
755 err_code |= ERR_ALERT | ERR_FATAL;
756 goto out;
757 }
758
759 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200760 if (res == PARSE_TIME_OVER) {
761 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
762 file, linenum, args[cur_arg+1], args[cur_arg]);
763 err_code |= ERR_ALERT | ERR_FATAL;
764 goto out;
765 }
766 else if (res == PARSE_TIME_UNDER) {
767 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
768 file, linenum, args[cur_arg+1], args[cur_arg]);
769 err_code |= ERR_ALERT | ERR_FATAL;
770 goto out;
771 }
772 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100773 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
774 file, linenum, *res, args[cur_arg]);
775 err_code |= ERR_ALERT | ERR_FATAL;
776 goto out;
777 }
778 curproxy->cookie_maxidle = maxidle;
779 cur_arg++;
780 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100781 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100782 unsigned int maxlife;
783 const char *res;
784
785 if (!*args[cur_arg + 1]) {
786 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
787 file, linenum, args[cur_arg]);
788 err_code |= ERR_ALERT | ERR_FATAL;
789 goto out;
790 }
791
Willy Tarreau9faebe32019-06-07 19:00:37 +0200792
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100793 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200794 if (res == PARSE_TIME_OVER) {
795 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
796 file, linenum, args[cur_arg+1], args[cur_arg]);
797 err_code |= ERR_ALERT | ERR_FATAL;
798 goto out;
799 }
800 else if (res == PARSE_TIME_UNDER) {
801 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
802 file, linenum, args[cur_arg+1], args[cur_arg]);
803 err_code |= ERR_ALERT | ERR_FATAL;
804 goto out;
805 }
806 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100807 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
808 file, linenum, *res, args[cur_arg]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812 curproxy->cookie_maxlife = maxlife;
813 cur_arg++;
814 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100815 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100816
817 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
818 err_code |= ERR_WARN;
819 curproxy->ck_opts |= PR_CK_DYNAMIC;
820 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100821 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100822 char *val;
823 if (!*args[cur_arg + 1]) {
824 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
825 file, linenum, args[cur_arg]);
826 err_code |= ERR_ALERT | ERR_FATAL;
827 goto out;
828 }
829 val = args[cur_arg + 1];
830 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100831 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100832 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
833 file, linenum, *val);
834 err_code |= ERR_ALERT | ERR_FATAL;
835 goto out;
836 }
837 val++;
838 }
839 /* don't add ';' for the first attribute */
840 if (!curproxy->cookie_attrs)
841 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
842 else
843 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
844 cur_arg++;
845 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100846
847 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100848 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 +0100849 file, linenum, args[0]);
850 err_code |= ERR_ALERT | ERR_FATAL;
851 goto out;
852 }
853 cur_arg++;
854 }
855 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
856 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
857 file, linenum);
858 err_code |= ERR_ALERT | ERR_FATAL;
859 }
860
861 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
862 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
863 file, linenum);
864 err_code |= ERR_ALERT | ERR_FATAL;
865 }
866
867 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
868 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
869 file, linenum);
870 err_code |= ERR_ALERT | ERR_FATAL;
871 }
872 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100873 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100874 if (*(args[1]) == 0) {
875 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
876 file, linenum, args[0]);
877 err_code |= ERR_ALERT | ERR_FATAL;
878 goto out;
879 }
880
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100881 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100882 if (*(args[1]) == 0) {
883 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
884 file, linenum, args[1]);
885 err_code |= ERR_ALERT | ERR_FATAL;
886 goto out;
887 }
888 free(curproxy->email_alert.from);
889 curproxy->email_alert.from = strdup(args[2]);
890 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100891 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100892 if (*(args[1]) == 0) {
893 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
894 file, linenum, args[1]);
895 err_code |= ERR_ALERT | ERR_FATAL;
896 goto out;
897 }
898 free(curproxy->email_alert.mailers.name);
899 curproxy->email_alert.mailers.name = strdup(args[2]);
900 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100901 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100902 if (*(args[1]) == 0) {
903 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
904 file, linenum, args[1]);
905 err_code |= ERR_ALERT | ERR_FATAL;
906 goto out;
907 }
908 free(curproxy->email_alert.myhostname);
909 curproxy->email_alert.myhostname = strdup(args[2]);
910 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100911 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100912 curproxy->email_alert.level = get_log_level(args[2]);
913 if (curproxy->email_alert.level < 0) {
914 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
915 file, linenum, args[1], args[2]);
916 err_code |= ERR_ALERT | ERR_FATAL;
917 goto out;
918 }
919 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100920 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100921 if (*(args[1]) == 0) {
922 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
923 file, linenum, args[1]);
924 err_code |= ERR_ALERT | ERR_FATAL;
925 goto out;
926 }
927 free(curproxy->email_alert.to);
928 curproxy->email_alert.to = strdup(args[2]);
929 }
930 else {
931 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
932 file, linenum, args[1]);
933 err_code |= ERR_ALERT | ERR_FATAL;
934 goto out;
935 }
936 /* Indicate that the email_alert is at least partially configured */
937 curproxy->email_alert.set = 1;
938 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100939 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100940 if (*(args[1]) == 0) {
941 ha_alert("parsing [%s:%d] : missing persist method.\n",
942 file, linenum);
943 err_code |= ERR_ALERT | ERR_FATAL;
944 goto out;
945 }
946
947 if (!strncmp(args[1], "rdp-cookie", 10)) {
948 curproxy->options2 |= PR_O2_RDPC_PRST;
949
950 if (*(args[1] + 10) == '(') { /* cookie name */
951 const char *beg, *end;
952
953 beg = args[1] + 11;
954 end = strchr(beg, ')');
955
956 if (alertif_too_many_args(1, file, linenum, args, &err_code))
957 goto out;
958
959 if (!end || end == beg) {
960 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
961 file, linenum);
962 err_code |= ERR_ALERT | ERR_FATAL;
963 goto out;
964 }
965
966 free(curproxy->rdp_cookie_name);
967 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
968 curproxy->rdp_cookie_len = end-beg;
969 }
970 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
971 free(curproxy->rdp_cookie_name);
972 curproxy->rdp_cookie_name = strdup("msts");
973 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
974 }
975 else { /* syntax */
976 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
977 file, linenum);
978 err_code |= ERR_ALERT | ERR_FATAL;
979 goto out;
980 }
981 }
982 else {
983 ha_alert("parsing [%s:%d] : unknown persist method.\n",
984 file, linenum);
985 err_code |= ERR_ALERT | ERR_FATAL;
986 goto out;
987 }
988 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100989 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +0200990 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 +0100991 err_code |= ERR_ALERT | ERR_FATAL;
992 goto out;
993 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100994 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100995 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
996 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100997 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100998 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
999 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001000 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 +01001001 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1002 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001003 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001004 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1005 }
1006 else {
1007 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1008 file, linenum, args[0], args[1]);
1009 err_code |= ERR_ALERT | ERR_FATAL;
1010 goto out;
1011 }
1012 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001013 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001014 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1015 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001016 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001017 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001018
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001019 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001020
1021 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001022 curproxy->server_state_file_name = strdup(curproxy->id);
1023 else
1024 curproxy->server_state_file_name = strdup(args[1]);
1025 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001026 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001027 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1028 err_code |= ERR_WARN;
1029 if (*(args[1]) == 0) {
1030 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1031 file, linenum, args[0]);
1032 err_code |= ERR_ALERT | ERR_FATAL;
1033 goto out;
1034 }
1035 curproxy->max_out_conns = atoi(args[1]);
1036 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001037 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001038 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1039 err_code |= ERR_WARN;
1040
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001041 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001042 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001043 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1044 err_code |= ERR_ALERT | ERR_FATAL;
1045 goto out;
1046 }
1047
1048 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1049 goto out;
1050
1051 if (*(args[4]) == 0) {
1052 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1053 file, linenum, args[0]);
1054 err_code |= ERR_ALERT | ERR_FATAL;
1055 goto out;
1056 }
1057 free(curproxy->capture_name);
1058 curproxy->capture_name = strdup(args[2]);
1059 curproxy->capture_namelen = strlen(curproxy->capture_name);
1060 curproxy->capture_len = atol(args[4]);
1061 curproxy->to_log |= LW_COOKIE;
1062 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001063 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001064 struct cap_hdr *hdr;
1065
Willy Tarreau5d095c22021-02-12 10:15:59 +01001066 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001067 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071
1072 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1073 goto out;
1074
1075 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1076 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1077 file, linenum, args[0], args[1]);
1078 err_code |= ERR_ALERT | ERR_FATAL;
1079 goto out;
1080 }
1081
1082 hdr = calloc(1, sizeof(*hdr));
1083 hdr->next = curproxy->req_cap;
1084 hdr->name = strdup(args[3]);
1085 hdr->namelen = strlen(args[3]);
1086 hdr->len = atol(args[5]);
1087 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1088 hdr->index = curproxy->nb_req_cap++;
1089 curproxy->req_cap = hdr;
1090 curproxy->to_log |= LW_REQHDR;
1091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001092 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001093 struct cap_hdr *hdr;
1094
Willy Tarreau5d095c22021-02-12 10:15:59 +01001095 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001096 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1097 err_code |= ERR_ALERT | ERR_FATAL;
1098 goto out;
1099 }
1100
1101 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1102 goto out;
1103
1104 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1105 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1106 file, linenum, args[0], args[1]);
1107 err_code |= ERR_ALERT | ERR_FATAL;
1108 goto out;
1109 }
1110 hdr = calloc(1, sizeof(*hdr));
1111 hdr->next = curproxy->rsp_cap;
1112 hdr->name = strdup(args[3]);
1113 hdr->namelen = strlen(args[3]);
1114 hdr->len = atol(args[5]);
1115 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1116 hdr->index = curproxy->nb_rsp_cap++;
1117 curproxy->rsp_cap = hdr;
1118 curproxy->to_log |= LW_RSPHDR;
1119 }
1120 else {
1121 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1122 file, linenum, args[0]);
1123 err_code |= ERR_ALERT | ERR_FATAL;
1124 goto out;
1125 }
1126 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001127 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001128 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1129 err_code |= ERR_WARN;
1130
1131 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1132 goto out;
1133
1134 if (*(args[1]) == 0) {
1135 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1136 file, linenum, args[0]);
1137 err_code |= ERR_ALERT | ERR_FATAL;
1138 goto out;
1139 }
1140 curproxy->conn_retries = atol(args[1]);
1141 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001142 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001143 struct act_rule *rule;
1144
Willy Tarreau5d095c22021-02-12 10:15:59 +01001145 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001146 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1147 err_code |= ERR_ALERT | ERR_FATAL;
1148 goto out;
1149 }
1150
1151 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1152 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001153 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001154 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1155 file, linenum, args[0]);
1156 err_code |= ERR_WARN;
1157 }
1158
1159 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1160
1161 if (!rule) {
1162 err_code |= ERR_ALERT | ERR_ABORT;
1163 goto out;
1164 }
1165
1166 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1167 err_code |= warnif_cond_conflicts(rule->cond,
1168 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1169 file, linenum);
1170
1171 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1172 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001173 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001174 struct act_rule *rule;
1175
Willy Tarreau5d095c22021-02-12 10:15:59 +01001176 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001177 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1178 err_code |= ERR_ALERT | ERR_FATAL;
1179 goto out;
1180 }
1181
1182 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1183 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001184 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001185 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1186 file, linenum, args[0]);
1187 err_code |= ERR_WARN;
1188 }
1189
1190 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1191
1192 if (!rule) {
1193 err_code |= ERR_ALERT | ERR_ABORT;
1194 goto out;
1195 }
1196
1197 err_code |= warnif_cond_conflicts(rule->cond,
1198 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1199 file, linenum);
1200
1201 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1202 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001203 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001204 struct act_rule *rule;
1205
Willy Tarreau5d095c22021-02-12 10:15:59 +01001206 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001207 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1208 err_code |= ERR_ALERT | ERR_FATAL;
1209 goto out;
1210 }
1211
1212 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1213 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1214 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1215 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1216 file, linenum, args[0]);
1217 err_code |= ERR_WARN;
1218 }
1219
1220 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1221
1222 if (!rule) {
1223 err_code |= ERR_ALERT | ERR_ABORT;
1224 goto out;
1225 }
1226
1227 err_code |= warnif_cond_conflicts(rule->cond,
1228 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1229 file, linenum);
1230
1231 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1232 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001233 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001234 /* set the header name and length into the proxy structure */
1235 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1236 err_code |= ERR_WARN;
1237
1238 if (!*args[1]) {
1239 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1240 file, linenum, args[0]);
1241 err_code |= ERR_ALERT | ERR_FATAL;
1242 goto out;
1243 }
1244
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001245 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001246 free(curproxy->server_id_hdr_name);
1247 curproxy->server_id_hdr_name = strdup(args[1]);
1248 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001249 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 +01001250 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001251 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001252 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 +01001253
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001254 err_code |= ERR_ALERT | ERR_FATAL;
1255 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001256 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001257 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001258 struct redirect_rule *rule;
1259
Willy Tarreau5d095c22021-02-12 10:15:59 +01001260 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001261 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1262 err_code |= ERR_ALERT | ERR_FATAL;
1263 goto out;
1264 }
1265
1266 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1267 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1268 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1269 err_code |= ERR_ALERT | ERR_FATAL;
1270 goto out;
1271 }
1272
1273 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1274 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1275 err_code |= warnif_cond_conflicts(rule->cond,
1276 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1277 file, linenum);
1278 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001279 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001280 struct switching_rule *rule;
1281
Willy Tarreau5d095c22021-02-12 10:15:59 +01001282 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001283 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1284 err_code |= ERR_ALERT | ERR_FATAL;
1285 goto out;
1286 }
1287
1288 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1289 err_code |= ERR_WARN;
1290
1291 if (*(args[1]) == 0) {
1292 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1293 err_code |= ERR_ALERT | ERR_FATAL;
1294 goto out;
1295 }
1296
1297 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1298 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1299 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1300 file, linenum, errmsg);
1301 err_code |= ERR_ALERT | ERR_FATAL;
1302 goto out;
1303 }
1304
1305 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1306 }
1307 else if (*args[2]) {
1308 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1309 file, linenum, args[2]);
1310 err_code |= ERR_ALERT | ERR_FATAL;
1311 goto out;
1312 }
1313
1314 rule = calloc(1, sizeof(*rule));
1315 if (!rule) {
1316 ha_alert("Out of memory error.\n");
1317 goto out;
1318 }
1319 rule->cond = cond;
1320 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001321 if (!rule->be.name) {
1322 ha_alert("Out of memory error.\n");
1323 goto out;
1324 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001325 rule->line = linenum;
1326 rule->file = strdup(file);
1327 if (!rule->file) {
1328 ha_alert("Out of memory error.\n");
1329 goto out;
1330 }
1331 LIST_INIT(&rule->list);
1332 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1333 }
1334 else if (strcmp(args[0], "use-server") == 0) {
1335 struct server_rule *rule;
1336
Willy Tarreau5d095c22021-02-12 10:15:59 +01001337 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001338 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1339 err_code |= ERR_ALERT | ERR_FATAL;
1340 goto out;
1341 }
1342
1343 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1344 err_code |= ERR_WARN;
1345
1346 if (*(args[1]) == 0) {
1347 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1348 err_code |= ERR_ALERT | ERR_FATAL;
1349 goto out;
1350 }
1351
1352 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1353 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1354 file, linenum, args[0]);
1355 err_code |= ERR_ALERT | ERR_FATAL;
1356 goto out;
1357 }
1358
1359 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1360 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1361 file, linenum, errmsg);
1362 err_code |= ERR_ALERT | ERR_FATAL;
1363 goto out;
1364 }
1365
1366 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1367
1368 rule = calloc(1, sizeof(*rule));
1369 rule->cond = cond;
1370 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001371 rule->line = linenum;
1372 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001373 LIST_INIT(&rule->list);
1374 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1375 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1376 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001377 else if ((strcmp(args[0], "force-persist") == 0) ||
1378 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001379 struct persist_rule *rule;
1380
Willy Tarreau5d095c22021-02-12 10:15:59 +01001381 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001382 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1383 err_code |= ERR_ALERT | ERR_FATAL;
1384 goto out;
1385 }
1386
1387 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1388 err_code |= ERR_WARN;
1389
1390 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1391 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1392 file, linenum, args[0]);
1393 err_code |= ERR_ALERT | ERR_FATAL;
1394 goto out;
1395 }
1396
1397 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1398 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1399 file, linenum, args[0], errmsg);
1400 err_code |= ERR_ALERT | ERR_FATAL;
1401 goto out;
1402 }
1403
1404 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1405 * where force-persist is applied.
1406 */
1407 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1408
1409 rule = calloc(1, sizeof(*rule));
1410 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001411 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001412 rule->type = PERSIST_TYPE_FORCE;
1413 } else {
1414 rule->type = PERSIST_TYPE_IGNORE;
1415 }
1416 LIST_INIT(&rule->list);
1417 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1418 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001419 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001420 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001421
Willy Tarreau5d095c22021-02-12 10:15:59 +01001422 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001423 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1424 file, linenum);
1425 err_code |= ERR_ALERT | ERR_FATAL;
1426 goto out;
1427 }
1428
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001429 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001430 if (other) {
1431 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 +01001432 file, linenum, curproxy->id,
1433 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1434 other->proxy ? other->id : other->peers.p->id,
1435 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001436 err_code |= ERR_ALERT | ERR_FATAL;
1437 goto out;
1438 }
1439
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001440 curproxy->table = calloc(1, sizeof *curproxy->table);
1441 if (!curproxy->table) {
1442 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1443 file, linenum, args[0], args[1]);
1444 err_code |= ERR_ALERT | ERR_FATAL;
1445 goto out;
1446 }
1447
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001448 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1449 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001450 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001451 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001452
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001453 /* Store the proxy in the stick-table. */
1454 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001455
1456 stktable_store_name(curproxy->table);
1457 curproxy->table->next = stktables_list;
1458 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001459
1460 /* Add this proxy to the list of proxies which refer to its stick-table. */
1461 if (curproxy->table->proxies_list != curproxy) {
1462 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1463 curproxy->table->proxies_list = curproxy;
1464 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001465 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001466 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001467 struct sticking_rule *rule;
1468 struct sample_expr *expr;
1469 int myidx = 0;
1470 const char *name = NULL;
1471 int flags;
1472
Willy Tarreau5d095c22021-02-12 10:15:59 +01001473 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001474 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1475 err_code |= ERR_ALERT | ERR_FATAL;
1476 goto out;
1477 }
1478
1479 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1480 err_code |= ERR_WARN;
1481 goto out;
1482 }
1483
1484 myidx++;
1485 if ((strcmp(args[myidx], "store") == 0) ||
1486 (strcmp(args[myidx], "store-request") == 0)) {
1487 myidx++;
1488 flags = STK_IS_STORE;
1489 }
1490 else if (strcmp(args[myidx], "store-response") == 0) {
1491 myidx++;
1492 flags = STK_IS_STORE | STK_ON_RSP;
1493 }
1494 else if (strcmp(args[myidx], "match") == 0) {
1495 myidx++;
1496 flags = STK_IS_MATCH;
1497 }
1498 else if (strcmp(args[myidx], "on") == 0) {
1499 myidx++;
1500 flags = STK_IS_MATCH | STK_IS_STORE;
1501 }
1502 else {
1503 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1504 err_code |= ERR_ALERT | ERR_FATAL;
1505 goto out;
1506 }
1507
1508 if (*(args[myidx]) == 0) {
1509 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1510 err_code |= ERR_ALERT | ERR_FATAL;
1511 goto out;
1512 }
1513
1514 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001515 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001516 if (!expr) {
1517 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1518 err_code |= ERR_ALERT | ERR_FATAL;
1519 goto out;
1520 }
1521
1522 if (flags & STK_ON_RSP) {
1523 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1524 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1525 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1526 err_code |= ERR_ALERT | ERR_FATAL;
1527 free(expr);
1528 goto out;
1529 }
1530 } else {
1531 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1532 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1533 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1534 err_code |= ERR_ALERT | ERR_FATAL;
1535 free(expr);
1536 goto out;
1537 }
1538 }
1539
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001540 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001541 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1542
1543 if (strcmp(args[myidx], "table") == 0) {
1544 myidx++;
1545 name = args[myidx++];
1546 }
1547
1548 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1549 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1550 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1551 file, linenum, args[0], errmsg);
1552 err_code |= ERR_ALERT | ERR_FATAL;
1553 free(expr);
1554 goto out;
1555 }
1556 }
1557 else if (*(args[myidx])) {
1558 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1559 file, linenum, args[0], args[myidx]);
1560 err_code |= ERR_ALERT | ERR_FATAL;
1561 free(expr);
1562 goto out;
1563 }
1564 if (flags & STK_ON_RSP)
1565 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1566 else
1567 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1568
1569 rule = calloc(1, sizeof(*rule));
1570 rule->cond = cond;
1571 rule->expr = expr;
1572 rule->flags = flags;
1573 rule->table.name = name ? strdup(name) : NULL;
1574 LIST_INIT(&rule->list);
1575 if (flags & STK_ON_RSP)
1576 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1577 else
1578 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1579 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001580 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001581 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001582 curproxy->uri_auth = NULL; /* we must detach from the default config */
1583
1584 if (!*args[1]) {
1585 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001586 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001587 struct stats_admin_rule *rule;
1588
Willy Tarreau5d095c22021-02-12 10:15:59 +01001589 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001590 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1591 err_code |= ERR_ALERT | ERR_FATAL;
1592 goto out;
1593 }
1594
1595 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1596 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1597 err_code |= ERR_ALERT | ERR_ABORT;
1598 goto out;
1599 }
1600
1601 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1602 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1603 file, linenum, args[0], args[1]);
1604 err_code |= ERR_ALERT | ERR_FATAL;
1605 goto out;
1606 }
1607 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1608 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1609 file, linenum, args[0], args[1], errmsg);
1610 err_code |= ERR_ALERT | ERR_FATAL;
1611 goto out;
1612 }
1613
1614 err_code |= warnif_cond_conflicts(cond,
1615 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1616 file, linenum);
1617
1618 rule = calloc(1, sizeof(*rule));
1619 rule->cond = cond;
1620 LIST_INIT(&rule->list);
1621 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001622 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001623 if (*(args[2]) == 0) {
1624 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1625 err_code |= ERR_ALERT | ERR_FATAL;
1626 goto out;
1627 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1628 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1629 err_code |= ERR_ALERT | ERR_ABORT;
1630 goto out;
1631 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001632 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001633 if (*(args[2]) == 0) {
1634 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1635 err_code |= ERR_ALERT | ERR_FATAL;
1636 goto out;
1637 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1638 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1639 err_code |= ERR_ALERT | ERR_ABORT;
1640 goto out;
1641 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001642 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001643 unsigned interval;
1644
1645 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001646 if (err == PARSE_TIME_OVER) {
1647 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1648 file, linenum, args[2]);
1649 err_code |= ERR_ALERT | ERR_FATAL;
1650 goto out;
1651 }
1652 else if (err == PARSE_TIME_UNDER) {
1653 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1654 file, linenum, args[2]);
1655 err_code |= ERR_ALERT | ERR_FATAL;
1656 goto out;
1657 }
1658 else if (err) {
1659 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001660 file, linenum, *err);
1661 err_code |= ERR_ALERT | ERR_FATAL;
1662 goto out;
1663 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1664 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1665 err_code |= ERR_ALERT | ERR_ABORT;
1666 goto out;
1667 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001668 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001669 struct act_rule *rule;
1670
Willy Tarreau5d095c22021-02-12 10:15:59 +01001671 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001672 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1673 err_code |= ERR_ALERT | ERR_FATAL;
1674 goto out;
1675 }
1676
1677 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1678 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1679 err_code |= ERR_ALERT | ERR_ABORT;
1680 goto out;
1681 }
1682
1683 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1684 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1685 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1686 file, linenum, args[0]);
1687 err_code |= ERR_WARN;
1688 }
1689
1690 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1691
1692 if (!rule) {
1693 err_code |= ERR_ALERT | ERR_ABORT;
1694 goto out;
1695 }
1696
1697 err_code |= warnif_cond_conflicts(rule->cond,
1698 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1699 file, linenum);
1700 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1701
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001702 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001703 if (*(args[2]) == 0) {
1704 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1705 err_code |= ERR_ALERT | ERR_FATAL;
1706 goto out;
1707 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1708 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1709 err_code |= ERR_ALERT | ERR_ABORT;
1710 goto out;
1711 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001712 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001713 if (*(args[2]) == 0) {
1714 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1715 err_code |= ERR_ALERT | ERR_FATAL;
1716 goto out;
1717 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1718 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1719 err_code |= ERR_ALERT | ERR_ABORT;
1720 goto out;
1721 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001722 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001723 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1724 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1725 err_code |= ERR_ALERT | ERR_ABORT;
1726 goto out;
1727 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001728 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001729 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001730 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1731 err_code |= ERR_ALERT | ERR_ABORT;
1732 goto out;
1733 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001734 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001735 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001736 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1737 err_code |= ERR_ALERT | ERR_ABORT;
1738 goto out;
1739 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001740 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001741 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1742 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1743 err_code |= ERR_ALERT | ERR_ABORT;
1744 goto out;
1745 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001746 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001747
1748 if (*args[2]) {
1749 int i;
1750 char c;
1751
1752 for (i=0; args[2][i]; i++) {
1753 c = args[2][i];
1754 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1755 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1756 break;
1757 }
1758
1759 if (!i || args[2][i]) {
1760 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1761 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1762 file, linenum, args[0], args[1]);
1763 err_code |= ERR_ALERT | ERR_FATAL;
1764 goto out;
1765 }
1766 }
1767
1768 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1769 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1770 err_code |= ERR_ALERT | ERR_ABORT;
1771 goto out;
1772 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001773 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001774 char *desc = NULL;
1775
1776 if (*args[2]) {
1777 int i, len=0;
1778 char *d;
1779
1780 for (i = 2; *args[i]; i++)
1781 len += strlen(args[i]) + 1;
1782
1783 desc = d = calloc(1, len);
1784
1785 d += snprintf(d, desc + len - d, "%s", args[2]);
1786 for (i = 3; *args[i]; i++)
1787 d += snprintf(d, desc + len - d, " %s", args[i]);
1788 }
1789
1790 if (!*args[2] && !global.desc)
1791 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1792 file, linenum, args[1]);
1793 else {
1794 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1795 free(desc);
1796 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1797 err_code |= ERR_ALERT | ERR_ABORT;
1798 goto out;
1799 }
1800 free(desc);
1801 }
1802 } else {
1803stats_error_parsing:
1804 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1805 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1806 err_code |= ERR_ALERT | ERR_FATAL;
1807 goto out;
1808 }
1809 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001810 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001811 int optnum;
1812
1813 if (*(args[1]) == '\0') {
1814 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1815 file, linenum, args[0]);
1816 err_code |= ERR_ALERT | ERR_FATAL;
1817 goto out;
1818 }
1819
1820 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001821 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001822 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1823 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1824 file, linenum, cfg_opts[optnum].name);
1825 err_code |= ERR_ALERT | ERR_FATAL;
1826 goto out;
1827 }
1828 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1829 goto out;
1830
1831 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1832 err_code |= ERR_WARN;
1833 goto out;
1834 }
1835
1836 curproxy->no_options &= ~cfg_opts[optnum].val;
1837 curproxy->options &= ~cfg_opts[optnum].val;
1838
1839 switch (kwm) {
1840 case KWM_STD:
1841 curproxy->options |= cfg_opts[optnum].val;
1842 break;
1843 case KWM_NO:
1844 curproxy->no_options |= cfg_opts[optnum].val;
1845 break;
1846 case KWM_DEF: /* already cleared */
1847 break;
1848 }
1849
1850 goto out;
1851 }
1852 }
1853
1854 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001855 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001856 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1857 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1858 file, linenum, cfg_opts2[optnum].name);
1859 err_code |= ERR_ALERT | ERR_FATAL;
1860 goto out;
1861 }
1862 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1863 goto out;
1864 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1865 err_code |= ERR_WARN;
1866 goto out;
1867 }
1868
Christopher Faulet31930372019-07-15 10:16:58 +02001869 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001870 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001871 if (kwm ==KWM_NO) {
1872 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1873 " The HTX mode is now the only supported mode.\n",
1874 file, linenum, cfg_opts2[optnum].name);
1875 err_code |= ERR_WARN;
1876 }
Christopher Faulet31930372019-07-15 10:16:58 +02001877 goto out;
1878 }
1879
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001880 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1881 curproxy->options2 &= ~cfg_opts2[optnum].val;
1882
1883 switch (kwm) {
1884 case KWM_STD:
1885 curproxy->options2 |= cfg_opts2[optnum].val;
1886 break;
1887 case KWM_NO:
1888 curproxy->no_options2 |= cfg_opts2[optnum].val;
1889 break;
1890 case KWM_DEF: /* already cleared */
1891 break;
1892 }
1893 goto out;
1894 }
1895 }
1896
1897 /* HTTP options override each other. They can be cancelled using
1898 * "no option xxx" which only switches to default mode if the mode
1899 * was this one (useful for cancelling options set in defaults
1900 * sections).
1901 */
1902 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001903 if (strcmp(args[1], "forceclose") == 0) {
1904 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1905 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1906 file, linenum, args[1]);
1907 err_code |= ERR_WARN;
1908 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001909 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1910 goto out;
1911 if (kwm == KWM_STD) {
1912 curproxy->options &= ~PR_O_HTTP_MODE;
1913 curproxy->options |= PR_O_HTTP_CLO;
1914 goto out;
1915 }
1916 else if (kwm == KWM_NO) {
1917 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1918 curproxy->options &= ~PR_O_HTTP_MODE;
1919 goto out;
1920 }
1921 }
1922 else if (strcmp(args[1], "http-server-close") == 0) {
1923 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1924 goto out;
1925 if (kwm == KWM_STD) {
1926 curproxy->options &= ~PR_O_HTTP_MODE;
1927 curproxy->options |= PR_O_HTTP_SCL;
1928 goto out;
1929 }
1930 else if (kwm == KWM_NO) {
1931 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1932 curproxy->options &= ~PR_O_HTTP_MODE;
1933 goto out;
1934 }
1935 }
1936 else if (strcmp(args[1], "http-keep-alive") == 0) {
1937 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1938 goto out;
1939 if (kwm == KWM_STD) {
1940 curproxy->options &= ~PR_O_HTTP_MODE;
1941 curproxy->options |= PR_O_HTTP_KAL;
1942 goto out;
1943 }
1944 else if (kwm == KWM_NO) {
1945 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1946 curproxy->options &= ~PR_O_HTTP_MODE;
1947 goto out;
1948 }
1949 }
1950 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001951 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
1952 file, linenum, args[1]);
1953 err_code |= ERR_WARN;
1954 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001955 }
1956
1957 /* Redispatch can take an integer argument that control when the
1958 * resispatch occurs. All values are relative to the retries option.
1959 * This can be cancelled using "no option xxx".
1960 */
1961 if (strcmp(args[1], "redispatch") == 0) {
1962 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
1963 err_code |= ERR_WARN;
1964 goto out;
1965 }
1966
1967 curproxy->no_options &= ~PR_O_REDISP;
1968 curproxy->options &= ~PR_O_REDISP;
1969
1970 switch (kwm) {
1971 case KWM_STD:
1972 curproxy->options |= PR_O_REDISP;
1973 curproxy->redispatch_after = -1;
1974 if(*args[2]) {
1975 curproxy->redispatch_after = atol(args[2]);
1976 }
1977 break;
1978 case KWM_NO:
1979 curproxy->no_options |= PR_O_REDISP;
1980 curproxy->redispatch_after = 0;
1981 break;
1982 case KWM_DEF: /* already cleared */
1983 break;
1984 }
1985 goto out;
1986 }
1987
1988 if (kwm != KWM_STD) {
1989 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
1990 file, linenum, args[1]);
1991 err_code |= ERR_ALERT | ERR_FATAL;
1992 goto out;
1993 }
1994
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001995 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001996 char *logformat;
1997 /* generate a complete HTTP log */
1998 logformat = default_http_log_format;
1999 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002000 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002001 curproxy->options2 |= PR_O2_CLFLOG;
2002 logformat = clf_http_log_format;
2003 } else {
2004 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2005 err_code |= ERR_ALERT | ERR_FATAL;
2006 goto out;
2007 }
2008 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2009 goto out;
2010 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002011 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002012 char *oldlogformat = "log-format";
2013 char *clflogformat = "";
2014
2015 if (curproxy->conf.logformat_string == default_http_log_format)
2016 oldlogformat = "option httplog";
2017 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2018 oldlogformat = "option tcplog";
2019 else if (curproxy->conf.logformat_string == clf_http_log_format)
2020 oldlogformat = "option httplog clf";
2021 if (logformat == clf_http_log_format)
2022 clflogformat = " clf";
2023 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2024 file, linenum, clflogformat, oldlogformat);
2025 }
2026 if (curproxy->conf.logformat_string != default_http_log_format &&
2027 curproxy->conf.logformat_string != default_tcp_log_format &&
2028 curproxy->conf.logformat_string != clf_http_log_format)
2029 free(curproxy->conf.logformat_string);
2030 curproxy->conf.logformat_string = logformat;
2031
2032 free(curproxy->conf.lfs_file);
2033 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2034 curproxy->conf.lfs_line = curproxy->conf.args.line;
2035
Willy Tarreau5d095c22021-02-12 10:15:59 +01002036 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002037 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2038 file, linenum, curproxy->id);
2039 err_code |= ERR_WARN;
2040 }
2041 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002042 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002043 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002044 char *oldlogformat = "log-format";
2045
2046 if (curproxy->conf.logformat_string == default_http_log_format)
2047 oldlogformat = "option httplog";
2048 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2049 oldlogformat = "option tcplog";
2050 else if (curproxy->conf.logformat_string == clf_http_log_format)
2051 oldlogformat = "option httplog clf";
2052 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2053 file, linenum, oldlogformat);
2054 }
2055 /* generate a detailed TCP log */
2056 if (curproxy->conf.logformat_string != default_http_log_format &&
2057 curproxy->conf.logformat_string != default_tcp_log_format &&
2058 curproxy->conf.logformat_string != clf_http_log_format)
2059 free(curproxy->conf.logformat_string);
2060 curproxy->conf.logformat_string = default_tcp_log_format;
2061
2062 free(curproxy->conf.lfs_file);
2063 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2064 curproxy->conf.lfs_line = curproxy->conf.args.line;
2065
2066 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2067 goto out;
2068
Willy Tarreau5d095c22021-02-12 10:15:59 +01002069 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002070 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2071 file, linenum, curproxy->id);
2072 err_code |= ERR_WARN;
2073 }
2074 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002075 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002076 /* enable TCP keep-alives on client and server streams */
2077 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2078 err_code |= ERR_WARN;
2079
2080 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2081 goto out;
2082
2083 if (curproxy->cap & PR_CAP_FE)
2084 curproxy->options |= PR_O_TCP_CLI_KA;
2085 if (curproxy->cap & PR_CAP_BE)
2086 curproxy->options |= PR_O_TCP_SRV_KA;
2087 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002088 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002089 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002090 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002091 goto out;
2092 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002093 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002094 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002095 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002096 goto out;
2097 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002098 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002099 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002100 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002101 goto out;
2102 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002103 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002104 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002105 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002106 goto out;
2107 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002108 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002109 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002110 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002111 goto out;
2112 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002113 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002114 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002115 if (err_code & ERR_FATAL)
2116 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002117 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002118 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002119 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002120 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002121 goto out;
2122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002123 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002124 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002125 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002126 goto out;
2127 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002128 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002129 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002130 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002131 goto out;
2132 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002133 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002134 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002135 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002136 goto out;
2137 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002138 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002139 int cur_arg;
2140
2141 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002142 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002143 */
2144
2145 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2146
2147 free(curproxy->fwdfor_hdr_name);
2148 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2149 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002150 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002151
2152 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2153 cur_arg = 2;
2154 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002155 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002156 unsigned char mask;
2157 int i;
2158
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002159 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002160 if (*(args[cur_arg+1]) &&
2161 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2162 curproxy->except_xff_net.family = AF_INET;
2163 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2164 }
2165 else if (*(args[cur_arg+1]) &&
2166 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2167 curproxy->except_xff_net.family = AF_INET6;
2168 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2169 for (i = 0; i < 16; i++)
2170 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2171 }
2172 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002173 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2174 file, linenum, args[0], args[1], args[cur_arg]);
2175 err_code |= ERR_ALERT | ERR_FATAL;
2176 goto out;
2177 }
2178 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002179 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002180 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002181 /* suboption header - needs additional argument for it */
2182 if (*(args[cur_arg+1]) == 0) {
2183 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2184 file, linenum, args[0], args[1], args[cur_arg]);
2185 err_code |= ERR_ALERT | ERR_FATAL;
2186 goto out;
2187 }
2188 free(curproxy->fwdfor_hdr_name);
2189 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2190 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2191 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002192 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002193 curproxy->options &= ~PR_O_FF_ALWAYS;
2194 cur_arg += 1;
2195 } else {
2196 /* unknown suboption - catchall */
2197 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2198 file, linenum, args[0], args[1]);
2199 err_code |= ERR_ALERT | ERR_FATAL;
2200 goto out;
2201 }
2202 } /* end while loop */
2203 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002204 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002205 int cur_arg;
2206
2207 /* insert x-original-to field, but not for the IP address listed as an except.
2208 * set default options (ie: bitfield, header name, etc)
2209 */
2210
2211 curproxy->options |= PR_O_ORGTO;
2212
2213 free(curproxy->orgto_hdr_name);
2214 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2215 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002216 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002217
2218 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2219 cur_arg = 2;
2220 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002221 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002222 unsigned char mask;
2223 int i;
2224
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002225 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002226 if (*(args[cur_arg+1]) &&
2227 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2228 curproxy->except_xot_net.family = AF_INET;
2229 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2230 }
2231 else if (*(args[cur_arg+1]) &&
2232 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2233 curproxy->except_xot_net.family = AF_INET6;
2234 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2235 for (i = 0; i < 16; i++)
2236 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2237 }
2238 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002239 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2240 file, linenum, args[0], args[1], args[cur_arg]);
2241 err_code |= ERR_ALERT | ERR_FATAL;
2242 goto out;
2243 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002244 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002245 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002246 /* suboption header - needs additional argument for it */
2247 if (*(args[cur_arg+1]) == 0) {
2248 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2249 file, linenum, args[0], args[1], args[cur_arg]);
2250 err_code |= ERR_ALERT | ERR_FATAL;
2251 goto out;
2252 }
2253 free(curproxy->orgto_hdr_name);
2254 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2255 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2256 cur_arg += 2;
2257 } else {
2258 /* unknown suboption - catchall */
2259 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2260 file, linenum, args[0], args[1]);
2261 err_code |= ERR_ALERT | ERR_FATAL;
2262 goto out;
2263 }
2264 } /* end while loop */
2265 }
2266 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002267 const char *best = proxy_find_best_option(args[1], common_options);
2268
2269 if (best)
2270 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2271 else
2272 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2273
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002274 err_code |= ERR_ALERT | ERR_FATAL;
2275 goto out;
2276 }
2277 goto out;
2278 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002279 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002280 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2281 err_code |= ERR_WARN;
2282
2283 if (*(args[1]) == 0) {
2284 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2285 err_code |= ERR_ALERT | ERR_FATAL;
2286 goto out;
2287 }
2288 free(curproxy->defbe.name);
2289 curproxy->defbe.name = strdup(args[1]);
2290
2291 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2292 goto out;
2293 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002294 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002295 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 +01002296
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002297 err_code |= ERR_ALERT | ERR_FATAL;
2298 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002299 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002300 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002301 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2302 err_code |= ERR_WARN;
2303
2304 if (strcmp(args[1], "never") == 0) {
2305 /* enable a graceful server shutdown on an HTTP 404 response */
2306 curproxy->options &= ~PR_O_REUSE_MASK;
2307 curproxy->options |= PR_O_REUSE_NEVR;
2308 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2309 goto out;
2310 }
2311 else if (strcmp(args[1], "safe") == 0) {
2312 /* enable a graceful server shutdown on an HTTP 404 response */
2313 curproxy->options &= ~PR_O_REUSE_MASK;
2314 curproxy->options |= PR_O_REUSE_SAFE;
2315 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2316 goto out;
2317 }
2318 else if (strcmp(args[1], "aggressive") == 0) {
2319 curproxy->options &= ~PR_O_REUSE_MASK;
2320 curproxy->options |= PR_O_REUSE_AGGR;
2321 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2322 goto out;
2323 }
2324 else if (strcmp(args[1], "always") == 0) {
2325 /* enable a graceful server shutdown on an HTTP 404 response */
2326 curproxy->options &= ~PR_O_REUSE_MASK;
2327 curproxy->options |= PR_O_REUSE_ALWS;
2328 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2329 goto out;
2330 }
2331 else {
2332 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2333 err_code |= ERR_ALERT | ERR_FATAL;
2334 goto out;
2335 }
2336 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002337 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002338 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002339 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2340 err_code |= ERR_ALERT | ERR_FATAL;
2341 goto out;
2342 }
2343
2344 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2345 err_code |= ERR_WARN;
2346
2347 if (strcmp(args[1], "fail") == 0) {
2348 /* add a condition to fail monitor requests */
2349 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2350 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2351 file, linenum, args[0], args[1]);
2352 err_code |= ERR_ALERT | ERR_FATAL;
2353 goto out;
2354 }
2355
2356 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2357 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2358 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2359 file, linenum, args[0], args[1], errmsg);
2360 err_code |= ERR_ALERT | ERR_FATAL;
2361 goto out;
2362 }
2363 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2364 }
2365 else {
2366 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2367 err_code |= ERR_ALERT | ERR_FATAL;
2368 goto out;
2369 }
2370 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002371#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002372 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002373 /* enable transparent proxy connections */
2374 curproxy->options |= PR_O_TRANSP;
2375 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2376 goto out;
2377 }
2378#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002379 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002380 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2381 err_code |= ERR_WARN;
2382
2383 if (*(args[1]) == 0) {
2384 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2385 err_code |= ERR_ALERT | ERR_FATAL;
2386 goto out;
2387 }
2388 curproxy->maxconn = atol(args[1]);
2389 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2390 goto out;
2391 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002392 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002393 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2394 err_code |= ERR_WARN;
2395
2396 if (*(args[1]) == 0) {
2397 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2398 err_code |= ERR_ALERT | ERR_FATAL;
2399 goto out;
2400 }
2401 curproxy->backlog = atol(args[1]);
2402 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2403 goto out;
2404 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002405 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002406 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2407 err_code |= ERR_WARN;
2408
2409 if (*(args[1]) == 0) {
2410 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2411 err_code |= ERR_ALERT | ERR_FATAL;
2412 goto out;
2413 }
2414 curproxy->fullconn = atol(args[1]);
2415 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2416 goto out;
2417 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002418 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002419 if (*(args[1]) == 0) {
2420 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2421 err_code |= ERR_ALERT | ERR_FATAL;
2422 goto out;
2423 }
2424 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002425 if (err == PARSE_TIME_OVER) {
2426 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2427 file, linenum, args[1]);
2428 err_code |= ERR_ALERT | ERR_FATAL;
2429 goto out;
2430 }
2431 else if (err == PARSE_TIME_UNDER) {
2432 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2433 file, linenum, args[1]);
2434 err_code |= ERR_ALERT | ERR_FATAL;
2435 goto out;
2436 }
2437 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002438 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2439 file, linenum, *err);
2440 err_code |= ERR_ALERT | ERR_FATAL;
2441 goto out;
2442 }
2443 curproxy->grace = val;
2444 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2445 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002446
2447 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2448 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002449 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002450 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002451 struct sockaddr_storage *sk;
2452 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002453
Willy Tarreau5d095c22021-02-12 10:15:59 +01002454 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002455 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2456 err_code |= ERR_ALERT | ERR_FATAL;
2457 goto out;
2458 }
2459 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2460 err_code |= ERR_WARN;
2461
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002462 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2463 &errmsg, NULL, NULL,
2464 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 +01002465 if (!sk) {
2466 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2467 err_code |= ERR_ALERT | ERR_FATAL;
2468 goto out;
2469 }
2470
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002471 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2472 goto out;
2473
2474 curproxy->dispatch_addr = *sk;
2475 curproxy->options |= PR_O_DISPATCH;
2476 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002477 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002478 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2479 err_code |= ERR_WARN;
2480
2481 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2482 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2483 err_code |= ERR_ALERT | ERR_FATAL;
2484 goto out;
2485 }
2486 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002487 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002488 /**
2489 * The syntax for hash-type config element is
2490 * hash-type {map-based|consistent} [[<algo>] avalanche]
2491 *
2492 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2493 */
2494 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2495
2496 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2497 err_code |= ERR_WARN;
2498
2499 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2500 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2501 }
2502 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2503 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2504 }
2505 else if (strcmp(args[1], "avalanche") == 0) {
2506 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]);
2507 err_code |= ERR_ALERT | ERR_FATAL;
2508 goto out;
2509 }
2510 else {
2511 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2512 err_code |= ERR_ALERT | ERR_FATAL;
2513 goto out;
2514 }
2515
2516 /* set the hash function to use */
2517 if (!*args[2]) {
2518 /* the default algo is sdbm */
2519 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2520
2521 /* if consistent with no argument, then avalanche modifier is also applied */
2522 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2523 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2524 } else {
2525 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002526 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002527 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2528 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002529 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002530 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2531 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002532 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002533 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2534 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002535 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002536 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2537 }
2538 else {
2539 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2540 err_code |= ERR_ALERT | ERR_FATAL;
2541 goto out;
2542 }
2543
2544 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002545 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002546 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2547 }
2548 else if (*args[3]) {
2549 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2550 err_code |= ERR_ALERT | ERR_FATAL;
2551 goto out;
2552 }
2553 }
2554 }
2555 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2556 if (*(args[1]) == 0) {
2557 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2558 err_code |= ERR_ALERT | ERR_FATAL;
2559 goto out;
2560 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002561 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2562 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002563 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2564 err_code |= ERR_ALERT | ERR_FATAL;
2565 goto out;
2566 }
2567 }
2568 else if (strcmp(args[0], "unique-id-format") == 0) {
2569 if (!*(args[1])) {
2570 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2571 err_code |= ERR_ALERT | ERR_FATAL;
2572 goto out;
2573 }
2574 if (*(args[2])) {
2575 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2576 err_code |= ERR_ALERT | ERR_FATAL;
2577 goto out;
2578 }
2579 free(curproxy->conf.uniqueid_format_string);
2580 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2581
2582 free(curproxy->conf.uif_file);
2583 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2584 curproxy->conf.uif_line = curproxy->conf.args.line;
2585 }
2586
2587 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002588 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002589 if (!*(args[1])) {
2590 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2591 err_code |= ERR_ALERT | ERR_FATAL;
2592 goto out;
2593 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002594 copy = strdup(args[1]);
2595 if (copy == NULL) {
2596 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2597 err_code |= ERR_ALERT | ERR_FATAL;
2598 goto out;
2599 }
2600
2601 istfree(&curproxy->header_unique_id);
2602 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002603 }
2604
2605 else if (strcmp(args[0], "log-format") == 0) {
2606 if (!*(args[1])) {
2607 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2608 err_code |= ERR_ALERT | ERR_FATAL;
2609 goto out;
2610 }
2611 if (*(args[2])) {
2612 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2613 err_code |= ERR_ALERT | ERR_FATAL;
2614 goto out;
2615 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002616 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002617 char *oldlogformat = "log-format";
2618
2619 if (curproxy->conf.logformat_string == default_http_log_format)
2620 oldlogformat = "option httplog";
2621 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2622 oldlogformat = "option tcplog";
2623 else if (curproxy->conf.logformat_string == clf_http_log_format)
2624 oldlogformat = "option httplog clf";
2625 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2626 file, linenum, oldlogformat);
2627 }
2628 if (curproxy->conf.logformat_string != default_http_log_format &&
2629 curproxy->conf.logformat_string != default_tcp_log_format &&
2630 curproxy->conf.logformat_string != clf_http_log_format)
2631 free(curproxy->conf.logformat_string);
2632 curproxy->conf.logformat_string = strdup(args[1]);
2633
2634 free(curproxy->conf.lfs_file);
2635 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2636 curproxy->conf.lfs_line = curproxy->conf.args.line;
2637
2638 /* get a chance to improve log-format error reporting by
2639 * reporting the correct line-number when possible.
2640 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002641 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002642 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2643 file, linenum, curproxy->id);
2644 err_code |= ERR_WARN;
2645 }
2646 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002647 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002648 if (!*(args[1])) {
2649 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2650 err_code |= ERR_ALERT | ERR_FATAL;
2651 goto out;
2652 }
2653 if (*(args[2])) {
2654 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2655 err_code |= ERR_ALERT | ERR_FATAL;
2656 goto out;
2657 }
2658
2659 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2660 free(curproxy->conf.logformat_sd_string);
2661 curproxy->conf.logformat_sd_string = strdup(args[1]);
2662
2663 free(curproxy->conf.lfsd_file);
2664 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2665 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2666
2667 /* get a chance to improve log-format-sd error reporting by
2668 * reporting the correct line-number when possible.
2669 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002670 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002671 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2672 file, linenum, curproxy->id);
2673 err_code |= ERR_WARN;
2674 }
2675 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002676 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002677 if (*(args[1]) == 0) {
2678 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2679 err_code |= ERR_ALERT | ERR_FATAL;
2680 goto out;
2681 }
2682 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002683 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2684 if (b_orig(&curproxy->log_tag) == NULL) {
2685 chunk_destroy(&curproxy->log_tag);
2686 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2687 err_code |= ERR_ALERT | ERR_FATAL;
2688 goto out;
2689 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002690 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002691 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002692 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2693 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2694 err_code |= ERR_ALERT | ERR_FATAL;
2695 goto out;
2696 }
2697 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002698 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002699 int cur_arg;
2700 int port1, port2;
2701 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002702
2703 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2704 err_code |= ERR_WARN;
2705
2706 if (!*args[1]) {
2707 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2708 file, linenum, "source", "usesrc", "interface");
2709 err_code |= ERR_ALERT | ERR_FATAL;
2710 goto out;
2711 }
2712
Christopher Faulet31930372019-07-15 10:16:58 +02002713 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002714 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002715 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002716 curproxy->conn_src.iface_len = 0;
2717
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002718 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2719 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002720 if (!sk) {
2721 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2722 file, linenum, args[0], args[1], errmsg);
2723 err_code |= ERR_ALERT | ERR_FATAL;
2724 goto out;
2725 }
2726
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002727 curproxy->conn_src.source_addr = *sk;
2728 curproxy->conn_src.opts |= CO_SRC_BIND;
2729
2730 cur_arg = 2;
2731 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002732 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002733#if defined(CONFIG_HAP_TRANSPARENT)
2734 if (!*args[cur_arg + 1]) {
2735 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2736 file, linenum, "usesrc");
2737 err_code |= ERR_ALERT | ERR_FATAL;
2738 goto out;
2739 }
2740
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002741 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002742 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2743 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002744 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002745 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2746 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2747 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2748 char *name, *end;
2749
2750 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002751 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002752 name++;
2753
2754 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002755 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002756 end++;
2757
2758 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2759 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002760 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002761 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2762 curproxy->conn_src.bind_hdr_len = end - name;
2763 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2764 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2765 curproxy->conn_src.bind_hdr_occ = -1;
2766
2767 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002768 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002769 end++;
2770 if (*end == ',') {
2771 end++;
2772 name = end;
2773 if (*end == '-')
2774 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002775 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002776 end++;
2777 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2778 }
2779
2780 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2781 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2782 " occurrences values smaller than %d.\n",
2783 file, linenum, MAX_HDR_HISTORY);
2784 err_code |= ERR_ALERT | ERR_FATAL;
2785 goto out;
2786 }
2787 } else {
2788 struct sockaddr_storage *sk;
2789
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002790 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2791 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002792 if (!sk) {
2793 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2794 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2795 err_code |= ERR_ALERT | ERR_FATAL;
2796 goto out;
2797 }
2798
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002799 curproxy->conn_src.tproxy_addr = *sk;
2800 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2801 }
2802 global.last_checks |= LSTCHK_NETADM;
2803#else /* no TPROXY support */
2804 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2805 file, linenum, "usesrc");
2806 err_code |= ERR_ALERT | ERR_FATAL;
2807 goto out;
2808#endif
2809 cur_arg += 2;
2810 continue;
2811 }
2812
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002813 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002814#ifdef SO_BINDTODEVICE
2815 if (!*args[cur_arg + 1]) {
2816 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2817 file, linenum, args[0]);
2818 err_code |= ERR_ALERT | ERR_FATAL;
2819 goto out;
2820 }
2821 free(curproxy->conn_src.iface_name);
2822 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2823 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2824 global.last_checks |= LSTCHK_NETADM;
2825#else
2826 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2827 file, linenum, args[0], args[cur_arg]);
2828 err_code |= ERR_ALERT | ERR_FATAL;
2829 goto out;
2830#endif
2831 cur_arg += 2;
2832 continue;
2833 }
2834 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2835 file, linenum, args[0], "interface", "usesrc");
2836 err_code |= ERR_ALERT | ERR_FATAL;
2837 goto out;
2838 }
2839 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002840 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002841 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2842 file, linenum, "usesrc", "source");
2843 err_code |= ERR_ALERT | ERR_FATAL;
2844 goto out;
2845 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002846 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 +02002847 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002848 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002849 file, linenum, args[0]);
2850 err_code |= ERR_ALERT | ERR_FATAL;
2851 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002852 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002853 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002854 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2855 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2856 err_code |= ERR_ALERT | ERR_FATAL;
2857 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002858 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002859 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002860 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2861 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2862 err_code |= ERR_ALERT | ERR_FATAL;
2863 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002864 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002865 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002866 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2867 err_code |= ERR_ALERT | ERR_FATAL;
2868 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002869 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002870 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002871 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2872 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2873 err_code |= ERR_ALERT | ERR_FATAL;
2874 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002875 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002876 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002877 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2878 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2879 err_code |= ERR_ALERT | ERR_FATAL;
2880 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002881 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002882 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002883 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2884 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2885 err_code |= ERR_ALERT | ERR_FATAL;
2886 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002887 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002888 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002889 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2890 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2891 err_code |= ERR_ALERT | ERR_FATAL;
2892 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002893 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002894 else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002895 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2896 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2897 err_code |= ERR_ALERT | ERR_FATAL;
2898 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002899 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002900 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002901 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2902 err_code |= ERR_ALERT | ERR_FATAL;
2903 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002904 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002905 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 +02002906 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2907 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2908 err_code |= ERR_ALERT | ERR_FATAL;
2909 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002910 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002911 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 +02002912 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2913 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2914 err_code |= ERR_ALERT | ERR_FATAL;
2915 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002916 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002917 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002918 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2919 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2920 err_code |= ERR_ALERT | ERR_FATAL;
2921 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002922 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002923 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 +02002924 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2925 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2926 err_code |= ERR_ALERT | ERR_FATAL;
2927 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002928 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002929 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002930 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2931 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2932 err_code |= ERR_ALERT | ERR_FATAL;
2933 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002934 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002935 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002936 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2937 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2938 err_code |= ERR_ALERT | ERR_FATAL;
2939 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002940 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002941 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302942 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002943 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2944 err_code |= ERR_ALERT | ERR_FATAL;
2945 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002946 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002947 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002948 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2949 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2950 err_code |= ERR_ALERT | ERR_FATAL;
2951 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002952 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002953 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002954 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2955 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2956 err_code |= ERR_ALERT | ERR_FATAL;
2957 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002958 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002959 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002960 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2961 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2962 err_code |= ERR_ALERT | ERR_FATAL;
2963 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002964 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002965 else {
2966 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002967 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002968 int index;
2969
2970 list_for_each_entry(kwl, &cfg_keywords.list, list) {
2971 for (index = 0; kwl->kw[index].kw != NULL; index++) {
2972 if (kwl->kw[index].section != CFG_LISTEN)
2973 continue;
2974 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
2975 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01002976 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002977 if (rc < 0) {
2978 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2979 err_code |= ERR_ALERT | ERR_FATAL;
2980 goto out;
2981 }
2982 else if (rc > 0) {
2983 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2984 err_code |= ERR_WARN;
2985 goto out;
2986 }
2987 goto out;
2988 }
2989 }
2990 }
2991
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002992 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
2993 if (best)
2994 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
2995 else
2996 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002997 err_code |= ERR_ALERT | ERR_FATAL;
2998 goto out;
2999 }
3000 out:
3001 free(errmsg);
3002 return err_code;
3003}