blob: b2c81da611c7e111a8cef0862425dc747c443bf9 [file] [log] [blame]
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13
Willy Tarreaudcc048a2020-06-04 19:11:43 +020014#include <haproxy/acl.h>
Eric Salama7cea6062020-10-02 11:58:19 +020015#include <haproxy/buf.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020016#include <haproxy/capture-t.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020017#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020018#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020019#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020020#include <haproxy/connection.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020021#include <haproxy/extcheck.h>
Willy Tarreau87735332020-06-04 09:08:41 +020022#include <haproxy/http_htx.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020023#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020024#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020025#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020026#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020027#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020028#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020029#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020030#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020031#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020032#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/tcpcheck.h>
34#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010035
Willy Tarreauc0ff6792021-03-12 09:14:19 +010036/* some keywords that are still being parsed using strcmp() and are not
37 * registered anywhere. They are used as suggestions for mistyped words.
38 */
39static const char *common_kw_list[] = {
40 "listen", "frontend", "backend", "defaults", "server",
41 "default-server", "server-template", "bind", "monitor-net",
42 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
43 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
44 "persist", "appsession", "load-server-state-from-file",
45 "server-state-file-name", "max-session-srv-conns", "capture",
46 "retries", "http-request", "http-response", "http-after-response",
47 "http-send-name-header", "block", "redirect", "use_backend",
48 "use-server", "force-persist", "ignore-persist", "force-persist",
49 "stick-table", "stick", "stats", "option", "default_backend",
50 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
51 "fullconn", "grace", "dispatch", "balance", "hash-type",
52 "hash-balance-factor", "unique-id-format", "unique-id-header",
53 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
54 NULL /* must be last */
55};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010056
Willy Tarreau31a3cea2021-03-15 11:11:55 +010057static const char *common_options[] = {
58 "httpclose", "forceclose", "http-server-close", "http-keep-alive",
59 "http-tunnel", "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
60 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
61 "mysql-check", "ldap-check", "spop-check", "tcp-check",
62 "external-check", "forwardfor", "original-to",
63 NULL /* must be last */
64};
65
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010066/* Report a warning if a rule is placed after a 'tcp-request session' rule.
67 * Return 1 if the warning has been emitted, otherwise 0.
68 */
69int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
70{
71 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
72 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
73 file, line, arg);
74 return 1;
75 }
76 return 0;
77}
78
79/* Report a warning if a rule is placed after a 'tcp-request content' rule.
80 * Return 1 if the warning has been emitted, otherwise 0.
81 */
82int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
83{
84 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
85 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
86 file, line, arg);
87 return 1;
88 }
89 return 0;
90}
91
92/* Report a warning if a rule is placed after a 'monitor fail' rule.
93 * Return 1 if the warning has been emitted, otherwise 0.
94 */
95int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
96{
97 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
98 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
99 file, line, arg);
100 return 1;
101 }
102 return 0;
103}
104
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100105/* Report a warning if a rule is placed after an 'http_request' rule.
106 * Return 1 if the warning has been emitted, otherwise 0.
107 */
108int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
109{
110 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
111 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
112 file, line, arg);
113 return 1;
114 }
115 return 0;
116}
117
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100118/* Report a warning if a rule is placed after a redirect rule.
119 * Return 1 if the warning has been emitted, otherwise 0.
120 */
121int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
122{
123 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
124 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
125 file, line, arg);
126 return 1;
127 }
128 return 0;
129}
130
131/* Report a warning if a rule is placed after a 'use_backend' rule.
132 * Return 1 if the warning has been emitted, otherwise 0.
133 */
134int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
135{
136 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
137 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
138 file, line, arg);
139 return 1;
140 }
141 return 0;
142}
143
144/* Report a warning if a rule is placed after a 'use-server' rule.
145 * Return 1 if the warning has been emitted, otherwise 0.
146 */
147int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
148{
149 if (!LIST_ISEMPTY(&proxy->server_rules)) {
150 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
151 file, line, arg);
152 return 1;
153 }
154 return 0;
155}
156
157/* report a warning if a redirect rule is dangerously placed */
158int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
159{
160 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
161 warnif_rule_after_use_server(proxy, file, line, arg);
162}
163
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100164/* report a warning if an http-request rule is dangerously placed */
165int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
166{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200167 return warnif_rule_after_redirect(proxy, file, line, arg) ||
168 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100169}
170
171/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200172int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100173{
174 return warnif_rule_after_http_req(proxy, file, line, arg) ||
175 warnif_misplaced_http_req(proxy, file, line, arg);
176}
177
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100178/* report a warning if a "tcp request content" rule is dangerously placed */
179int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
180{
181 return warnif_rule_after_monitor(proxy, file, line, arg) ||
182 warnif_misplaced_monitor(proxy, file, line, arg);
183}
184
185/* report a warning if a "tcp request session" rule is dangerously placed */
186int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
187{
188 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
189 warnif_misplaced_tcp_cont(proxy, file, line, arg);
190}
191
192/* report a warning if a "tcp request connection" rule is dangerously placed */
193int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
194{
195 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
196 warnif_misplaced_tcp_sess(proxy, file, line, arg);
197}
198
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100199int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
200{
201 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100202 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100203 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100204 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100205 int rc;
206 unsigned val;
207 int err_code = 0;
208 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100209 char *errmsg = NULL;
210 struct bind_conf *bind_conf;
211
Willy Tarreaue90904d2021-02-12 14:08:31 +0100212 if (!last_defproxy) {
213 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100214 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
215 proxy_preset_defaults(last_defproxy);
216
Willy Tarreaue90904d2021-02-12 14:08:31 +0100217 curr_defproxy = last_defproxy;
218 if (!last_defproxy) {
219 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
220 err_code |= ERR_ALERT | ERR_ABORT;
221 goto out;
222 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100223 }
224
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100225 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100226 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100228 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100229 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100230 rc = PR_CAP_BE;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100231 else if (strcmp(args[0], "defaults") == 0) {
232 /* "defaults" must first delete the last no-name defaults if any */
233 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
234 curr_defproxy = NULL;
235 rc = PR_CAP_DEF | PR_CAP_LISTEN;
236 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100237 else
238 rc = PR_CAP_NONE;
239
Willy Tarreaue90904d2021-02-12 14:08:31 +0100240 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100241 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100242 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100243 file, linenum, args[0]);
244 err_code |= ERR_ALERT | ERR_ABORT;
245 goto out;
246 }
247
248 err = invalid_char(args[1]);
249 if (err) {
250 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
251 file, linenum, *err, args[0], args[1]);
252 err_code |= ERR_ALERT | ERR_FATAL;
253 }
254
255 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
256 if (curproxy) {
257 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
258 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
259 curproxy->id, curproxy->conf.file, curproxy->conf.line);
260 err_code |= ERR_ALERT | ERR_FATAL;
261 }
262
Emeric Brunb0c331f2020-10-07 17:05:59 +0200263 curproxy = log_forward_by_name(args[1]);
264 if (curproxy) {
265 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
266 file, linenum, proxy_cap_str(rc), args[1],
267 curproxy->id, curproxy->conf.file, curproxy->conf.line);
268 err_code |= ERR_ALERT | ERR_FATAL;
269 }
270
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100271 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
272 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100273 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100274 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
275 goto out;
276 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100277 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100278
Willy Tarreaue90904d2021-02-12 14:08:31 +0100279 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100280 const char *name = args[1];
281 int arg = 2;
282
283 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
284 // also support "defaults from blah" (no name then)
285 arg = 1;
286 name = "";
287 }
288
289 /* only regular proxies inherit from the previous defaults section */
290 if (!(rc & PR_CAP_DEF))
291 curr_defproxy = last_defproxy;
292
293 if (strcmp(args[arg], "from") == 0) {
294 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
295
296 if (!curr_defproxy) {
297 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
298 err_code |= ERR_ALERT | ERR_ABORT;
299 goto out;
300 }
301
302 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
303 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
304
305 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
306 file, linenum, args[arg+1], proxy_cap_str(rc), name,
307 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
308 err_code |= ERR_ALERT | ERR_FATAL;
309 }
310
311 err = invalid_char(args[arg+1]);
312 if (err) {
313 ha_alert("parsing [%s:%d] : character '%c' is not permitted in defaults section name '%s' when designated by its name (section found at %s:%d).\n",
314 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
315 err_code |= ERR_ALERT | ERR_FATAL;
316 }
317 }
318
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100319 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100320 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100321 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100322 goto out;
323 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100324
Willy Tarreaue90904d2021-02-12 14:08:31 +0100325 if (rc & PR_CAP_DEF) {
326 /* last and current proxies must be updated to this one */
327 curr_defproxy = last_defproxy = curproxy;
328 } else {
329 /* regular proxies are in a list */
330 curproxy->next = proxies_list;
331 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100332 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100333 goto out;
334 }
335 else if (curproxy == NULL) {
336 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
337 err_code |= ERR_ALERT | ERR_FATAL;
338 goto out;
339 }
340
341 /* update the current file and line being parsed */
342 curproxy->conf.args.file = curproxy->conf.file;
343 curproxy->conf.args.line = linenum;
344
345 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100346 if ((strcmp(args[0], "server") == 0)) {
347 err_code |= parse_server(file, linenum, args,
348 curproxy, curr_defproxy,
349 SRV_PARSE_PARSE_ADDR);
350
351 if (err_code & ERR_FATAL)
352 goto out;
353 }
354 else if (strcmp(args[0], "default-server") == 0) {
355 err_code |= parse_server(file, linenum, args,
356 curproxy, curr_defproxy,
357 SRV_PARSE_DEFAULT_SERVER);
358
359 if (err_code & ERR_FATAL)
360 goto out;
361 }
362 else if (strcmp(args[0], "server-template") == 0) {
363 err_code |= parse_server(file, linenum, args,
364 curproxy, curr_defproxy,
365 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
366
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100367 if (err_code & ERR_FATAL)
368 goto out;
369 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100370 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100371 struct listener *l;
372 int cur_arg;
373
Willy Tarreau5d095c22021-02-12 10:15:59 +0100374 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100375 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
376 err_code |= ERR_ALERT | ERR_FATAL;
377 goto out;
378 }
379 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
380 err_code |= ERR_WARN;
381
382 if (!*(args[1])) {
383 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
384 file, linenum, args[0]);
385 err_code |= ERR_ALERT | ERR_FATAL;
386 goto out;
387 }
388
389 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200390 if (!bind_conf)
391 goto alloc_error;
392
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100393 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200394 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
395 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
396 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100397
398 /* NOTE: the following line might create several listeners if there
399 * are comma-separated IPs or port ranges. So all further processing
400 * will have to be applied to all listeners created after last_listen.
401 */
402 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
403 if (errmsg && *errmsg) {
404 indent_msg(&errmsg, 2);
405 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
406 }
407 else
408 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
409 file, linenum, args[0], args[1]);
410 err_code |= ERR_ALERT | ERR_FATAL;
411 goto out;
412 }
413
414 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
415 /* Set default global rights and owner for unix bind */
416 global.maxsock++;
417 }
418
419 cur_arg = 2;
420 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100421 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100422 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100423
424 kw = bind_find_kw(args[cur_arg]);
425 if (kw) {
426 char *err = NULL;
427 int code;
428
429 if (!kw->parse) {
430 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
431 file, linenum, args[0], args[1], args[cur_arg]);
432 cur_arg += 1 + kw->skip ;
433 err_code |= ERR_ALERT | ERR_FATAL;
434 goto out;
435 }
436
437 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
438 err_code |= code;
439
440 if (code) {
441 if (err && *err) {
442 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200443 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
444 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
445 else
446 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100447 }
448 else
449 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
450 file, linenum, args[0], args[1], args[cur_arg]);
451 if (code & ERR_FATAL) {
452 free(err);
453 cur_arg += 1 + kw->skip;
454 goto out;
455 }
456 }
457 free(err);
458 cur_arg += 1 + kw->skip;
459 continue;
460 }
461
Willy Tarreau433b05f2021-03-12 10:14:07 +0100462 best = bind_find_best_kw(args[cur_arg]);
463 if (best)
464 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
465 file, linenum, args[0], args[1], args[cur_arg], best);
466 else
467 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
468 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100469
470 err_code |= ERR_ALERT | ERR_FATAL;
471 goto out;
472 }
473 goto out;
474 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100475 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200476 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]);
477 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100478 goto out;
479 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100480 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100481 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
482 err_code |= ERR_WARN;
483
484 if (alertif_too_many_args(1, file, linenum, args, &err_code))
485 goto out;
486
487 if (!*args[1]) {
488 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
489 file, linenum, args[0]);
490 err_code |= ERR_ALERT | ERR_FATAL;
491 goto out;
492 }
493
494 free(curproxy->monitor_uri);
495 curproxy->monitor_uri_len = strlen(args[1]);
496 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200497 if (!curproxy->monitor_uri)
498 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100499 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
500 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
501
502 goto out;
503 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100504 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100505 if (alertif_too_many_args(1, file, linenum, args, &err_code))
506 goto out;
507
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100508 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
509 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
510 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200511 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
512 err_code |= ERR_ALERT | ERR_FATAL;
513 goto out;
514 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100515 else {
516 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
517 err_code |= ERR_ALERT | ERR_FATAL;
518 goto out;
519 }
520 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100521 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100522 struct eb32_node *node;
523
Willy Tarreau5d095c22021-02-12 10:15:59 +0100524 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100525 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
526 file, linenum, args[0]);
527 err_code |= ERR_ALERT | ERR_FATAL;
528 goto out;
529 }
530
531 if (alertif_too_many_args(1, file, linenum, args, &err_code))
532 goto out;
533
534 if (!*args[1]) {
535 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
536 file, linenum, args[0]);
537 err_code |= ERR_ALERT | ERR_FATAL;
538 goto out;
539 }
540
541 curproxy->uuid = atol(args[1]);
542 curproxy->conf.id.key = curproxy->uuid;
543 curproxy->options |= PR_O_FORCED_ID;
544
545 if (curproxy->uuid <= 0) {
546 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
547 file, linenum);
548 err_code |= ERR_ALERT | ERR_FATAL;
549 goto out;
550 }
551
552 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
553 if (node) {
554 struct proxy *target = container_of(node, struct proxy, conf.id);
555 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
556 file, linenum, proxy_type_str(curproxy), curproxy->id,
557 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
558 err_code |= ERR_ALERT | ERR_FATAL;
559 goto out;
560 }
561 eb32_insert(&used_proxy_id, &curproxy->conf.id);
562 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100563 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100564 int i, len=0;
565 char *d;
566
Willy Tarreau5d095c22021-02-12 10:15:59 +0100567 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100568 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
569 file, linenum, args[0]);
570 err_code |= ERR_ALERT | ERR_FATAL;
571 goto out;
572 }
573
574 if (!*args[1]) {
575 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
576 file, linenum, args[0]);
577 return -1;
578 }
579
580 for (i = 1; *args[i]; i++)
581 len += strlen(args[i]) + 1;
582
583 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200584 if (!d)
585 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100586 curproxy->desc = d;
587
588 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
589 for (i = 2; *args[i]; i++)
590 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
591
592 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100593 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100594 if (alertif_too_many_args(0, file, linenum, args, &err_code))
595 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200596 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100597 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100598 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100599 if (alertif_too_many_args(0, file, linenum, args, &err_code))
600 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200601 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100602 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100603 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100604 int cur_arg = 1;
605 unsigned long set = 0;
606
607 while (*args[cur_arg]) {
608 if (strcmp(args[cur_arg], "all") == 0) {
609 set = 0;
610 break;
611 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100612 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100613 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
614 err_code |= ERR_ALERT | ERR_FATAL;
615 goto out;
616 }
617 cur_arg++;
618 }
619 curproxy->bind_proc = set;
620 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100621 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100622 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100623 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
624 err_code |= ERR_ALERT | ERR_FATAL;
625 goto out;
626 }
627
628 err = invalid_char(args[1]);
629 if (err) {
630 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
631 file, linenum, *err, args[1]);
632 err_code |= ERR_ALERT | ERR_FATAL;
633 goto out;
634 }
635
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100636 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100637 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100638 "logical disjunction within a condition.\n",
639 file, linenum, args[1]);
640 err_code |= ERR_ALERT | ERR_FATAL;
641 goto out;
642 }
643
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100644 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
645 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
646 file, linenum, args[1], errmsg);
647 err_code |= ERR_ALERT | ERR_FATAL;
648 goto out;
649 }
650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100651 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100652
653 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
654 err_code |= ERR_WARN;
655
656 if (*(args[1]) == 0) {
657 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
658 file, linenum, args[0]);
659 err_code |= ERR_ALERT | ERR_FATAL;
660 goto out;
661 }
662 free(curproxy->dyncookie_key);
663 curproxy->dyncookie_key = strdup(args[1]);
664 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100665 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100666 int cur_arg;
667
668 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
669 err_code |= ERR_WARN;
670
671 if (*(args[1]) == 0) {
672 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
673 file, linenum, args[0]);
674 err_code |= ERR_ALERT | ERR_FATAL;
675 goto out;
676 }
677
678 curproxy->ck_opts = 0;
679 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100680 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100681 free(curproxy->cookie_name);
682 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200683 if (!curproxy->cookie_name)
684 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100685 curproxy->cookie_len = strlen(curproxy->cookie_name);
686
687 cur_arg = 2;
688 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100689 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100690 curproxy->ck_opts |= PR_CK_RW;
691 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100692 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100693 curproxy->ck_opts |= PR_CK_IND;
694 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100695 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100696 curproxy->ck_opts |= PR_CK_INS;
697 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100698 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100699 curproxy->ck_opts |= PR_CK_NOC;
700 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100701 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100702 curproxy->ck_opts |= PR_CK_POST;
703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100704 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100705 curproxy->ck_opts |= PR_CK_PSV;
706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100708 curproxy->ck_opts |= PR_CK_PFX;
709 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100710 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100711 curproxy->ck_opts |= PR_CK_HTTPONLY;
712 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100713 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100714 curproxy->ck_opts |= PR_CK_SECURE;
715 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100716 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100717 if (!*args[cur_arg + 1]) {
718 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
719 file, linenum, args[cur_arg]);
720 err_code |= ERR_ALERT | ERR_FATAL;
721 goto out;
722 }
723
Joao Moraise1583752019-10-30 21:04:00 -0300724 if (!strchr(args[cur_arg + 1], '.')) {
725 /* rfc6265, 5.2.3 The Domain Attribute */
726 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
727 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100728 file, linenum, args[cur_arg + 1]);
729 err_code |= ERR_WARN;
730 }
731
732 err = invalid_domainchar(args[cur_arg + 1]);
733 if (err) {
734 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
735 file, linenum, *err, args[cur_arg + 1]);
736 err_code |= ERR_ALERT | ERR_FATAL;
737 goto out;
738 }
739
740 if (!curproxy->cookie_domain) {
741 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
742 } else {
743 /* one domain was already specified, add another one by
744 * building the string which will be returned along with
745 * the cookie.
746 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200747 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
748 }
749
Christopher Fauletb15625a2021-04-12 21:31:45 +0200750 if (!curproxy->cookie_domain)
751 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100752 cur_arg++;
753 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100754 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100755 unsigned int maxidle;
756 const char *res;
757
758 if (!*args[cur_arg + 1]) {
759 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
760 file, linenum, args[cur_arg]);
761 err_code |= ERR_ALERT | ERR_FATAL;
762 goto out;
763 }
764
765 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200766 if (res == PARSE_TIME_OVER) {
767 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\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 == PARSE_TIME_UNDER) {
773 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
774 file, linenum, args[cur_arg+1], args[cur_arg]);
775 err_code |= ERR_ALERT | ERR_FATAL;
776 goto out;
777 }
778 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100779 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
780 file, linenum, *res, args[cur_arg]);
781 err_code |= ERR_ALERT | ERR_FATAL;
782 goto out;
783 }
784 curproxy->cookie_maxidle = maxidle;
785 cur_arg++;
786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100788 unsigned int maxlife;
789 const char *res;
790
791 if (!*args[cur_arg + 1]) {
792 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
793 file, linenum, args[cur_arg]);
794 err_code |= ERR_ALERT | ERR_FATAL;
795 goto out;
796 }
797
Willy Tarreau9faebe32019-06-07 19:00:37 +0200798
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100799 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200800 if (res == PARSE_TIME_OVER) {
801 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\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 == PARSE_TIME_UNDER) {
807 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
808 file, linenum, args[cur_arg+1], args[cur_arg]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100813 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
814 file, linenum, *res, args[cur_arg]);
815 err_code |= ERR_ALERT | ERR_FATAL;
816 goto out;
817 }
818 curproxy->cookie_maxlife = maxlife;
819 cur_arg++;
820 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100821 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100822
823 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
824 err_code |= ERR_WARN;
825 curproxy->ck_opts |= PR_CK_DYNAMIC;
826 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100827 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100828 char *val;
829 if (!*args[cur_arg + 1]) {
830 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
831 file, linenum, args[cur_arg]);
832 err_code |= ERR_ALERT | ERR_FATAL;
833 goto out;
834 }
835 val = args[cur_arg + 1];
836 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100837 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100838 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
839 file, linenum, *val);
840 err_code |= ERR_ALERT | ERR_FATAL;
841 goto out;
842 }
843 val++;
844 }
845 /* don't add ';' for the first attribute */
846 if (!curproxy->cookie_attrs)
847 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
848 else
849 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200850
Christopher Fauletb15625a2021-04-12 21:31:45 +0200851 if (!curproxy->cookie_attrs)
852 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100853 cur_arg++;
854 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100855
856 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100857 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 +0100858 file, linenum, args[0]);
859 err_code |= ERR_ALERT | ERR_FATAL;
860 goto out;
861 }
862 cur_arg++;
863 }
864 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
865 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
866 file, linenum);
867 err_code |= ERR_ALERT | ERR_FATAL;
868 }
869
870 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
871 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
872 file, linenum);
873 err_code |= ERR_ALERT | ERR_FATAL;
874 }
875
876 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
877 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
878 file, linenum);
879 err_code |= ERR_ALERT | ERR_FATAL;
880 }
881 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100882 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100883 if (*(args[1]) == 0) {
884 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
885 file, linenum, args[0]);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto out;
888 }
889
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100890 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100891 if (*(args[1]) == 0) {
892 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
893 file, linenum, args[1]);
894 err_code |= ERR_ALERT | ERR_FATAL;
895 goto out;
896 }
897 free(curproxy->email_alert.from);
898 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200899 if (!curproxy->email_alert.from)
900 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100901 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100902 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100903 if (*(args[1]) == 0) {
904 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
905 file, linenum, args[1]);
906 err_code |= ERR_ALERT | ERR_FATAL;
907 goto out;
908 }
909 free(curproxy->email_alert.mailers.name);
910 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200911 if (!curproxy->email_alert.mailers.name)
912 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100913 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100914 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100915 if (*(args[1]) == 0) {
916 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
917 file, linenum, args[1]);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921 free(curproxy->email_alert.myhostname);
922 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200923 if (!curproxy->email_alert.myhostname)
924 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100926 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100927 curproxy->email_alert.level = get_log_level(args[2]);
928 if (curproxy->email_alert.level < 0) {
929 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
930 file, linenum, args[1], args[2]);
931 err_code |= ERR_ALERT | ERR_FATAL;
932 goto out;
933 }
934 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100935 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100936 if (*(args[1]) == 0) {
937 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
938 file, linenum, args[1]);
939 err_code |= ERR_ALERT | ERR_FATAL;
940 goto out;
941 }
942 free(curproxy->email_alert.to);
943 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200944 if (!curproxy->email_alert.to)
945 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100946 }
947 else {
948 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
949 file, linenum, args[1]);
950 err_code |= ERR_ALERT | ERR_FATAL;
951 goto out;
952 }
953 /* Indicate that the email_alert is at least partially configured */
954 curproxy->email_alert.set = 1;
955 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100956 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100957 if (*(args[1]) == 0) {
958 ha_alert("parsing [%s:%d] : missing persist method.\n",
959 file, linenum);
960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
962 }
963
964 if (!strncmp(args[1], "rdp-cookie", 10)) {
965 curproxy->options2 |= PR_O2_RDPC_PRST;
966
967 if (*(args[1] + 10) == '(') { /* cookie name */
968 const char *beg, *end;
969
970 beg = args[1] + 11;
971 end = strchr(beg, ')');
972
973 if (alertif_too_many_args(1, file, linenum, args, &err_code))
974 goto out;
975
976 if (!end || end == beg) {
977 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
978 file, linenum);
979 err_code |= ERR_ALERT | ERR_FATAL;
980 goto out;
981 }
982
983 free(curproxy->rdp_cookie_name);
984 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200985 if (!curproxy->rdp_cookie_name)
986 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100987 curproxy->rdp_cookie_len = end-beg;
988 }
989 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
990 free(curproxy->rdp_cookie_name);
991 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +0200992 if (!curproxy->rdp_cookie_name)
993 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100994 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
995 }
996 else { /* syntax */
997 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
998 file, linenum);
999 err_code |= ERR_ALERT | ERR_FATAL;
1000 goto out;
1001 }
1002 }
1003 else {
1004 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1005 file, linenum);
1006 err_code |= ERR_ALERT | ERR_FATAL;
1007 goto out;
1008 }
1009 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001010 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001011 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 +01001012 err_code |= ERR_ALERT | ERR_FATAL;
1013 goto out;
1014 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001015 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001016 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1017 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001018 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001019 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1020 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001021 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 +01001022 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1023 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001024 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001025 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1026 }
1027 else {
1028 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1029 file, linenum, args[0], args[1]);
1030 err_code |= ERR_ALERT | ERR_FATAL;
1031 goto out;
1032 }
1033 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001034 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001035 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1036 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001037 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001038 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001039
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001040 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001041
1042 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001043 curproxy->server_state_file_name = strdup(curproxy->id);
1044 else
1045 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001046
Christopher Fauletb15625a2021-04-12 21:31:45 +02001047 if (!curproxy->server_state_file_name)
1048 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001049 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001050 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001051 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1052 err_code |= ERR_WARN;
1053 if (*(args[1]) == 0) {
1054 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1055 file, linenum, args[0]);
1056 err_code |= ERR_ALERT | ERR_FATAL;
1057 goto out;
1058 }
1059 curproxy->max_out_conns = atoi(args[1]);
1060 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001061 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001062 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1063 err_code |= ERR_WARN;
1064
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001065 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
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[4]) == 0) {
1076 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1077 file, linenum, args[0]);
1078 err_code |= ERR_ALERT | ERR_FATAL;
1079 goto out;
1080 }
1081 free(curproxy->capture_name);
1082 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001083 if (!curproxy->capture_name)
1084 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001085 curproxy->capture_namelen = strlen(curproxy->capture_name);
1086 curproxy->capture_len = atol(args[4]);
1087 curproxy->to_log |= LW_COOKIE;
1088 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001089 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001090 struct cap_hdr *hdr;
1091
Willy Tarreau5d095c22021-02-12 10:15:59 +01001092 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001093 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1094 err_code |= ERR_ALERT | ERR_FATAL;
1095 goto out;
1096 }
1097
1098 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1099 goto out;
1100
1101 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1102 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1103 file, linenum, args[0], args[1]);
1104 err_code |= ERR_ALERT | ERR_FATAL;
1105 goto out;
1106 }
1107
1108 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001109 if (!hdr)
1110 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001111 hdr->next = curproxy->req_cap;
1112 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001113 if (!hdr->name)
1114 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001115 hdr->namelen = strlen(args[3]);
1116 hdr->len = atol(args[5]);
1117 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001118 if (!hdr->pool) {
1119 req_caphdr_alloc_error:
1120 if (hdr)
1121 ha_free(&hdr->name);
1122 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001123 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001124 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001125 hdr->index = curproxy->nb_req_cap++;
1126 curproxy->req_cap = hdr;
1127 curproxy->to_log |= LW_REQHDR;
1128 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001129 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001130 struct cap_hdr *hdr;
1131
Willy Tarreau5d095c22021-02-12 10:15:59 +01001132 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001133 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1134 err_code |= ERR_ALERT | ERR_FATAL;
1135 goto out;
1136 }
1137
1138 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1139 goto out;
1140
1141 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1142 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1143 file, linenum, args[0], args[1]);
1144 err_code |= ERR_ALERT | ERR_FATAL;
1145 goto out;
1146 }
1147 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001148 if (!hdr)
1149 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001150 hdr->next = curproxy->rsp_cap;
1151 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001152 if (!hdr->name)
1153 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001154 hdr->namelen = strlen(args[3]);
1155 hdr->len = atol(args[5]);
1156 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001157 if (!hdr->pool) {
1158 res_caphdr_alloc_error:
1159 if (hdr)
1160 ha_free(&hdr->name);
1161 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001162 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001163 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001164 hdr->index = curproxy->nb_rsp_cap++;
1165 curproxy->rsp_cap = hdr;
1166 curproxy->to_log |= LW_RSPHDR;
1167 }
1168 else {
1169 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1170 file, linenum, args[0]);
1171 err_code |= ERR_ALERT | ERR_FATAL;
1172 goto out;
1173 }
1174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001175 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001176 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1177 err_code |= ERR_WARN;
1178
1179 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1180 goto out;
1181
1182 if (*(args[1]) == 0) {
1183 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1184 file, linenum, args[0]);
1185 err_code |= ERR_ALERT | ERR_FATAL;
1186 goto out;
1187 }
1188 curproxy->conn_retries = atol(args[1]);
1189 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001190 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001191 struct act_rule *rule;
1192
Willy Tarreau5d095c22021-02-12 10:15:59 +01001193 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001194 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1195 err_code |= ERR_ALERT | ERR_FATAL;
1196 goto out;
1197 }
1198
1199 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1200 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001201 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001202 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1203 file, linenum, args[0]);
1204 err_code |= ERR_WARN;
1205 }
1206
1207 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1208
1209 if (!rule) {
1210 err_code |= ERR_ALERT | ERR_ABORT;
1211 goto out;
1212 }
1213
1214 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1215 err_code |= warnif_cond_conflicts(rule->cond,
1216 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1217 file, linenum);
1218
1219 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1220 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001221 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001222 struct act_rule *rule;
1223
Willy Tarreau5d095c22021-02-12 10:15:59 +01001224 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001225 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1226 err_code |= ERR_ALERT | ERR_FATAL;
1227 goto out;
1228 }
1229
1230 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1231 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001232 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001233 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1234 file, linenum, args[0]);
1235 err_code |= ERR_WARN;
1236 }
1237
1238 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1239
1240 if (!rule) {
1241 err_code |= ERR_ALERT | ERR_ABORT;
1242 goto out;
1243 }
1244
1245 err_code |= warnif_cond_conflicts(rule->cond,
1246 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1247 file, linenum);
1248
1249 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1250 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001251 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001252 struct act_rule *rule;
1253
Willy Tarreau5d095c22021-02-12 10:15:59 +01001254 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001255 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1256 err_code |= ERR_ALERT | ERR_FATAL;
1257 goto out;
1258 }
1259
1260 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1261 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1262 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1263 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1264 file, linenum, args[0]);
1265 err_code |= ERR_WARN;
1266 }
1267
1268 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1269
1270 if (!rule) {
1271 err_code |= ERR_ALERT | ERR_ABORT;
1272 goto out;
1273 }
1274
1275 err_code |= warnif_cond_conflicts(rule->cond,
1276 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1277 file, linenum);
1278
1279 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1280 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001281 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001282 /* set the header name and length into the proxy structure */
1283 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1284 err_code |= ERR_WARN;
1285
1286 if (!*args[1]) {
1287 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1288 file, linenum, args[0]);
1289 err_code |= ERR_ALERT | ERR_FATAL;
1290 goto out;
1291 }
1292
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001293 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001294 free(curproxy->server_id_hdr_name);
1295 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001296 if (!curproxy->server_id_hdr_name)
1297 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001298 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001299 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 +01001300 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001301 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001302 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 +01001303
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001304 err_code |= ERR_ALERT | ERR_FATAL;
1305 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001306 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001307 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001308 struct redirect_rule *rule;
1309
Willy Tarreau5d095c22021-02-12 10:15:59 +01001310 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001311 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1312 err_code |= ERR_ALERT | ERR_FATAL;
1313 goto out;
1314 }
1315
1316 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1317 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1318 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1319 err_code |= ERR_ALERT | ERR_FATAL;
1320 goto out;
1321 }
1322
1323 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1324 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1325 err_code |= warnif_cond_conflicts(rule->cond,
1326 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1327 file, linenum);
1328 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001329 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001330 struct switching_rule *rule;
1331
Willy Tarreau5d095c22021-02-12 10:15:59 +01001332 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001333 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1334 err_code |= ERR_ALERT | ERR_FATAL;
1335 goto out;
1336 }
1337
1338 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1339 err_code |= ERR_WARN;
1340
1341 if (*(args[1]) == 0) {
1342 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1343 err_code |= ERR_ALERT | ERR_FATAL;
1344 goto out;
1345 }
1346
1347 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1348 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1349 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1350 file, linenum, errmsg);
1351 err_code |= ERR_ALERT | ERR_FATAL;
1352 goto out;
1353 }
1354
1355 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1356 }
1357 else if (*args[2]) {
1358 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1359 file, linenum, args[2]);
1360 err_code |= ERR_ALERT | ERR_FATAL;
1361 goto out;
1362 }
1363
1364 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001365 if (!rule)
1366 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001367 rule->cond = cond;
1368 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001369 if (!rule->be.name)
1370 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001371 rule->line = linenum;
1372 rule->file = strdup(file);
1373 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001374 use_backend_alloc_error:
1375 if (cond)
1376 prune_acl_cond(cond);
1377 ha_free(&cond);
1378 if (rule)
1379 ha_free(&(rule->be.name));
1380 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001381 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001382 }
1383 LIST_INIT(&rule->list);
1384 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1385 }
1386 else if (strcmp(args[0], "use-server") == 0) {
1387 struct server_rule *rule;
1388
Willy Tarreau5d095c22021-02-12 10:15:59 +01001389 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001390 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1391 err_code |= ERR_ALERT | ERR_FATAL;
1392 goto out;
1393 }
1394
1395 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1396 err_code |= ERR_WARN;
1397
1398 if (*(args[1]) == 0) {
1399 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1400 err_code |= ERR_ALERT | ERR_FATAL;
1401 goto out;
1402 }
1403
1404 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1405 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1406 file, linenum, args[0]);
1407 err_code |= ERR_ALERT | ERR_FATAL;
1408 goto out;
1409 }
1410
1411 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1412 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1413 file, linenum, errmsg);
1414 err_code |= ERR_ALERT | ERR_FATAL;
1415 goto out;
1416 }
1417
1418 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1419
1420 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001421 if (!rule)
1422 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001423 rule->cond = cond;
1424 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001425 if (!rule->srv.name)
1426 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001427 rule->line = linenum;
1428 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001429 if (!rule->file) {
1430 use_server_alloc_error:
1431 if (cond)
1432 prune_acl_cond(cond);
1433 ha_free(&cond);
1434 if (rule)
1435 ha_free(&(rule->srv.name));
1436 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001437 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001438 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001439 LIST_INIT(&rule->list);
1440 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1441 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1442 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001443 else if ((strcmp(args[0], "force-persist") == 0) ||
1444 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001445 struct persist_rule *rule;
1446
Willy Tarreau5d095c22021-02-12 10:15:59 +01001447 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1449 err_code |= ERR_ALERT | ERR_FATAL;
1450 goto out;
1451 }
1452
1453 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1454 err_code |= ERR_WARN;
1455
1456 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1457 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1458 file, linenum, args[0]);
1459 err_code |= ERR_ALERT | ERR_FATAL;
1460 goto out;
1461 }
1462
1463 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1464 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1465 file, linenum, args[0], errmsg);
1466 err_code |= ERR_ALERT | ERR_FATAL;
1467 goto out;
1468 }
1469
1470 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1471 * where force-persist is applied.
1472 */
1473 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1474
1475 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001476 if (!rule) {
1477 if (cond)
1478 prune_acl_cond(cond);
1479 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001480 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001481 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001482 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001483 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001484 rule->type = PERSIST_TYPE_FORCE;
1485 } else {
1486 rule->type = PERSIST_TYPE_IGNORE;
1487 }
1488 LIST_INIT(&rule->list);
1489 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1490 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001491 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001492 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001493
Willy Tarreau5d095c22021-02-12 10:15:59 +01001494 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001495 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1496 file, linenum);
1497 err_code |= ERR_ALERT | ERR_FATAL;
1498 goto out;
1499 }
1500
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001501 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001502 if (other) {
1503 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 +01001504 file, linenum, curproxy->id,
1505 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1506 other->proxy ? other->id : other->peers.p->id,
1507 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001508 err_code |= ERR_ALERT | ERR_FATAL;
1509 goto out;
1510 }
1511
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001512 curproxy->table = calloc(1, sizeof *curproxy->table);
1513 if (!curproxy->table) {
1514 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1515 file, linenum, args[0], args[1]);
1516 err_code |= ERR_ALERT | ERR_FATAL;
1517 goto out;
1518 }
1519
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001520 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1521 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001522 if (err_code & ERR_FATAL) {
1523 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001524 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001525 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001526
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001527 /* Store the proxy in the stick-table. */
1528 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001529
1530 stktable_store_name(curproxy->table);
1531 curproxy->table->next = stktables_list;
1532 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001533
1534 /* Add this proxy to the list of proxies which refer to its stick-table. */
1535 if (curproxy->table->proxies_list != curproxy) {
1536 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1537 curproxy->table->proxies_list = curproxy;
1538 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001539 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001540 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001541 struct sticking_rule *rule;
1542 struct sample_expr *expr;
1543 int myidx = 0;
1544 const char *name = NULL;
1545 int flags;
1546
Willy Tarreau5d095c22021-02-12 10:15:59 +01001547 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001548 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1549 err_code |= ERR_ALERT | ERR_FATAL;
1550 goto out;
1551 }
1552
1553 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1554 err_code |= ERR_WARN;
1555 goto out;
1556 }
1557
1558 myidx++;
1559 if ((strcmp(args[myidx], "store") == 0) ||
1560 (strcmp(args[myidx], "store-request") == 0)) {
1561 myidx++;
1562 flags = STK_IS_STORE;
1563 }
1564 else if (strcmp(args[myidx], "store-response") == 0) {
1565 myidx++;
1566 flags = STK_IS_STORE | STK_ON_RSP;
1567 }
1568 else if (strcmp(args[myidx], "match") == 0) {
1569 myidx++;
1570 flags = STK_IS_MATCH;
1571 }
1572 else if (strcmp(args[myidx], "on") == 0) {
1573 myidx++;
1574 flags = STK_IS_MATCH | STK_IS_STORE;
1575 }
1576 else {
1577 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1578 err_code |= ERR_ALERT | ERR_FATAL;
1579 goto out;
1580 }
1581
1582 if (*(args[myidx]) == 0) {
1583 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1584 err_code |= ERR_ALERT | ERR_FATAL;
1585 goto out;
1586 }
1587
1588 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001589 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001590 if (!expr) {
1591 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1592 err_code |= ERR_ALERT | ERR_FATAL;
1593 goto out;
1594 }
1595
1596 if (flags & STK_ON_RSP) {
1597 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1598 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1599 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1600 err_code |= ERR_ALERT | ERR_FATAL;
1601 free(expr);
1602 goto out;
1603 }
1604 } else {
1605 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1606 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1607 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1608 err_code |= ERR_ALERT | ERR_FATAL;
1609 free(expr);
1610 goto out;
1611 }
1612 }
1613
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001614 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001615 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1616
1617 if (strcmp(args[myidx], "table") == 0) {
1618 myidx++;
1619 name = args[myidx++];
1620 }
1621
1622 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1623 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1624 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1625 file, linenum, args[0], errmsg);
1626 err_code |= ERR_ALERT | ERR_FATAL;
1627 free(expr);
1628 goto out;
1629 }
1630 }
1631 else if (*(args[myidx])) {
1632 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1633 file, linenum, args[0], args[myidx]);
1634 err_code |= ERR_ALERT | ERR_FATAL;
1635 free(expr);
1636 goto out;
1637 }
1638 if (flags & STK_ON_RSP)
1639 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1640 else
1641 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1642
1643 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001644 if (!rule) {
1645 if (cond)
1646 prune_acl_cond(cond);
1647 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001648 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001649 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001650 rule->cond = cond;
1651 rule->expr = expr;
1652 rule->flags = flags;
1653 rule->table.name = name ? strdup(name) : NULL;
1654 LIST_INIT(&rule->list);
1655 if (flags & STK_ON_RSP)
1656 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1657 else
1658 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1659 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001660 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001661 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001662 curproxy->uri_auth = NULL; /* we must detach from the default config */
1663
1664 if (!*args[1]) {
1665 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001666 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001667 struct stats_admin_rule *rule;
1668
Willy Tarreau5d095c22021-02-12 10:15:59 +01001669 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001670 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1671 err_code |= ERR_ALERT | ERR_FATAL;
1672 goto out;
1673 }
1674
Christopher Fauletb15625a2021-04-12 21:31:45 +02001675 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1676 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001677
1678 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1679 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1680 file, linenum, args[0], args[1]);
1681 err_code |= ERR_ALERT | ERR_FATAL;
1682 goto out;
1683 }
1684 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1685 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1686 file, linenum, args[0], args[1], errmsg);
1687 err_code |= ERR_ALERT | ERR_FATAL;
1688 goto out;
1689 }
1690
1691 err_code |= warnif_cond_conflicts(cond,
1692 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1693 file, linenum);
1694
1695 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001696 if (!rule) {
1697 if (cond)
1698 prune_acl_cond(cond);
1699 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001700 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001701 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001702 rule->cond = cond;
1703 LIST_INIT(&rule->list);
1704 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001705 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706 if (*(args[2]) == 0) {
1707 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1708 err_code |= ERR_ALERT | ERR_FATAL;
1709 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001710 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1711 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001712 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001713 if (*(args[2]) == 0) {
1714 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1715 err_code |= ERR_ALERT | ERR_FATAL;
1716 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001717 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1718 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001719 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001720 unsigned interval;
1721
1722 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001723 if (err == PARSE_TIME_OVER) {
1724 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1725 file, linenum, args[2]);
1726 err_code |= ERR_ALERT | ERR_FATAL;
1727 goto out;
1728 }
1729 else if (err == PARSE_TIME_UNDER) {
1730 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1731 file, linenum, args[2]);
1732 err_code |= ERR_ALERT | ERR_FATAL;
1733 goto out;
1734 }
1735 else if (err) {
1736 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001737 file, linenum, *err);
1738 err_code |= ERR_ALERT | ERR_FATAL;
1739 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001740 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1741 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001742 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001743 struct act_rule *rule;
1744
Willy Tarreau5d095c22021-02-12 10:15:59 +01001745 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001746 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1747 err_code |= ERR_ALERT | ERR_FATAL;
1748 goto out;
1749 }
1750
Christopher Fauletb15625a2021-04-12 21:31:45 +02001751 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1752 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001753
1754 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1755 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1756 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1757 file, linenum, args[0]);
1758 err_code |= ERR_WARN;
1759 }
1760
1761 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1762
1763 if (!rule) {
1764 err_code |= ERR_ALERT | ERR_ABORT;
1765 goto out;
1766 }
1767
1768 err_code |= warnif_cond_conflicts(rule->cond,
1769 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1770 file, linenum);
1771 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1772
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001773 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001774 if (*(args[2]) == 0) {
1775 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1776 err_code |= ERR_ALERT | ERR_FATAL;
1777 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001778 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1779 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001780 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001781 if (*(args[2]) == 0) {
1782 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1783 err_code |= ERR_ALERT | ERR_FATAL;
1784 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001785 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1786 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001787 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001788 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1789 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001790 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001791 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1792 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001793 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001794 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1795 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001796 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001797 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1798 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001799 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001800
1801 if (*args[2]) {
1802 int i;
1803 char c;
1804
1805 for (i=0; args[2][i]; i++) {
1806 c = args[2][i];
1807 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1808 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1809 break;
1810 }
1811
1812 if (!i || args[2][i]) {
1813 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1814 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1815 file, linenum, args[0], args[1]);
1816 err_code |= ERR_ALERT | ERR_FATAL;
1817 goto out;
1818 }
1819 }
1820
Christopher Fauletb15625a2021-04-12 21:31:45 +02001821 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1822 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001823 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001824 char *desc = NULL;
1825
1826 if (*args[2]) {
1827 int i, len=0;
1828 char *d;
1829
1830 for (i = 2; *args[i]; i++)
1831 len += strlen(args[i]) + 1;
1832
1833 desc = d = calloc(1, len);
1834
1835 d += snprintf(d, desc + len - d, "%s", args[2]);
1836 for (i = 3; *args[i]; i++)
1837 d += snprintf(d, desc + len - d, " %s", args[i]);
1838 }
1839
1840 if (!*args[2] && !global.desc)
1841 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1842 file, linenum, args[1]);
1843 else {
1844 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1845 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001846 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001847 }
1848 free(desc);
1849 }
1850 } else {
1851stats_error_parsing:
1852 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1853 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1854 err_code |= ERR_ALERT | ERR_FATAL;
1855 goto out;
1856 }
1857 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001858 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001859 int optnum;
1860
1861 if (*(args[1]) == '\0') {
1862 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1863 file, linenum, args[0]);
1864 err_code |= ERR_ALERT | ERR_FATAL;
1865 goto out;
1866 }
1867
1868 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001869 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001870 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1871 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1872 file, linenum, cfg_opts[optnum].name);
1873 err_code |= ERR_ALERT | ERR_FATAL;
1874 goto out;
1875 }
1876 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1877 goto out;
1878
1879 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1880 err_code |= ERR_WARN;
1881 goto out;
1882 }
1883
1884 curproxy->no_options &= ~cfg_opts[optnum].val;
1885 curproxy->options &= ~cfg_opts[optnum].val;
1886
1887 switch (kwm) {
1888 case KWM_STD:
1889 curproxy->options |= cfg_opts[optnum].val;
1890 break;
1891 case KWM_NO:
1892 curproxy->no_options |= cfg_opts[optnum].val;
1893 break;
1894 case KWM_DEF: /* already cleared */
1895 break;
1896 }
1897
1898 goto out;
1899 }
1900 }
1901
1902 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001903 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001904 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1905 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1906 file, linenum, cfg_opts2[optnum].name);
1907 err_code |= ERR_ALERT | ERR_FATAL;
1908 goto out;
1909 }
1910 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1911 goto out;
1912 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1913 err_code |= ERR_WARN;
1914 goto out;
1915 }
1916
Christopher Faulet31930372019-07-15 10:16:58 +02001917 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001918 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001919 if (kwm ==KWM_NO) {
1920 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1921 " The HTX mode is now the only supported mode.\n",
1922 file, linenum, cfg_opts2[optnum].name);
1923 err_code |= ERR_WARN;
1924 }
Christopher Faulet31930372019-07-15 10:16:58 +02001925 goto out;
1926 }
1927
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001928 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1929 curproxy->options2 &= ~cfg_opts2[optnum].val;
1930
1931 switch (kwm) {
1932 case KWM_STD:
1933 curproxy->options2 |= cfg_opts2[optnum].val;
1934 break;
1935 case KWM_NO:
1936 curproxy->no_options2 |= cfg_opts2[optnum].val;
1937 break;
1938 case KWM_DEF: /* already cleared */
1939 break;
1940 }
1941 goto out;
1942 }
1943 }
1944
1945 /* HTTP options override each other. They can be cancelled using
1946 * "no option xxx" which only switches to default mode if the mode
1947 * was this one (useful for cancelling options set in defaults
1948 * sections).
1949 */
1950 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001951 if (strcmp(args[1], "forceclose") == 0) {
1952 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1953 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1954 file, linenum, args[1]);
1955 err_code |= ERR_WARN;
1956 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001957 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1958 goto out;
1959 if (kwm == KWM_STD) {
1960 curproxy->options &= ~PR_O_HTTP_MODE;
1961 curproxy->options |= PR_O_HTTP_CLO;
1962 goto out;
1963 }
1964 else if (kwm == KWM_NO) {
1965 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1966 curproxy->options &= ~PR_O_HTTP_MODE;
1967 goto out;
1968 }
1969 }
1970 else if (strcmp(args[1], "http-server-close") == 0) {
1971 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1972 goto out;
1973 if (kwm == KWM_STD) {
1974 curproxy->options &= ~PR_O_HTTP_MODE;
1975 curproxy->options |= PR_O_HTTP_SCL;
1976 goto out;
1977 }
1978 else if (kwm == KWM_NO) {
1979 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1980 curproxy->options &= ~PR_O_HTTP_MODE;
1981 goto out;
1982 }
1983 }
1984 else if (strcmp(args[1], "http-keep-alive") == 0) {
1985 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1986 goto out;
1987 if (kwm == KWM_STD) {
1988 curproxy->options &= ~PR_O_HTTP_MODE;
1989 curproxy->options |= PR_O_HTTP_KAL;
1990 goto out;
1991 }
1992 else if (kwm == KWM_NO) {
1993 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1994 curproxy->options &= ~PR_O_HTTP_MODE;
1995 goto out;
1996 }
1997 }
1998 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001999 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2000 file, linenum, args[1]);
2001 err_code |= ERR_WARN;
2002 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002003 }
2004
2005 /* Redispatch can take an integer argument that control when the
2006 * resispatch occurs. All values are relative to the retries option.
2007 * This can be cancelled using "no option xxx".
2008 */
2009 if (strcmp(args[1], "redispatch") == 0) {
2010 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2011 err_code |= ERR_WARN;
2012 goto out;
2013 }
2014
2015 curproxy->no_options &= ~PR_O_REDISP;
2016 curproxy->options &= ~PR_O_REDISP;
2017
2018 switch (kwm) {
2019 case KWM_STD:
2020 curproxy->options |= PR_O_REDISP;
2021 curproxy->redispatch_after = -1;
2022 if(*args[2]) {
2023 curproxy->redispatch_after = atol(args[2]);
2024 }
2025 break;
2026 case KWM_NO:
2027 curproxy->no_options |= PR_O_REDISP;
2028 curproxy->redispatch_after = 0;
2029 break;
2030 case KWM_DEF: /* already cleared */
2031 break;
2032 }
2033 goto out;
2034 }
2035
2036 if (kwm != KWM_STD) {
2037 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2038 file, linenum, args[1]);
2039 err_code |= ERR_ALERT | ERR_FATAL;
2040 goto out;
2041 }
2042
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002043 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002044 char *logformat;
2045 /* generate a complete HTTP log */
2046 logformat = default_http_log_format;
2047 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002048 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002049 curproxy->options2 |= PR_O2_CLFLOG;
2050 logformat = clf_http_log_format;
2051 } else {
2052 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2053 err_code |= ERR_ALERT | ERR_FATAL;
2054 goto out;
2055 }
2056 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2057 goto out;
2058 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002059 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002060 char *oldlogformat = "log-format";
2061 char *clflogformat = "";
2062
2063 if (curproxy->conf.logformat_string == default_http_log_format)
2064 oldlogformat = "option httplog";
2065 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2066 oldlogformat = "option tcplog";
2067 else if (curproxy->conf.logformat_string == clf_http_log_format)
2068 oldlogformat = "option httplog clf";
2069 if (logformat == clf_http_log_format)
2070 clflogformat = " clf";
2071 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2072 file, linenum, clflogformat, oldlogformat);
2073 }
2074 if (curproxy->conf.logformat_string != default_http_log_format &&
2075 curproxy->conf.logformat_string != default_tcp_log_format &&
2076 curproxy->conf.logformat_string != clf_http_log_format)
2077 free(curproxy->conf.logformat_string);
2078 curproxy->conf.logformat_string = logformat;
2079
2080 free(curproxy->conf.lfs_file);
2081 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2082 curproxy->conf.lfs_line = curproxy->conf.args.line;
2083
Willy Tarreau5d095c22021-02-12 10:15:59 +01002084 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002085 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2086 file, linenum, curproxy->id);
2087 err_code |= ERR_WARN;
2088 }
2089 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002090 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002091 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002092 char *oldlogformat = "log-format";
2093
2094 if (curproxy->conf.logformat_string == default_http_log_format)
2095 oldlogformat = "option httplog";
2096 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2097 oldlogformat = "option tcplog";
2098 else if (curproxy->conf.logformat_string == clf_http_log_format)
2099 oldlogformat = "option httplog clf";
2100 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2101 file, linenum, oldlogformat);
2102 }
2103 /* generate a detailed TCP log */
2104 if (curproxy->conf.logformat_string != default_http_log_format &&
2105 curproxy->conf.logformat_string != default_tcp_log_format &&
2106 curproxy->conf.logformat_string != clf_http_log_format)
2107 free(curproxy->conf.logformat_string);
2108 curproxy->conf.logformat_string = default_tcp_log_format;
2109
2110 free(curproxy->conf.lfs_file);
2111 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2112 curproxy->conf.lfs_line = curproxy->conf.args.line;
2113
2114 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2115 goto out;
2116
Willy Tarreau5d095c22021-02-12 10:15:59 +01002117 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002118 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2119 file, linenum, curproxy->id);
2120 err_code |= ERR_WARN;
2121 }
2122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002123 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002124 /* enable TCP keep-alives on client and server streams */
2125 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2126 err_code |= ERR_WARN;
2127
2128 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2129 goto out;
2130
2131 if (curproxy->cap & PR_CAP_FE)
2132 curproxy->options |= PR_O_TCP_CLI_KA;
2133 if (curproxy->cap & PR_CAP_BE)
2134 curproxy->options |= PR_O_TCP_SRV_KA;
2135 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002136 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002137 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002138 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002139 goto out;
2140 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002141 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002142 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002143 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002144 goto out;
2145 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002146 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002147 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002148 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002149 goto out;
2150 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002151 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002152 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002153 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002154 goto out;
2155 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002156 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002157 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002158 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002159 goto out;
2160 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002161 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002162 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002163 if (err_code & ERR_FATAL)
2164 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002165 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002166 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002167 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002168 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002169 goto out;
2170 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002171 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002172 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002173 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002174 goto out;
2175 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002176 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002177 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002178 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002179 goto out;
2180 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002181 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002182 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002183 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002184 goto out;
2185 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002186 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002187 int cur_arg;
2188
2189 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002190 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002191 */
2192
2193 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2194
2195 free(curproxy->fwdfor_hdr_name);
2196 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002197 if (!curproxy->fwdfor_hdr_name)
2198 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002199 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002200 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002201
2202 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2203 cur_arg = 2;
2204 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002205 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002206 unsigned char mask;
2207 int i;
2208
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002209 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002210 if (*(args[cur_arg+1]) &&
2211 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2212 curproxy->except_xff_net.family = AF_INET;
2213 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2214 }
2215 else if (*(args[cur_arg+1]) &&
2216 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2217 curproxy->except_xff_net.family = AF_INET6;
2218 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2219 for (i = 0; i < 16; i++)
2220 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2221 }
2222 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002223 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2224 file, linenum, args[0], args[1], args[cur_arg]);
2225 err_code |= ERR_ALERT | ERR_FATAL;
2226 goto out;
2227 }
2228 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002229 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002230 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002231 /* suboption header - needs additional argument for it */
2232 if (*(args[cur_arg+1]) == 0) {
2233 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2234 file, linenum, args[0], args[1], args[cur_arg]);
2235 err_code |= ERR_ALERT | ERR_FATAL;
2236 goto out;
2237 }
2238 free(curproxy->fwdfor_hdr_name);
2239 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002240 if (!curproxy->fwdfor_hdr_name)
2241 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002242 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2243 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002244 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002245 curproxy->options &= ~PR_O_FF_ALWAYS;
2246 cur_arg += 1;
2247 } else {
2248 /* unknown suboption - catchall */
2249 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2250 file, linenum, args[0], args[1]);
2251 err_code |= ERR_ALERT | ERR_FATAL;
2252 goto out;
2253 }
2254 } /* end while loop */
2255 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002256 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002257 int cur_arg;
2258
2259 /* insert x-original-to field, but not for the IP address listed as an except.
2260 * set default options (ie: bitfield, header name, etc)
2261 */
2262
2263 curproxy->options |= PR_O_ORGTO;
2264
2265 free(curproxy->orgto_hdr_name);
2266 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002267 if (!curproxy->orgto_hdr_name)
2268 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002270 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002271
2272 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2273 cur_arg = 2;
2274 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002275 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002276 unsigned char mask;
2277 int i;
2278
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002279 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002280 if (*(args[cur_arg+1]) &&
2281 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2282 curproxy->except_xot_net.family = AF_INET;
2283 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2284 }
2285 else if (*(args[cur_arg+1]) &&
2286 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2287 curproxy->except_xot_net.family = AF_INET6;
2288 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2289 for (i = 0; i < 16; i++)
2290 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2291 }
2292 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002293 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2294 file, linenum, args[0], args[1], args[cur_arg]);
2295 err_code |= ERR_ALERT | ERR_FATAL;
2296 goto out;
2297 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002298 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002299 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002300 /* suboption header - needs additional argument for it */
2301 if (*(args[cur_arg+1]) == 0) {
2302 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2303 file, linenum, args[0], args[1], args[cur_arg]);
2304 err_code |= ERR_ALERT | ERR_FATAL;
2305 goto out;
2306 }
2307 free(curproxy->orgto_hdr_name);
2308 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002309 if (!curproxy->orgto_hdr_name)
2310 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002311 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2312 cur_arg += 2;
2313 } else {
2314 /* unknown suboption - catchall */
2315 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2316 file, linenum, args[0], args[1]);
2317 err_code |= ERR_ALERT | ERR_FATAL;
2318 goto out;
2319 }
2320 } /* end while loop */
2321 }
2322 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002323 const char *best = proxy_find_best_option(args[1], common_options);
2324
2325 if (best)
2326 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2327 else
2328 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2329
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002330 err_code |= ERR_ALERT | ERR_FATAL;
2331 goto out;
2332 }
2333 goto out;
2334 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002335 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002336 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2337 err_code |= ERR_WARN;
2338
2339 if (*(args[1]) == 0) {
2340 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2341 err_code |= ERR_ALERT | ERR_FATAL;
2342 goto out;
2343 }
2344 free(curproxy->defbe.name);
2345 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002346 if (!curproxy->defbe.name)
2347 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002348
2349 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2350 goto out;
2351 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002352 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002353 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 +01002354
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002355 err_code |= ERR_ALERT | ERR_FATAL;
2356 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002357 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002358 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002359 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2360 err_code |= ERR_WARN;
2361
2362 if (strcmp(args[1], "never") == 0) {
2363 /* enable a graceful server shutdown on an HTTP 404 response */
2364 curproxy->options &= ~PR_O_REUSE_MASK;
2365 curproxy->options |= PR_O_REUSE_NEVR;
2366 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2367 goto out;
2368 }
2369 else if (strcmp(args[1], "safe") == 0) {
2370 /* enable a graceful server shutdown on an HTTP 404 response */
2371 curproxy->options &= ~PR_O_REUSE_MASK;
2372 curproxy->options |= PR_O_REUSE_SAFE;
2373 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2374 goto out;
2375 }
2376 else if (strcmp(args[1], "aggressive") == 0) {
2377 curproxy->options &= ~PR_O_REUSE_MASK;
2378 curproxy->options |= PR_O_REUSE_AGGR;
2379 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2380 goto out;
2381 }
2382 else if (strcmp(args[1], "always") == 0) {
2383 /* enable a graceful server shutdown on an HTTP 404 response */
2384 curproxy->options &= ~PR_O_REUSE_MASK;
2385 curproxy->options |= PR_O_REUSE_ALWS;
2386 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2387 goto out;
2388 }
2389 else {
2390 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2391 err_code |= ERR_ALERT | ERR_FATAL;
2392 goto out;
2393 }
2394 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002395 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002396 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002397 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2398 err_code |= ERR_ALERT | ERR_FATAL;
2399 goto out;
2400 }
2401
2402 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2403 err_code |= ERR_WARN;
2404
2405 if (strcmp(args[1], "fail") == 0) {
2406 /* add a condition to fail monitor requests */
2407 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2408 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2409 file, linenum, args[0], args[1]);
2410 err_code |= ERR_ALERT | ERR_FATAL;
2411 goto out;
2412 }
2413
2414 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2415 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2416 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2417 file, linenum, args[0], args[1], errmsg);
2418 err_code |= ERR_ALERT | ERR_FATAL;
2419 goto out;
2420 }
2421 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2422 }
2423 else {
2424 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2425 err_code |= ERR_ALERT | ERR_FATAL;
2426 goto out;
2427 }
2428 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002429#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002430 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002431 /* enable transparent proxy connections */
2432 curproxy->options |= PR_O_TRANSP;
2433 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2434 goto out;
2435 }
2436#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002437 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002438 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2439 err_code |= ERR_WARN;
2440
2441 if (*(args[1]) == 0) {
2442 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2443 err_code |= ERR_ALERT | ERR_FATAL;
2444 goto out;
2445 }
2446 curproxy->maxconn = atol(args[1]);
2447 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2448 goto out;
2449 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002450 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002451 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2452 err_code |= ERR_WARN;
2453
2454 if (*(args[1]) == 0) {
2455 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2456 err_code |= ERR_ALERT | ERR_FATAL;
2457 goto out;
2458 }
2459 curproxy->backlog = atol(args[1]);
2460 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2461 goto out;
2462 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002463 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002464 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2465 err_code |= ERR_WARN;
2466
2467 if (*(args[1]) == 0) {
2468 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2469 err_code |= ERR_ALERT | ERR_FATAL;
2470 goto out;
2471 }
2472 curproxy->fullconn = atol(args[1]);
2473 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2474 goto out;
2475 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002476 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002477 if (*(args[1]) == 0) {
2478 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2479 err_code |= ERR_ALERT | ERR_FATAL;
2480 goto out;
2481 }
2482 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002483 if (err == PARSE_TIME_OVER) {
2484 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2485 file, linenum, args[1]);
2486 err_code |= ERR_ALERT | ERR_FATAL;
2487 goto out;
2488 }
2489 else if (err == PARSE_TIME_UNDER) {
2490 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2491 file, linenum, args[1]);
2492 err_code |= ERR_ALERT | ERR_FATAL;
2493 goto out;
2494 }
2495 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002496 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2497 file, linenum, *err);
2498 err_code |= ERR_ALERT | ERR_FATAL;
2499 goto out;
2500 }
2501 curproxy->grace = val;
2502 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2503 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002504
2505 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2506 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002507 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002508 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002509 struct sockaddr_storage *sk;
2510 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002511
Willy Tarreau5d095c22021-02-12 10:15:59 +01002512 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002513 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2514 err_code |= ERR_ALERT | ERR_FATAL;
2515 goto out;
2516 }
2517 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2518 err_code |= ERR_WARN;
2519
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002520 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2521 &errmsg, NULL, NULL,
2522 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 +01002523 if (!sk) {
2524 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2525 err_code |= ERR_ALERT | ERR_FATAL;
2526 goto out;
2527 }
2528
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002529 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2530 goto out;
2531
2532 curproxy->dispatch_addr = *sk;
2533 curproxy->options |= PR_O_DISPATCH;
2534 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002535 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002536 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2537 err_code |= ERR_WARN;
2538
2539 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2540 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2541 err_code |= ERR_ALERT | ERR_FATAL;
2542 goto out;
2543 }
2544 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002545 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002546 /**
2547 * The syntax for hash-type config element is
2548 * hash-type {map-based|consistent} [[<algo>] avalanche]
2549 *
2550 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2551 */
2552 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2553
2554 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2555 err_code |= ERR_WARN;
2556
2557 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2558 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2559 }
2560 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2561 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2562 }
2563 else if (strcmp(args[1], "avalanche") == 0) {
2564 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]);
2565 err_code |= ERR_ALERT | ERR_FATAL;
2566 goto out;
2567 }
2568 else {
2569 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2570 err_code |= ERR_ALERT | ERR_FATAL;
2571 goto out;
2572 }
2573
2574 /* set the hash function to use */
2575 if (!*args[2]) {
2576 /* the default algo is sdbm */
2577 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2578
2579 /* if consistent with no argument, then avalanche modifier is also applied */
2580 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2581 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2582 } else {
2583 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002584 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002585 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2586 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002587 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002588 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2589 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002590 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002591 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2592 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002593 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002594 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2595 }
2596 else {
2597 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2598 err_code |= ERR_ALERT | ERR_FATAL;
2599 goto out;
2600 }
2601
2602 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002603 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2605 }
2606 else if (*args[3]) {
2607 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2608 err_code |= ERR_ALERT | ERR_FATAL;
2609 goto out;
2610 }
2611 }
2612 }
2613 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2614 if (*(args[1]) == 0) {
2615 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2616 err_code |= ERR_ALERT | ERR_FATAL;
2617 goto out;
2618 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002619 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2620 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002621 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2622 err_code |= ERR_ALERT | ERR_FATAL;
2623 goto out;
2624 }
2625 }
2626 else if (strcmp(args[0], "unique-id-format") == 0) {
2627 if (!*(args[1])) {
2628 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2629 err_code |= ERR_ALERT | ERR_FATAL;
2630 goto out;
2631 }
2632 if (*(args[2])) {
2633 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2634 err_code |= ERR_ALERT | ERR_FATAL;
2635 goto out;
2636 }
2637 free(curproxy->conf.uniqueid_format_string);
2638 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002639 if (!curproxy->conf.uniqueid_format_string)
2640 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002641
2642 free(curproxy->conf.uif_file);
2643 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2644 curproxy->conf.uif_line = curproxy->conf.args.line;
2645 }
2646
2647 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002648 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002649 if (!*(args[1])) {
2650 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2651 err_code |= ERR_ALERT | ERR_FATAL;
2652 goto out;
2653 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002654 copy = strdup(args[1]);
2655 if (copy == NULL) {
2656 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2657 err_code |= ERR_ALERT | ERR_FATAL;
2658 goto out;
2659 }
2660
2661 istfree(&curproxy->header_unique_id);
2662 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002663 }
2664
2665 else if (strcmp(args[0], "log-format") == 0) {
2666 if (!*(args[1])) {
2667 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2668 err_code |= ERR_ALERT | ERR_FATAL;
2669 goto out;
2670 }
2671 if (*(args[2])) {
2672 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2673 err_code |= ERR_ALERT | ERR_FATAL;
2674 goto out;
2675 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002676 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002677 char *oldlogformat = "log-format";
2678
2679 if (curproxy->conf.logformat_string == default_http_log_format)
2680 oldlogformat = "option httplog";
2681 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2682 oldlogformat = "option tcplog";
2683 else if (curproxy->conf.logformat_string == clf_http_log_format)
2684 oldlogformat = "option httplog clf";
2685 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2686 file, linenum, oldlogformat);
2687 }
2688 if (curproxy->conf.logformat_string != default_http_log_format &&
2689 curproxy->conf.logformat_string != default_tcp_log_format &&
2690 curproxy->conf.logformat_string != clf_http_log_format)
2691 free(curproxy->conf.logformat_string);
2692 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002693 if (!curproxy->conf.logformat_string)
2694 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002695
2696 free(curproxy->conf.lfs_file);
2697 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2698 curproxy->conf.lfs_line = curproxy->conf.args.line;
2699
2700 /* get a chance to improve log-format error reporting by
2701 * reporting the correct line-number when possible.
2702 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002703 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002704 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2705 file, linenum, curproxy->id);
2706 err_code |= ERR_WARN;
2707 }
2708 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002709 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002710 if (!*(args[1])) {
2711 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2712 err_code |= ERR_ALERT | ERR_FATAL;
2713 goto out;
2714 }
2715 if (*(args[2])) {
2716 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2717 err_code |= ERR_ALERT | ERR_FATAL;
2718 goto out;
2719 }
2720
2721 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2722 free(curproxy->conf.logformat_sd_string);
2723 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002724 if (!curproxy->conf.logformat_sd_string)
2725 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002726
2727 free(curproxy->conf.lfsd_file);
2728 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2729 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2730
2731 /* get a chance to improve log-format-sd error reporting by
2732 * reporting the correct line-number when possible.
2733 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002734 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002735 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2736 file, linenum, curproxy->id);
2737 err_code |= ERR_WARN;
2738 }
2739 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002740 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002741 if (*(args[1]) == 0) {
2742 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2743 err_code |= ERR_ALERT | ERR_FATAL;
2744 goto out;
2745 }
2746 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002747 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2748 if (b_orig(&curproxy->log_tag) == NULL) {
2749 chunk_destroy(&curproxy->log_tag);
2750 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2751 err_code |= ERR_ALERT | ERR_FATAL;
2752 goto out;
2753 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002754 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002755 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002756 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002757 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2758 err_code |= ERR_ALERT | ERR_FATAL;
2759 goto out;
2760 }
2761 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002762 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002763 int cur_arg;
2764 int port1, port2;
2765 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002766
2767 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2768 err_code |= ERR_WARN;
2769
2770 if (!*args[1]) {
2771 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2772 file, linenum, "source", "usesrc", "interface");
2773 err_code |= ERR_ALERT | ERR_FATAL;
2774 goto out;
2775 }
2776
Christopher Faulet31930372019-07-15 10:16:58 +02002777 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002778 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002779 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002780 curproxy->conn_src.iface_len = 0;
2781
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002782 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2783 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002784 if (!sk) {
2785 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2786 file, linenum, args[0], args[1], errmsg);
2787 err_code |= ERR_ALERT | ERR_FATAL;
2788 goto out;
2789 }
2790
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002791 curproxy->conn_src.source_addr = *sk;
2792 curproxy->conn_src.opts |= CO_SRC_BIND;
2793
2794 cur_arg = 2;
2795 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002796 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002797#if defined(CONFIG_HAP_TRANSPARENT)
2798 if (!*args[cur_arg + 1]) {
2799 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2800 file, linenum, "usesrc");
2801 err_code |= ERR_ALERT | ERR_FATAL;
2802 goto out;
2803 }
2804
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002805 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002806 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2807 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002808 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002809 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2810 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2811 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2812 char *name, *end;
2813
2814 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002815 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002816 name++;
2817
2818 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002819 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002820 end++;
2821
2822 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2823 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002824 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002825 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002826 if (!curproxy->conn_src.bind_hdr_name)
2827 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002828 curproxy->conn_src.bind_hdr_len = end - name;
2829 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2830 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2831 curproxy->conn_src.bind_hdr_occ = -1;
2832
2833 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002834 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002835 end++;
2836 if (*end == ',') {
2837 end++;
2838 name = end;
2839 if (*end == '-')
2840 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002841 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002842 end++;
2843 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2844 }
2845
2846 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2847 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2848 " occurrences values smaller than %d.\n",
2849 file, linenum, MAX_HDR_HISTORY);
2850 err_code |= ERR_ALERT | ERR_FATAL;
2851 goto out;
2852 }
2853 } else {
2854 struct sockaddr_storage *sk;
2855
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002856 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2857 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002858 if (!sk) {
2859 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2860 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2861 err_code |= ERR_ALERT | ERR_FATAL;
2862 goto out;
2863 }
2864
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002865 curproxy->conn_src.tproxy_addr = *sk;
2866 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2867 }
2868 global.last_checks |= LSTCHK_NETADM;
2869#else /* no TPROXY support */
2870 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2871 file, linenum, "usesrc");
2872 err_code |= ERR_ALERT | ERR_FATAL;
2873 goto out;
2874#endif
2875 cur_arg += 2;
2876 continue;
2877 }
2878
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002879 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002880#ifdef SO_BINDTODEVICE
2881 if (!*args[cur_arg + 1]) {
2882 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2883 file, linenum, args[0]);
2884 err_code |= ERR_ALERT | ERR_FATAL;
2885 goto out;
2886 }
2887 free(curproxy->conn_src.iface_name);
2888 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002889 if (!curproxy->conn_src.iface_name)
2890 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002891 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2892 global.last_checks |= LSTCHK_NETADM;
2893#else
2894 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2895 file, linenum, args[0], args[cur_arg]);
2896 err_code |= ERR_ALERT | ERR_FATAL;
2897 goto out;
2898#endif
2899 cur_arg += 2;
2900 continue;
2901 }
2902 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2903 file, linenum, args[0], "interface", "usesrc");
2904 err_code |= ERR_ALERT | ERR_FATAL;
2905 goto out;
2906 }
2907 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002908 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002909 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2910 file, linenum, "usesrc", "source");
2911 err_code |= ERR_ALERT | ERR_FATAL;
2912 goto out;
2913 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002914 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 +02002915 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002916 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002917 file, linenum, args[0]);
2918 err_code |= ERR_ALERT | ERR_FATAL;
2919 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002920 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002921 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002922 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2923 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2924 err_code |= ERR_ALERT | ERR_FATAL;
2925 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002926 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002927 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002928 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2929 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2930 err_code |= ERR_ALERT | ERR_FATAL;
2931 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002932 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002933 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002934 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2935 err_code |= ERR_ALERT | ERR_FATAL;
2936 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002937 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002938 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002939 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2940 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2941 err_code |= ERR_ALERT | ERR_FATAL;
2942 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002943 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002944 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002945 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2946 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2947 err_code |= ERR_ALERT | ERR_FATAL;
2948 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002949 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002950 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002951 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2952 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2953 err_code |= ERR_ALERT | ERR_FATAL;
2954 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002955 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002956 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002957 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2958 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2959 err_code |= ERR_ALERT | ERR_FATAL;
2960 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002961 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002962 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 +02002963 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2964 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2965 err_code |= ERR_ALERT | ERR_FATAL;
2966 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002967 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002968 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002969 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2970 err_code |= ERR_ALERT | ERR_FATAL;
2971 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002972 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002973 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 +02002974 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2975 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2976 err_code |= ERR_ALERT | ERR_FATAL;
2977 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002978 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002979 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 +02002980 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2981 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2982 err_code |= ERR_ALERT | ERR_FATAL;
2983 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002984 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002985 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002986 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2987 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2988 err_code |= ERR_ALERT | ERR_FATAL;
2989 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002990 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002991 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 +02002992 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2993 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2994 err_code |= ERR_ALERT | ERR_FATAL;
2995 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002996 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002997 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002998 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2999 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3000 err_code |= ERR_ALERT | ERR_FATAL;
3001 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003002 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003003 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003004 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3005 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3006 err_code |= ERR_ALERT | ERR_FATAL;
3007 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003008 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003009 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303010 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003011 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3012 err_code |= ERR_ALERT | ERR_FATAL;
3013 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003014 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003015 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003016 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3017 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3018 err_code |= ERR_ALERT | ERR_FATAL;
3019 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003020 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003021 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003022 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3023 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3024 err_code |= ERR_ALERT | ERR_FATAL;
3025 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003026 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003027 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003028 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3029 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3030 err_code |= ERR_ALERT | ERR_FATAL;
3031 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003032 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003033 else {
3034 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003035 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003036 int index;
3037
3038 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3039 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3040 if (kwl->kw[index].section != CFG_LISTEN)
3041 continue;
3042 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3043 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003044 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003045 if (rc < 0) {
3046 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3047 err_code |= ERR_ALERT | ERR_FATAL;
3048 goto out;
3049 }
3050 else if (rc > 0) {
3051 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3052 err_code |= ERR_WARN;
3053 goto out;
3054 }
3055 goto out;
3056 }
3057 }
3058 }
3059
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003060 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3061 if (best)
3062 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3063 else
3064 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003065 err_code |= ERR_ALERT | ERR_FATAL;
3066 goto out;
3067 }
3068 out:
3069 free(errmsg);
3070 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003071
3072 alloc_error:
3073 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3074 err_code |= ERR_ALERT | ERR_ABORT;
3075 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003076}