blob: 3864a11c8986c586240d4fc95465cd093385be32 [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:
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001411 free_acl_cond(cond);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001412 if (rule)
1413 ha_free(&(rule->be.name));
1414 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001415 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001416 }
1417 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001418 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001419 }
1420 else if (strcmp(args[0], "use-server") == 0) {
1421 struct server_rule *rule;
1422
Willy Tarreau5d095c22021-02-12 10:15:59 +01001423 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001424 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1425 err_code |= ERR_ALERT | ERR_FATAL;
1426 goto out;
1427 }
1428
1429 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1430 err_code |= ERR_WARN;
1431
1432 if (*(args[1]) == 0) {
1433 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1434 err_code |= ERR_ALERT | ERR_FATAL;
1435 goto out;
1436 }
1437
1438 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1439 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1440 file, linenum, args[0]);
1441 err_code |= ERR_ALERT | ERR_FATAL;
1442 goto out;
1443 }
1444
1445 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1446 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1447 file, linenum, errmsg);
1448 err_code |= ERR_ALERT | ERR_FATAL;
1449 goto out;
1450 }
1451
1452 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1453
1454 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001455 if (!rule)
1456 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001457 rule->cond = cond;
1458 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001459 if (!rule->srv.name)
1460 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001461 rule->line = linenum;
1462 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001463 if (!rule->file) {
1464 use_server_alloc_error:
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001465 free_acl_cond(cond);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001466 if (rule)
1467 ha_free(&(rule->srv.name));
1468 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001469 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001470 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001471 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001472 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001473 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1474 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001475 else if ((strcmp(args[0], "force-persist") == 0) ||
1476 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001477 struct persist_rule *rule;
1478
Willy Tarreau5d095c22021-02-12 10:15:59 +01001479 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001480 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1481 err_code |= ERR_ALERT | ERR_FATAL;
1482 goto out;
1483 }
1484
1485 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1486 err_code |= ERR_WARN;
1487
1488 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1489 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1490 file, linenum, args[0]);
1491 err_code |= ERR_ALERT | ERR_FATAL;
1492 goto out;
1493 }
1494
1495 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1496 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1497 file, linenum, args[0], errmsg);
1498 err_code |= ERR_ALERT | ERR_FATAL;
1499 goto out;
1500 }
1501
1502 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1503 * where force-persist is applied.
1504 */
1505 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1506
1507 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001508 if (!rule) {
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001509 free_acl_cond(cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001510 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001511 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001512 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001513 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001514 rule->type = PERSIST_TYPE_FORCE;
1515 } else {
1516 rule->type = PERSIST_TYPE_IGNORE;
1517 }
1518 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001519 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001520 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001521 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001522 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001523
Willy Tarreau5d095c22021-02-12 10:15:59 +01001524 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001525 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1526 file, linenum);
1527 err_code |= ERR_ALERT | ERR_FATAL;
1528 goto out;
1529 }
1530
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001531 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001532 if (other) {
1533 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 +01001534 file, linenum, curproxy->id,
1535 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1536 other->proxy ? other->id : other->peers.p->id,
1537 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001538 err_code |= ERR_ALERT | ERR_FATAL;
1539 goto out;
1540 }
1541
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001542 curproxy->table = calloc(1, sizeof *curproxy->table);
1543 if (!curproxy->table) {
1544 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1545 file, linenum, args[0], args[1]);
1546 err_code |= ERR_ALERT | ERR_FATAL;
1547 goto out;
1548 }
1549
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001550 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1551 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001552 if (err_code & ERR_FATAL) {
1553 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001554 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001555 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001556
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001557 /* Store the proxy in the stick-table. */
1558 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001559
1560 stktable_store_name(curproxy->table);
1561 curproxy->table->next = stktables_list;
1562 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001563
1564 /* Add this proxy to the list of proxies which refer to its stick-table. */
1565 if (curproxy->table->proxies_list != curproxy) {
1566 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1567 curproxy->table->proxies_list = curproxy;
1568 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001569 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001570 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001571 struct sticking_rule *rule;
1572 struct sample_expr *expr;
1573 int myidx = 0;
1574 const char *name = NULL;
1575 int flags;
1576
Willy Tarreau5d095c22021-02-12 10:15:59 +01001577 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001578 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1579 err_code |= ERR_ALERT | ERR_FATAL;
1580 goto out;
1581 }
1582
1583 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1584 err_code |= ERR_WARN;
1585 goto out;
1586 }
1587
1588 myidx++;
1589 if ((strcmp(args[myidx], "store") == 0) ||
1590 (strcmp(args[myidx], "store-request") == 0)) {
1591 myidx++;
1592 flags = STK_IS_STORE;
1593 }
1594 else if (strcmp(args[myidx], "store-response") == 0) {
1595 myidx++;
1596 flags = STK_IS_STORE | STK_ON_RSP;
1597 }
1598 else if (strcmp(args[myidx], "match") == 0) {
1599 myidx++;
1600 flags = STK_IS_MATCH;
1601 }
1602 else if (strcmp(args[myidx], "on") == 0) {
1603 myidx++;
1604 flags = STK_IS_MATCH | STK_IS_STORE;
1605 }
1606 else {
1607 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1608 err_code |= ERR_ALERT | ERR_FATAL;
1609 goto out;
1610 }
1611
1612 if (*(args[myidx]) == 0) {
1613 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1614 err_code |= ERR_ALERT | ERR_FATAL;
1615 goto out;
1616 }
1617
1618 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001619 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001620 if (!expr) {
1621 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1622 err_code |= ERR_ALERT | ERR_FATAL;
1623 goto out;
1624 }
1625
1626 if (flags & STK_ON_RSP) {
1627 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1628 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1629 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1630 err_code |= ERR_ALERT | ERR_FATAL;
1631 free(expr);
1632 goto out;
1633 }
1634 } else {
1635 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1636 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1637 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1638 err_code |= ERR_ALERT | ERR_FATAL;
1639 free(expr);
1640 goto out;
1641 }
1642 }
1643
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001644 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001645 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1646
1647 if (strcmp(args[myidx], "table") == 0) {
1648 myidx++;
1649 name = args[myidx++];
1650 }
1651
1652 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1653 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1654 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1655 file, linenum, args[0], errmsg);
1656 err_code |= ERR_ALERT | ERR_FATAL;
1657 free(expr);
1658 goto out;
1659 }
1660 }
1661 else if (*(args[myidx])) {
1662 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1663 file, linenum, args[0], args[myidx]);
1664 err_code |= ERR_ALERT | ERR_FATAL;
1665 free(expr);
1666 goto out;
1667 }
1668 if (flags & STK_ON_RSP)
1669 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1670 else
1671 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1672
1673 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001674 if (!rule) {
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001675 free_acl_cond(cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001676 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001677 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001678 rule->cond = cond;
1679 rule->expr = expr;
1680 rule->flags = flags;
1681 rule->table.name = name ? strdup(name) : NULL;
1682 LIST_INIT(&rule->list);
1683 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001684 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001685 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001686 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001687 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001688 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001689 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001690 curproxy->uri_auth = NULL; /* we must detach from the default config */
1691
1692 if (!*args[1]) {
1693 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001694 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001695 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001696 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001697
Willy Tarreau5d095c22021-02-12 10:15:59 +01001698 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001699 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1700 err_code |= ERR_ALERT | ERR_FATAL;
1701 goto out;
1702 }
1703
Christopher Fauletb15625a2021-04-12 21:31:45 +02001704 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1705 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706
1707 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1708 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1709 file, linenum, args[0], args[1]);
1710 err_code |= ERR_ALERT | ERR_FATAL;
1711 goto out;
1712 }
1713 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1714 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1715 file, linenum, args[0], args[1], errmsg);
1716 err_code |= ERR_ALERT | ERR_FATAL;
1717 goto out;
1718 }
1719
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001720 if (curproxy->cap & PR_CAP_FE)
1721 where |= SMP_VAL_FE_HRQ_HDR;
1722 if (curproxy->cap & PR_CAP_BE)
1723 where |= SMP_VAL_BE_HRQ_HDR;
1724 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001725
1726 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001727 if (!rule) {
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001728 free_acl_cond(cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001729 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001730 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001731 rule->cond = cond;
1732 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001733 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001734 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001735 if (*(args[2]) == 0) {
1736 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1737 err_code |= ERR_ALERT | ERR_FATAL;
1738 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001739 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1740 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001741 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001742 if (*(args[2]) == 0) {
1743 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1744 err_code |= ERR_ALERT | ERR_FATAL;
1745 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001746 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1747 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001748 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001749 unsigned interval;
1750
1751 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001752 if (err == PARSE_TIME_OVER) {
1753 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1754 file, linenum, args[2]);
1755 err_code |= ERR_ALERT | ERR_FATAL;
1756 goto out;
1757 }
1758 else if (err == PARSE_TIME_UNDER) {
1759 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1760 file, linenum, args[2]);
1761 err_code |= ERR_ALERT | ERR_FATAL;
1762 goto out;
1763 }
1764 else if (err) {
1765 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001766 file, linenum, *err);
1767 err_code |= ERR_ALERT | ERR_FATAL;
1768 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001769 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1770 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001771 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001772 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001773 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001774
Willy Tarreau5d095c22021-02-12 10:15:59 +01001775 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001776 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1777 err_code |= ERR_ALERT | ERR_FATAL;
1778 goto out;
1779 }
1780
Christopher Fauletb15625a2021-04-12 21:31:45 +02001781 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1782 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001783
1784 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1785 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1786 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1787 file, linenum, args[0]);
1788 err_code |= ERR_WARN;
1789 }
1790
1791 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1792
1793 if (!rule) {
1794 err_code |= ERR_ALERT | ERR_ABORT;
1795 goto out;
1796 }
1797
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001798 if (curproxy->cap & PR_CAP_FE)
1799 where |= SMP_VAL_FE_HRQ_HDR;
1800 if (curproxy->cap & PR_CAP_BE)
1801 where |= SMP_VAL_BE_HRQ_HDR;
1802 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001803 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001804
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001805 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001806 if (*(args[2]) == 0) {
1807 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1808 err_code |= ERR_ALERT | ERR_FATAL;
1809 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001810 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1811 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001812 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001813 if (*(args[2]) == 0) {
1814 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1815 err_code |= ERR_ALERT | ERR_FATAL;
1816 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001817 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1818 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001819 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001820 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1821 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001822 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001823 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1824 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001825 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001826 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1827 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001828 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001829 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1830 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001831 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001832
1833 if (*args[2]) {
1834 int i;
1835 char c;
1836
1837 for (i=0; args[2][i]; i++) {
1838 c = args[2][i];
1839 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1840 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1841 break;
1842 }
1843
1844 if (!i || args[2][i]) {
1845 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1846 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1847 file, linenum, args[0], args[1]);
1848 err_code |= ERR_ALERT | ERR_FATAL;
1849 goto out;
1850 }
1851 }
1852
Christopher Fauletb15625a2021-04-12 21:31:45 +02001853 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1854 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001855 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001856 char *desc = NULL;
1857
1858 if (*args[2]) {
1859 int i, len=0;
1860 char *d;
1861
1862 for (i = 2; *args[i]; i++)
1863 len += strlen(args[i]) + 1;
1864
1865 desc = d = calloc(1, len);
1866
1867 d += snprintf(d, desc + len - d, "%s", args[2]);
1868 for (i = 3; *args[i]; i++)
1869 d += snprintf(d, desc + len - d, " %s", args[i]);
1870 }
1871
1872 if (!*args[2] && !global.desc)
1873 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1874 file, linenum, args[1]);
1875 else {
1876 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1877 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001878 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001879 }
1880 free(desc);
1881 }
1882 } else {
1883stats_error_parsing:
1884 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1885 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1886 err_code |= ERR_ALERT | ERR_FATAL;
1887 goto out;
1888 }
1889 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001890 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001891 int optnum;
1892
1893 if (*(args[1]) == '\0') {
1894 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1895 file, linenum, args[0]);
1896 err_code |= ERR_ALERT | ERR_FATAL;
1897 goto out;
1898 }
1899
1900 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001901 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001902 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1903 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1904 file, linenum, cfg_opts[optnum].name);
1905 err_code |= ERR_ALERT | ERR_FATAL;
1906 goto out;
1907 }
1908 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1909 goto out;
1910
1911 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1912 err_code |= ERR_WARN;
1913 goto out;
1914 }
1915
1916 curproxy->no_options &= ~cfg_opts[optnum].val;
1917 curproxy->options &= ~cfg_opts[optnum].val;
1918
1919 switch (kwm) {
1920 case KWM_STD:
1921 curproxy->options |= cfg_opts[optnum].val;
1922 break;
1923 case KWM_NO:
1924 curproxy->no_options |= cfg_opts[optnum].val;
1925 break;
1926 case KWM_DEF: /* already cleared */
1927 break;
1928 }
1929
1930 goto out;
1931 }
1932 }
1933
1934 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001935 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001936 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1937 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1938 file, linenum, cfg_opts2[optnum].name);
1939 err_code |= ERR_ALERT | ERR_FATAL;
1940 goto out;
1941 }
1942 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1943 goto out;
1944 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1945 err_code |= ERR_WARN;
1946 goto out;
1947 }
1948
1949 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1950 curproxy->options2 &= ~cfg_opts2[optnum].val;
1951
1952 switch (kwm) {
1953 case KWM_STD:
1954 curproxy->options2 |= cfg_opts2[optnum].val;
1955 break;
1956 case KWM_NO:
1957 curproxy->no_options2 |= cfg_opts2[optnum].val;
1958 break;
1959 case KWM_DEF: /* already cleared */
1960 break;
1961 }
1962 goto out;
1963 }
1964 }
1965
1966 /* HTTP options override each other. They can be cancelled using
1967 * "no option xxx" which only switches to default mode if the mode
1968 * was this one (useful for cancelling options set in defaults
1969 * sections).
1970 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001971 if (strcmp(args[1], "forceclose") == 0) {
1972 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",
1973 file, linenum, args[1]);
1974 err_code |= ERR_ALERT | ERR_FATAL;
1975 goto out;
1976 }
1977 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001978 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1979 goto out;
1980 if (kwm == KWM_STD) {
1981 curproxy->options &= ~PR_O_HTTP_MODE;
1982 curproxy->options |= PR_O_HTTP_CLO;
1983 goto out;
1984 }
1985 else if (kwm == KWM_NO) {
1986 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1987 curproxy->options &= ~PR_O_HTTP_MODE;
1988 goto out;
1989 }
1990 }
1991 else if (strcmp(args[1], "http-server-close") == 0) {
1992 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1993 goto out;
1994 if (kwm == KWM_STD) {
1995 curproxy->options &= ~PR_O_HTTP_MODE;
1996 curproxy->options |= PR_O_HTTP_SCL;
1997 goto out;
1998 }
1999 else if (kwm == KWM_NO) {
2000 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2001 curproxy->options &= ~PR_O_HTTP_MODE;
2002 goto out;
2003 }
2004 }
2005 else if (strcmp(args[1], "http-keep-alive") == 0) {
2006 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2007 goto out;
2008 if (kwm == KWM_STD) {
2009 curproxy->options &= ~PR_O_HTTP_MODE;
2010 curproxy->options |= PR_O_HTTP_KAL;
2011 goto out;
2012 }
2013 else if (kwm == KWM_NO) {
2014 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2015 curproxy->options &= ~PR_O_HTTP_MODE;
2016 goto out;
2017 }
2018 }
2019 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002020 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 +02002021 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002022 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002023 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002024 }
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +01002025 else if (strcmp(args[1], "forwarded") == 0) {
2026 if (kwm == KWM_STD) {
2027 err_code |= proxy_http_parse_7239(args, 0, curproxy, curr_defproxy, file, linenum);
2028 goto out;
2029 }
2030 else if (kwm == KWM_NO) {
Aurelien DARRAGONb2e2ec52023-01-09 11:09:03 +01002031 if (curproxy->http_ext)
2032 http_ext_7239_clean(curproxy);
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +01002033 goto out;
2034 }
2035 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002036
2037 /* Redispatch can take an integer argument that control when the
2038 * resispatch occurs. All values are relative to the retries option.
2039 * This can be cancelled using "no option xxx".
2040 */
2041 if (strcmp(args[1], "redispatch") == 0) {
2042 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2043 err_code |= ERR_WARN;
2044 goto out;
2045 }
2046
2047 curproxy->no_options &= ~PR_O_REDISP;
2048 curproxy->options &= ~PR_O_REDISP;
2049
2050 switch (kwm) {
2051 case KWM_STD:
2052 curproxy->options |= PR_O_REDISP;
2053 curproxy->redispatch_after = -1;
2054 if(*args[2]) {
2055 curproxy->redispatch_after = atol(args[2]);
2056 }
2057 break;
2058 case KWM_NO:
2059 curproxy->no_options |= PR_O_REDISP;
2060 curproxy->redispatch_after = 0;
2061 break;
2062 case KWM_DEF: /* already cleared */
2063 break;
2064 }
2065 goto out;
2066 }
2067
Willy Tarreau25241232021-07-18 19:18:56 +02002068 if (strcmp(args[1], "http_proxy") == 0) {
2069 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",
2070 file, linenum, args[1]);
2071 err_code |= ERR_ALERT | ERR_FATAL;
2072 goto out;
2073 }
2074
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002075 if (kwm != KWM_STD) {
2076 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2077 file, linenum, args[1]);
2078 err_code |= ERR_ALERT | ERR_FATAL;
2079 goto out;
2080 }
2081
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002082 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002083 char *logformat;
2084 /* generate a complete HTTP log */
2085 logformat = default_http_log_format;
2086 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002087 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002088 curproxy->options2 |= PR_O2_CLFLOG;
2089 logformat = clf_http_log_format;
2090 } else {
2091 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2092 err_code |= ERR_ALERT | ERR_FATAL;
2093 goto out;
2094 }
2095 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2096 goto out;
2097 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002098 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002099 char *oldlogformat = "log-format";
2100 char *clflogformat = "";
2101
2102 if (curproxy->conf.logformat_string == default_http_log_format)
2103 oldlogformat = "option httplog";
2104 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2105 oldlogformat = "option tcplog";
2106 else if (curproxy->conf.logformat_string == clf_http_log_format)
2107 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002108 else if (curproxy->conf.logformat_string == default_https_log_format)
2109 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002110 if (logformat == clf_http_log_format)
2111 clflogformat = " clf";
2112 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2113 file, linenum, clflogformat, oldlogformat);
2114 }
2115 if (curproxy->conf.logformat_string != default_http_log_format &&
2116 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002117 curproxy->conf.logformat_string != clf_http_log_format &&
2118 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002119 free(curproxy->conf.logformat_string);
2120 curproxy->conf.logformat_string = logformat;
2121
2122 free(curproxy->conf.lfs_file);
2123 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2124 curproxy->conf.lfs_line = curproxy->conf.args.line;
2125
Willy Tarreau5d095c22021-02-12 10:15:59 +01002126 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002127 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2128 file, linenum, curproxy->id);
2129 err_code |= ERR_WARN;
2130 }
2131 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002132 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002133 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002134 char *oldlogformat = "log-format";
2135
2136 if (curproxy->conf.logformat_string == default_http_log_format)
2137 oldlogformat = "option httplog";
2138 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2139 oldlogformat = "option tcplog";
2140 else if (curproxy->conf.logformat_string == clf_http_log_format)
2141 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002142 else if (curproxy->conf.logformat_string == default_https_log_format)
2143 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002144 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2145 file, linenum, oldlogformat);
2146 }
2147 /* generate a detailed TCP log */
2148 if (curproxy->conf.logformat_string != default_http_log_format &&
2149 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002150 curproxy->conf.logformat_string != clf_http_log_format &&
2151 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002152 free(curproxy->conf.logformat_string);
2153 curproxy->conf.logformat_string = default_tcp_log_format;
2154
2155 free(curproxy->conf.lfs_file);
2156 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2157 curproxy->conf.lfs_line = curproxy->conf.args.line;
2158
2159 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2160 goto out;
2161
Willy Tarreau5d095c22021-02-12 10:15:59 +01002162 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002163 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2164 file, linenum, curproxy->id);
2165 err_code |= ERR_WARN;
2166 }
2167 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002168 else if (strcmp(args[1], "httpslog") == 0) {
2169 char *logformat;
2170 /* generate a complete HTTP log */
2171 logformat = default_https_log_format;
2172 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2173 char *oldlogformat = "log-format";
2174
2175 if (curproxy->conf.logformat_string == default_http_log_format)
2176 oldlogformat = "option httplog";
2177 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2178 oldlogformat = "option tcplog";
2179 else if (curproxy->conf.logformat_string == clf_http_log_format)
2180 oldlogformat = "option httplog clf";
2181 else if (curproxy->conf.logformat_string == default_https_log_format)
2182 oldlogformat = "option httpslog";
2183 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2184 file, linenum, oldlogformat);
2185 }
2186 if (curproxy->conf.logformat_string != default_http_log_format &&
2187 curproxy->conf.logformat_string != default_tcp_log_format &&
2188 curproxy->conf.logformat_string != clf_http_log_format &&
2189 curproxy->conf.logformat_string != default_https_log_format)
2190 free(curproxy->conf.logformat_string);
2191 curproxy->conf.logformat_string = logformat;
2192
2193 free(curproxy->conf.lfs_file);
2194 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2195 curproxy->conf.lfs_line = curproxy->conf.args.line;
2196
2197 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2198 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2199 file, linenum, curproxy->id);
2200 err_code |= ERR_WARN;
2201 }
2202 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002203 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002204 /* enable TCP keep-alives on client and server streams */
2205 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2206 err_code |= ERR_WARN;
2207
2208 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2209 goto out;
2210
2211 if (curproxy->cap & PR_CAP_FE)
2212 curproxy->options |= PR_O_TCP_CLI_KA;
2213 if (curproxy->cap & PR_CAP_BE)
2214 curproxy->options |= PR_O_TCP_SRV_KA;
2215 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002216 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002217 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002218 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002219 goto out;
2220 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002221 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002222 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002223 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002224 goto out;
2225 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002226 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002227 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +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], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002232 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +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], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002237 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +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], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002242 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002243 if (err_code & ERR_FATAL)
2244 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002245 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002246 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002247 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13: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], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002252 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002253 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002254 goto out;
2255 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002256 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002257 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +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], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002262 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +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], "forwardfor") == 0) {
Aurelien DARRAGON730b9832022-12-28 18:53:05 +01002267 err_code |= proxy_http_parse_xff(args, 0, curproxy, curr_defproxy, file, linenum);
2268 if (err_code & ERR_FATAL)
2269 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002270 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002271 else if (strcmp(args[1], "originalto") == 0) {
Aurelien DARRAGONf9583412022-12-29 15:45:41 +01002272 err_code |= proxy_http_parse_xot(args, 0, curproxy, curr_defproxy, file, linenum);
2273 if (err_code & ERR_FATAL)
2274 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002275 }
Christopher Faulet18c13d32022-05-16 11:43:10 +02002276 else if (strcmp(args[1], "http-restrict-req-hdr-names") == 0) {
Christopher Faulet18c13d32022-05-16 11:43:10 +02002277 if (alertif_too_many_args(2, file, linenum, args, &err_code))
2278 goto out;
2279
2280 if (*(args[2]) == 0) {
2281 ha_alert("parsing [%s:%d] : missing parameter. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2282 file, linenum, args[1]);
2283 err_code |= ERR_ALERT | ERR_FATAL;
2284 goto out;
2285 }
2286
2287 curproxy->options2 &= ~PR_O2_RSTRICT_REQ_HDR_NAMES_MASK;
2288 if (strcmp(args[2], "preserve") == 0)
2289 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_NOOP;
2290 else if (strcmp(args[2], "reject") == 0)
2291 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_BLK;
2292 else if (strcmp(args[2], "delete") == 0)
2293 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_DEL;
2294 else {
2295 ha_alert("parsing [%s:%d] : invalid parameter '%s'. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2296 file, linenum, args[2], args[1]);
2297 err_code |= ERR_ALERT | ERR_FATAL;
2298 goto out;
2299 }
2300 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002301 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002302 const char *best = proxy_find_best_option(args[1], common_options);
2303
2304 if (best)
2305 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2306 else
2307 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2308
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002309 err_code |= ERR_ALERT | ERR_FATAL;
2310 goto out;
2311 }
2312 goto out;
2313 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002314 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002315 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2316 err_code |= ERR_WARN;
2317
2318 if (*(args[1]) == 0) {
2319 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2320 err_code |= ERR_ALERT | ERR_FATAL;
2321 goto out;
2322 }
2323 free(curproxy->defbe.name);
2324 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002325 if (!curproxy->defbe.name)
2326 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002327
2328 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2329 goto out;
2330 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002331 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002332 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 +01002333
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002334 err_code |= ERR_ALERT | ERR_FATAL;
2335 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002336 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002337 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002338 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2339 err_code |= ERR_WARN;
2340
2341 if (strcmp(args[1], "never") == 0) {
2342 /* enable a graceful server shutdown on an HTTP 404 response */
2343 curproxy->options &= ~PR_O_REUSE_MASK;
2344 curproxy->options |= PR_O_REUSE_NEVR;
2345 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2346 goto out;
2347 }
2348 else if (strcmp(args[1], "safe") == 0) {
2349 /* enable a graceful server shutdown on an HTTP 404 response */
2350 curproxy->options &= ~PR_O_REUSE_MASK;
2351 curproxy->options |= PR_O_REUSE_SAFE;
2352 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2353 goto out;
2354 }
2355 else if (strcmp(args[1], "aggressive") == 0) {
2356 curproxy->options &= ~PR_O_REUSE_MASK;
2357 curproxy->options |= PR_O_REUSE_AGGR;
2358 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2359 goto out;
2360 }
2361 else if (strcmp(args[1], "always") == 0) {
2362 /* enable a graceful server shutdown on an HTTP 404 response */
2363 curproxy->options &= ~PR_O_REUSE_MASK;
2364 curproxy->options |= PR_O_REUSE_ALWS;
2365 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2366 goto out;
2367 }
2368 else {
2369 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2370 err_code |= ERR_ALERT | ERR_FATAL;
2371 goto out;
2372 }
2373 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002374 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002375 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002376 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2377 err_code |= ERR_ALERT | ERR_FATAL;
2378 goto out;
2379 }
2380
2381 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2382 err_code |= ERR_WARN;
2383
2384 if (strcmp(args[1], "fail") == 0) {
2385 /* add a condition to fail monitor requests */
2386 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2387 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2388 file, linenum, args[0], args[1]);
2389 err_code |= ERR_ALERT | ERR_FATAL;
2390 goto out;
2391 }
2392
2393 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2394 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2395 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2396 file, linenum, args[0], args[1], errmsg);
2397 err_code |= ERR_ALERT | ERR_FATAL;
2398 goto out;
2399 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002400 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002401 }
2402 else {
2403 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2404 err_code |= ERR_ALERT | ERR_FATAL;
2405 goto out;
2406 }
2407 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002408#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002409 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002410 /* enable transparent proxy connections */
2411 curproxy->options |= PR_O_TRANSP;
2412 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2413 goto out;
2414 }
2415#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002416 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002417 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2418 err_code |= ERR_WARN;
2419
2420 if (*(args[1]) == 0) {
2421 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2422 err_code |= ERR_ALERT | ERR_FATAL;
2423 goto out;
2424 }
2425 curproxy->maxconn = atol(args[1]);
2426 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2427 goto out;
2428 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002429 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002430 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2431 err_code |= ERR_WARN;
2432
2433 if (*(args[1]) == 0) {
2434 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2435 err_code |= ERR_ALERT | ERR_FATAL;
2436 goto out;
2437 }
2438 curproxy->backlog = atol(args[1]);
2439 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2440 goto out;
2441 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002442 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002443 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2444 err_code |= ERR_WARN;
2445
2446 if (*(args[1]) == 0) {
2447 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2448 err_code |= ERR_ALERT | ERR_FATAL;
2449 goto out;
2450 }
2451 curproxy->fullconn = atol(args[1]);
2452 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2453 goto out;
2454 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002455 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002456 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 +02002457 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002458 err_code |= ERR_ALERT | ERR_FATAL;
2459 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002460 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002461 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002462 struct sockaddr_storage *sk;
2463 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002464
Willy Tarreau5d095c22021-02-12 10:15:59 +01002465 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002466 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2467 err_code |= ERR_ALERT | ERR_FATAL;
2468 goto out;
2469 }
2470 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2471 err_code |= ERR_WARN;
2472
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002473 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2474 &errmsg, NULL, NULL,
2475 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 +01002476 if (!sk) {
2477 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2478 err_code |= ERR_ALERT | ERR_FATAL;
2479 goto out;
2480 }
2481
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002482 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2483 goto out;
2484
2485 curproxy->dispatch_addr = *sk;
2486 curproxy->options |= PR_O_DISPATCH;
2487 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002488 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002489 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2490 err_code |= ERR_WARN;
2491
2492 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2493 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2494 err_code |= ERR_ALERT | ERR_FATAL;
2495 goto out;
2496 }
2497 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002498 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002499 /**
2500 * The syntax for hash-type config element is
2501 * hash-type {map-based|consistent} [[<algo>] avalanche]
2502 *
2503 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2504 */
2505 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2506
2507 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2508 err_code |= ERR_WARN;
2509
2510 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2511 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2512 }
2513 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2514 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2515 }
2516 else if (strcmp(args[1], "avalanche") == 0) {
2517 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]);
2518 err_code |= ERR_ALERT | ERR_FATAL;
2519 goto out;
2520 }
2521 else {
2522 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2523 err_code |= ERR_ALERT | ERR_FATAL;
2524 goto out;
2525 }
2526
2527 /* set the hash function to use */
2528 if (!*args[2]) {
2529 /* the default algo is sdbm */
2530 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2531
2532 /* if consistent with no argument, then avalanche modifier is also applied */
2533 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2534 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2535 } else {
2536 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002537 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002538 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2539 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002540 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002541 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2542 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002543 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002544 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2545 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002546 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002547 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2548 }
2549 else {
2550 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2551 err_code |= ERR_ALERT | ERR_FATAL;
2552 goto out;
2553 }
2554
2555 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002556 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002557 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2558 }
2559 else if (*args[3]) {
2560 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2561 err_code |= ERR_ALERT | ERR_FATAL;
2562 goto out;
2563 }
2564 }
2565 }
2566 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2567 if (*(args[1]) == 0) {
2568 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2569 err_code |= ERR_ALERT | ERR_FATAL;
2570 goto out;
2571 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002572 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2573 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002574 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2575 err_code |= ERR_ALERT | ERR_FATAL;
2576 goto out;
2577 }
2578 }
2579 else if (strcmp(args[0], "unique-id-format") == 0) {
2580 if (!*(args[1])) {
2581 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2582 err_code |= ERR_ALERT | ERR_FATAL;
2583 goto out;
2584 }
2585 if (*(args[2])) {
2586 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2587 err_code |= ERR_ALERT | ERR_FATAL;
2588 goto out;
2589 }
2590 free(curproxy->conf.uniqueid_format_string);
2591 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002592 if (!curproxy->conf.uniqueid_format_string)
2593 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002594
2595 free(curproxy->conf.uif_file);
2596 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2597 curproxy->conf.uif_line = curproxy->conf.args.line;
2598 }
2599
2600 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002601 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002602 if (!*(args[1])) {
2603 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2604 err_code |= ERR_ALERT | ERR_FATAL;
2605 goto out;
2606 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002607 copy = strdup(args[1]);
2608 if (copy == NULL) {
2609 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2610 err_code |= ERR_ALERT | ERR_FATAL;
2611 goto out;
2612 }
2613
2614 istfree(&curproxy->header_unique_id);
2615 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002616 }
2617
2618 else if (strcmp(args[0], "log-format") == 0) {
2619 if (!*(args[1])) {
2620 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2621 err_code |= ERR_ALERT | ERR_FATAL;
2622 goto out;
2623 }
2624 if (*(args[2])) {
2625 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2626 err_code |= ERR_ALERT | ERR_FATAL;
2627 goto out;
2628 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002629 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002630 char *oldlogformat = "log-format";
2631
2632 if (curproxy->conf.logformat_string == default_http_log_format)
2633 oldlogformat = "option httplog";
2634 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2635 oldlogformat = "option tcplog";
2636 else if (curproxy->conf.logformat_string == clf_http_log_format)
2637 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002638 else if (curproxy->conf.logformat_string == default_https_log_format)
2639 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002640 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2641 file, linenum, oldlogformat);
2642 }
2643 if (curproxy->conf.logformat_string != default_http_log_format &&
2644 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002645 curproxy->conf.logformat_string != clf_http_log_format &&
2646 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002647 free(curproxy->conf.logformat_string);
2648 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002649 if (!curproxy->conf.logformat_string)
2650 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002651
2652 free(curproxy->conf.lfs_file);
2653 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2654 curproxy->conf.lfs_line = curproxy->conf.args.line;
2655
2656 /* get a chance to improve log-format error reporting by
2657 * reporting the correct line-number when possible.
2658 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002659 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002660 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2661 file, linenum, curproxy->id);
2662 err_code |= ERR_WARN;
2663 }
2664 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002665 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002666 if (!*(args[1])) {
2667 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2668 err_code |= ERR_ALERT | ERR_FATAL;
2669 goto out;
2670 }
2671 if (*(args[2])) {
2672 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2673 err_code |= ERR_ALERT | ERR_FATAL;
2674 goto out;
2675 }
2676
2677 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2678 free(curproxy->conf.logformat_sd_string);
2679 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002680 if (!curproxy->conf.logformat_sd_string)
2681 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002682
2683 free(curproxy->conf.lfsd_file);
2684 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2685 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2686
2687 /* get a chance to improve log-format-sd error reporting by
2688 * reporting the correct line-number when possible.
2689 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002690 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002691 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2692 file, linenum, curproxy->id);
2693 err_code |= ERR_WARN;
2694 }
2695 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002696 else if (strcmp(args[0], "error-log-format") == 0) {
2697 if (!*(args[1])) {
2698 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2699 err_code |= ERR_ALERT | ERR_FATAL;
2700 goto out;
2701 }
2702 if (*(args[2])) {
2703 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2704 err_code |= ERR_ALERT | ERR_FATAL;
2705 goto out;
2706 }
2707 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2708 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2709 file, linenum);
2710 }
2711 free(curproxy->conf.error_logformat_string);
2712 curproxy->conf.error_logformat_string = strdup(args[1]);
2713 if (!curproxy->conf.error_logformat_string)
2714 goto alloc_error;
2715
2716 free(curproxy->conf.elfs_file);
2717 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2718 curproxy->conf.elfs_line = curproxy->conf.args.line;
2719
2720 /* get a chance to improve log-format error reporting by
2721 * reporting the correct line-number when possible.
2722 */
2723 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2724 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2725 file, linenum, curproxy->id);
2726 err_code |= ERR_WARN;
2727 }
2728 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002729 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002730 if (*(args[1]) == 0) {
2731 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2732 err_code |= ERR_ALERT | ERR_FATAL;
2733 goto out;
2734 }
2735 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002736 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2737 if (b_orig(&curproxy->log_tag) == NULL) {
2738 chunk_destroy(&curproxy->log_tag);
2739 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2740 err_code |= ERR_ALERT | ERR_FATAL;
2741 goto out;
2742 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002743 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002744 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002745 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002746 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2747 err_code |= ERR_ALERT | ERR_FATAL;
2748 goto out;
2749 }
2750 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002751 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002752 int cur_arg;
2753 int port1, port2;
2754 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002755
2756 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2757 err_code |= ERR_WARN;
2758
2759 if (!*args[1]) {
2760 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2761 file, linenum, "source", "usesrc", "interface");
2762 err_code |= ERR_ALERT | ERR_FATAL;
2763 goto out;
2764 }
2765
Christopher Faulet31930372019-07-15 10:16:58 +02002766 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002767 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002768 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002769 curproxy->conn_src.iface_len = 0;
2770
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002771 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2772 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002773 if (!sk) {
2774 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2775 file, linenum, args[0], args[1], errmsg);
2776 err_code |= ERR_ALERT | ERR_FATAL;
2777 goto out;
2778 }
2779
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002780 curproxy->conn_src.source_addr = *sk;
2781 curproxy->conn_src.opts |= CO_SRC_BIND;
2782
2783 cur_arg = 2;
2784 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002785 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002786#if defined(CONFIG_HAP_TRANSPARENT)
2787 if (!*args[cur_arg + 1]) {
2788 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2789 file, linenum, "usesrc");
2790 err_code |= ERR_ALERT | ERR_FATAL;
2791 goto out;
2792 }
2793
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002794 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002795 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2796 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002797 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002798 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2799 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2800 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2801 char *name, *end;
2802
2803 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002804 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002805 name++;
2806
2807 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002808 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002809 end++;
2810
2811 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2812 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002813 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002814 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002815 if (!curproxy->conn_src.bind_hdr_name)
2816 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002817 curproxy->conn_src.bind_hdr_len = end - name;
2818 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2819 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2820 curproxy->conn_src.bind_hdr_occ = -1;
2821
2822 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002823 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002824 end++;
2825 if (*end == ',') {
2826 end++;
2827 name = end;
2828 if (*end == '-')
2829 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002830 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002831 end++;
2832 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2833 }
2834
2835 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2836 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2837 " occurrences values smaller than %d.\n",
2838 file, linenum, MAX_HDR_HISTORY);
2839 err_code |= ERR_ALERT | ERR_FATAL;
2840 goto out;
2841 }
2842 } else {
2843 struct sockaddr_storage *sk;
2844
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002845 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2846 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002847 if (!sk) {
2848 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2849 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2850 err_code |= ERR_ALERT | ERR_FATAL;
2851 goto out;
2852 }
2853
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002854 curproxy->conn_src.tproxy_addr = *sk;
2855 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2856 }
2857 global.last_checks |= LSTCHK_NETADM;
2858#else /* no TPROXY support */
2859 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2860 file, linenum, "usesrc");
2861 err_code |= ERR_ALERT | ERR_FATAL;
2862 goto out;
2863#endif
2864 cur_arg += 2;
2865 continue;
2866 }
2867
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002868 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002869#ifdef SO_BINDTODEVICE
2870 if (!*args[cur_arg + 1]) {
2871 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2872 file, linenum, args[0]);
2873 err_code |= ERR_ALERT | ERR_FATAL;
2874 goto out;
2875 }
2876 free(curproxy->conn_src.iface_name);
2877 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002878 if (!curproxy->conn_src.iface_name)
2879 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002880 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2881 global.last_checks |= LSTCHK_NETADM;
2882#else
2883 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2884 file, linenum, args[0], args[cur_arg]);
2885 err_code |= ERR_ALERT | ERR_FATAL;
2886 goto out;
2887#endif
2888 cur_arg += 2;
2889 continue;
2890 }
2891 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2892 file, linenum, args[0], "interface", "usesrc");
2893 err_code |= ERR_ALERT | ERR_FATAL;
2894 goto out;
2895 }
2896 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002897 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002898 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2899 file, linenum, "usesrc", "source");
2900 err_code |= ERR_ALERT | ERR_FATAL;
2901 goto out;
2902 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002903 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 +02002904 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002905 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002906 file, linenum, args[0]);
2907 err_code |= ERR_ALERT | ERR_FATAL;
2908 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002909 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002910 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002911 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2912 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2913 err_code |= ERR_ALERT | ERR_FATAL;
2914 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002915 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002916 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002917 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2918 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2919 err_code |= ERR_ALERT | ERR_FATAL;
2920 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002921 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002922 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002923 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2924 err_code |= ERR_ALERT | ERR_FATAL;
2925 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002926 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002927 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002928 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2929 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2930 err_code |= ERR_ALERT | ERR_FATAL;
2931 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002932 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002933 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002934 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2935 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2936 err_code |= ERR_ALERT | ERR_FATAL;
2937 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002938 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002939 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002940 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2941 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2942 err_code |= ERR_ALERT | ERR_FATAL;
2943 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002944 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002945 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002946 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2947 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2948 err_code |= ERR_ALERT | ERR_FATAL;
2949 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002950 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002951 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 +02002952 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2953 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2954 err_code |= ERR_ALERT | ERR_FATAL;
2955 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002956 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002957 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002958 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2959 err_code |= ERR_ALERT | ERR_FATAL;
2960 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002961 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002962 else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002963 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2964 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2965 err_code |= ERR_ALERT | ERR_FATAL;
2966 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002967 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002968 else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002969 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2970 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2971 err_code |= ERR_ALERT | ERR_FATAL;
2972 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002973 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002974 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002975 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2976 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2977 err_code |= ERR_ALERT | ERR_FATAL;
2978 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002979 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002980 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 +02002981 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2982 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2983 err_code |= ERR_ALERT | ERR_FATAL;
2984 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002985 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002986 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002987 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2988 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2989 err_code |= ERR_ALERT | ERR_FATAL;
2990 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002991 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002992 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002993 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2994 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2995 err_code |= ERR_ALERT | ERR_FATAL;
2996 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002997 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002998 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302999 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003000 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3001 err_code |= ERR_ALERT | ERR_FATAL;
3002 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003003 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003004 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003005 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3006 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3007 err_code |= ERR_ALERT | ERR_FATAL;
3008 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003009 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003010 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003011 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3012 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3013 err_code |= ERR_ALERT | ERR_FATAL;
3014 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003015 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003016 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003017 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3018 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3019 err_code |= ERR_ALERT | ERR_FATAL;
3020 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003021 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003022 else {
3023 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003024 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003025 int index;
3026
3027 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3028 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3029 if (kwl->kw[index].section != CFG_LISTEN)
3030 continue;
3031 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003032 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003033 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003034 err_code |= ERR_ALERT | ERR_FATAL;
3035 goto out;
3036 }
3037
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003038 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003039 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003040 if (rc < 0) {
3041 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3042 err_code |= ERR_ALERT | ERR_FATAL;
3043 goto out;
3044 }
3045 else if (rc > 0) {
3046 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3047 err_code |= ERR_WARN;
3048 goto out;
3049 }
3050 goto out;
3051 }
3052 }
3053 }
3054
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003055 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3056 if (best)
3057 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3058 else
3059 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003060 err_code |= ERR_ALERT | ERR_FATAL;
3061 goto out;
3062 }
3063 out:
3064 free(errmsg);
3065 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003066
3067 alloc_error:
3068 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3069 err_code |= ERR_ALERT | ERR_ABORT;
3070 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003071}