blob: 98e31ec665a2aa8001f197647356f2c9ee59aa57 [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 Tarreaub7fc4c42021-10-06 18:56:42 +020022#include <haproxy/http_ana.h>
Willy Tarreau87735332020-06-04 09:08:41 +020023#include <haproxy/http_htx.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020024#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020025#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020026#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020027#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020028#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020029#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020030#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020031#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020032#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020033#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020034#include <haproxy/tcpcheck.h>
Willy Tarreaue9dcb3c2021-05-08 13:00:23 +020035#include <haproxy/tools.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020036#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010037
Willy Tarreauc0ff6792021-03-12 09:14:19 +010038/* some keywords that are still being parsed using strcmp() and are not
39 * registered anywhere. They are used as suggestions for mistyped words.
40 */
41static const char *common_kw_list[] = {
42 "listen", "frontend", "backend", "defaults", "server",
43 "default-server", "server-template", "bind", "monitor-net",
44 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
45 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
46 "persist", "appsession", "load-server-state-from-file",
47 "server-state-file-name", "max-session-srv-conns", "capture",
48 "retries", "http-request", "http-response", "http-after-response",
49 "http-send-name-header", "block", "redirect", "use_backend",
50 "use-server", "force-persist", "ignore-persist", "force-persist",
51 "stick-table", "stick", "stats", "option", "default_backend",
52 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
Willy Tarreaueb778242021-06-11 16:27:10 +020053 "fullconn", "dispatch", "balance", "hash-type",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010054 "hash-balance-factor", "unique-id-format", "unique-id-header",
55 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +020056 "error-log-format",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010057 NULL /* must be last */
58};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010059
Willy Tarreau31a3cea2021-03-15 11:11:55 +010060static const char *common_options[] = {
Willy Tarreau6ba69842021-06-11 16:01:50 +020061 "httpclose", "http-server-close", "http-keep-alive",
Willy Tarreaud2f25372021-06-11 16:06:29 +020062 "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010063 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
64 "mysql-check", "ldap-check", "spop-check", "tcp-check",
65 "external-check", "forwardfor", "original-to",
66 NULL /* must be last */
67};
68
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010069/* Report a warning if a rule is placed after a 'tcp-request session' rule.
70 * Return 1 if the warning has been emitted, otherwise 0.
71 */
72int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
73{
74 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
75 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
76 file, line, arg);
77 return 1;
78 }
79 return 0;
80}
81
82/* Report a warning if a rule is placed after a 'tcp-request content' rule.
83 * Return 1 if the warning has been emitted, otherwise 0.
84 */
85int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
86{
87 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
88 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
89 file, line, arg);
90 return 1;
91 }
92 return 0;
93}
94
95/* Report a warning if a rule is placed after a 'monitor fail' rule.
96 * Return 1 if the warning has been emitted, otherwise 0.
97 */
98int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
99{
100 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
101 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
102 file, line, arg);
103 return 1;
104 }
105 return 0;
106}
107
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100108/* Report a warning if a rule is placed after an 'http_request' rule.
109 * Return 1 if the warning has been emitted, otherwise 0.
110 */
111int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
112{
113 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
114 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
115 file, line, arg);
116 return 1;
117 }
118 return 0;
119}
120
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100121/* Report a warning if a rule is placed after a redirect rule.
122 * Return 1 if the warning has been emitted, otherwise 0.
123 */
124int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
125{
126 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
127 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
128 file, line, arg);
129 return 1;
130 }
131 return 0;
132}
133
134/* Report a warning if a rule is placed after a 'use_backend' rule.
135 * Return 1 if the warning has been emitted, otherwise 0.
136 */
137int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
138{
139 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
140 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
141 file, line, arg);
142 return 1;
143 }
144 return 0;
145}
146
147/* Report a warning if a rule is placed after a 'use-server' rule.
148 * Return 1 if the warning has been emitted, otherwise 0.
149 */
150int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
151{
152 if (!LIST_ISEMPTY(&proxy->server_rules)) {
153 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
154 file, line, arg);
155 return 1;
156 }
157 return 0;
158}
159
160/* report a warning if a redirect rule is dangerously placed */
161int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
162{
163 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
164 warnif_rule_after_use_server(proxy, file, line, arg);
165}
166
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100167/* report a warning if an http-request rule is dangerously placed */
168int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
169{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200170 return warnif_rule_after_redirect(proxy, file, line, arg) ||
171 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100172}
173
174/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200175int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100176{
177 return warnif_rule_after_http_req(proxy, file, line, arg) ||
178 warnif_misplaced_http_req(proxy, file, line, arg);
179}
180
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100181/* report a warning if a "tcp request content" rule is dangerously placed */
182int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
183{
184 return warnif_rule_after_monitor(proxy, file, line, arg) ||
185 warnif_misplaced_monitor(proxy, file, line, arg);
186}
187
188/* report a warning if a "tcp request session" rule is dangerously placed */
189int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
190{
191 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
192 warnif_misplaced_tcp_cont(proxy, file, line, arg);
193}
194
195/* report a warning if a "tcp request connection" rule is dangerously placed */
196int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
197{
198 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
199 warnif_misplaced_tcp_sess(proxy, file, line, arg);
200}
201
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100202int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
203{
204 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100205 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100206 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100208 int rc;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100209 int err_code = 0;
210 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100211 char *errmsg = NULL;
212 struct bind_conf *bind_conf;
213
Willy Tarreaue90904d2021-02-12 14:08:31 +0100214 if (!last_defproxy) {
215 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100216 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
217 proxy_preset_defaults(last_defproxy);
218
Willy Tarreaue90904d2021-02-12 14:08:31 +0100219 curr_defproxy = last_defproxy;
220 if (!last_defproxy) {
221 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
222 err_code |= ERR_ALERT | ERR_ABORT;
223 goto out;
224 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100225 }
226
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 if (strcmp(args[0], "listen") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200228 rc = PR_CAP_LISTEN | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100229 else if (strcmp(args[0], "frontend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200230 rc = PR_CAP_FE | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100231 else if (strcmp(args[0], "backend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200232 rc = PR_CAP_BE | PR_CAP_LB;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100233 else if (strcmp(args[0], "defaults") == 0) {
234 /* "defaults" must first delete the last no-name defaults if any */
235 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
236 curr_defproxy = NULL;
237 rc = PR_CAP_DEF | PR_CAP_LISTEN;
238 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100239 else
240 rc = PR_CAP_NONE;
241
Willy Tarreaue90904d2021-02-12 14:08:31 +0100242 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100243 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100244 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100245 file, linenum, args[0]);
246 err_code |= ERR_ALERT | ERR_ABORT;
247 goto out;
248 }
249
250 err = invalid_char(args[1]);
251 if (err) {
252 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
253 file, linenum, *err, args[0], args[1]);
254 err_code |= ERR_ALERT | ERR_FATAL;
255 }
256
257 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
258 if (curproxy) {
259 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
260 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
261 curproxy->id, curproxy->conf.file, curproxy->conf.line);
262 err_code |= ERR_ALERT | ERR_FATAL;
263 }
264
Emeric Brunb0c331f2020-10-07 17:05:59 +0200265 curproxy = log_forward_by_name(args[1]);
266 if (curproxy) {
267 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
268 file, linenum, proxy_cap_str(rc), args[1],
269 curproxy->id, curproxy->conf.file, curproxy->conf.line);
270 err_code |= ERR_ALERT | ERR_FATAL;
271 }
272
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100273 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
274 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100275 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100276 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
277 goto out;
278 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100279 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100280
Willy Tarreaue90904d2021-02-12 14:08:31 +0100281 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100282 const char *name = args[1];
283 int arg = 2;
284
285 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
286 // also support "defaults from blah" (no name then)
287 arg = 1;
288 name = "";
289 }
290
291 /* only regular proxies inherit from the previous defaults section */
292 if (!(rc & PR_CAP_DEF))
293 curr_defproxy = last_defproxy;
294
295 if (strcmp(args[arg], "from") == 0) {
296 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
297
298 if (!curr_defproxy) {
299 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
300 err_code |= ERR_ALERT | ERR_ABORT;
301 goto out;
302 }
303
304 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
305 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
306
307 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
308 file, linenum, args[arg+1], proxy_cap_str(rc), name,
309 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
310 err_code |= ERR_ALERT | ERR_FATAL;
311 }
312
313 err = invalid_char(args[arg+1]);
314 if (err) {
315 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",
316 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
317 err_code |= ERR_ALERT | ERR_FATAL;
318 }
319 }
320
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100321 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100322 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100323 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100324 goto out;
325 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100326
Willy Tarreaue90904d2021-02-12 14:08:31 +0100327 if (rc & PR_CAP_DEF) {
328 /* last and current proxies must be updated to this one */
329 curr_defproxy = last_defproxy = curproxy;
330 } else {
331 /* regular proxies are in a list */
332 curproxy->next = proxies_list;
333 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100334 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100335 goto out;
336 }
337 else if (curproxy == NULL) {
338 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
339 err_code |= ERR_ALERT | ERR_FATAL;
340 goto out;
341 }
342
343 /* update the current file and line being parsed */
344 curproxy->conf.args.file = curproxy->conf.file;
345 curproxy->conf.args.line = linenum;
346
347 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100348 if ((strcmp(args[0], "server") == 0)) {
349 err_code |= parse_server(file, linenum, args,
350 curproxy, curr_defproxy,
351 SRV_PARSE_PARSE_ADDR);
352
353 if (err_code & ERR_FATAL)
354 goto out;
355 }
356 else if (strcmp(args[0], "default-server") == 0) {
357 err_code |= parse_server(file, linenum, args,
358 curproxy, curr_defproxy,
359 SRV_PARSE_DEFAULT_SERVER);
360
361 if (err_code & ERR_FATAL)
362 goto out;
363 }
364 else if (strcmp(args[0], "server-template") == 0) {
365 err_code |= parse_server(file, linenum, args,
366 curproxy, curr_defproxy,
367 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
368
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100369 if (err_code & ERR_FATAL)
370 goto out;
371 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100372 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100373 struct listener *l;
374 int cur_arg;
375
Willy Tarreau5d095c22021-02-12 10:15:59 +0100376 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100377 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
378 err_code |= ERR_ALERT | ERR_FATAL;
379 goto out;
380 }
381 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
382 err_code |= ERR_WARN;
383
384 if (!*(args[1])) {
385 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
386 file, linenum, args[0]);
387 err_code |= ERR_ALERT | ERR_FATAL;
388 goto out;
389 }
390
391 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200392 if (!bind_conf)
393 goto alloc_error;
394
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100395 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200396 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
397 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
398 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100399
400 /* NOTE: the following line might create several listeners if there
401 * are comma-separated IPs or port ranges. So all further processing
402 * will have to be applied to all listeners created after last_listen.
403 */
404 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
405 if (errmsg && *errmsg) {
406 indent_msg(&errmsg, 2);
407 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
408 }
409 else
410 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
411 file, linenum, args[0], args[1]);
412 err_code |= ERR_ALERT | ERR_FATAL;
413 goto out;
414 }
415
416 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
417 /* Set default global rights and owner for unix bind */
418 global.maxsock++;
419 }
420
421 cur_arg = 2;
422 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100423 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100424 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100425
426 kw = bind_find_kw(args[cur_arg]);
427 if (kw) {
428 char *err = NULL;
429 int code;
430
431 if (!kw->parse) {
432 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
433 file, linenum, args[0], args[1], args[cur_arg]);
434 cur_arg += 1 + kw->skip ;
435 err_code |= ERR_ALERT | ERR_FATAL;
436 goto out;
437 }
438
439 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
440 err_code |= code;
441
442 if (code) {
443 if (err && *err) {
444 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200445 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
446 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
447 else
448 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100449 }
450 else
451 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
452 file, linenum, args[0], args[1], args[cur_arg]);
453 if (code & ERR_FATAL) {
454 free(err);
455 cur_arg += 1 + kw->skip;
456 goto out;
457 }
458 }
459 free(err);
460 cur_arg += 1 + kw->skip;
461 continue;
462 }
463
Willy Tarreau433b05f2021-03-12 10:14:07 +0100464 best = bind_find_best_kw(args[cur_arg]);
465 if (best)
466 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
467 file, linenum, args[0], args[1], args[cur_arg], best);
468 else
469 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
470 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100471
472 err_code |= ERR_ALERT | ERR_FATAL;
473 goto out;
474 }
475 goto out;
476 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100477 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200478 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]);
479 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100480 goto out;
481 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100482 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100483 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
484 err_code |= ERR_WARN;
485
486 if (alertif_too_many_args(1, file, linenum, args, &err_code))
487 goto out;
488
489 if (!*args[1]) {
490 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
491 file, linenum, args[0]);
492 err_code |= ERR_ALERT | ERR_FATAL;
493 goto out;
494 }
495
496 free(curproxy->monitor_uri);
497 curproxy->monitor_uri_len = strlen(args[1]);
498 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200499 if (!curproxy->monitor_uri)
500 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100501 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
502 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
503
504 goto out;
505 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100506 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100507 if (alertif_too_many_args(1, file, linenum, args, &err_code))
508 goto out;
509
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100510 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
511 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
512 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200513 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
514 err_code |= ERR_ALERT | ERR_FATAL;
515 goto out;
516 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100517 else {
518 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
519 err_code |= ERR_ALERT | ERR_FATAL;
520 goto out;
521 }
522 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100523 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100524 struct eb32_node *node;
525
Willy Tarreau5d095c22021-02-12 10:15:59 +0100526 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100527 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
528 file, linenum, args[0]);
529 err_code |= ERR_ALERT | ERR_FATAL;
530 goto out;
531 }
532
533 if (alertif_too_many_args(1, file, linenum, args, &err_code))
534 goto out;
535
536 if (!*args[1]) {
537 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
538 file, linenum, args[0]);
539 err_code |= ERR_ALERT | ERR_FATAL;
540 goto out;
541 }
542
543 curproxy->uuid = atol(args[1]);
544 curproxy->conf.id.key = curproxy->uuid;
545 curproxy->options |= PR_O_FORCED_ID;
546
547 if (curproxy->uuid <= 0) {
548 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
549 file, linenum);
550 err_code |= ERR_ALERT | ERR_FATAL;
551 goto out;
552 }
553
554 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
555 if (node) {
556 struct proxy *target = container_of(node, struct proxy, conf.id);
557 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
558 file, linenum, proxy_type_str(curproxy), curproxy->id,
559 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
560 err_code |= ERR_ALERT | ERR_FATAL;
561 goto out;
562 }
563 eb32_insert(&used_proxy_id, &curproxy->conf.id);
564 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100565 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100566 int i, len=0;
567 char *d;
568
Willy Tarreau5d095c22021-02-12 10:15:59 +0100569 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100570 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
571 file, linenum, args[0]);
572 err_code |= ERR_ALERT | ERR_FATAL;
573 goto out;
574 }
575
576 if (!*args[1]) {
577 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
578 file, linenum, args[0]);
579 return -1;
580 }
581
582 for (i = 1; *args[i]; i++)
583 len += strlen(args[i]) + 1;
584
585 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200586 if (!d)
587 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100588 curproxy->desc = d;
589
590 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
591 for (i = 2; *args[i]; i++)
592 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
593
594 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100595 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100596 if (alertif_too_many_args(0, file, linenum, args, &err_code))
597 goto out;
William Lallemand8e765b82021-08-03 11:58:03 +0200598 curproxy->disabled = PR_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100599 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100600 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100601 if (alertif_too_many_args(0, file, linenum, args, &err_code))
602 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200603 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100604 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100605 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100606 int cur_arg = 1;
607 unsigned long set = 0;
608
609 while (*args[cur_arg]) {
610 if (strcmp(args[cur_arg], "all") == 0) {
611 set = 0;
612 break;
613 }
Willy Tarreau72faef32021-06-15 08:36:30 +0200614 if (parse_process_number(args[cur_arg], &set, 1, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100615 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
616 err_code |= ERR_ALERT | ERR_FATAL;
617 goto out;
618 }
619 cur_arg++;
620 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200621 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
622 file, linenum, args[0]);
623 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100624 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100625 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100626 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100627 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
628 err_code |= ERR_ALERT | ERR_FATAL;
629 goto out;
630 }
631
632 err = invalid_char(args[1]);
633 if (err) {
634 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
635 file, linenum, *err, args[1]);
636 err_code |= ERR_ALERT | ERR_FATAL;
637 goto out;
638 }
639
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100640 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100641 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100642 "logical disjunction within a condition.\n",
643 file, linenum, args[1]);
644 err_code |= ERR_ALERT | ERR_FATAL;
645 goto out;
646 }
647
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100648 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
649 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
650 file, linenum, args[1], errmsg);
651 err_code |= ERR_ALERT | ERR_FATAL;
652 goto out;
653 }
654 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100655 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100656
657 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
658 err_code |= ERR_WARN;
659
660 if (*(args[1]) == 0) {
661 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
662 file, linenum, args[0]);
663 err_code |= ERR_ALERT | ERR_FATAL;
664 goto out;
665 }
666 free(curproxy->dyncookie_key);
667 curproxy->dyncookie_key = strdup(args[1]);
668 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100669 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100670 int cur_arg;
671
672 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
673 err_code |= ERR_WARN;
674
675 if (*(args[1]) == 0) {
676 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
677 file, linenum, args[0]);
678 err_code |= ERR_ALERT | ERR_FATAL;
679 goto out;
680 }
681
682 curproxy->ck_opts = 0;
683 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100684 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100685 free(curproxy->cookie_name);
686 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200687 if (!curproxy->cookie_name)
688 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100689 curproxy->cookie_len = strlen(curproxy->cookie_name);
690
691 cur_arg = 2;
692 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100693 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100694 curproxy->ck_opts |= PR_CK_RW;
695 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100696 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100697 curproxy->ck_opts |= PR_CK_IND;
698 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100699 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100700 curproxy->ck_opts |= PR_CK_INS;
701 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100702 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100703 curproxy->ck_opts |= PR_CK_NOC;
704 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100705 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100706 curproxy->ck_opts |= PR_CK_POST;
707 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100708 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100709 curproxy->ck_opts |= PR_CK_PSV;
710 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100711 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100712 curproxy->ck_opts |= PR_CK_PFX;
713 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100714 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100715 curproxy->ck_opts |= PR_CK_HTTPONLY;
716 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100717 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100718 curproxy->ck_opts |= PR_CK_SECURE;
719 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100720 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100721 if (!*args[cur_arg + 1]) {
722 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
723 file, linenum, args[cur_arg]);
724 err_code |= ERR_ALERT | ERR_FATAL;
725 goto out;
726 }
727
Joao Moraise1583752019-10-30 21:04:00 -0300728 if (!strchr(args[cur_arg + 1], '.')) {
729 /* rfc6265, 5.2.3 The Domain Attribute */
730 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
731 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100732 file, linenum, args[cur_arg + 1]);
733 err_code |= ERR_WARN;
734 }
735
736 err = invalid_domainchar(args[cur_arg + 1]);
737 if (err) {
738 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
739 file, linenum, *err, args[cur_arg + 1]);
740 err_code |= ERR_ALERT | ERR_FATAL;
741 goto out;
742 }
743
744 if (!curproxy->cookie_domain) {
745 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
746 } else {
747 /* one domain was already specified, add another one by
748 * building the string which will be returned along with
749 * the cookie.
750 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200751 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
752 }
753
Christopher Fauletb15625a2021-04-12 21:31:45 +0200754 if (!curproxy->cookie_domain)
755 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100756 cur_arg++;
757 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100758 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100759 unsigned int maxidle;
760 const char *res;
761
762 if (!*args[cur_arg + 1]) {
763 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
764 file, linenum, args[cur_arg]);
765 err_code |= ERR_ALERT | ERR_FATAL;
766 goto out;
767 }
768
769 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200770 if (res == PARSE_TIME_OVER) {
771 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
772 file, linenum, args[cur_arg+1], args[cur_arg]);
773 err_code |= ERR_ALERT | ERR_FATAL;
774 goto out;
775 }
776 else if (res == PARSE_TIME_UNDER) {
777 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
778 file, linenum, args[cur_arg+1], args[cur_arg]);
779 err_code |= ERR_ALERT | ERR_FATAL;
780 goto out;
781 }
782 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100783 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
784 file, linenum, *res, args[cur_arg]);
785 err_code |= ERR_ALERT | ERR_FATAL;
786 goto out;
787 }
788 curproxy->cookie_maxidle = maxidle;
789 cur_arg++;
790 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100791 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100792 unsigned int maxlife;
793 const char *res;
794
795 if (!*args[cur_arg + 1]) {
796 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
797 file, linenum, args[cur_arg]);
798 err_code |= ERR_ALERT | ERR_FATAL;
799 goto out;
800 }
801
Willy Tarreau9faebe32019-06-07 19:00:37 +0200802
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100803 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200804 if (res == PARSE_TIME_OVER) {
805 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
806 file, linenum, args[cur_arg+1], args[cur_arg]);
807 err_code |= ERR_ALERT | ERR_FATAL;
808 goto out;
809 }
810 else if (res == PARSE_TIME_UNDER) {
811 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
812 file, linenum, args[cur_arg+1], args[cur_arg]);
813 err_code |= ERR_ALERT | ERR_FATAL;
814 goto out;
815 }
816 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100817 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
818 file, linenum, *res, args[cur_arg]);
819 err_code |= ERR_ALERT | ERR_FATAL;
820 goto out;
821 }
822 curproxy->cookie_maxlife = maxlife;
823 cur_arg++;
824 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100825 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100826
827 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
828 err_code |= ERR_WARN;
829 curproxy->ck_opts |= PR_CK_DYNAMIC;
830 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100831 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100832 char *val;
833 if (!*args[cur_arg + 1]) {
834 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
835 file, linenum, args[cur_arg]);
836 err_code |= ERR_ALERT | ERR_FATAL;
837 goto out;
838 }
839 val = args[cur_arg + 1];
840 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100841 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100842 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
843 file, linenum, *val);
844 err_code |= ERR_ALERT | ERR_FATAL;
845 goto out;
846 }
847 val++;
848 }
849 /* don't add ';' for the first attribute */
850 if (!curproxy->cookie_attrs)
851 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
852 else
853 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200854
Christopher Fauletb15625a2021-04-12 21:31:45 +0200855 if (!curproxy->cookie_attrs)
856 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100857 cur_arg++;
858 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100859
860 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100861 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 +0100862 file, linenum, args[0]);
863 err_code |= ERR_ALERT | ERR_FATAL;
864 goto out;
865 }
866 cur_arg++;
867 }
868 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
869 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
870 file, linenum);
871 err_code |= ERR_ALERT | ERR_FATAL;
872 }
873
874 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
875 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
876 file, linenum);
877 err_code |= ERR_ALERT | ERR_FATAL;
878 }
879
880 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
881 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
882 file, linenum);
883 err_code |= ERR_ALERT | ERR_FATAL;
884 }
885 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100886 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100887 if (*(args[1]) == 0) {
888 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
889 file, linenum, args[0]);
890 err_code |= ERR_ALERT | ERR_FATAL;
891 goto out;
892 }
893
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100894 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100895 if (*(args[1]) == 0) {
896 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
897 file, linenum, args[1]);
898 err_code |= ERR_ALERT | ERR_FATAL;
899 goto out;
900 }
901 free(curproxy->email_alert.from);
902 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200903 if (!curproxy->email_alert.from)
904 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100905 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100906 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100907 if (*(args[1]) == 0) {
908 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
909 file, linenum, args[1]);
910 err_code |= ERR_ALERT | ERR_FATAL;
911 goto out;
912 }
913 free(curproxy->email_alert.mailers.name);
914 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200915 if (!curproxy->email_alert.mailers.name)
916 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100917 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100918 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100919 if (*(args[1]) == 0) {
920 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
921 file, linenum, args[1]);
922 err_code |= ERR_ALERT | ERR_FATAL;
923 goto out;
924 }
925 free(curproxy->email_alert.myhostname);
926 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200927 if (!curproxy->email_alert.myhostname)
928 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100929 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100930 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100931 curproxy->email_alert.level = get_log_level(args[2]);
932 if (curproxy->email_alert.level < 0) {
933 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
934 file, linenum, args[1], args[2]);
935 err_code |= ERR_ALERT | ERR_FATAL;
936 goto out;
937 }
938 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100939 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100940 if (*(args[1]) == 0) {
941 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
942 file, linenum, args[1]);
943 err_code |= ERR_ALERT | ERR_FATAL;
944 goto out;
945 }
946 free(curproxy->email_alert.to);
947 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200948 if (!curproxy->email_alert.to)
949 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100950 }
951 else {
952 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
953 file, linenum, args[1]);
954 err_code |= ERR_ALERT | ERR_FATAL;
955 goto out;
956 }
957 /* Indicate that the email_alert is at least partially configured */
958 curproxy->email_alert.set = 1;
959 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100960 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100961 if (*(args[1]) == 0) {
962 ha_alert("parsing [%s:%d] : missing persist method.\n",
963 file, linenum);
964 err_code |= ERR_ALERT | ERR_FATAL;
965 goto out;
966 }
967
968 if (!strncmp(args[1], "rdp-cookie", 10)) {
969 curproxy->options2 |= PR_O2_RDPC_PRST;
970
971 if (*(args[1] + 10) == '(') { /* cookie name */
972 const char *beg, *end;
973
974 beg = args[1] + 11;
975 end = strchr(beg, ')');
976
977 if (alertif_too_many_args(1, file, linenum, args, &err_code))
978 goto out;
979
980 if (!end || end == beg) {
981 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
982 file, linenum);
983 err_code |= ERR_ALERT | ERR_FATAL;
984 goto out;
985 }
986
987 free(curproxy->rdp_cookie_name);
988 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200989 if (!curproxy->rdp_cookie_name)
990 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100991 curproxy->rdp_cookie_len = end-beg;
992 }
993 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
994 free(curproxy->rdp_cookie_name);
995 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +0200996 if (!curproxy->rdp_cookie_name)
997 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100998 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
999 }
1000 else { /* syntax */
1001 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1002 file, linenum);
1003 err_code |= ERR_ALERT | ERR_FATAL;
1004 goto out;
1005 }
1006 }
1007 else {
1008 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1009 file, linenum);
1010 err_code |= ERR_ALERT | ERR_FATAL;
1011 goto out;
1012 }
1013 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001014 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001015 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 +01001016 err_code |= ERR_ALERT | ERR_FATAL;
1017 goto out;
1018 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001019 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001020 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1021 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001022 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001023 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1024 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001025 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 +01001026 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1027 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001028 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001029 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1030 }
1031 else {
1032 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1033 file, linenum, args[0], args[1]);
1034 err_code |= ERR_ALERT | ERR_FATAL;
1035 goto out;
1036 }
1037 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001038 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001039 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1040 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001041 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001042 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001043
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001044 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001045
1046 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001047 curproxy->server_state_file_name = strdup(curproxy->id);
1048 else
1049 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001050
Christopher Fauletb15625a2021-04-12 21:31:45 +02001051 if (!curproxy->server_state_file_name)
1052 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001053 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001054 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001055 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1056 err_code |= ERR_WARN;
1057 if (*(args[1]) == 0) {
1058 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1059 file, linenum, args[0]);
1060 err_code |= ERR_ALERT | ERR_FATAL;
1061 goto out;
1062 }
1063 curproxy->max_out_conns = atoi(args[1]);
1064 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001065 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001066 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1067 err_code |= ERR_WARN;
1068
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001069 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001070 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001071 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1072 err_code |= ERR_ALERT | ERR_FATAL;
1073 goto out;
1074 }
1075
1076 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1077 goto out;
1078
1079 if (*(args[4]) == 0) {
1080 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1081 file, linenum, args[0]);
1082 err_code |= ERR_ALERT | ERR_FATAL;
1083 goto out;
1084 }
1085 free(curproxy->capture_name);
1086 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001087 if (!curproxy->capture_name)
1088 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001089 curproxy->capture_namelen = strlen(curproxy->capture_name);
1090 curproxy->capture_len = atol(args[4]);
1091 curproxy->to_log |= LW_COOKIE;
1092 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001093 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001094 struct cap_hdr *hdr;
1095
Willy Tarreau5d095c22021-02-12 10:15:59 +01001096 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001097 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1098 err_code |= ERR_ALERT | ERR_FATAL;
1099 goto out;
1100 }
1101
1102 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1103 goto out;
1104
1105 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1106 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1107 file, linenum, args[0], args[1]);
1108 err_code |= ERR_ALERT | ERR_FATAL;
1109 goto out;
1110 }
1111
1112 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001113 if (!hdr)
1114 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001115 hdr->next = curproxy->req_cap;
1116 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001117 if (!hdr->name)
1118 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001119 hdr->namelen = strlen(args[3]);
1120 hdr->len = atol(args[5]);
1121 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001122 if (!hdr->pool) {
1123 req_caphdr_alloc_error:
1124 if (hdr)
1125 ha_free(&hdr->name);
1126 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001127 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001128 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001129 hdr->index = curproxy->nb_req_cap++;
1130 curproxy->req_cap = hdr;
1131 curproxy->to_log |= LW_REQHDR;
1132 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001133 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001134 struct cap_hdr *hdr;
1135
Willy Tarreau5d095c22021-02-12 10:15:59 +01001136 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001137 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1138 err_code |= ERR_ALERT | ERR_FATAL;
1139 goto out;
1140 }
1141
1142 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1143 goto out;
1144
1145 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1146 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1147 file, linenum, args[0], args[1]);
1148 err_code |= ERR_ALERT | ERR_FATAL;
1149 goto out;
1150 }
1151 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001152 if (!hdr)
1153 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001154 hdr->next = curproxy->rsp_cap;
1155 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001156 if (!hdr->name)
1157 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001158 hdr->namelen = strlen(args[3]);
1159 hdr->len = atol(args[5]);
1160 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001161 if (!hdr->pool) {
1162 res_caphdr_alloc_error:
1163 if (hdr)
1164 ha_free(&hdr->name);
1165 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001166 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001167 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001168 hdr->index = curproxy->nb_rsp_cap++;
1169 curproxy->rsp_cap = hdr;
1170 curproxy->to_log |= LW_RSPHDR;
1171 }
1172 else {
1173 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1174 file, linenum, args[0]);
1175 err_code |= ERR_ALERT | ERR_FATAL;
1176 goto out;
1177 }
1178 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001179 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001180 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1181 err_code |= ERR_WARN;
1182
1183 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1184 goto out;
1185
1186 if (*(args[1]) == 0) {
1187 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1188 file, linenum, args[0]);
1189 err_code |= ERR_ALERT | ERR_FATAL;
1190 goto out;
1191 }
1192 curproxy->conn_retries = atol(args[1]);
1193 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001194 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001195 struct act_rule *rule;
1196
Willy Tarreau5d095c22021-02-12 10:15:59 +01001197 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001198 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1199 err_code |= ERR_ALERT | ERR_FATAL;
1200 goto out;
1201 }
1202
1203 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1204 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001205 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001206 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1207 file, linenum, args[0]);
1208 err_code |= ERR_WARN;
1209 }
1210
1211 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1212
1213 if (!rule) {
1214 err_code |= ERR_ALERT | ERR_ABORT;
1215 goto out;
1216 }
1217
1218 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1219 err_code |= warnif_cond_conflicts(rule->cond,
1220 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1221 file, linenum);
1222
Willy Tarreau2b718102021-04-21 07:32:39 +02001223 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001224 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001225 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001226 struct act_rule *rule;
1227
Willy Tarreau5d095c22021-02-12 10:15:59 +01001228 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001229 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1230 err_code |= ERR_ALERT | ERR_FATAL;
1231 goto out;
1232 }
1233
1234 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1235 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001236 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001237 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1238 file, linenum, args[0]);
1239 err_code |= ERR_WARN;
1240 }
1241
1242 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1243
1244 if (!rule) {
1245 err_code |= ERR_ALERT | ERR_ABORT;
1246 goto out;
1247 }
1248
1249 err_code |= warnif_cond_conflicts(rule->cond,
1250 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1251 file, linenum);
1252
Willy Tarreau2b718102021-04-21 07:32:39 +02001253 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001254 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001255 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001256 struct act_rule *rule;
1257
Willy Tarreau5d095c22021-02-12 10:15:59 +01001258 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001259 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1260 err_code |= ERR_ALERT | ERR_FATAL;
1261 goto out;
1262 }
1263
1264 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1265 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1266 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1267 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1268 file, linenum, args[0]);
1269 err_code |= ERR_WARN;
1270 }
1271
1272 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1273
1274 if (!rule) {
1275 err_code |= ERR_ALERT | ERR_ABORT;
1276 goto out;
1277 }
1278
1279 err_code |= warnif_cond_conflicts(rule->cond,
1280 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1281 file, linenum);
1282
Willy Tarreau2b718102021-04-21 07:32:39 +02001283 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001284 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001285 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001286 /* set the header name and length into the proxy structure */
1287 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1288 err_code |= ERR_WARN;
1289
1290 if (!*args[1]) {
1291 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1292 file, linenum, args[0]);
1293 err_code |= ERR_ALERT | ERR_FATAL;
1294 goto out;
1295 }
1296
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001297 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001298 free(curproxy->server_id_hdr_name);
1299 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001300 if (!curproxy->server_id_hdr_name)
1301 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001302 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001303 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 +01001304 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001305 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001306 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 +01001307
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001308 err_code |= ERR_ALERT | ERR_FATAL;
1309 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001310 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001311 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001312 struct redirect_rule *rule;
1313
Willy Tarreau5d095c22021-02-12 10:15:59 +01001314 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001315 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1316 err_code |= ERR_ALERT | ERR_FATAL;
1317 goto out;
1318 }
1319
1320 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1321 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1322 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1323 err_code |= ERR_ALERT | ERR_FATAL;
1324 goto out;
1325 }
1326
Willy Tarreau2b718102021-04-21 07:32:39 +02001327 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001328 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1329 err_code |= warnif_cond_conflicts(rule->cond,
1330 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1331 file, linenum);
1332 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001333 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001334 struct switching_rule *rule;
1335
Willy Tarreau5d095c22021-02-12 10:15:59 +01001336 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001337 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1338 err_code |= ERR_ALERT | ERR_FATAL;
1339 goto out;
1340 }
1341
1342 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1343 err_code |= ERR_WARN;
1344
1345 if (*(args[1]) == 0) {
1346 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1347 err_code |= ERR_ALERT | ERR_FATAL;
1348 goto out;
1349 }
1350
1351 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1352 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1353 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1354 file, linenum, errmsg);
1355 err_code |= ERR_ALERT | ERR_FATAL;
1356 goto out;
1357 }
1358
1359 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1360 }
1361 else if (*args[2]) {
1362 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1363 file, linenum, args[2]);
1364 err_code |= ERR_ALERT | ERR_FATAL;
1365 goto out;
1366 }
1367
1368 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001369 if (!rule)
1370 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001371 rule->cond = cond;
1372 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001373 if (!rule->be.name)
1374 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001375 rule->line = linenum;
1376 rule->file = strdup(file);
1377 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001378 use_backend_alloc_error:
1379 if (cond)
1380 prune_acl_cond(cond);
1381 ha_free(&cond);
1382 if (rule)
1383 ha_free(&(rule->be.name));
1384 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001385 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001386 }
1387 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001388 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001389 }
1390 else if (strcmp(args[0], "use-server") == 0) {
1391 struct server_rule *rule;
1392
Willy Tarreau5d095c22021-02-12 10:15:59 +01001393 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001394 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1395 err_code |= ERR_ALERT | ERR_FATAL;
1396 goto out;
1397 }
1398
1399 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1400 err_code |= ERR_WARN;
1401
1402 if (*(args[1]) == 0) {
1403 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1404 err_code |= ERR_ALERT | ERR_FATAL;
1405 goto out;
1406 }
1407
1408 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1409 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1410 file, linenum, args[0]);
1411 err_code |= ERR_ALERT | ERR_FATAL;
1412 goto out;
1413 }
1414
1415 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1416 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1417 file, linenum, errmsg);
1418 err_code |= ERR_ALERT | ERR_FATAL;
1419 goto out;
1420 }
1421
1422 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1423
1424 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001425 if (!rule)
1426 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001427 rule->cond = cond;
1428 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001429 if (!rule->srv.name)
1430 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001431 rule->line = linenum;
1432 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001433 if (!rule->file) {
1434 use_server_alloc_error:
1435 if (cond)
1436 prune_acl_cond(cond);
1437 ha_free(&cond);
1438 if (rule)
1439 ha_free(&(rule->srv.name));
1440 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001441 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001442 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001443 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001444 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001445 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1446 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001447 else if ((strcmp(args[0], "force-persist") == 0) ||
1448 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001449 struct persist_rule *rule;
1450
Willy Tarreau5d095c22021-02-12 10:15:59 +01001451 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001452 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1453 err_code |= ERR_ALERT | ERR_FATAL;
1454 goto out;
1455 }
1456
1457 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1458 err_code |= ERR_WARN;
1459
1460 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1461 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1462 file, linenum, args[0]);
1463 err_code |= ERR_ALERT | ERR_FATAL;
1464 goto out;
1465 }
1466
1467 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1468 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1469 file, linenum, args[0], errmsg);
1470 err_code |= ERR_ALERT | ERR_FATAL;
1471 goto out;
1472 }
1473
1474 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1475 * where force-persist is applied.
1476 */
1477 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1478
1479 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001480 if (!rule) {
1481 if (cond)
1482 prune_acl_cond(cond);
1483 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001484 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001485 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001486 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001487 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001488 rule->type = PERSIST_TYPE_FORCE;
1489 } else {
1490 rule->type = PERSIST_TYPE_IGNORE;
1491 }
1492 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001493 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001494 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001495 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001496 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001497
Willy Tarreau5d095c22021-02-12 10:15:59 +01001498 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001499 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1500 file, linenum);
1501 err_code |= ERR_ALERT | ERR_FATAL;
1502 goto out;
1503 }
1504
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001505 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001506 if (other) {
1507 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 +01001508 file, linenum, curproxy->id,
1509 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1510 other->proxy ? other->id : other->peers.p->id,
1511 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001512 err_code |= ERR_ALERT | ERR_FATAL;
1513 goto out;
1514 }
1515
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001516 curproxy->table = calloc(1, sizeof *curproxy->table);
1517 if (!curproxy->table) {
1518 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1519 file, linenum, args[0], args[1]);
1520 err_code |= ERR_ALERT | ERR_FATAL;
1521 goto out;
1522 }
1523
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001524 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1525 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001526 if (err_code & ERR_FATAL) {
1527 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001528 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001529 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001530
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001531 /* Store the proxy in the stick-table. */
1532 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001533
1534 stktable_store_name(curproxy->table);
1535 curproxy->table->next = stktables_list;
1536 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001537
1538 /* Add this proxy to the list of proxies which refer to its stick-table. */
1539 if (curproxy->table->proxies_list != curproxy) {
1540 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1541 curproxy->table->proxies_list = curproxy;
1542 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001543 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001544 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001545 struct sticking_rule *rule;
1546 struct sample_expr *expr;
1547 int myidx = 0;
1548 const char *name = NULL;
1549 int flags;
1550
Willy Tarreau5d095c22021-02-12 10:15:59 +01001551 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001552 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1553 err_code |= ERR_ALERT | ERR_FATAL;
1554 goto out;
1555 }
1556
1557 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1558 err_code |= ERR_WARN;
1559 goto out;
1560 }
1561
1562 myidx++;
1563 if ((strcmp(args[myidx], "store") == 0) ||
1564 (strcmp(args[myidx], "store-request") == 0)) {
1565 myidx++;
1566 flags = STK_IS_STORE;
1567 }
1568 else if (strcmp(args[myidx], "store-response") == 0) {
1569 myidx++;
1570 flags = STK_IS_STORE | STK_ON_RSP;
1571 }
1572 else if (strcmp(args[myidx], "match") == 0) {
1573 myidx++;
1574 flags = STK_IS_MATCH;
1575 }
1576 else if (strcmp(args[myidx], "on") == 0) {
1577 myidx++;
1578 flags = STK_IS_MATCH | STK_IS_STORE;
1579 }
1580 else {
1581 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1582 err_code |= ERR_ALERT | ERR_FATAL;
1583 goto out;
1584 }
1585
1586 if (*(args[myidx]) == 0) {
1587 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1588 err_code |= ERR_ALERT | ERR_FATAL;
1589 goto out;
1590 }
1591
1592 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001593 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001594 if (!expr) {
1595 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1596 err_code |= ERR_ALERT | ERR_FATAL;
1597 goto out;
1598 }
1599
1600 if (flags & STK_ON_RSP) {
1601 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1602 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1603 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1604 err_code |= ERR_ALERT | ERR_FATAL;
1605 free(expr);
1606 goto out;
1607 }
1608 } else {
1609 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1610 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1611 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1612 err_code |= ERR_ALERT | ERR_FATAL;
1613 free(expr);
1614 goto out;
1615 }
1616 }
1617
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001618 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001619 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1620
1621 if (strcmp(args[myidx], "table") == 0) {
1622 myidx++;
1623 name = args[myidx++];
1624 }
1625
1626 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1627 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1628 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1629 file, linenum, args[0], errmsg);
1630 err_code |= ERR_ALERT | ERR_FATAL;
1631 free(expr);
1632 goto out;
1633 }
1634 }
1635 else if (*(args[myidx])) {
1636 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1637 file, linenum, args[0], args[myidx]);
1638 err_code |= ERR_ALERT | ERR_FATAL;
1639 free(expr);
1640 goto out;
1641 }
1642 if (flags & STK_ON_RSP)
1643 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1644 else
1645 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1646
1647 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001648 if (!rule) {
1649 if (cond)
1650 prune_acl_cond(cond);
1651 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001652 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001653 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001654 rule->cond = cond;
1655 rule->expr = expr;
1656 rule->flags = flags;
1657 rule->table.name = name ? strdup(name) : NULL;
1658 LIST_INIT(&rule->list);
1659 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001660 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001661 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001662 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001663 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001664 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001665 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001666 curproxy->uri_auth = NULL; /* we must detach from the default config */
1667
1668 if (!*args[1]) {
1669 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001670 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001671 struct stats_admin_rule *rule;
1672
Willy Tarreau5d095c22021-02-12 10:15:59 +01001673 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001674 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1675 err_code |= ERR_ALERT | ERR_FATAL;
1676 goto out;
1677 }
1678
Christopher Fauletb15625a2021-04-12 21:31:45 +02001679 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1680 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001681
1682 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1683 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1684 file, linenum, args[0], args[1]);
1685 err_code |= ERR_ALERT | ERR_FATAL;
1686 goto out;
1687 }
1688 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1689 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1690 file, linenum, args[0], args[1], errmsg);
1691 err_code |= ERR_ALERT | ERR_FATAL;
1692 goto out;
1693 }
1694
1695 err_code |= warnif_cond_conflicts(cond,
1696 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1697 file, linenum);
1698
1699 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001700 if (!rule) {
1701 if (cond)
1702 prune_acl_cond(cond);
1703 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001704 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001705 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706 rule->cond = cond;
1707 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001708 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001709 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001710 if (*(args[2]) == 0) {
1711 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1712 err_code |= ERR_ALERT | ERR_FATAL;
1713 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001714 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1715 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001716 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001717 if (*(args[2]) == 0) {
1718 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1719 err_code |= ERR_ALERT | ERR_FATAL;
1720 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001721 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1722 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001723 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001724 unsigned interval;
1725
1726 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001727 if (err == PARSE_TIME_OVER) {
1728 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1729 file, linenum, args[2]);
1730 err_code |= ERR_ALERT | ERR_FATAL;
1731 goto out;
1732 }
1733 else if (err == PARSE_TIME_UNDER) {
1734 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1735 file, linenum, args[2]);
1736 err_code |= ERR_ALERT | ERR_FATAL;
1737 goto out;
1738 }
1739 else if (err) {
1740 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001741 file, linenum, *err);
1742 err_code |= ERR_ALERT | ERR_FATAL;
1743 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001744 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1745 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001746 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001747 struct act_rule *rule;
1748
Willy Tarreau5d095c22021-02-12 10:15:59 +01001749 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001750 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1751 err_code |= ERR_ALERT | ERR_FATAL;
1752 goto out;
1753 }
1754
Christopher Fauletb15625a2021-04-12 21:31:45 +02001755 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1756 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001757
1758 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1759 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1760 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1761 file, linenum, args[0]);
1762 err_code |= ERR_WARN;
1763 }
1764
1765 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1766
1767 if (!rule) {
1768 err_code |= ERR_ALERT | ERR_ABORT;
1769 goto out;
1770 }
1771
1772 err_code |= warnif_cond_conflicts(rule->cond,
1773 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1774 file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001775 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001776
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001777 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001778 if (*(args[2]) == 0) {
1779 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1780 err_code |= ERR_ALERT | ERR_FATAL;
1781 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001782 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1783 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001784 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001785 if (*(args[2]) == 0) {
1786 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1787 err_code |= ERR_ALERT | ERR_FATAL;
1788 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001789 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1790 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001791 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001792 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1793 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001794 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001795 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1796 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001797 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001798 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1799 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001800 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001801 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1802 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001803 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001804
1805 if (*args[2]) {
1806 int i;
1807 char c;
1808
1809 for (i=0; args[2][i]; i++) {
1810 c = args[2][i];
1811 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1812 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1813 break;
1814 }
1815
1816 if (!i || args[2][i]) {
1817 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1818 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1819 file, linenum, args[0], args[1]);
1820 err_code |= ERR_ALERT | ERR_FATAL;
1821 goto out;
1822 }
1823 }
1824
Christopher Fauletb15625a2021-04-12 21:31:45 +02001825 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1826 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001827 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001828 char *desc = NULL;
1829
1830 if (*args[2]) {
1831 int i, len=0;
1832 char *d;
1833
1834 for (i = 2; *args[i]; i++)
1835 len += strlen(args[i]) + 1;
1836
1837 desc = d = calloc(1, len);
1838
1839 d += snprintf(d, desc + len - d, "%s", args[2]);
1840 for (i = 3; *args[i]; i++)
1841 d += snprintf(d, desc + len - d, " %s", args[i]);
1842 }
1843
1844 if (!*args[2] && !global.desc)
1845 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1846 file, linenum, args[1]);
1847 else {
1848 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1849 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001850 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001851 }
1852 free(desc);
1853 }
1854 } else {
1855stats_error_parsing:
1856 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1857 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1858 err_code |= ERR_ALERT | ERR_FATAL;
1859 goto out;
1860 }
1861 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001862 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001863 int optnum;
1864
1865 if (*(args[1]) == '\0') {
1866 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1867 file, linenum, args[0]);
1868 err_code |= ERR_ALERT | ERR_FATAL;
1869 goto out;
1870 }
1871
1872 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001873 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001874 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1875 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1876 file, linenum, cfg_opts[optnum].name);
1877 err_code |= ERR_ALERT | ERR_FATAL;
1878 goto out;
1879 }
1880 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1881 goto out;
1882
1883 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1884 err_code |= ERR_WARN;
1885 goto out;
1886 }
1887
1888 curproxy->no_options &= ~cfg_opts[optnum].val;
1889 curproxy->options &= ~cfg_opts[optnum].val;
1890
1891 switch (kwm) {
1892 case KWM_STD:
1893 curproxy->options |= cfg_opts[optnum].val;
1894 break;
1895 case KWM_NO:
1896 curproxy->no_options |= cfg_opts[optnum].val;
1897 break;
1898 case KWM_DEF: /* already cleared */
1899 break;
1900 }
1901
1902 goto out;
1903 }
1904 }
1905
1906 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001907 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001908 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1909 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1910 file, linenum, cfg_opts2[optnum].name);
1911 err_code |= ERR_ALERT | ERR_FATAL;
1912 goto out;
1913 }
1914 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1915 goto out;
1916 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1917 err_code |= ERR_WARN;
1918 goto out;
1919 }
1920
1921 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1922 curproxy->options2 &= ~cfg_opts2[optnum].val;
1923
1924 switch (kwm) {
1925 case KWM_STD:
1926 curproxy->options2 |= cfg_opts2[optnum].val;
1927 break;
1928 case KWM_NO:
1929 curproxy->no_options2 |= cfg_opts2[optnum].val;
1930 break;
1931 case KWM_DEF: /* already cleared */
1932 break;
1933 }
1934 goto out;
1935 }
1936 }
1937
1938 /* HTTP options override each other. They can be cancelled using
1939 * "no option xxx" which only switches to default mode if the mode
1940 * was this one (useful for cancelling options set in defaults
1941 * sections).
1942 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001943 if (strcmp(args[1], "forceclose") == 0) {
1944 ha_alert("parsing [%s:%d]: option '%s' is not supported any more since HAProxy 2.0, please just remove it, or use 'option httpclose' if absolutely needed.\n",
1945 file, linenum, args[1]);
1946 err_code |= ERR_ALERT | ERR_FATAL;
1947 goto out;
1948 }
1949 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001950 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1951 goto out;
1952 if (kwm == KWM_STD) {
1953 curproxy->options &= ~PR_O_HTTP_MODE;
1954 curproxy->options |= PR_O_HTTP_CLO;
1955 goto out;
1956 }
1957 else if (kwm == KWM_NO) {
1958 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1959 curproxy->options &= ~PR_O_HTTP_MODE;
1960 goto out;
1961 }
1962 }
1963 else if (strcmp(args[1], "http-server-close") == 0) {
1964 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1965 goto out;
1966 if (kwm == KWM_STD) {
1967 curproxy->options &= ~PR_O_HTTP_MODE;
1968 curproxy->options |= PR_O_HTTP_SCL;
1969 goto out;
1970 }
1971 else if (kwm == KWM_NO) {
1972 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1973 curproxy->options &= ~PR_O_HTTP_MODE;
1974 goto out;
1975 }
1976 }
1977 else if (strcmp(args[1], "http-keep-alive") == 0) {
1978 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1979 goto out;
1980 if (kwm == KWM_STD) {
1981 curproxy->options &= ~PR_O_HTTP_MODE;
1982 curproxy->options |= PR_O_HTTP_KAL;
1983 goto out;
1984 }
1985 else if (kwm == KWM_NO) {
1986 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1987 curproxy->options &= ~PR_O_HTTP_MODE;
1988 goto out;
1989 }
1990 }
1991 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02001992 ha_alert("parsing [%s:%d]: option '%s' is not supported any more since HAProxy 2.1, please just remove it, it shouldn't be needed.\n",
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001993 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02001994 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001995 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001996 }
1997
1998 /* Redispatch can take an integer argument that control when the
1999 * resispatch occurs. All values are relative to the retries option.
2000 * This can be cancelled using "no option xxx".
2001 */
2002 if (strcmp(args[1], "redispatch") == 0) {
2003 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2004 err_code |= ERR_WARN;
2005 goto out;
2006 }
2007
2008 curproxy->no_options &= ~PR_O_REDISP;
2009 curproxy->options &= ~PR_O_REDISP;
2010
2011 switch (kwm) {
2012 case KWM_STD:
2013 curproxy->options |= PR_O_REDISP;
2014 curproxy->redispatch_after = -1;
2015 if(*args[2]) {
2016 curproxy->redispatch_after = atol(args[2]);
2017 }
2018 break;
2019 case KWM_NO:
2020 curproxy->no_options |= PR_O_REDISP;
2021 curproxy->redispatch_after = 0;
2022 break;
2023 case KWM_DEF: /* already cleared */
2024 break;
2025 }
2026 goto out;
2027 }
2028
Willy Tarreau25241232021-07-18 19:18:56 +02002029 if (strcmp(args[1], "http_proxy") == 0) {
2030 ha_alert("parsing [%s:%d]: option '%s' is not supported any more since HAProxy 2.5. This option stopped working in HAProxy 1.9 and usually had nasty side effects. It can be more reliably implemented with combinations of 'http-request set-dst' and 'http-request set-uri', and even 'http-request do-resolve' if DNS resolution is desired.\n",
2031 file, linenum, args[1]);
2032 err_code |= ERR_ALERT | ERR_FATAL;
2033 goto out;
2034 }
2035
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002036 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";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002069 else if (curproxy->conf.logformat_string == default_https_log_format)
2070 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002071 if (logformat == clf_http_log_format)
2072 clflogformat = " clf";
2073 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2074 file, linenum, clflogformat, oldlogformat);
2075 }
2076 if (curproxy->conf.logformat_string != default_http_log_format &&
2077 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002078 curproxy->conf.logformat_string != clf_http_log_format &&
2079 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002080 free(curproxy->conf.logformat_string);
2081 curproxy->conf.logformat_string = logformat;
2082
2083 free(curproxy->conf.lfs_file);
2084 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2085 curproxy->conf.lfs_line = curproxy->conf.args.line;
2086
Willy Tarreau5d095c22021-02-12 10:15:59 +01002087 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002088 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2089 file, linenum, curproxy->id);
2090 err_code |= ERR_WARN;
2091 }
2092 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002093 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002094 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002095 char *oldlogformat = "log-format";
2096
2097 if (curproxy->conf.logformat_string == default_http_log_format)
2098 oldlogformat = "option httplog";
2099 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2100 oldlogformat = "option tcplog";
2101 else if (curproxy->conf.logformat_string == clf_http_log_format)
2102 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002103 else if (curproxy->conf.logformat_string == default_https_log_format)
2104 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002105 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2106 file, linenum, oldlogformat);
2107 }
2108 /* generate a detailed TCP log */
2109 if (curproxy->conf.logformat_string != default_http_log_format &&
2110 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002111 curproxy->conf.logformat_string != clf_http_log_format &&
2112 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002113 free(curproxy->conf.logformat_string);
2114 curproxy->conf.logformat_string = default_tcp_log_format;
2115
2116 free(curproxy->conf.lfs_file);
2117 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2118 curproxy->conf.lfs_line = curproxy->conf.args.line;
2119
2120 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2121 goto out;
2122
Willy Tarreau5d095c22021-02-12 10:15:59 +01002123 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002124 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2125 file, linenum, curproxy->id);
2126 err_code |= ERR_WARN;
2127 }
2128 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002129 else if (strcmp(args[1], "httpslog") == 0) {
2130 char *logformat;
2131 /* generate a complete HTTP log */
2132 logformat = default_https_log_format;
2133 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2134 char *oldlogformat = "log-format";
2135
2136 if (curproxy->conf.logformat_string == default_http_log_format)
2137 oldlogformat = "option httplog";
2138 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2139 oldlogformat = "option tcplog";
2140 else if (curproxy->conf.logformat_string == clf_http_log_format)
2141 oldlogformat = "option httplog clf";
2142 else if (curproxy->conf.logformat_string == default_https_log_format)
2143 oldlogformat = "option httpslog";
2144 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2145 file, linenum, oldlogformat);
2146 }
2147 if (curproxy->conf.logformat_string != default_http_log_format &&
2148 curproxy->conf.logformat_string != default_tcp_log_format &&
2149 curproxy->conf.logformat_string != clf_http_log_format &&
2150 curproxy->conf.logformat_string != default_https_log_format)
2151 free(curproxy->conf.logformat_string);
2152 curproxy->conf.logformat_string = logformat;
2153
2154 free(curproxy->conf.lfs_file);
2155 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2156 curproxy->conf.lfs_line = curproxy->conf.args.line;
2157
2158 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2159 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2160 file, linenum, curproxy->id);
2161 err_code |= ERR_WARN;
2162 }
2163 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002164 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002165 /* enable TCP keep-alives on client and server streams */
2166 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2167 err_code |= ERR_WARN;
2168
2169 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2170 goto out;
2171
2172 if (curproxy->cap & PR_CAP_FE)
2173 curproxy->options |= PR_O_TCP_CLI_KA;
2174 if (curproxy->cap & PR_CAP_BE)
2175 curproxy->options |= PR_O_TCP_SRV_KA;
2176 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002177 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002178 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002179 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002180 goto out;
2181 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002182 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002183 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002184 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002185 goto out;
2186 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002187 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002188 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002189 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002190 goto out;
2191 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002192 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002193 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002194 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002195 goto out;
2196 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002197 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002198 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002199 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002200 goto out;
2201 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002202 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002203 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002204 if (err_code & ERR_FATAL)
2205 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002206 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002207 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002208 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002209 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002210 goto out;
2211 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002212 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002213 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002214 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002215 goto out;
2216 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002217 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002218 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002219 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002220 goto out;
2221 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002222 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002223 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002224 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002225 goto out;
2226 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002227 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002228 int cur_arg;
2229
2230 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002231 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002232 */
2233
2234 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2235
2236 free(curproxy->fwdfor_hdr_name);
2237 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002238 if (!curproxy->fwdfor_hdr_name)
2239 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002240 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002241 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002242
2243 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2244 cur_arg = 2;
2245 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002246 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002247 unsigned char mask;
2248 int i;
2249
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002250 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002251 if (*(args[cur_arg+1]) &&
2252 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2253 curproxy->except_xff_net.family = AF_INET;
2254 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2255 }
2256 else if (*(args[cur_arg+1]) &&
2257 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2258 curproxy->except_xff_net.family = AF_INET6;
2259 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2260 for (i = 0; i < 16; i++)
2261 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2262 }
2263 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002264 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2265 file, linenum, args[0], args[1], args[cur_arg]);
2266 err_code |= ERR_ALERT | ERR_FATAL;
2267 goto out;
2268 }
2269 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002270 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002271 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002272 /* suboption header - needs additional argument for it */
2273 if (*(args[cur_arg+1]) == 0) {
2274 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2275 file, linenum, args[0], args[1], args[cur_arg]);
2276 err_code |= ERR_ALERT | ERR_FATAL;
2277 goto out;
2278 }
2279 free(curproxy->fwdfor_hdr_name);
2280 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002281 if (!curproxy->fwdfor_hdr_name)
2282 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002283 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2284 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002285 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002286 curproxy->options &= ~PR_O_FF_ALWAYS;
2287 cur_arg += 1;
2288 } else {
2289 /* unknown suboption - catchall */
2290 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2291 file, linenum, args[0], args[1]);
2292 err_code |= ERR_ALERT | ERR_FATAL;
2293 goto out;
2294 }
2295 } /* end while loop */
2296 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002297 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002298 int cur_arg;
2299
2300 /* insert x-original-to field, but not for the IP address listed as an except.
2301 * set default options (ie: bitfield, header name, etc)
2302 */
2303
2304 curproxy->options |= PR_O_ORGTO;
2305
2306 free(curproxy->orgto_hdr_name);
2307 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002308 if (!curproxy->orgto_hdr_name)
2309 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002310 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002311 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002312
2313 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2314 cur_arg = 2;
2315 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002316 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002317 unsigned char mask;
2318 int i;
2319
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002320 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002321 if (*(args[cur_arg+1]) &&
2322 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2323 curproxy->except_xot_net.family = AF_INET;
2324 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2325 }
2326 else if (*(args[cur_arg+1]) &&
2327 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2328 curproxy->except_xot_net.family = AF_INET6;
2329 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2330 for (i = 0; i < 16; i++)
2331 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2332 }
2333 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002334 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2335 file, linenum, args[0], args[1], args[cur_arg]);
2336 err_code |= ERR_ALERT | ERR_FATAL;
2337 goto out;
2338 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002339 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002340 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002341 /* suboption header - needs additional argument for it */
2342 if (*(args[cur_arg+1]) == 0) {
2343 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2344 file, linenum, args[0], args[1], args[cur_arg]);
2345 err_code |= ERR_ALERT | ERR_FATAL;
2346 goto out;
2347 }
2348 free(curproxy->orgto_hdr_name);
2349 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002350 if (!curproxy->orgto_hdr_name)
2351 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002352 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2353 cur_arg += 2;
2354 } else {
2355 /* unknown suboption - catchall */
2356 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2357 file, linenum, args[0], args[1]);
2358 err_code |= ERR_ALERT | ERR_FATAL;
2359 goto out;
2360 }
2361 } /* end while loop */
2362 }
2363 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002364 const char *best = proxy_find_best_option(args[1], common_options);
2365
2366 if (best)
2367 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2368 else
2369 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2370
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002371 err_code |= ERR_ALERT | ERR_FATAL;
2372 goto out;
2373 }
2374 goto out;
2375 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002376 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002377 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2378 err_code |= ERR_WARN;
2379
2380 if (*(args[1]) == 0) {
2381 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2382 err_code |= ERR_ALERT | ERR_FATAL;
2383 goto out;
2384 }
2385 free(curproxy->defbe.name);
2386 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002387 if (!curproxy->defbe.name)
2388 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002389
2390 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2391 goto out;
2392 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002393 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002394 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 +01002395
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002396 err_code |= ERR_ALERT | ERR_FATAL;
2397 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002398 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002399 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002400 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2401 err_code |= ERR_WARN;
2402
2403 if (strcmp(args[1], "never") == 0) {
2404 /* enable a graceful server shutdown on an HTTP 404 response */
2405 curproxy->options &= ~PR_O_REUSE_MASK;
2406 curproxy->options |= PR_O_REUSE_NEVR;
2407 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2408 goto out;
2409 }
2410 else if (strcmp(args[1], "safe") == 0) {
2411 /* enable a graceful server shutdown on an HTTP 404 response */
2412 curproxy->options &= ~PR_O_REUSE_MASK;
2413 curproxy->options |= PR_O_REUSE_SAFE;
2414 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2415 goto out;
2416 }
2417 else if (strcmp(args[1], "aggressive") == 0) {
2418 curproxy->options &= ~PR_O_REUSE_MASK;
2419 curproxy->options |= PR_O_REUSE_AGGR;
2420 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2421 goto out;
2422 }
2423 else if (strcmp(args[1], "always") == 0) {
2424 /* enable a graceful server shutdown on an HTTP 404 response */
2425 curproxy->options &= ~PR_O_REUSE_MASK;
2426 curproxy->options |= PR_O_REUSE_ALWS;
2427 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2428 goto out;
2429 }
2430 else {
2431 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2432 err_code |= ERR_ALERT | ERR_FATAL;
2433 goto out;
2434 }
2435 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002436 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002437 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002438 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2439 err_code |= ERR_ALERT | ERR_FATAL;
2440 goto out;
2441 }
2442
2443 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2444 err_code |= ERR_WARN;
2445
2446 if (strcmp(args[1], "fail") == 0) {
2447 /* add a condition to fail monitor requests */
2448 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2449 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2450 file, linenum, args[0], args[1]);
2451 err_code |= ERR_ALERT | ERR_FATAL;
2452 goto out;
2453 }
2454
2455 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2456 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2457 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2458 file, linenum, args[0], args[1], errmsg);
2459 err_code |= ERR_ALERT | ERR_FATAL;
2460 goto out;
2461 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002462 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002463 }
2464 else {
2465 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2466 err_code |= ERR_ALERT | ERR_FATAL;
2467 goto out;
2468 }
2469 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002470#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002471 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002472 /* enable transparent proxy connections */
2473 curproxy->options |= PR_O_TRANSP;
2474 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2475 goto out;
2476 }
2477#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002478 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002479 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2480 err_code |= ERR_WARN;
2481
2482 if (*(args[1]) == 0) {
2483 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2484 err_code |= ERR_ALERT | ERR_FATAL;
2485 goto out;
2486 }
2487 curproxy->maxconn = atol(args[1]);
2488 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2489 goto out;
2490 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002491 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002492 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2493 err_code |= ERR_WARN;
2494
2495 if (*(args[1]) == 0) {
2496 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2497 err_code |= ERR_ALERT | ERR_FATAL;
2498 goto out;
2499 }
2500 curproxy->backlog = atol(args[1]);
2501 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2502 goto out;
2503 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002504 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002505 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2506 err_code |= ERR_WARN;
2507
2508 if (*(args[1]) == 0) {
2509 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2510 err_code |= ERR_ALERT | ERR_FATAL;
2511 goto out;
2512 }
2513 curproxy->fullconn = atol(args[1]);
2514 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2515 goto out;
2516 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002517 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002518 ha_alert("parsing [%s:%d]: the '%s' keyword is not supported any more since HAProxy version 2.5.\n",
Willy Tarreauab0a5192020-10-09 19:07:01 +02002519 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002520 err_code |= ERR_ALERT | ERR_FATAL;
2521 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002522 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002523 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002524 struct sockaddr_storage *sk;
2525 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002526
Willy Tarreau5d095c22021-02-12 10:15:59 +01002527 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002528 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2529 err_code |= ERR_ALERT | ERR_FATAL;
2530 goto out;
2531 }
2532 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2533 err_code |= ERR_WARN;
2534
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002535 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2536 &errmsg, NULL, NULL,
2537 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 +01002538 if (!sk) {
2539 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2540 err_code |= ERR_ALERT | ERR_FATAL;
2541 goto out;
2542 }
2543
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002544 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2545 goto out;
2546
2547 curproxy->dispatch_addr = *sk;
2548 curproxy->options |= PR_O_DISPATCH;
2549 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002550 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002551 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2552 err_code |= ERR_WARN;
2553
2554 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2555 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2556 err_code |= ERR_ALERT | ERR_FATAL;
2557 goto out;
2558 }
2559 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002560 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002561 /**
2562 * The syntax for hash-type config element is
2563 * hash-type {map-based|consistent} [[<algo>] avalanche]
2564 *
2565 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2566 */
2567 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2568
2569 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2570 err_code |= ERR_WARN;
2571
2572 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2573 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2574 }
2575 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2576 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2577 }
2578 else if (strcmp(args[1], "avalanche") == 0) {
2579 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]);
2580 err_code |= ERR_ALERT | ERR_FATAL;
2581 goto out;
2582 }
2583 else {
2584 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2585 err_code |= ERR_ALERT | ERR_FATAL;
2586 goto out;
2587 }
2588
2589 /* set the hash function to use */
2590 if (!*args[2]) {
2591 /* the default algo is sdbm */
2592 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2593
2594 /* if consistent with no argument, then avalanche modifier is also applied */
2595 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2596 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2597 } else {
2598 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002599 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002600 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2601 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002602 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002603 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2604 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002605 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002606 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2607 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002608 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002609 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2610 }
2611 else {
2612 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2613 err_code |= ERR_ALERT | ERR_FATAL;
2614 goto out;
2615 }
2616
2617 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002618 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002619 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2620 }
2621 else if (*args[3]) {
2622 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2623 err_code |= ERR_ALERT | ERR_FATAL;
2624 goto out;
2625 }
2626 }
2627 }
2628 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2629 if (*(args[1]) == 0) {
2630 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2631 err_code |= ERR_ALERT | ERR_FATAL;
2632 goto out;
2633 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002634 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2635 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002636 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2637 err_code |= ERR_ALERT | ERR_FATAL;
2638 goto out;
2639 }
2640 }
2641 else if (strcmp(args[0], "unique-id-format") == 0) {
2642 if (!*(args[1])) {
2643 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2644 err_code |= ERR_ALERT | ERR_FATAL;
2645 goto out;
2646 }
2647 if (*(args[2])) {
2648 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2649 err_code |= ERR_ALERT | ERR_FATAL;
2650 goto out;
2651 }
2652 free(curproxy->conf.uniqueid_format_string);
2653 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002654 if (!curproxy->conf.uniqueid_format_string)
2655 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002656
2657 free(curproxy->conf.uif_file);
2658 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2659 curproxy->conf.uif_line = curproxy->conf.args.line;
2660 }
2661
2662 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002663 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002664 if (!*(args[1])) {
2665 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2666 err_code |= ERR_ALERT | ERR_FATAL;
2667 goto out;
2668 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002669 copy = strdup(args[1]);
2670 if (copy == NULL) {
2671 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2672 err_code |= ERR_ALERT | ERR_FATAL;
2673 goto out;
2674 }
2675
2676 istfree(&curproxy->header_unique_id);
2677 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002678 }
2679
2680 else if (strcmp(args[0], "log-format") == 0) {
2681 if (!*(args[1])) {
2682 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2683 err_code |= ERR_ALERT | ERR_FATAL;
2684 goto out;
2685 }
2686 if (*(args[2])) {
2687 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2688 err_code |= ERR_ALERT | ERR_FATAL;
2689 goto out;
2690 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002691 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002692 char *oldlogformat = "log-format";
2693
2694 if (curproxy->conf.logformat_string == default_http_log_format)
2695 oldlogformat = "option httplog";
2696 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2697 oldlogformat = "option tcplog";
2698 else if (curproxy->conf.logformat_string == clf_http_log_format)
2699 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002700 else if (curproxy->conf.logformat_string == default_https_log_format)
2701 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002702 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2703 file, linenum, oldlogformat);
2704 }
2705 if (curproxy->conf.logformat_string != default_http_log_format &&
2706 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002707 curproxy->conf.logformat_string != clf_http_log_format &&
2708 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002709 free(curproxy->conf.logformat_string);
2710 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002711 if (!curproxy->conf.logformat_string)
2712 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002713
2714 free(curproxy->conf.lfs_file);
2715 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2716 curproxy->conf.lfs_line = curproxy->conf.args.line;
2717
2718 /* get a chance to improve log-format error reporting by
2719 * reporting the correct line-number when possible.
2720 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002721 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002722 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2723 file, linenum, curproxy->id);
2724 err_code |= ERR_WARN;
2725 }
2726 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002727 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002728 if (!*(args[1])) {
2729 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2730 err_code |= ERR_ALERT | ERR_FATAL;
2731 goto out;
2732 }
2733 if (*(args[2])) {
2734 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2735 err_code |= ERR_ALERT | ERR_FATAL;
2736 goto out;
2737 }
2738
2739 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2740 free(curproxy->conf.logformat_sd_string);
2741 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002742 if (!curproxy->conf.logformat_sd_string)
2743 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002744
2745 free(curproxy->conf.lfsd_file);
2746 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2747 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2748
2749 /* get a chance to improve log-format-sd error reporting by
2750 * reporting the correct line-number when possible.
2751 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002752 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002753 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2754 file, linenum, curproxy->id);
2755 err_code |= ERR_WARN;
2756 }
2757 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002758 else if (strcmp(args[0], "error-log-format") == 0) {
2759 if (!*(args[1])) {
2760 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2761 err_code |= ERR_ALERT | ERR_FATAL;
2762 goto out;
2763 }
2764 if (*(args[2])) {
2765 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2766 err_code |= ERR_ALERT | ERR_FATAL;
2767 goto out;
2768 }
2769 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2770 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2771 file, linenum);
2772 }
2773 free(curproxy->conf.error_logformat_string);
2774 curproxy->conf.error_logformat_string = strdup(args[1]);
2775 if (!curproxy->conf.error_logformat_string)
2776 goto alloc_error;
2777
2778 free(curproxy->conf.elfs_file);
2779 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2780 curproxy->conf.elfs_line = curproxy->conf.args.line;
2781
2782 /* get a chance to improve log-format error reporting by
2783 * reporting the correct line-number when possible.
2784 */
2785 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2786 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2787 file, linenum, curproxy->id);
2788 err_code |= ERR_WARN;
2789 }
2790 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002791 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002792 if (*(args[1]) == 0) {
2793 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2794 err_code |= ERR_ALERT | ERR_FATAL;
2795 goto out;
2796 }
2797 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002798 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2799 if (b_orig(&curproxy->log_tag) == NULL) {
2800 chunk_destroy(&curproxy->log_tag);
2801 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2802 err_code |= ERR_ALERT | ERR_FATAL;
2803 goto out;
2804 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002805 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002806 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002807 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002808 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2809 err_code |= ERR_ALERT | ERR_FATAL;
2810 goto out;
2811 }
2812 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002813 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002814 int cur_arg;
2815 int port1, port2;
2816 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002817
2818 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2819 err_code |= ERR_WARN;
2820
2821 if (!*args[1]) {
2822 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2823 file, linenum, "source", "usesrc", "interface");
2824 err_code |= ERR_ALERT | ERR_FATAL;
2825 goto out;
2826 }
2827
Christopher Faulet31930372019-07-15 10:16:58 +02002828 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002829 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002830 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002831 curproxy->conn_src.iface_len = 0;
2832
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002833 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2834 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002835 if (!sk) {
2836 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2837 file, linenum, args[0], args[1], errmsg);
2838 err_code |= ERR_ALERT | ERR_FATAL;
2839 goto out;
2840 }
2841
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002842 curproxy->conn_src.source_addr = *sk;
2843 curproxy->conn_src.opts |= CO_SRC_BIND;
2844
2845 cur_arg = 2;
2846 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002847 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002848#if defined(CONFIG_HAP_TRANSPARENT)
2849 if (!*args[cur_arg + 1]) {
2850 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2851 file, linenum, "usesrc");
2852 err_code |= ERR_ALERT | ERR_FATAL;
2853 goto out;
2854 }
2855
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002856 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002857 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2858 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002859 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002860 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2861 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2862 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2863 char *name, *end;
2864
2865 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002866 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002867 name++;
2868
2869 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002870 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002871 end++;
2872
2873 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2874 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002875 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002876 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002877 if (!curproxy->conn_src.bind_hdr_name)
2878 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002879 curproxy->conn_src.bind_hdr_len = end - name;
2880 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2881 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2882 curproxy->conn_src.bind_hdr_occ = -1;
2883
2884 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002885 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002886 end++;
2887 if (*end == ',') {
2888 end++;
2889 name = end;
2890 if (*end == '-')
2891 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002892 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002893 end++;
2894 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2895 }
2896
2897 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2898 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2899 " occurrences values smaller than %d.\n",
2900 file, linenum, MAX_HDR_HISTORY);
2901 err_code |= ERR_ALERT | ERR_FATAL;
2902 goto out;
2903 }
2904 } else {
2905 struct sockaddr_storage *sk;
2906
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002907 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2908 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002909 if (!sk) {
2910 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2911 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2912 err_code |= ERR_ALERT | ERR_FATAL;
2913 goto out;
2914 }
2915
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002916 curproxy->conn_src.tproxy_addr = *sk;
2917 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2918 }
2919 global.last_checks |= LSTCHK_NETADM;
2920#else /* no TPROXY support */
2921 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2922 file, linenum, "usesrc");
2923 err_code |= ERR_ALERT | ERR_FATAL;
2924 goto out;
2925#endif
2926 cur_arg += 2;
2927 continue;
2928 }
2929
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002930 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002931#ifdef SO_BINDTODEVICE
2932 if (!*args[cur_arg + 1]) {
2933 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2934 file, linenum, args[0]);
2935 err_code |= ERR_ALERT | ERR_FATAL;
2936 goto out;
2937 }
2938 free(curproxy->conn_src.iface_name);
2939 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002940 if (!curproxy->conn_src.iface_name)
2941 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002942 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2943 global.last_checks |= LSTCHK_NETADM;
2944#else
2945 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2946 file, linenum, args[0], args[cur_arg]);
2947 err_code |= ERR_ALERT | ERR_FATAL;
2948 goto out;
2949#endif
2950 cur_arg += 2;
2951 continue;
2952 }
2953 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2954 file, linenum, args[0], "interface", "usesrc");
2955 err_code |= ERR_ALERT | ERR_FATAL;
2956 goto out;
2957 }
2958 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002959 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002960 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2961 file, linenum, "usesrc", "source");
2962 err_code |= ERR_ALERT | ERR_FATAL;
2963 goto out;
2964 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002965 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 +02002966 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002967 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002968 file, linenum, args[0]);
2969 err_code |= ERR_ALERT | ERR_FATAL;
2970 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002972 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002973 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2974 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2975 err_code |= ERR_ALERT | ERR_FATAL;
2976 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002977 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002978 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002979 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2980 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2981 err_code |= ERR_ALERT | ERR_FATAL;
2982 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002983 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002984 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002985 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2986 err_code |= ERR_ALERT | ERR_FATAL;
2987 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002988 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002989 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002990 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2991 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2992 err_code |= ERR_ALERT | ERR_FATAL;
2993 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002994 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002995 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002996 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2997 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2998 err_code |= ERR_ALERT | ERR_FATAL;
2999 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003000 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003001 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003002 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3003 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3004 err_code |= ERR_ALERT | ERR_FATAL;
3005 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003006 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003007 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003008 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3009 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3010 err_code |= ERR_ALERT | ERR_FATAL;
3011 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003012 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003013 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 +02003014 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3015 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3016 err_code |= ERR_ALERT | ERR_FATAL;
3017 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003018 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003019 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003020 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3021 err_code |= ERR_ALERT | ERR_FATAL;
3022 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003023 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003024 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 +02003025 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3026 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3027 err_code |= ERR_ALERT | ERR_FATAL;
3028 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003029 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003030 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 +02003031 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3032 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3033 err_code |= ERR_ALERT | ERR_FATAL;
3034 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003035 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003036 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003037 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3038 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3039 err_code |= ERR_ALERT | ERR_FATAL;
3040 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003041 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003042 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 +02003043 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3044 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3045 err_code |= ERR_ALERT | ERR_FATAL;
3046 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003047 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003048 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003049 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3050 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3051 err_code |= ERR_ALERT | ERR_FATAL;
3052 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003053 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003054 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003055 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3056 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3057 err_code |= ERR_ALERT | ERR_FATAL;
3058 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003059 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003060 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303061 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003062 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3063 err_code |= ERR_ALERT | ERR_FATAL;
3064 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003065 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003066 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003067 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3068 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3069 err_code |= ERR_ALERT | ERR_FATAL;
3070 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003071 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003072 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003073 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3074 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3075 err_code |= ERR_ALERT | ERR_FATAL;
3076 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003077 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003078 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003079 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3080 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3081 err_code |= ERR_ALERT | ERR_FATAL;
3082 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003083 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003084 else {
3085 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003086 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003087 int index;
3088
3089 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3090 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3091 if (kwl->kw[index].section != CFG_LISTEN)
3092 continue;
3093 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003094 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003095 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003096 err_code |= ERR_ALERT | ERR_FATAL;
3097 goto out;
3098 }
3099
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003100 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003101 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003102 if (rc < 0) {
3103 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3104 err_code |= ERR_ALERT | ERR_FATAL;
3105 goto out;
3106 }
3107 else if (rc > 0) {
3108 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3109 err_code |= ERR_WARN;
3110 goto out;
3111 }
3112 goto out;
3113 }
3114 }
3115 }
3116
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003117 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3118 if (best)
3119 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3120 else
3121 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003122 err_code |= ERR_ALERT | ERR_FATAL;
3123 goto out;
3124 }
3125 out:
3126 free(errmsg);
3127 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003128
3129 alloc_error:
3130 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3131 err_code |= ERR_ALERT | ERR_ABORT;
3132 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003133}