blob: 485b0b36c3d6b306c20b144619b7a9ed4e2c7487 [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>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010011#include <unistd.h>
12
Willy Tarreaudcc048a2020-06-04 19:11:43 +020013#include <haproxy/acl.h>
Eric Salama7cea6062020-10-02 11:58:19 +020014#include <haproxy/buf.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020015#include <haproxy/capture-t.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020016#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020017#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020018#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020019#include <haproxy/connection.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020020#include <haproxy/extcheck.h>
Willy Tarreaub7fc4c42021-10-06 18:56:42 +020021#include <haproxy/http_ana.h>
Willy Tarreau87735332020-06-04 09:08:41 +020022#include <haproxy/http_htx.h>
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +010023#include <haproxy/http_ext.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",
Willy Tarreau94f763b2022-07-15 17:14:40 +020045 "acl", "dynamic-cookie-key", "cookie", "email-alert",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010046 "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",
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +010065 "external-check", "forwardfor", "original-to", "forwarded",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010066 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 */
Willy Tarreaue90904d2021-02-12 14:08:31 +0100235 curr_defproxy = NULL;
236 rc = PR_CAP_DEF | PR_CAP_LISTEN;
237 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100238 else
239 rc = PR_CAP_NONE;
240
Willy Tarreaue90904d2021-02-12 14:08:31 +0100241 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100242 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100243 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100244 file, linenum, args[0]);
245 err_code |= ERR_ALERT | ERR_ABORT;
246 goto out;
247 }
248
249 err = invalid_char(args[1]);
250 if (err) {
251 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
252 file, linenum, *err, args[0], args[1]);
253 err_code |= ERR_ALERT | ERR_FATAL;
254 }
255
256 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
257 if (curproxy) {
258 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
259 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
260 curproxy->id, curproxy->conf.file, curproxy->conf.line);
261 err_code |= ERR_ALERT | ERR_FATAL;
262 }
263
Emeric Brunb0c331f2020-10-07 17:05:59 +0200264 curproxy = log_forward_by_name(args[1]);
265 if (curproxy) {
266 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
267 file, linenum, proxy_cap_str(rc), args[1],
268 curproxy->id, curproxy->conf.file, curproxy->conf.line);
269 err_code |= ERR_ALERT | ERR_FATAL;
270 }
271
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100272 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
273 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100274 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100275 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
276 goto out;
277 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100278 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100279
Willy Tarreaue90904d2021-02-12 14:08:31 +0100280 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100281 const char *name = args[1];
282 int arg = 2;
283
284 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
285 // also support "defaults from blah" (no name then)
286 arg = 1;
287 name = "";
288 }
289
290 /* only regular proxies inherit from the previous defaults section */
291 if (!(rc & PR_CAP_DEF))
292 curr_defproxy = last_defproxy;
293
294 if (strcmp(args[arg], "from") == 0) {
Aurelien DARRAGON9dce88b2022-11-21 17:01:11 +0100295 struct ebpt_node *next_by_name;
296
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100297 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
298
299 if (!curr_defproxy) {
300 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
301 err_code |= ERR_ALERT | ERR_ABORT;
302 goto out;
303 }
304
Aurelien DARRAGON9dce88b2022-11-21 17:01:11 +0100305 if ((next_by_name = ebpt_next_dup(&curr_defproxy->conf.by_name))) {
306 struct proxy *px2 = container_of(next_by_name, struct proxy, conf.by_name);
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100307
308 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
309 file, linenum, args[arg+1], proxy_cap_str(rc), name,
310 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
311 err_code |= ERR_ALERT | ERR_FATAL;
312 }
313
314 err = invalid_char(args[arg+1]);
315 if (err) {
316 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",
317 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
318 err_code |= ERR_ALERT | ERR_FATAL;
319 }
Christopher Fauletb4054202021-10-12 18:57:43 +0200320 curr_defproxy->flags |= PR_FL_EXPLICIT_REF;
321 }
322 else if (curr_defproxy)
323 curr_defproxy->flags |= PR_FL_IMPLICIT_REF;
324
325 if (curr_defproxy && (curr_defproxy->flags & (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) == (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) {
326 ha_alert("parsing [%s:%d] : defaults section '%s' (declared at %s:%d) is explicitly referenced by another proxy and implicitly used here."
327 " To avoid any ambiguity don't mix both usage. Add a last defaults section not explicitly used or always use explicit references.\n",
328 file, linenum, curr_defproxy->id, curr_defproxy->conf.file, curr_defproxy->conf.line);
329 err_code |= ERR_WARN;
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100330 }
331
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100332 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100333 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100334 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100335 goto out;
336 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100337
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200338 if (curr_defproxy && (!LIST_ISEMPTY(&curr_defproxy->http_req_rules) ||
339 !LIST_ISEMPTY(&curr_defproxy->http_res_rules) ||
340 !LIST_ISEMPTY(&curr_defproxy->http_after_res_rules) ||
341 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
342 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules) ||
343 !LIST_ISEMPTY(&curr_defproxy->tcp_req.inspect_rules) ||
344 !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules))) {
345 /* If the current default proxy defines TCP/HTTP rules, the
346 * current proxy will keep a reference on it. But some sanity
347 * checks are performed first:
348 *
349 * - It cannot be used to init a defaults section
350 * - It cannot be used to init a listen section
351 * - It cannot be used to init backend and frontend sections at
352 * same time. It can be used to init several sections of the
353 * same type only.
354 * - It cannot define L4/L5 TCP rules if it is used to init
355 * backend sections.
356 * - It cannot define 'tcp-response content' rules if it
357 * is used to init frontend sections.
358 *
359 * If no error is found, refcount of the default proxy is incremented.
360 */
361
362 /* Note: Add tcpcheck_rules too if unresolve args become allowed in defaults section */
363 if (rc & PR_CAP_DEF) {
364 ha_alert("parsing [%s:%d]: a defaults section cannot inherit from a defaults section defining TCP/HTTP rules (defaults section at %s:%d).\n",
365 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
366 err_code |= ERR_ALERT | ERR_ABORT;
367 }
368 else if ((rc & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
369 ha_alert("parsing [%s:%d]: a listen section cannot inherit from a defaults section defining TCP/HTTP rules.\n",
370 file, linenum);
371 err_code |= ERR_ALERT | ERR_ABORT;
372 }
373 else {
374 char defcap = (curr_defproxy->cap & PR_CAP_LISTEN);
375
376 if ((defcap == PR_CAP_BE || defcap == PR_CAP_FE) && (rc & PR_CAP_LISTEN) != defcap) {
377 ha_alert("parsing [%s:%d]: frontends and backends cannot inherit from the same defaults section"
378 " if it defines TCP/HTTP rules (defaults section at %s:%d).\n",
379 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
380 err_code |= ERR_ALERT | ERR_ABORT;
381 }
382 else if (!(rc & PR_CAP_FE) && (!LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
383 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules))) {
384 ha_alert("parsing [%s:%d]: a backend section cannot inherit from a defaults section defining"
385 " 'tcp-request connection' or 'tcp-request session' rules (defaults section at %s:%d).\n",
386 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
387 err_code |= ERR_ALERT | ERR_ABORT;
388 }
389 else if (!(rc & PR_CAP_BE) && !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules)) {
390 ha_alert("parsing [%s:%d]: a frontend section cannot inherit from a defaults section defining"
391 " 'tcp-response content' rules (defaults section at %s:%d).\n",
392 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
393 err_code |= ERR_ALERT | ERR_ABORT;
394 }
395 else {
396 curr_defproxy->cap = (curr_defproxy->cap & ~PR_CAP_LISTEN) | (rc & PR_CAP_LISTEN);
397 proxy_ref_defaults(curproxy, curr_defproxy);
398 }
399 }
400 }
401
Christopher Faulet6ff7de52021-10-13 15:18:36 +0200402 if (curr_defproxy && (curr_defproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) &&
403 (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_BE) {
404 /* If the current default proxy defines tcpcheck rules, the
405 * current proxy will keep a reference on it. but only if the
406 * current proxy has the backend capability.
407 */
408 proxy_ref_defaults(curproxy, curr_defproxy);
409 }
410
Christopher Faulet6c10f5c2022-04-25 14:24:56 +0200411 if ((rc & PR_CAP_BE) && curr_defproxy && (curr_defproxy->nb_req_cap || curr_defproxy->nb_rsp_cap)) {
412 ha_alert("parsing [%s:%d]: backend or defaults sections cannot inherit from a defaults section defining"
413 " capptures (defaults section at %s:%d).\n",
414 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
415 err_code |= ERR_ALERT | ERR_ABORT;
416 }
417
Willy Tarreaue90904d2021-02-12 14:08:31 +0100418 if (rc & PR_CAP_DEF) {
419 /* last and current proxies must be updated to this one */
420 curr_defproxy = last_defproxy = curproxy;
421 } else {
422 /* regular proxies are in a list */
423 curproxy->next = proxies_list;
424 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100425 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100426 goto out;
427 }
428 else if (curproxy == NULL) {
429 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
430 err_code |= ERR_ALERT | ERR_FATAL;
431 goto out;
432 }
433
434 /* update the current file and line being parsed */
435 curproxy->conf.args.file = curproxy->conf.file;
436 curproxy->conf.args.line = linenum;
437
438 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100439 if ((strcmp(args[0], "server") == 0)) {
440 err_code |= parse_server(file, linenum, args,
441 curproxy, curr_defproxy,
442 SRV_PARSE_PARSE_ADDR);
443
444 if (err_code & ERR_FATAL)
445 goto out;
446 }
447 else if (strcmp(args[0], "default-server") == 0) {
448 err_code |= parse_server(file, linenum, args,
449 curproxy, curr_defproxy,
450 SRV_PARSE_DEFAULT_SERVER);
451
452 if (err_code & ERR_FATAL)
453 goto out;
454 }
455 else if (strcmp(args[0], "server-template") == 0) {
456 err_code |= parse_server(file, linenum, args,
457 curproxy, curr_defproxy,
458 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
459
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100460 if (err_code & ERR_FATAL)
461 goto out;
462 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100463 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100464 struct listener *l;
465 int cur_arg;
466
Willy Tarreau5d095c22021-02-12 10:15:59 +0100467 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100468 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
469 err_code |= ERR_ALERT | ERR_FATAL;
470 goto out;
471 }
472 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
473 err_code |= ERR_WARN;
474
475 if (!*(args[1])) {
476 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
477 file, linenum, args[0]);
478 err_code |= ERR_ALERT | ERR_FATAL;
479 goto out;
480 }
481
482 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200483 if (!bind_conf)
484 goto alloc_error;
485
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100486 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200487 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
488 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
489 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100490
491 /* NOTE: the following line might create several listeners if there
492 * are comma-separated IPs or port ranges. So all further processing
493 * will have to be applied to all listeners created after last_listen.
494 */
495 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
496 if (errmsg && *errmsg) {
497 indent_msg(&errmsg, 2);
498 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
499 }
500 else
501 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
502 file, linenum, args[0], args[1]);
503 err_code |= ERR_ALERT | ERR_FATAL;
504 goto out;
505 }
506
507 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
508 /* Set default global rights and owner for unix bind */
509 global.maxsock++;
510 }
511
512 cur_arg = 2;
Willy Tarreau55f0f7b2022-05-20 15:44:17 +0200513 err_code |= bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100514 goto out;
515 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100516 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200517 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]);
518 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100519 goto out;
520 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100521 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100522 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
523 err_code |= ERR_WARN;
524
525 if (alertif_too_many_args(1, file, linenum, args, &err_code))
526 goto out;
527
528 if (!*args[1]) {
529 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
530 file, linenum, args[0]);
531 err_code |= ERR_ALERT | ERR_FATAL;
532 goto out;
533 }
534
Tim Duesterhus4b1fcaa2022-03-05 00:52:40 +0100535 istfree(&curproxy->monitor_uri);
536 curproxy->monitor_uri = istdup(ist(args[1]));
537 if (!isttest(curproxy->monitor_uri))
Christopher Fauletb15625a2021-04-12 21:31:45 +0200538 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100539
540 goto out;
541 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100542 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100543 if (alertif_too_many_args(1, file, linenum, args, &err_code))
544 goto out;
545
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100546 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
547 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
548 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200549 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
550 err_code |= ERR_ALERT | ERR_FATAL;
551 goto out;
552 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100553 else {
554 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
555 err_code |= ERR_ALERT | ERR_FATAL;
556 goto out;
557 }
558 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100559 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100560 struct eb32_node *node;
561
Willy Tarreau5d095c22021-02-12 10:15:59 +0100562 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100563 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
564 file, linenum, args[0]);
565 err_code |= ERR_ALERT | ERR_FATAL;
566 goto out;
567 }
568
569 if (alertif_too_many_args(1, file, linenum, args, &err_code))
570 goto out;
571
572 if (!*args[1]) {
573 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
574 file, linenum, args[0]);
575 err_code |= ERR_ALERT | ERR_FATAL;
576 goto out;
577 }
578
579 curproxy->uuid = atol(args[1]);
580 curproxy->conf.id.key = curproxy->uuid;
581 curproxy->options |= PR_O_FORCED_ID;
582
583 if (curproxy->uuid <= 0) {
584 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
585 file, linenum);
586 err_code |= ERR_ALERT | ERR_FATAL;
587 goto out;
588 }
589
590 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
591 if (node) {
592 struct proxy *target = container_of(node, struct proxy, conf.id);
593 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
594 file, linenum, proxy_type_str(curproxy), curproxy->id,
595 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
596 err_code |= ERR_ALERT | ERR_FATAL;
597 goto out;
598 }
599 eb32_insert(&used_proxy_id, &curproxy->conf.id);
600 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100601 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100602 int i, len=0;
603 char *d;
604
Willy Tarreau5d095c22021-02-12 10:15:59 +0100605 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100606 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
607 file, linenum, args[0]);
608 err_code |= ERR_ALERT | ERR_FATAL;
609 goto out;
610 }
611
612 if (!*args[1]) {
613 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
614 file, linenum, args[0]);
615 return -1;
616 }
617
618 for (i = 1; *args[i]; i++)
619 len += strlen(args[i]) + 1;
620
621 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200622 if (!d)
623 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100624 curproxy->desc = d;
625
626 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
627 for (i = 2; *args[i]; i++)
628 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
629
630 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100631 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100632 if (alertif_too_many_args(0, file, linenum, args, &err_code))
633 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200634 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100635 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100636 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100637 if (alertif_too_many_args(0, file, linenum, args, &err_code))
638 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200639 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100640 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100641 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau94f763b2022-07-15 17:14:40 +0200642 ha_alert("parsing [%s:%d]: '%s' is not supported anymore.\n", file, linenum, args[0]);
643 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100644 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100645 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200646 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
647 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100648 err_code |= ERR_ALERT | ERR_FATAL;
649 goto out;
650 }
651
652 err = invalid_char(args[1]);
653 if (err) {
654 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
655 file, linenum, *err, args[1]);
656 err_code |= ERR_ALERT | ERR_FATAL;
657 goto out;
658 }
659
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100660 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100661 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100662 "logical disjunction within a condition.\n",
663 file, linenum, args[1]);
664 err_code |= ERR_ALERT | ERR_FATAL;
665 goto out;
666 }
667
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100668 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
669 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
670 file, linenum, args[1], errmsg);
671 err_code |= ERR_ALERT | ERR_FATAL;
672 goto out;
673 }
674 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100675 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100676
677 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
678 err_code |= ERR_WARN;
679
680 if (*(args[1]) == 0) {
681 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
682 file, linenum, args[0]);
683 err_code |= ERR_ALERT | ERR_FATAL;
684 goto out;
685 }
686 free(curproxy->dyncookie_key);
687 curproxy->dyncookie_key = strdup(args[1]);
688 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100689 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100690 int cur_arg;
691
692 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
693 err_code |= ERR_WARN;
694
695 if (*(args[1]) == 0) {
696 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
697 file, linenum, args[0]);
698 err_code |= ERR_ALERT | ERR_FATAL;
699 goto out;
700 }
701
702 curproxy->ck_opts = 0;
703 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100704 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100705 free(curproxy->cookie_name);
706 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200707 if (!curproxy->cookie_name)
708 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100709 curproxy->cookie_len = strlen(curproxy->cookie_name);
710
711 cur_arg = 2;
712 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100713 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100714 curproxy->ck_opts |= PR_CK_RW;
715 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100716 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100717 curproxy->ck_opts |= PR_CK_IND;
718 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100719 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100720 curproxy->ck_opts |= PR_CK_INS;
721 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100722 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100723 curproxy->ck_opts |= PR_CK_NOC;
724 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100725 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100726 curproxy->ck_opts |= PR_CK_POST;
727 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100728 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100729 curproxy->ck_opts |= PR_CK_PSV;
730 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100731 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100732 curproxy->ck_opts |= PR_CK_PFX;
733 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100734 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100735 curproxy->ck_opts |= PR_CK_HTTPONLY;
736 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100737 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100738 curproxy->ck_opts |= PR_CK_SECURE;
739 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100740 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100741 if (!*args[cur_arg + 1]) {
742 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
743 file, linenum, args[cur_arg]);
744 err_code |= ERR_ALERT | ERR_FATAL;
745 goto out;
746 }
747
Joao Moraise1583752019-10-30 21:04:00 -0300748 if (!strchr(args[cur_arg + 1], '.')) {
749 /* rfc6265, 5.2.3 The Domain Attribute */
750 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
751 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100752 file, linenum, args[cur_arg + 1]);
753 err_code |= ERR_WARN;
754 }
755
756 err = invalid_domainchar(args[cur_arg + 1]);
757 if (err) {
758 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
759 file, linenum, *err, args[cur_arg + 1]);
760 err_code |= ERR_ALERT | ERR_FATAL;
761 goto out;
762 }
763
764 if (!curproxy->cookie_domain) {
765 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
766 } else {
767 /* one domain was already specified, add another one by
768 * building the string which will be returned along with
769 * the cookie.
770 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200771 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
772 }
773
Christopher Fauletb15625a2021-04-12 21:31:45 +0200774 if (!curproxy->cookie_domain)
775 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100776 cur_arg++;
777 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100778 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100779 unsigned int maxidle;
780 const char *res;
781
782 if (!*args[cur_arg + 1]) {
783 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
784 file, linenum, args[cur_arg]);
785 err_code |= ERR_ALERT | ERR_FATAL;
786 goto out;
787 }
788
789 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200790 if (res == PARSE_TIME_OVER) {
791 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
792 file, linenum, args[cur_arg+1], args[cur_arg]);
793 err_code |= ERR_ALERT | ERR_FATAL;
794 goto out;
795 }
796 else if (res == PARSE_TIME_UNDER) {
797 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
798 file, linenum, args[cur_arg+1], args[cur_arg]);
799 err_code |= ERR_ALERT | ERR_FATAL;
800 goto out;
801 }
802 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100803 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
804 file, linenum, *res, args[cur_arg]);
805 err_code |= ERR_ALERT | ERR_FATAL;
806 goto out;
807 }
808 curproxy->cookie_maxidle = maxidle;
809 cur_arg++;
810 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100811 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100812 unsigned int maxlife;
813 const char *res;
814
815 if (!*args[cur_arg + 1]) {
816 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
817 file, linenum, args[cur_arg]);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821
Willy Tarreau9faebe32019-06-07 19:00:37 +0200822
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100823 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200824 if (res == PARSE_TIME_OVER) {
825 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
826 file, linenum, args[cur_arg+1], args[cur_arg]);
827 err_code |= ERR_ALERT | ERR_FATAL;
828 goto out;
829 }
830 else if (res == PARSE_TIME_UNDER) {
831 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
832 file, linenum, args[cur_arg+1], args[cur_arg]);
833 err_code |= ERR_ALERT | ERR_FATAL;
834 goto out;
835 }
836 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100837 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
838 file, linenum, *res, args[cur_arg]);
839 err_code |= ERR_ALERT | ERR_FATAL;
840 goto out;
841 }
842 curproxy->cookie_maxlife = maxlife;
843 cur_arg++;
844 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100845 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100846
847 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
848 err_code |= ERR_WARN;
849 curproxy->ck_opts |= PR_CK_DYNAMIC;
850 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100851 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100852 char *val;
853 if (!*args[cur_arg + 1]) {
854 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
855 file, linenum, args[cur_arg]);
856 err_code |= ERR_ALERT | ERR_FATAL;
857 goto out;
858 }
859 val = args[cur_arg + 1];
860 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100861 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100862 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
863 file, linenum, *val);
864 err_code |= ERR_ALERT | ERR_FATAL;
865 goto out;
866 }
867 val++;
868 }
869 /* don't add ';' for the first attribute */
870 if (!curproxy->cookie_attrs)
871 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
872 else
873 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200874
Christopher Fauletb15625a2021-04-12 21:31:45 +0200875 if (!curproxy->cookie_attrs)
876 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100877 cur_arg++;
878 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100879
880 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100881 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 +0100882 file, linenum, args[0]);
883 err_code |= ERR_ALERT | ERR_FATAL;
884 goto out;
885 }
886 cur_arg++;
887 }
888 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
889 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
890 file, linenum);
891 err_code |= ERR_ALERT | ERR_FATAL;
892 }
893
894 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
895 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
896 file, linenum);
897 err_code |= ERR_ALERT | ERR_FATAL;
898 }
899
900 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
901 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
902 file, linenum);
903 err_code |= ERR_ALERT | ERR_FATAL;
904 }
905 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100906 else if (strcmp(args[0], "email-alert") == 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[0]);
910 err_code |= ERR_ALERT | ERR_FATAL;
911 goto out;
912 }
913
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100914 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100915 if (*(args[1]) == 0) {
916 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
917 file, linenum, args[1]);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921 free(curproxy->email_alert.from);
922 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200923 if (!curproxy->email_alert.from)
924 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100926 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100927 if (*(args[1]) == 0) {
928 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
929 file, linenum, args[1]);
930 err_code |= ERR_ALERT | ERR_FATAL;
931 goto out;
932 }
933 free(curproxy->email_alert.mailers.name);
934 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200935 if (!curproxy->email_alert.mailers.name)
936 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100937 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100938 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100939 if (*(args[1]) == 0) {
940 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
941 file, linenum, args[1]);
942 err_code |= ERR_ALERT | ERR_FATAL;
943 goto out;
944 }
945 free(curproxy->email_alert.myhostname);
946 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200947 if (!curproxy->email_alert.myhostname)
948 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100949 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100950 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100951 curproxy->email_alert.level = get_log_level(args[2]);
952 if (curproxy->email_alert.level < 0) {
953 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
954 file, linenum, args[1], args[2]);
955 err_code |= ERR_ALERT | ERR_FATAL;
956 goto out;
957 }
958 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100959 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100960 if (*(args[1]) == 0) {
961 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
962 file, linenum, args[1]);
963 err_code |= ERR_ALERT | ERR_FATAL;
964 goto out;
965 }
966 free(curproxy->email_alert.to);
967 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200968 if (!curproxy->email_alert.to)
969 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100970 }
971 else {
972 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
973 file, linenum, args[1]);
974 err_code |= ERR_ALERT | ERR_FATAL;
975 goto out;
976 }
977 /* Indicate that the email_alert is at least partially configured */
978 curproxy->email_alert.set = 1;
979 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100980 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100981 if (*(args[1]) == 0) {
982 ha_alert("parsing [%s:%d] : missing persist method.\n",
983 file, linenum);
984 err_code |= ERR_ALERT | ERR_FATAL;
985 goto out;
986 }
987
988 if (!strncmp(args[1], "rdp-cookie", 10)) {
989 curproxy->options2 |= PR_O2_RDPC_PRST;
990
991 if (*(args[1] + 10) == '(') { /* cookie name */
992 const char *beg, *end;
993
994 beg = args[1] + 11;
995 end = strchr(beg, ')');
996
997 if (alertif_too_many_args(1, file, linenum, args, &err_code))
998 goto out;
999
1000 if (!end || end == beg) {
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 free(curproxy->rdp_cookie_name);
1008 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001009 if (!curproxy->rdp_cookie_name)
1010 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001011 curproxy->rdp_cookie_len = end-beg;
1012 }
1013 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1014 free(curproxy->rdp_cookie_name);
1015 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +02001016 if (!curproxy->rdp_cookie_name)
1017 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001018 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1019 }
1020 else { /* syntax */
1021 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1022 file, linenum);
1023 err_code |= ERR_ALERT | ERR_FATAL;
1024 goto out;
1025 }
1026 }
1027 else {
1028 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1029 file, linenum);
1030 err_code |= ERR_ALERT | ERR_FATAL;
1031 goto out;
1032 }
1033 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001034 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001035 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 +01001036 err_code |= ERR_ALERT | ERR_FATAL;
1037 goto out;
1038 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001039 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001040 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1041 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001042 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001043 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1044 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001045 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 +01001046 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1047 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001048 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001049 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1050 }
1051 else {
1052 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1053 file, linenum, args[0], args[1]);
1054 err_code |= ERR_ALERT | ERR_FATAL;
1055 goto out;
1056 }
1057 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001058 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001059 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1060 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001061 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001062 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001063
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001064 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001065
1066 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001067 curproxy->server_state_file_name = strdup(curproxy->id);
1068 else
1069 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001070
Christopher Fauletb15625a2021-04-12 21:31:45 +02001071 if (!curproxy->server_state_file_name)
1072 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001073 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001074 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001075 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1076 err_code |= ERR_WARN;
1077 if (*(args[1]) == 0) {
1078 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1079 file, linenum, args[0]);
1080 err_code |= ERR_ALERT | ERR_FATAL;
1081 goto out;
1082 }
1083 curproxy->max_out_conns = atoi(args[1]);
1084 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001085 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001086 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1087 err_code |= ERR_WARN;
1088
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001089 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001090 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001091 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1092 err_code |= ERR_ALERT | ERR_FATAL;
1093 goto out;
1094 }
1095
1096 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1097 goto out;
1098
1099 if (*(args[4]) == 0) {
1100 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1101 file, linenum, args[0]);
1102 err_code |= ERR_ALERT | ERR_FATAL;
1103 goto out;
1104 }
1105 free(curproxy->capture_name);
1106 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001107 if (!curproxy->capture_name)
1108 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001109 curproxy->capture_namelen = strlen(curproxy->capture_name);
1110 curproxy->capture_len = atol(args[4]);
1111 curproxy->to_log |= LW_COOKIE;
1112 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001113 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001114 struct cap_hdr *hdr;
1115
Willy Tarreau5d095c22021-02-12 10:15:59 +01001116 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001117 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1118 err_code |= ERR_ALERT | ERR_FATAL;
1119 goto out;
1120 }
1121
1122 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1123 goto out;
1124
1125 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1126 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1127 file, linenum, args[0], args[1]);
1128 err_code |= ERR_ALERT | ERR_FATAL;
1129 goto out;
1130 }
1131
1132 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001133 if (!hdr)
1134 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001135 hdr->next = curproxy->req_cap;
1136 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001137 if (!hdr->name)
1138 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001139 hdr->namelen = strlen(args[3]);
1140 hdr->len = atol(args[5]);
1141 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001142 if (!hdr->pool) {
1143 req_caphdr_alloc_error:
1144 if (hdr)
1145 ha_free(&hdr->name);
1146 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001147 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001148 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001149 hdr->index = curproxy->nb_req_cap++;
1150 curproxy->req_cap = hdr;
1151 curproxy->to_log |= LW_REQHDR;
1152 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001153 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001154 struct cap_hdr *hdr;
1155
Willy Tarreau5d095c22021-02-12 10:15:59 +01001156 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001157 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1158 err_code |= ERR_ALERT | ERR_FATAL;
1159 goto out;
1160 }
1161
1162 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1163 goto out;
1164
1165 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1166 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1167 file, linenum, args[0], args[1]);
1168 err_code |= ERR_ALERT | ERR_FATAL;
1169 goto out;
1170 }
1171 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001172 if (!hdr)
1173 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001174 hdr->next = curproxy->rsp_cap;
1175 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001176 if (!hdr->name)
1177 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001178 hdr->namelen = strlen(args[3]);
1179 hdr->len = atol(args[5]);
1180 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001181 if (!hdr->pool) {
1182 res_caphdr_alloc_error:
1183 if (hdr)
1184 ha_free(&hdr->name);
1185 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001186 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001187 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001188 hdr->index = curproxy->nb_rsp_cap++;
1189 curproxy->rsp_cap = hdr;
1190 curproxy->to_log |= LW_RSPHDR;
1191 }
1192 else {
1193 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1194 file, linenum, args[0]);
1195 err_code |= ERR_ALERT | ERR_FATAL;
1196 goto out;
1197 }
1198 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001199 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001200 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1201 err_code |= ERR_WARN;
1202
1203 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1204 goto out;
1205
1206 if (*(args[1]) == 0) {
1207 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1208 file, linenum, args[0]);
1209 err_code |= ERR_ALERT | ERR_FATAL;
1210 goto out;
1211 }
1212 curproxy->conn_retries = atol(args[1]);
1213 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001214 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001215 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001216 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001217
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001218 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1219 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001220 err_code |= ERR_ALERT | ERR_FATAL;
1221 goto out;
1222 }
1223
1224 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1225 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001226 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001227 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1228 file, linenum, args[0]);
1229 err_code |= ERR_WARN;
1230 }
1231
1232 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1233
1234 if (!rule) {
1235 err_code |= ERR_ALERT | ERR_ABORT;
1236 goto out;
1237 }
1238
1239 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001240
1241 if (curproxy->cap & PR_CAP_FE)
1242 where |= SMP_VAL_FE_HRQ_HDR;
1243 if (curproxy->cap & PR_CAP_BE)
1244 where |= SMP_VAL_BE_HRQ_HDR;
1245 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001246
Willy Tarreau2b718102021-04-21 07:32:39 +02001247 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001248 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001249 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001250 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001251 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001252
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001253 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1254 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001255 err_code |= ERR_ALERT | ERR_FATAL;
1256 goto out;
1257 }
1258
1259 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1260 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001261 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001262 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1263 file, linenum, args[0]);
1264 err_code |= ERR_WARN;
1265 }
1266
1267 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1268
1269 if (!rule) {
1270 err_code |= ERR_ALERT | ERR_ABORT;
1271 goto out;
1272 }
1273
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001274 if (curproxy->cap & PR_CAP_FE)
1275 where |= SMP_VAL_FE_HRS_HDR;
1276 if (curproxy->cap & PR_CAP_BE)
1277 where |= SMP_VAL_BE_HRS_HDR;
1278 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001279
Willy Tarreau2b718102021-04-21 07:32:39 +02001280 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001281 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001282 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001283 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001284 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001285 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1286 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001287 err_code |= ERR_ALERT | ERR_FATAL;
1288 goto out;
1289 }
1290
1291 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1292 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1293 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1294 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1295 file, linenum, args[0]);
1296 err_code |= ERR_WARN;
1297 }
1298
1299 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1300
1301 if (!rule) {
1302 err_code |= ERR_ALERT | ERR_ABORT;
1303 goto out;
1304 }
1305
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001306 if (curproxy->cap & PR_CAP_FE)
1307 where |= SMP_VAL_FE_HRS_HDR;
1308 if (curproxy->cap & PR_CAP_BE)
1309 where |= SMP_VAL_BE_HRS_HDR;
1310 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001311
Willy Tarreau2b718102021-04-21 07:32:39 +02001312 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001313 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001314 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001315 /* set the header name and length into the proxy structure */
1316 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1317 err_code |= ERR_WARN;
1318
1319 if (!*args[1]) {
1320 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1321 file, linenum, args[0]);
1322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001326 /* set the desired header name, in lower case */
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001327 istfree(&curproxy->server_id_hdr_name);
1328 curproxy->server_id_hdr_name = istdup(ist(args[1]));
1329 if (!isttest(curproxy->server_id_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02001330 goto alloc_error;
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001331 ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001332 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001333 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001334 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 +01001335
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001336 err_code |= ERR_ALERT | ERR_FATAL;
1337 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001338 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001339 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001340 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001341 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001342
Willy Tarreau5d095c22021-02-12 10:15:59 +01001343 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001344 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1345 err_code |= ERR_ALERT | ERR_FATAL;
1346 goto out;
1347 }
1348
1349 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1350 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1351 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1352 err_code |= ERR_ALERT | ERR_FATAL;
1353 goto out;
1354 }
1355
Willy Tarreau2b718102021-04-21 07:32:39 +02001356 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001357 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001358
1359 if (curproxy->cap & PR_CAP_FE)
1360 where |= SMP_VAL_FE_HRQ_HDR;
1361 if (curproxy->cap & PR_CAP_BE)
1362 where |= SMP_VAL_BE_HRQ_HDR;
1363 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001364 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001365 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001366 struct switching_rule *rule;
1367
Willy Tarreau5d095c22021-02-12 10:15:59 +01001368 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001369 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1370 err_code |= ERR_ALERT | ERR_FATAL;
1371 goto out;
1372 }
1373
1374 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1375 err_code |= ERR_WARN;
1376
1377 if (*(args[1]) == 0) {
1378 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1379 err_code |= ERR_ALERT | ERR_FATAL;
1380 goto out;
1381 }
1382
1383 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1384 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1385 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1386 file, linenum, errmsg);
1387 err_code |= ERR_ALERT | ERR_FATAL;
1388 goto out;
1389 }
1390
1391 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1392 }
1393 else if (*args[2]) {
1394 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1395 file, linenum, args[2]);
1396 err_code |= ERR_ALERT | ERR_FATAL;
1397 goto out;
1398 }
1399
1400 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001401 if (!rule)
1402 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001403 rule->cond = cond;
1404 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001405 if (!rule->be.name)
1406 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001407 rule->line = linenum;
1408 rule->file = strdup(file);
1409 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001410 use_backend_alloc_error:
1411 if (cond)
1412 prune_acl_cond(cond);
1413 ha_free(&cond);
1414 if (rule)
1415 ha_free(&(rule->be.name));
1416 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001417 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001418 }
1419 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001420 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001421 }
1422 else if (strcmp(args[0], "use-server") == 0) {
1423 struct server_rule *rule;
1424
Willy Tarreau5d095c22021-02-12 10:15:59 +01001425 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001426 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1427 err_code |= ERR_ALERT | ERR_FATAL;
1428 goto out;
1429 }
1430
1431 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1432 err_code |= ERR_WARN;
1433
1434 if (*(args[1]) == 0) {
1435 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1436 err_code |= ERR_ALERT | ERR_FATAL;
1437 goto out;
1438 }
1439
1440 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1441 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1442 file, linenum, args[0]);
1443 err_code |= ERR_ALERT | ERR_FATAL;
1444 goto out;
1445 }
1446
1447 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1448 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1449 file, linenum, errmsg);
1450 err_code |= ERR_ALERT | ERR_FATAL;
1451 goto out;
1452 }
1453
1454 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1455
1456 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001457 if (!rule)
1458 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001459 rule->cond = cond;
1460 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001461 if (!rule->srv.name)
1462 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001463 rule->line = linenum;
1464 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001465 if (!rule->file) {
1466 use_server_alloc_error:
1467 if (cond)
1468 prune_acl_cond(cond);
1469 ha_free(&cond);
1470 if (rule)
1471 ha_free(&(rule->srv.name));
1472 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001473 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001474 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001475 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001476 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001477 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1478 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001479 else if ((strcmp(args[0], "force-persist") == 0) ||
1480 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001481 struct persist_rule *rule;
1482
Willy Tarreau5d095c22021-02-12 10:15:59 +01001483 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001484 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1485 err_code |= ERR_ALERT | ERR_FATAL;
1486 goto out;
1487 }
1488
1489 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1490 err_code |= ERR_WARN;
1491
1492 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1493 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1494 file, linenum, args[0]);
1495 err_code |= ERR_ALERT | ERR_FATAL;
1496 goto out;
1497 }
1498
1499 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1500 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1501 file, linenum, args[0], errmsg);
1502 err_code |= ERR_ALERT | ERR_FATAL;
1503 goto out;
1504 }
1505
1506 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1507 * where force-persist is applied.
1508 */
1509 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1510
1511 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001512 if (!rule) {
1513 if (cond)
1514 prune_acl_cond(cond);
1515 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001516 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001517 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001518 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001519 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001520 rule->type = PERSIST_TYPE_FORCE;
1521 } else {
1522 rule->type = PERSIST_TYPE_IGNORE;
1523 }
1524 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001525 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001526 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001527 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001528 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001529
Willy Tarreau5d095c22021-02-12 10:15:59 +01001530 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001531 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1532 file, linenum);
1533 err_code |= ERR_ALERT | ERR_FATAL;
1534 goto out;
1535 }
1536
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001537 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001538 if (other) {
1539 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 +01001540 file, linenum, curproxy->id,
1541 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1542 other->proxy ? other->id : other->peers.p->id,
1543 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001544 err_code |= ERR_ALERT | ERR_FATAL;
1545 goto out;
1546 }
1547
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001548 curproxy->table = calloc(1, sizeof *curproxy->table);
1549 if (!curproxy->table) {
1550 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1551 file, linenum, args[0], args[1]);
1552 err_code |= ERR_ALERT | ERR_FATAL;
1553 goto out;
1554 }
1555
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001556 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1557 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001558 if (err_code & ERR_FATAL) {
1559 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001560 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001561 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001562
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001563 /* Store the proxy in the stick-table. */
1564 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001565
1566 stktable_store_name(curproxy->table);
1567 curproxy->table->next = stktables_list;
1568 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001569
1570 /* Add this proxy to the list of proxies which refer to its stick-table. */
1571 if (curproxy->table->proxies_list != curproxy) {
1572 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1573 curproxy->table->proxies_list = curproxy;
1574 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001575 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001576 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001577 struct sticking_rule *rule;
1578 struct sample_expr *expr;
1579 int myidx = 0;
1580 const char *name = NULL;
1581 int flags;
1582
Willy Tarreau5d095c22021-02-12 10:15:59 +01001583 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001584 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1585 err_code |= ERR_ALERT | ERR_FATAL;
1586 goto out;
1587 }
1588
1589 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1590 err_code |= ERR_WARN;
1591 goto out;
1592 }
1593
1594 myidx++;
1595 if ((strcmp(args[myidx], "store") == 0) ||
1596 (strcmp(args[myidx], "store-request") == 0)) {
1597 myidx++;
1598 flags = STK_IS_STORE;
1599 }
1600 else if (strcmp(args[myidx], "store-response") == 0) {
1601 myidx++;
1602 flags = STK_IS_STORE | STK_ON_RSP;
1603 }
1604 else if (strcmp(args[myidx], "match") == 0) {
1605 myidx++;
1606 flags = STK_IS_MATCH;
1607 }
1608 else if (strcmp(args[myidx], "on") == 0) {
1609 myidx++;
1610 flags = STK_IS_MATCH | STK_IS_STORE;
1611 }
1612 else {
1613 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1614 err_code |= ERR_ALERT | ERR_FATAL;
1615 goto out;
1616 }
1617
1618 if (*(args[myidx]) == 0) {
1619 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1620 err_code |= ERR_ALERT | ERR_FATAL;
1621 goto out;
1622 }
1623
1624 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001625 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001626 if (!expr) {
1627 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1628 err_code |= ERR_ALERT | ERR_FATAL;
1629 goto out;
1630 }
1631
1632 if (flags & STK_ON_RSP) {
1633 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1634 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1635 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1636 err_code |= ERR_ALERT | ERR_FATAL;
1637 free(expr);
1638 goto out;
1639 }
1640 } else {
1641 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1642 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1643 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1644 err_code |= ERR_ALERT | ERR_FATAL;
1645 free(expr);
1646 goto out;
1647 }
1648 }
1649
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001650 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001651 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1652
1653 if (strcmp(args[myidx], "table") == 0) {
1654 myidx++;
1655 name = args[myidx++];
1656 }
1657
1658 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1659 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1660 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1661 file, linenum, args[0], errmsg);
1662 err_code |= ERR_ALERT | ERR_FATAL;
1663 free(expr);
1664 goto out;
1665 }
1666 }
1667 else if (*(args[myidx])) {
1668 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1669 file, linenum, args[0], args[myidx]);
1670 err_code |= ERR_ALERT | ERR_FATAL;
1671 free(expr);
1672 goto out;
1673 }
1674 if (flags & STK_ON_RSP)
1675 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1676 else
1677 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1678
1679 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001680 if (!rule) {
1681 if (cond)
1682 prune_acl_cond(cond);
1683 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001684 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001685 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001686 rule->cond = cond;
1687 rule->expr = expr;
1688 rule->flags = flags;
1689 rule->table.name = name ? strdup(name) : NULL;
1690 LIST_INIT(&rule->list);
1691 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001692 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001693 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001694 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001695 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001696 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001697 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001698 curproxy->uri_auth = NULL; /* we must detach from the default config */
1699
1700 if (!*args[1]) {
1701 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001702 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001703 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001704 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001705
Willy Tarreau5d095c22021-02-12 10:15:59 +01001706 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001707 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1708 err_code |= ERR_ALERT | ERR_FATAL;
1709 goto out;
1710 }
1711
Christopher Fauletb15625a2021-04-12 21:31:45 +02001712 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1713 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001714
1715 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1716 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1717 file, linenum, args[0], args[1]);
1718 err_code |= ERR_ALERT | ERR_FATAL;
1719 goto out;
1720 }
1721 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1722 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1723 file, linenum, args[0], args[1], errmsg);
1724 err_code |= ERR_ALERT | ERR_FATAL;
1725 goto out;
1726 }
1727
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001728 if (curproxy->cap & PR_CAP_FE)
1729 where |= SMP_VAL_FE_HRQ_HDR;
1730 if (curproxy->cap & PR_CAP_BE)
1731 where |= SMP_VAL_BE_HRQ_HDR;
1732 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001733
1734 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001735 if (!rule) {
1736 if (cond)
1737 prune_acl_cond(cond);
1738 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001739 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001740 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001741 rule->cond = cond;
1742 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001743 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001744 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001745 if (*(args[2]) == 0) {
1746 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1747 err_code |= ERR_ALERT | ERR_FATAL;
1748 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001749 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1750 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001751 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001752 if (*(args[2]) == 0) {
1753 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1754 err_code |= ERR_ALERT | ERR_FATAL;
1755 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001756 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1757 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001758 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001759 unsigned interval;
1760
1761 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001762 if (err == PARSE_TIME_OVER) {
1763 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1764 file, linenum, args[2]);
1765 err_code |= ERR_ALERT | ERR_FATAL;
1766 goto out;
1767 }
1768 else if (err == PARSE_TIME_UNDER) {
1769 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1770 file, linenum, args[2]);
1771 err_code |= ERR_ALERT | ERR_FATAL;
1772 goto out;
1773 }
1774 else if (err) {
1775 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001776 file, linenum, *err);
1777 err_code |= ERR_ALERT | ERR_FATAL;
1778 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001779 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1780 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001781 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001782 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001783 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001784
Willy Tarreau5d095c22021-02-12 10:15:59 +01001785 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001786 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1787 err_code |= ERR_ALERT | ERR_FATAL;
1788 goto out;
1789 }
1790
Christopher Fauletb15625a2021-04-12 21:31:45 +02001791 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1792 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001793
1794 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1795 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1796 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1797 file, linenum, args[0]);
1798 err_code |= ERR_WARN;
1799 }
1800
1801 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1802
1803 if (!rule) {
1804 err_code |= ERR_ALERT | ERR_ABORT;
1805 goto out;
1806 }
1807
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001808 if (curproxy->cap & PR_CAP_FE)
1809 where |= SMP_VAL_FE_HRQ_HDR;
1810 if (curproxy->cap & PR_CAP_BE)
1811 where |= SMP_VAL_BE_HRQ_HDR;
1812 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001813 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001814
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001815 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001816 if (*(args[2]) == 0) {
1817 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1818 err_code |= ERR_ALERT | ERR_FATAL;
1819 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001820 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1821 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001822 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001823 if (*(args[2]) == 0) {
1824 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1825 err_code |= ERR_ALERT | ERR_FATAL;
1826 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001827 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1828 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001829 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001830 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1831 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001832 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001833 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1834 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001835 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001836 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1837 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001838 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001839 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1840 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001841 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001842
1843 if (*args[2]) {
1844 int i;
1845 char c;
1846
1847 for (i=0; args[2][i]; i++) {
1848 c = args[2][i];
1849 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1850 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1851 break;
1852 }
1853
1854 if (!i || args[2][i]) {
1855 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1856 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1857 file, linenum, args[0], args[1]);
1858 err_code |= ERR_ALERT | ERR_FATAL;
1859 goto out;
1860 }
1861 }
1862
Christopher Fauletb15625a2021-04-12 21:31:45 +02001863 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1864 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001865 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001866 char *desc = NULL;
1867
1868 if (*args[2]) {
1869 int i, len=0;
1870 char *d;
1871
1872 for (i = 2; *args[i]; i++)
1873 len += strlen(args[i]) + 1;
1874
1875 desc = d = calloc(1, len);
1876
1877 d += snprintf(d, desc + len - d, "%s", args[2]);
1878 for (i = 3; *args[i]; i++)
1879 d += snprintf(d, desc + len - d, " %s", args[i]);
1880 }
1881
1882 if (!*args[2] && !global.desc)
1883 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1884 file, linenum, args[1]);
1885 else {
1886 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1887 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001888 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001889 }
1890 free(desc);
1891 }
1892 } else {
1893stats_error_parsing:
1894 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1895 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1896 err_code |= ERR_ALERT | ERR_FATAL;
1897 goto out;
1898 }
1899 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001900 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001901 int optnum;
1902
1903 if (*(args[1]) == '\0') {
1904 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1905 file, linenum, args[0]);
1906 err_code |= ERR_ALERT | ERR_FATAL;
1907 goto out;
1908 }
1909
1910 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001911 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001912 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1913 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1914 file, linenum, cfg_opts[optnum].name);
1915 err_code |= ERR_ALERT | ERR_FATAL;
1916 goto out;
1917 }
1918 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1919 goto out;
1920
1921 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1922 err_code |= ERR_WARN;
1923 goto out;
1924 }
1925
1926 curproxy->no_options &= ~cfg_opts[optnum].val;
1927 curproxy->options &= ~cfg_opts[optnum].val;
1928
1929 switch (kwm) {
1930 case KWM_STD:
1931 curproxy->options |= cfg_opts[optnum].val;
1932 break;
1933 case KWM_NO:
1934 curproxy->no_options |= cfg_opts[optnum].val;
1935 break;
1936 case KWM_DEF: /* already cleared */
1937 break;
1938 }
1939
1940 goto out;
1941 }
1942 }
1943
1944 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001945 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001946 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1947 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1948 file, linenum, cfg_opts2[optnum].name);
1949 err_code |= ERR_ALERT | ERR_FATAL;
1950 goto out;
1951 }
1952 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1953 goto out;
1954 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1955 err_code |= ERR_WARN;
1956 goto out;
1957 }
1958
1959 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1960 curproxy->options2 &= ~cfg_opts2[optnum].val;
1961
1962 switch (kwm) {
1963 case KWM_STD:
1964 curproxy->options2 |= cfg_opts2[optnum].val;
1965 break;
1966 case KWM_NO:
1967 curproxy->no_options2 |= cfg_opts2[optnum].val;
1968 break;
1969 case KWM_DEF: /* already cleared */
1970 break;
1971 }
1972 goto out;
1973 }
1974 }
1975
1976 /* HTTP options override each other. They can be cancelled using
1977 * "no option xxx" which only switches to default mode if the mode
1978 * was this one (useful for cancelling options set in defaults
1979 * sections).
1980 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001981 if (strcmp(args[1], "forceclose") == 0) {
1982 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",
1983 file, linenum, args[1]);
1984 err_code |= ERR_ALERT | ERR_FATAL;
1985 goto out;
1986 }
1987 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001988 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1989 goto out;
1990 if (kwm == KWM_STD) {
1991 curproxy->options &= ~PR_O_HTTP_MODE;
1992 curproxy->options |= PR_O_HTTP_CLO;
1993 goto out;
1994 }
1995 else if (kwm == KWM_NO) {
1996 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1997 curproxy->options &= ~PR_O_HTTP_MODE;
1998 goto out;
1999 }
2000 }
2001 else if (strcmp(args[1], "http-server-close") == 0) {
2002 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2003 goto out;
2004 if (kwm == KWM_STD) {
2005 curproxy->options &= ~PR_O_HTTP_MODE;
2006 curproxy->options |= PR_O_HTTP_SCL;
2007 goto out;
2008 }
2009 else if (kwm == KWM_NO) {
2010 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2011 curproxy->options &= ~PR_O_HTTP_MODE;
2012 goto out;
2013 }
2014 }
2015 else if (strcmp(args[1], "http-keep-alive") == 0) {
2016 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2017 goto out;
2018 if (kwm == KWM_STD) {
2019 curproxy->options &= ~PR_O_HTTP_MODE;
2020 curproxy->options |= PR_O_HTTP_KAL;
2021 goto out;
2022 }
2023 else if (kwm == KWM_NO) {
2024 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2025 curproxy->options &= ~PR_O_HTTP_MODE;
2026 goto out;
2027 }
2028 }
2029 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002030 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 +02002031 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002032 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002033 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002034 }
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +01002035 else if (strcmp(args[1], "forwarded") == 0) {
2036 if (kwm == KWM_STD) {
2037 err_code |= proxy_http_parse_7239(args, 0, curproxy, curr_defproxy, file, linenum);
2038 goto out;
2039 }
2040 else if (kwm == KWM_NO) {
Aurelien DARRAGONb2e2ec52023-01-09 11:09:03 +01002041 if (curproxy->http_ext)
2042 http_ext_7239_clean(curproxy);
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +01002043 goto out;
2044 }
2045 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002046
2047 /* Redispatch can take an integer argument that control when the
2048 * resispatch occurs. All values are relative to the retries option.
2049 * This can be cancelled using "no option xxx".
2050 */
2051 if (strcmp(args[1], "redispatch") == 0) {
2052 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2053 err_code |= ERR_WARN;
2054 goto out;
2055 }
2056
2057 curproxy->no_options &= ~PR_O_REDISP;
2058 curproxy->options &= ~PR_O_REDISP;
2059
2060 switch (kwm) {
2061 case KWM_STD:
2062 curproxy->options |= PR_O_REDISP;
2063 curproxy->redispatch_after = -1;
2064 if(*args[2]) {
2065 curproxy->redispatch_after = atol(args[2]);
2066 }
2067 break;
2068 case KWM_NO:
2069 curproxy->no_options |= PR_O_REDISP;
2070 curproxy->redispatch_after = 0;
2071 break;
2072 case KWM_DEF: /* already cleared */
2073 break;
2074 }
2075 goto out;
2076 }
2077
Willy Tarreau25241232021-07-18 19:18:56 +02002078 if (strcmp(args[1], "http_proxy") == 0) {
2079 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",
2080 file, linenum, args[1]);
2081 err_code |= ERR_ALERT | ERR_FATAL;
2082 goto out;
2083 }
2084
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002085 if (kwm != KWM_STD) {
2086 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2087 file, linenum, args[1]);
2088 err_code |= ERR_ALERT | ERR_FATAL;
2089 goto out;
2090 }
2091
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002092 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002093 char *logformat;
2094 /* generate a complete HTTP log */
2095 logformat = default_http_log_format;
2096 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002097 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002098 curproxy->options2 |= PR_O2_CLFLOG;
2099 logformat = clf_http_log_format;
2100 } else {
2101 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2102 err_code |= ERR_ALERT | ERR_FATAL;
2103 goto out;
2104 }
2105 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2106 goto out;
2107 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002108 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002109 char *oldlogformat = "log-format";
2110 char *clflogformat = "";
2111
2112 if (curproxy->conf.logformat_string == default_http_log_format)
2113 oldlogformat = "option httplog";
2114 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2115 oldlogformat = "option tcplog";
2116 else if (curproxy->conf.logformat_string == clf_http_log_format)
2117 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002118 else if (curproxy->conf.logformat_string == default_https_log_format)
2119 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002120 if (logformat == clf_http_log_format)
2121 clflogformat = " clf";
2122 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2123 file, linenum, clflogformat, oldlogformat);
2124 }
2125 if (curproxy->conf.logformat_string != default_http_log_format &&
2126 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002127 curproxy->conf.logformat_string != clf_http_log_format &&
2128 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002129 free(curproxy->conf.logformat_string);
2130 curproxy->conf.logformat_string = logformat;
2131
2132 free(curproxy->conf.lfs_file);
2133 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2134 curproxy->conf.lfs_line = curproxy->conf.args.line;
2135
Willy Tarreau5d095c22021-02-12 10:15:59 +01002136 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002137 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2138 file, linenum, curproxy->id);
2139 err_code |= ERR_WARN;
2140 }
2141 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002142 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002143 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002144 char *oldlogformat = "log-format";
2145
2146 if (curproxy->conf.logformat_string == default_http_log_format)
2147 oldlogformat = "option httplog";
2148 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2149 oldlogformat = "option tcplog";
2150 else if (curproxy->conf.logformat_string == clf_http_log_format)
2151 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002152 else if (curproxy->conf.logformat_string == default_https_log_format)
2153 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002154 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2155 file, linenum, oldlogformat);
2156 }
2157 /* generate a detailed TCP log */
2158 if (curproxy->conf.logformat_string != default_http_log_format &&
2159 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002160 curproxy->conf.logformat_string != clf_http_log_format &&
2161 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002162 free(curproxy->conf.logformat_string);
2163 curproxy->conf.logformat_string = default_tcp_log_format;
2164
2165 free(curproxy->conf.lfs_file);
2166 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2167 curproxy->conf.lfs_line = curproxy->conf.args.line;
2168
2169 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2170 goto out;
2171
Willy Tarreau5d095c22021-02-12 10:15:59 +01002172 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002173 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2174 file, linenum, curproxy->id);
2175 err_code |= ERR_WARN;
2176 }
2177 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002178 else if (strcmp(args[1], "httpslog") == 0) {
2179 char *logformat;
2180 /* generate a complete HTTP log */
2181 logformat = default_https_log_format;
2182 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2183 char *oldlogformat = "log-format";
2184
2185 if (curproxy->conf.logformat_string == default_http_log_format)
2186 oldlogformat = "option httplog";
2187 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2188 oldlogformat = "option tcplog";
2189 else if (curproxy->conf.logformat_string == clf_http_log_format)
2190 oldlogformat = "option httplog clf";
2191 else if (curproxy->conf.logformat_string == default_https_log_format)
2192 oldlogformat = "option httpslog";
2193 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2194 file, linenum, oldlogformat);
2195 }
2196 if (curproxy->conf.logformat_string != default_http_log_format &&
2197 curproxy->conf.logformat_string != default_tcp_log_format &&
2198 curproxy->conf.logformat_string != clf_http_log_format &&
2199 curproxy->conf.logformat_string != default_https_log_format)
2200 free(curproxy->conf.logformat_string);
2201 curproxy->conf.logformat_string = logformat;
2202
2203 free(curproxy->conf.lfs_file);
2204 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2205 curproxy->conf.lfs_line = curproxy->conf.args.line;
2206
2207 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2208 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2209 file, linenum, curproxy->id);
2210 err_code |= ERR_WARN;
2211 }
2212 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002213 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002214 /* enable TCP keep-alives on client and server streams */
2215 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2216 err_code |= ERR_WARN;
2217
2218 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2219 goto out;
2220
2221 if (curproxy->cap & PR_CAP_FE)
2222 curproxy->options |= PR_O_TCP_CLI_KA;
2223 if (curproxy->cap & PR_CAP_BE)
2224 curproxy->options |= PR_O_TCP_SRV_KA;
2225 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002226 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002227 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002228 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002229 goto out;
2230 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002231 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002232 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002233 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002234 goto out;
2235 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002236 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002237 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002238 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002239 goto out;
2240 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002241 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002242 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002243 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002244 goto out;
2245 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002246 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002247 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002248 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002249 goto out;
2250 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002251 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002252 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002253 if (err_code & ERR_FATAL)
2254 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002255 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002256 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002257 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002258 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002259 goto out;
2260 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002261 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002262 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002263 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002264 goto out;
2265 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002266 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002267 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002268 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 goto out;
2270 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002271 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002272 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002273 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002274 goto out;
2275 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002276 else if (strcmp(args[1], "forwardfor") == 0) {
Aurelien DARRAGON730b9832022-12-28 18:53:05 +01002277 err_code |= proxy_http_parse_xff(args, 0, curproxy, curr_defproxy, file, linenum);
2278 if (err_code & ERR_FATAL)
2279 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002280 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002281 else if (strcmp(args[1], "originalto") == 0) {
Aurelien DARRAGONf9583412022-12-29 15:45:41 +01002282 err_code |= proxy_http_parse_xot(args, 0, curproxy, curr_defproxy, file, linenum);
2283 if (err_code & ERR_FATAL)
2284 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002285 }
Christopher Faulet18c13d32022-05-16 11:43:10 +02002286 else if (strcmp(args[1], "http-restrict-req-hdr-names") == 0) {
Christopher Faulet18c13d32022-05-16 11:43:10 +02002287 if (alertif_too_many_args(2, file, linenum, args, &err_code))
2288 goto out;
2289
2290 if (*(args[2]) == 0) {
2291 ha_alert("parsing [%s:%d] : missing parameter. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2292 file, linenum, args[1]);
2293 err_code |= ERR_ALERT | ERR_FATAL;
2294 goto out;
2295 }
2296
2297 curproxy->options2 &= ~PR_O2_RSTRICT_REQ_HDR_NAMES_MASK;
2298 if (strcmp(args[2], "preserve") == 0)
2299 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_NOOP;
2300 else if (strcmp(args[2], "reject") == 0)
2301 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_BLK;
2302 else if (strcmp(args[2], "delete") == 0)
2303 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_DEL;
2304 else {
2305 ha_alert("parsing [%s:%d] : invalid parameter '%s'. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2306 file, linenum, args[2], args[1]);
2307 err_code |= ERR_ALERT | ERR_FATAL;
2308 goto out;
2309 }
2310 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002311 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002312 const char *best = proxy_find_best_option(args[1], common_options);
2313
2314 if (best)
2315 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2316 else
2317 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2318
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002319 err_code |= ERR_ALERT | ERR_FATAL;
2320 goto out;
2321 }
2322 goto out;
2323 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002324 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002325 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2326 err_code |= ERR_WARN;
2327
2328 if (*(args[1]) == 0) {
2329 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2330 err_code |= ERR_ALERT | ERR_FATAL;
2331 goto out;
2332 }
2333 free(curproxy->defbe.name);
2334 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002335 if (!curproxy->defbe.name)
2336 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002337
2338 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2339 goto out;
2340 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002341 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002342 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 +01002343
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002344 err_code |= ERR_ALERT | ERR_FATAL;
2345 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002346 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002347 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002348 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2349 err_code |= ERR_WARN;
2350
2351 if (strcmp(args[1], "never") == 0) {
2352 /* enable a graceful server shutdown on an HTTP 404 response */
2353 curproxy->options &= ~PR_O_REUSE_MASK;
2354 curproxy->options |= PR_O_REUSE_NEVR;
2355 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2356 goto out;
2357 }
2358 else if (strcmp(args[1], "safe") == 0) {
2359 /* enable a graceful server shutdown on an HTTP 404 response */
2360 curproxy->options &= ~PR_O_REUSE_MASK;
2361 curproxy->options |= PR_O_REUSE_SAFE;
2362 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2363 goto out;
2364 }
2365 else if (strcmp(args[1], "aggressive") == 0) {
2366 curproxy->options &= ~PR_O_REUSE_MASK;
2367 curproxy->options |= PR_O_REUSE_AGGR;
2368 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2369 goto out;
2370 }
2371 else if (strcmp(args[1], "always") == 0) {
2372 /* enable a graceful server shutdown on an HTTP 404 response */
2373 curproxy->options &= ~PR_O_REUSE_MASK;
2374 curproxy->options |= PR_O_REUSE_ALWS;
2375 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2376 goto out;
2377 }
2378 else {
2379 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2380 err_code |= ERR_ALERT | ERR_FATAL;
2381 goto out;
2382 }
2383 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002384 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002385 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002386 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2387 err_code |= ERR_ALERT | ERR_FATAL;
2388 goto out;
2389 }
2390
2391 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2392 err_code |= ERR_WARN;
2393
2394 if (strcmp(args[1], "fail") == 0) {
2395 /* add a condition to fail monitor requests */
2396 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2397 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2398 file, linenum, args[0], args[1]);
2399 err_code |= ERR_ALERT | ERR_FATAL;
2400 goto out;
2401 }
2402
2403 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2404 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2405 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2406 file, linenum, args[0], args[1], errmsg);
2407 err_code |= ERR_ALERT | ERR_FATAL;
2408 goto out;
2409 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002410 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002411 }
2412 else {
2413 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2414 err_code |= ERR_ALERT | ERR_FATAL;
2415 goto out;
2416 }
2417 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002418#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002419 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002420 /* enable transparent proxy connections */
2421 curproxy->options |= PR_O_TRANSP;
2422 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2423 goto out;
2424 }
2425#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002426 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002427 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2428 err_code |= ERR_WARN;
2429
2430 if (*(args[1]) == 0) {
2431 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2432 err_code |= ERR_ALERT | ERR_FATAL;
2433 goto out;
2434 }
2435 curproxy->maxconn = atol(args[1]);
2436 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2437 goto out;
2438 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002439 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002440 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2441 err_code |= ERR_WARN;
2442
2443 if (*(args[1]) == 0) {
2444 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2445 err_code |= ERR_ALERT | ERR_FATAL;
2446 goto out;
2447 }
2448 curproxy->backlog = atol(args[1]);
2449 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2450 goto out;
2451 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002452 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002453 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2454 err_code |= ERR_WARN;
2455
2456 if (*(args[1]) == 0) {
2457 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2458 err_code |= ERR_ALERT | ERR_FATAL;
2459 goto out;
2460 }
2461 curproxy->fullconn = atol(args[1]);
2462 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2463 goto out;
2464 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002465 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002466 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 +02002467 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002468 err_code |= ERR_ALERT | ERR_FATAL;
2469 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002470 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002471 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002472 struct sockaddr_storage *sk;
2473 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002474
Willy Tarreau5d095c22021-02-12 10:15:59 +01002475 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002476 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2477 err_code |= ERR_ALERT | ERR_FATAL;
2478 goto out;
2479 }
2480 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2481 err_code |= ERR_WARN;
2482
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002483 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2484 &errmsg, NULL, NULL,
2485 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 +01002486 if (!sk) {
2487 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2488 err_code |= ERR_ALERT | ERR_FATAL;
2489 goto out;
2490 }
2491
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002492 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2493 goto out;
2494
2495 curproxy->dispatch_addr = *sk;
2496 curproxy->options |= PR_O_DISPATCH;
2497 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002498 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002499 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2500 err_code |= ERR_WARN;
2501
2502 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2503 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2504 err_code |= ERR_ALERT | ERR_FATAL;
2505 goto out;
2506 }
2507 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002508 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002509 /**
2510 * The syntax for hash-type config element is
2511 * hash-type {map-based|consistent} [[<algo>] avalanche]
2512 *
2513 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2514 */
2515 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2516
2517 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2518 err_code |= ERR_WARN;
2519
2520 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2521 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2522 }
2523 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2524 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2525 }
2526 else if (strcmp(args[1], "avalanche") == 0) {
2527 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]);
2528 err_code |= ERR_ALERT | ERR_FATAL;
2529 goto out;
2530 }
2531 else {
2532 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2533 err_code |= ERR_ALERT | ERR_FATAL;
2534 goto out;
2535 }
2536
2537 /* set the hash function to use */
2538 if (!*args[2]) {
2539 /* the default algo is sdbm */
2540 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2541
2542 /* if consistent with no argument, then avalanche modifier is also applied */
2543 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2544 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2545 } else {
2546 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002547 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002548 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2549 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002550 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002551 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2552 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002553 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002554 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2555 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002556 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002557 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2558 }
2559 else {
2560 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2561 err_code |= ERR_ALERT | ERR_FATAL;
2562 goto out;
2563 }
2564
2565 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002566 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002567 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2568 }
2569 else if (*args[3]) {
2570 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2571 err_code |= ERR_ALERT | ERR_FATAL;
2572 goto out;
2573 }
2574 }
2575 }
2576 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2577 if (*(args[1]) == 0) {
2578 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2579 err_code |= ERR_ALERT | ERR_FATAL;
2580 goto out;
2581 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002582 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2583 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002584 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2585 err_code |= ERR_ALERT | ERR_FATAL;
2586 goto out;
2587 }
2588 }
2589 else if (strcmp(args[0], "unique-id-format") == 0) {
2590 if (!*(args[1])) {
2591 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2592 err_code |= ERR_ALERT | ERR_FATAL;
2593 goto out;
2594 }
2595 if (*(args[2])) {
2596 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2597 err_code |= ERR_ALERT | ERR_FATAL;
2598 goto out;
2599 }
2600 free(curproxy->conf.uniqueid_format_string);
2601 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002602 if (!curproxy->conf.uniqueid_format_string)
2603 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604
2605 free(curproxy->conf.uif_file);
2606 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2607 curproxy->conf.uif_line = curproxy->conf.args.line;
2608 }
2609
2610 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002611 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002612 if (!*(args[1])) {
2613 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2614 err_code |= ERR_ALERT | ERR_FATAL;
2615 goto out;
2616 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002617 copy = strdup(args[1]);
2618 if (copy == NULL) {
2619 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2620 err_code |= ERR_ALERT | ERR_FATAL;
2621 goto out;
2622 }
2623
2624 istfree(&curproxy->header_unique_id);
2625 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002626 }
2627
2628 else if (strcmp(args[0], "log-format") == 0) {
2629 if (!*(args[1])) {
2630 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2631 err_code |= ERR_ALERT | ERR_FATAL;
2632 goto out;
2633 }
2634 if (*(args[2])) {
2635 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2636 err_code |= ERR_ALERT | ERR_FATAL;
2637 goto out;
2638 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002639 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002640 char *oldlogformat = "log-format";
2641
2642 if (curproxy->conf.logformat_string == default_http_log_format)
2643 oldlogformat = "option httplog";
2644 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2645 oldlogformat = "option tcplog";
2646 else if (curproxy->conf.logformat_string == clf_http_log_format)
2647 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002648 else if (curproxy->conf.logformat_string == default_https_log_format)
2649 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002650 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2651 file, linenum, oldlogformat);
2652 }
2653 if (curproxy->conf.logformat_string != default_http_log_format &&
2654 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002655 curproxy->conf.logformat_string != clf_http_log_format &&
2656 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002657 free(curproxy->conf.logformat_string);
2658 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002659 if (!curproxy->conf.logformat_string)
2660 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002661
2662 free(curproxy->conf.lfs_file);
2663 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2664 curproxy->conf.lfs_line = curproxy->conf.args.line;
2665
2666 /* get a chance to improve log-format error reporting by
2667 * reporting the correct line-number when possible.
2668 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002669 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002670 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2671 file, linenum, curproxy->id);
2672 err_code |= ERR_WARN;
2673 }
2674 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002675 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002676 if (!*(args[1])) {
2677 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2678 err_code |= ERR_ALERT | ERR_FATAL;
2679 goto out;
2680 }
2681 if (*(args[2])) {
2682 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2683 err_code |= ERR_ALERT | ERR_FATAL;
2684 goto out;
2685 }
2686
2687 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2688 free(curproxy->conf.logformat_sd_string);
2689 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002690 if (!curproxy->conf.logformat_sd_string)
2691 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002692
2693 free(curproxy->conf.lfsd_file);
2694 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2695 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2696
2697 /* get a chance to improve log-format-sd error reporting by
2698 * reporting the correct line-number when possible.
2699 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002700 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002701 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2702 file, linenum, curproxy->id);
2703 err_code |= ERR_WARN;
2704 }
2705 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002706 else if (strcmp(args[0], "error-log-format") == 0) {
2707 if (!*(args[1])) {
2708 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2709 err_code |= ERR_ALERT | ERR_FATAL;
2710 goto out;
2711 }
2712 if (*(args[2])) {
2713 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2714 err_code |= ERR_ALERT | ERR_FATAL;
2715 goto out;
2716 }
2717 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2718 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2719 file, linenum);
2720 }
2721 free(curproxy->conf.error_logformat_string);
2722 curproxy->conf.error_logformat_string = strdup(args[1]);
2723 if (!curproxy->conf.error_logformat_string)
2724 goto alloc_error;
2725
2726 free(curproxy->conf.elfs_file);
2727 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2728 curproxy->conf.elfs_line = curproxy->conf.args.line;
2729
2730 /* get a chance to improve log-format error reporting by
2731 * reporting the correct line-number when possible.
2732 */
2733 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2734 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2735 file, linenum, curproxy->id);
2736 err_code |= ERR_WARN;
2737 }
2738 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002739 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002740 if (*(args[1]) == 0) {
2741 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2742 err_code |= ERR_ALERT | ERR_FATAL;
2743 goto out;
2744 }
2745 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002746 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2747 if (b_orig(&curproxy->log_tag) == NULL) {
2748 chunk_destroy(&curproxy->log_tag);
2749 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2750 err_code |= ERR_ALERT | ERR_FATAL;
2751 goto out;
2752 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002753 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002754 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002755 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002756 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2757 err_code |= ERR_ALERT | ERR_FATAL;
2758 goto out;
2759 }
2760 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002761 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002762 int cur_arg;
2763 int port1, port2;
2764 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002765
2766 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2767 err_code |= ERR_WARN;
2768
2769 if (!*args[1]) {
2770 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2771 file, linenum, "source", "usesrc", "interface");
2772 err_code |= ERR_ALERT | ERR_FATAL;
2773 goto out;
2774 }
2775
Christopher Faulet31930372019-07-15 10:16:58 +02002776 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002777 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002778 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002779 curproxy->conn_src.iface_len = 0;
2780
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002781 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2782 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002783 if (!sk) {
2784 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2785 file, linenum, args[0], args[1], errmsg);
2786 err_code |= ERR_ALERT | ERR_FATAL;
2787 goto out;
2788 }
2789
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002790 curproxy->conn_src.source_addr = *sk;
2791 curproxy->conn_src.opts |= CO_SRC_BIND;
2792
2793 cur_arg = 2;
2794 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002795 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002796#if defined(CONFIG_HAP_TRANSPARENT)
2797 if (!*args[cur_arg + 1]) {
2798 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2799 file, linenum, "usesrc");
2800 err_code |= ERR_ALERT | ERR_FATAL;
2801 goto out;
2802 }
2803
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002804 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002805 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2806 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002807 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002808 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2809 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2810 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2811 char *name, *end;
2812
2813 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002814 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002815 name++;
2816
2817 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002818 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002819 end++;
2820
2821 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2822 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002823 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002824 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002825 if (!curproxy->conn_src.bind_hdr_name)
2826 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002827 curproxy->conn_src.bind_hdr_len = end - name;
2828 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2829 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2830 curproxy->conn_src.bind_hdr_occ = -1;
2831
2832 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002833 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002834 end++;
2835 if (*end == ',') {
2836 end++;
2837 name = end;
2838 if (*end == '-')
2839 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002840 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002841 end++;
2842 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2843 }
2844
2845 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2846 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2847 " occurrences values smaller than %d.\n",
2848 file, linenum, MAX_HDR_HISTORY);
2849 err_code |= ERR_ALERT | ERR_FATAL;
2850 goto out;
2851 }
2852 } else {
2853 struct sockaddr_storage *sk;
2854
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002855 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2856 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002857 if (!sk) {
2858 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2859 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2860 err_code |= ERR_ALERT | ERR_FATAL;
2861 goto out;
2862 }
2863
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002864 curproxy->conn_src.tproxy_addr = *sk;
2865 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2866 }
2867 global.last_checks |= LSTCHK_NETADM;
2868#else /* no TPROXY support */
2869 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2870 file, linenum, "usesrc");
2871 err_code |= ERR_ALERT | ERR_FATAL;
2872 goto out;
2873#endif
2874 cur_arg += 2;
2875 continue;
2876 }
2877
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002878 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002879#ifdef SO_BINDTODEVICE
2880 if (!*args[cur_arg + 1]) {
2881 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2882 file, linenum, args[0]);
2883 err_code |= ERR_ALERT | ERR_FATAL;
2884 goto out;
2885 }
2886 free(curproxy->conn_src.iface_name);
2887 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002888 if (!curproxy->conn_src.iface_name)
2889 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002890 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2891 global.last_checks |= LSTCHK_NETADM;
2892#else
2893 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2894 file, linenum, args[0], args[cur_arg]);
2895 err_code |= ERR_ALERT | ERR_FATAL;
2896 goto out;
2897#endif
2898 cur_arg += 2;
2899 continue;
2900 }
2901 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2902 file, linenum, args[0], "interface", "usesrc");
2903 err_code |= ERR_ALERT | ERR_FATAL;
2904 goto out;
2905 }
2906 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002907 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002908 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2909 file, linenum, "usesrc", "source");
2910 err_code |= ERR_ALERT | ERR_FATAL;
2911 goto out;
2912 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002913 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 +02002914 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002915 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002916 file, linenum, args[0]);
2917 err_code |= ERR_ALERT | ERR_FATAL;
2918 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002919 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002920 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002921 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2922 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2923 err_code |= ERR_ALERT | ERR_FATAL;
2924 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002926 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002927 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2928 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2929 err_code |= ERR_ALERT | ERR_FATAL;
2930 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002931 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002932 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002933 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2934 err_code |= ERR_ALERT | ERR_FATAL;
2935 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002936 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002937 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002938 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2939 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2940 err_code |= ERR_ALERT | ERR_FATAL;
2941 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002942 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002943 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002944 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2945 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2946 err_code |= ERR_ALERT | ERR_FATAL;
2947 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002948 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002949 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002950 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2951 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2952 err_code |= ERR_ALERT | ERR_FATAL;
2953 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002954 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002955 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002956 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2957 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2958 err_code |= ERR_ALERT | ERR_FATAL;
2959 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002960 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002961 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 +02002962 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2963 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2964 err_code |= ERR_ALERT | ERR_FATAL;
2965 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002966 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002967 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002968 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", 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], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
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 allow' 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], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002979 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2980 "Use 'http-request tarpit' 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], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002985 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2986 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2987 err_code |= ERR_ALERT | ERR_FATAL;
2988 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002989 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002990 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 +02002991 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2992 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2993 err_code |= ERR_ALERT | ERR_FATAL;
2994 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002995 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002996 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002997 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2998 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2999 err_code |= ERR_ALERT | ERR_FATAL;
3000 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003001 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003002 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003003 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3004 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3005 err_code |= ERR_ALERT | ERR_FATAL;
3006 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003007 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003008 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303009 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003010 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3011 err_code |= ERR_ALERT | ERR_FATAL;
3012 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003013 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003014 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003015 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3016 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3017 err_code |= ERR_ALERT | ERR_FATAL;
3018 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003019 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003020 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003021 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3022 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3023 err_code |= ERR_ALERT | ERR_FATAL;
3024 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003025 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003026 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003027 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3028 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3029 err_code |= ERR_ALERT | ERR_FATAL;
3030 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003031 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003032 else {
3033 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003034 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003035 int index;
3036
3037 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3038 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3039 if (kwl->kw[index].section != CFG_LISTEN)
3040 continue;
3041 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003042 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003043 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003044 err_code |= ERR_ALERT | ERR_FATAL;
3045 goto out;
3046 }
3047
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003048 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003049 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003050 if (rc < 0) {
3051 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3052 err_code |= ERR_ALERT | ERR_FATAL;
3053 goto out;
3054 }
3055 else if (rc > 0) {
3056 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3057 err_code |= ERR_WARN;
3058 goto out;
3059 }
3060 goto out;
3061 }
3062 }
3063 }
3064
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003065 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3066 if (best)
3067 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3068 else
3069 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003070 err_code |= ERR_ALERT | ERR_FATAL;
3071 goto out;
3072 }
3073 out:
3074 free(errmsg);
3075 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003076
3077 alloc_error:
3078 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3079 err_code |= ERR_ALERT | ERR_ABORT;
3080 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003081}