blob: bcc89ba364d27bc319dddfc1909d1fbef1f25884 [file] [log] [blame]
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13
Willy Tarreaudcc048a2020-06-04 19:11:43 +020014#include <haproxy/acl.h>
Eric Salama7cea6062020-10-02 11:58:19 +020015#include <haproxy/buf.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020016#include <haproxy/capture-t.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020017#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020018#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020019#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020020#include <haproxy/connection.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020021#include <haproxy/extcheck.h>
Willy Tarreaub7fc4c42021-10-06 18:56:42 +020022#include <haproxy/http_ana.h>
Willy Tarreau87735332020-06-04 09:08:41 +020023#include <haproxy/http_htx.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020024#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020025#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020026#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020027#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020028#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020029#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020030#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020031#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020032#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020033#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020034#include <haproxy/tcpcheck.h>
Willy Tarreaue9dcb3c2021-05-08 13:00:23 +020035#include <haproxy/tools.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020036#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010037
Willy Tarreauc0ff6792021-03-12 09:14:19 +010038/* some keywords that are still being parsed using strcmp() and are not
39 * registered anywhere. They are used as suggestions for mistyped words.
40 */
41static const char *common_kw_list[] = {
42 "listen", "frontend", "backend", "defaults", "server",
43 "default-server", "server-template", "bind", "monitor-net",
44 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
45 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
46 "persist", "appsession", "load-server-state-from-file",
47 "server-state-file-name", "max-session-srv-conns", "capture",
48 "retries", "http-request", "http-response", "http-after-response",
49 "http-send-name-header", "block", "redirect", "use_backend",
50 "use-server", "force-persist", "ignore-persist", "force-persist",
51 "stick-table", "stick", "stats", "option", "default_backend",
52 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
Willy Tarreaueb778242021-06-11 16:27:10 +020053 "fullconn", "dispatch", "balance", "hash-type",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010054 "hash-balance-factor", "unique-id-format", "unique-id-header",
55 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +020056 "error-log-format",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010057 NULL /* must be last */
58};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010059
Willy Tarreau31a3cea2021-03-15 11:11:55 +010060static const char *common_options[] = {
Willy Tarreau6ba69842021-06-11 16:01:50 +020061 "httpclose", "http-server-close", "http-keep-alive",
Willy Tarreaud2f25372021-06-11 16:06:29 +020062 "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010063 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
64 "mysql-check", "ldap-check", "spop-check", "tcp-check",
65 "external-check", "forwardfor", "original-to",
66 NULL /* must be last */
67};
68
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010069/* Report a warning if a rule is placed after a 'tcp-request session' rule.
70 * Return 1 if the warning has been emitted, otherwise 0.
71 */
72int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
73{
74 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
75 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
76 file, line, arg);
77 return 1;
78 }
79 return 0;
80}
81
82/* Report a warning if a rule is placed after a 'tcp-request content' rule.
83 * Return 1 if the warning has been emitted, otherwise 0.
84 */
85int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
86{
87 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
88 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
89 file, line, arg);
90 return 1;
91 }
92 return 0;
93}
94
95/* Report a warning if a rule is placed after a 'monitor fail' rule.
96 * Return 1 if the warning has been emitted, otherwise 0.
97 */
98int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
99{
100 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
101 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
102 file, line, arg);
103 return 1;
104 }
105 return 0;
106}
107
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100108/* Report a warning if a rule is placed after an 'http_request' rule.
109 * Return 1 if the warning has been emitted, otherwise 0.
110 */
111int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
112{
113 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
114 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
115 file, line, arg);
116 return 1;
117 }
118 return 0;
119}
120
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100121/* Report a warning if a rule is placed after a redirect rule.
122 * Return 1 if the warning has been emitted, otherwise 0.
123 */
124int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
125{
126 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
127 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
128 file, line, arg);
129 return 1;
130 }
131 return 0;
132}
133
134/* Report a warning if a rule is placed after a 'use_backend' rule.
135 * Return 1 if the warning has been emitted, otherwise 0.
136 */
137int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
138{
139 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
140 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
141 file, line, arg);
142 return 1;
143 }
144 return 0;
145}
146
147/* Report a warning if a rule is placed after a 'use-server' rule.
148 * Return 1 if the warning has been emitted, otherwise 0.
149 */
150int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
151{
152 if (!LIST_ISEMPTY(&proxy->server_rules)) {
153 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
154 file, line, arg);
155 return 1;
156 }
157 return 0;
158}
159
160/* report a warning if a redirect rule is dangerously placed */
161int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
162{
163 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
164 warnif_rule_after_use_server(proxy, file, line, arg);
165}
166
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100167/* report a warning if an http-request rule is dangerously placed */
168int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
169{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200170 return warnif_rule_after_redirect(proxy, file, line, arg) ||
171 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100172}
173
174/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200175int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100176{
177 return warnif_rule_after_http_req(proxy, file, line, arg) ||
178 warnif_misplaced_http_req(proxy, file, line, arg);
179}
180
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100181/* report a warning if a "tcp request content" rule is dangerously placed */
182int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
183{
184 return warnif_rule_after_monitor(proxy, file, line, arg) ||
185 warnif_misplaced_monitor(proxy, file, line, arg);
186}
187
188/* report a warning if a "tcp request session" rule is dangerously placed */
189int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
190{
191 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
192 warnif_misplaced_tcp_cont(proxy, file, line, arg);
193}
194
195/* report a warning if a "tcp request connection" rule is dangerously placed */
196int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
197{
198 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
199 warnif_misplaced_tcp_sess(proxy, file, line, arg);
200}
201
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100202int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
203{
204 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100205 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100206 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100208 int rc;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100209 int err_code = 0;
210 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100211 char *errmsg = NULL;
212 struct bind_conf *bind_conf;
213
Willy Tarreaue90904d2021-02-12 14:08:31 +0100214 if (!last_defproxy) {
215 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100216 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
217 proxy_preset_defaults(last_defproxy);
218
Willy Tarreaue90904d2021-02-12 14:08:31 +0100219 curr_defproxy = last_defproxy;
220 if (!last_defproxy) {
221 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
222 err_code |= ERR_ALERT | ERR_ABORT;
223 goto out;
224 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100225 }
226
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 if (strcmp(args[0], "listen") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200228 rc = PR_CAP_LISTEN | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100229 else if (strcmp(args[0], "frontend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200230 rc = PR_CAP_FE | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100231 else if (strcmp(args[0], "backend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200232 rc = PR_CAP_BE | PR_CAP_LB;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100233 else if (strcmp(args[0], "defaults") == 0) {
234 /* "defaults" must first delete the last no-name defaults if any */
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) {
295 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
296
297 if (!curr_defproxy) {
298 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
299 err_code |= ERR_ALERT | ERR_ABORT;
300 goto out;
301 }
302
303 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
304 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
305
306 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
307 file, linenum, args[arg+1], proxy_cap_str(rc), name,
308 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
309 err_code |= ERR_ALERT | ERR_FATAL;
310 }
311
312 err = invalid_char(args[arg+1]);
313 if (err) {
314 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",
315 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
316 err_code |= ERR_ALERT | ERR_FATAL;
317 }
Christopher Fauletb4054202021-10-12 18:57:43 +0200318 curr_defproxy->flags |= PR_FL_EXPLICIT_REF;
319 }
320 else if (curr_defproxy)
321 curr_defproxy->flags |= PR_FL_IMPLICIT_REF;
322
323 if (curr_defproxy && (curr_defproxy->flags & (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) == (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) {
324 ha_alert("parsing [%s:%d] : defaults section '%s' (declared at %s:%d) is explicitly referenced by another proxy and implicitly used here."
325 " To avoid any ambiguity don't mix both usage. Add a last defaults section not explicitly used or always use explicit references.\n",
326 file, linenum, curr_defproxy->id, curr_defproxy->conf.file, curr_defproxy->conf.line);
327 err_code |= ERR_WARN;
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100328 }
329
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100330 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100331 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100332 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100333 goto out;
334 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100335
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200336 if (curr_defproxy && (!LIST_ISEMPTY(&curr_defproxy->http_req_rules) ||
337 !LIST_ISEMPTY(&curr_defproxy->http_res_rules) ||
338 !LIST_ISEMPTY(&curr_defproxy->http_after_res_rules) ||
339 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
340 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules) ||
341 !LIST_ISEMPTY(&curr_defproxy->tcp_req.inspect_rules) ||
342 !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules))) {
343 /* If the current default proxy defines TCP/HTTP rules, the
344 * current proxy will keep a reference on it. But some sanity
345 * checks are performed first:
346 *
347 * - It cannot be used to init a defaults section
348 * - It cannot be used to init a listen section
349 * - It cannot be used to init backend and frontend sections at
350 * same time. It can be used to init several sections of the
351 * same type only.
352 * - It cannot define L4/L5 TCP rules if it is used to init
353 * backend sections.
354 * - It cannot define 'tcp-response content' rules if it
355 * is used to init frontend sections.
356 *
357 * If no error is found, refcount of the default proxy is incremented.
358 */
359
360 /* Note: Add tcpcheck_rules too if unresolve args become allowed in defaults section */
361 if (rc & PR_CAP_DEF) {
362 ha_alert("parsing [%s:%d]: a defaults section cannot inherit from a defaults section defining TCP/HTTP rules (defaults section at %s:%d).\n",
363 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
364 err_code |= ERR_ALERT | ERR_ABORT;
365 }
366 else if ((rc & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
367 ha_alert("parsing [%s:%d]: a listen section cannot inherit from a defaults section defining TCP/HTTP rules.\n",
368 file, linenum);
369 err_code |= ERR_ALERT | ERR_ABORT;
370 }
371 else {
372 char defcap = (curr_defproxy->cap & PR_CAP_LISTEN);
373
374 if ((defcap == PR_CAP_BE || defcap == PR_CAP_FE) && (rc & PR_CAP_LISTEN) != defcap) {
375 ha_alert("parsing [%s:%d]: frontends and backends cannot inherit from the same defaults section"
376 " if it defines TCP/HTTP rules (defaults section at %s:%d).\n",
377 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
378 err_code |= ERR_ALERT | ERR_ABORT;
379 }
380 else if (!(rc & PR_CAP_FE) && (!LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
381 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules))) {
382 ha_alert("parsing [%s:%d]: a backend section cannot inherit from a defaults section defining"
383 " 'tcp-request connection' or 'tcp-request session' rules (defaults section at %s:%d).\n",
384 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
385 err_code |= ERR_ALERT | ERR_ABORT;
386 }
387 else if (!(rc & PR_CAP_BE) && !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules)) {
388 ha_alert("parsing [%s:%d]: a frontend section cannot inherit from a defaults section defining"
389 " 'tcp-response content' rules (defaults section at %s:%d).\n",
390 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
391 err_code |= ERR_ALERT | ERR_ABORT;
392 }
393 else {
394 curr_defproxy->cap = (curr_defproxy->cap & ~PR_CAP_LISTEN) | (rc & PR_CAP_LISTEN);
395 proxy_ref_defaults(curproxy, curr_defproxy);
396 }
397 }
398 }
399
Christopher Faulet6ff7de52021-10-13 15:18:36 +0200400 if (curr_defproxy && (curr_defproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) &&
401 (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_BE) {
402 /* If the current default proxy defines tcpcheck rules, the
403 * current proxy will keep a reference on it. but only if the
404 * current proxy has the backend capability.
405 */
406 proxy_ref_defaults(curproxy, curr_defproxy);
407 }
408
Christopher Faulet6c10f5c2022-04-25 14:24:56 +0200409 if ((rc & PR_CAP_BE) && curr_defproxy && (curr_defproxy->nb_req_cap || curr_defproxy->nb_rsp_cap)) {
410 ha_alert("parsing [%s:%d]: backend or defaults sections cannot inherit from a defaults section defining"
411 " capptures (defaults section at %s:%d).\n",
412 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
413 err_code |= ERR_ALERT | ERR_ABORT;
414 }
415
Willy Tarreaue90904d2021-02-12 14:08:31 +0100416 if (rc & PR_CAP_DEF) {
417 /* last and current proxies must be updated to this one */
418 curr_defproxy = last_defproxy = curproxy;
419 } else {
420 /* regular proxies are in a list */
421 curproxy->next = proxies_list;
422 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100423 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100424 goto out;
425 }
426 else if (curproxy == NULL) {
427 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
428 err_code |= ERR_ALERT | ERR_FATAL;
429 goto out;
430 }
431
432 /* update the current file and line being parsed */
433 curproxy->conf.args.file = curproxy->conf.file;
434 curproxy->conf.args.line = linenum;
435
436 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100437 if ((strcmp(args[0], "server") == 0)) {
438 err_code |= parse_server(file, linenum, args,
439 curproxy, curr_defproxy,
440 SRV_PARSE_PARSE_ADDR);
441
442 if (err_code & ERR_FATAL)
443 goto out;
444 }
445 else if (strcmp(args[0], "default-server") == 0) {
446 err_code |= parse_server(file, linenum, args,
447 curproxy, curr_defproxy,
448 SRV_PARSE_DEFAULT_SERVER);
449
450 if (err_code & ERR_FATAL)
451 goto out;
452 }
453 else if (strcmp(args[0], "server-template") == 0) {
454 err_code |= parse_server(file, linenum, args,
455 curproxy, curr_defproxy,
456 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
457
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100458 if (err_code & ERR_FATAL)
459 goto out;
460 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100461 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100462 struct listener *l;
463 int cur_arg;
464
Willy Tarreau5d095c22021-02-12 10:15:59 +0100465 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100466 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
467 err_code |= ERR_ALERT | ERR_FATAL;
468 goto out;
469 }
470 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
471 err_code |= ERR_WARN;
472
473 if (!*(args[1])) {
474 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
475 file, linenum, args[0]);
476 err_code |= ERR_ALERT | ERR_FATAL;
477 goto out;
478 }
479
480 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200481 if (!bind_conf)
482 goto alloc_error;
483
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100484 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200485 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
486 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
487 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100488
489 /* NOTE: the following line might create several listeners if there
490 * are comma-separated IPs or port ranges. So all further processing
491 * will have to be applied to all listeners created after last_listen.
492 */
493 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
494 if (errmsg && *errmsg) {
495 indent_msg(&errmsg, 2);
496 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
497 }
498 else
499 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
500 file, linenum, args[0], args[1]);
501 err_code |= ERR_ALERT | ERR_FATAL;
502 goto out;
503 }
504
505 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
506 /* Set default global rights and owner for unix bind */
507 global.maxsock++;
508 }
509
510 cur_arg = 2;
511 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100512 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100513 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100514
515 kw = bind_find_kw(args[cur_arg]);
516 if (kw) {
517 char *err = NULL;
518 int code;
519
520 if (!kw->parse) {
521 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
522 file, linenum, args[0], args[1], args[cur_arg]);
523 cur_arg += 1 + kw->skip ;
524 err_code |= ERR_ALERT | ERR_FATAL;
525 goto out;
526 }
527
528 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
529 err_code |= code;
530
531 if (code) {
532 if (err && *err) {
533 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200534 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
535 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
536 else
537 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100538 }
539 else
540 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
541 file, linenum, args[0], args[1], args[cur_arg]);
542 if (code & ERR_FATAL) {
543 free(err);
544 cur_arg += 1 + kw->skip;
545 goto out;
546 }
547 }
548 free(err);
549 cur_arg += 1 + kw->skip;
550 continue;
551 }
552
Willy Tarreau433b05f2021-03-12 10:14:07 +0100553 best = bind_find_best_kw(args[cur_arg]);
554 if (best)
555 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
556 file, linenum, args[0], args[1], args[cur_arg], best);
557 else
558 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
559 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100560
561 err_code |= ERR_ALERT | ERR_FATAL;
562 goto out;
563 }
564 goto out;
565 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100566 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200567 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]);
568 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100569 goto out;
570 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100571 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100572 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
573 err_code |= ERR_WARN;
574
575 if (alertif_too_many_args(1, file, linenum, args, &err_code))
576 goto out;
577
578 if (!*args[1]) {
579 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
580 file, linenum, args[0]);
581 err_code |= ERR_ALERT | ERR_FATAL;
582 goto out;
583 }
584
Tim Duesterhus4b1fcaa2022-03-05 00:52:40 +0100585 istfree(&curproxy->monitor_uri);
586 curproxy->monitor_uri = istdup(ist(args[1]));
587 if (!isttest(curproxy->monitor_uri))
Christopher Fauletb15625a2021-04-12 21:31:45 +0200588 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100589
590 goto out;
591 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100592 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100593 if (alertif_too_many_args(1, file, linenum, args, &err_code))
594 goto out;
595
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100596 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
597 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
598 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200599 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
600 err_code |= ERR_ALERT | ERR_FATAL;
601 goto out;
602 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100603 else {
604 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
605 err_code |= ERR_ALERT | ERR_FATAL;
606 goto out;
607 }
608 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100609 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100610 struct eb32_node *node;
611
Willy Tarreau5d095c22021-02-12 10:15:59 +0100612 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100613 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
614 file, linenum, args[0]);
615 err_code |= ERR_ALERT | ERR_FATAL;
616 goto out;
617 }
618
619 if (alertif_too_many_args(1, file, linenum, args, &err_code))
620 goto out;
621
622 if (!*args[1]) {
623 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
624 file, linenum, args[0]);
625 err_code |= ERR_ALERT | ERR_FATAL;
626 goto out;
627 }
628
629 curproxy->uuid = atol(args[1]);
630 curproxy->conf.id.key = curproxy->uuid;
631 curproxy->options |= PR_O_FORCED_ID;
632
633 if (curproxy->uuid <= 0) {
634 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
635 file, linenum);
636 err_code |= ERR_ALERT | ERR_FATAL;
637 goto out;
638 }
639
640 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
641 if (node) {
642 struct proxy *target = container_of(node, struct proxy, conf.id);
643 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
644 file, linenum, proxy_type_str(curproxy), curproxy->id,
645 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
646 err_code |= ERR_ALERT | ERR_FATAL;
647 goto out;
648 }
649 eb32_insert(&used_proxy_id, &curproxy->conf.id);
650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100651 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100652 int i, len=0;
653 char *d;
654
Willy Tarreau5d095c22021-02-12 10:15:59 +0100655 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100656 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
657 file, linenum, args[0]);
658 err_code |= ERR_ALERT | ERR_FATAL;
659 goto out;
660 }
661
662 if (!*args[1]) {
663 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
664 file, linenum, args[0]);
665 return -1;
666 }
667
668 for (i = 1; *args[i]; i++)
669 len += strlen(args[i]) + 1;
670
671 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200672 if (!d)
673 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100674 curproxy->desc = d;
675
676 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
677 for (i = 2; *args[i]; i++)
678 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
679
680 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100681 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100682 if (alertif_too_many_args(0, file, linenum, args, &err_code))
683 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200684 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100685 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100686 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100687 if (alertif_too_many_args(0, file, linenum, args, &err_code))
688 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200689 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100690 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100691 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100692 int cur_arg = 1;
693 unsigned long set = 0;
694
695 while (*args[cur_arg]) {
696 if (strcmp(args[cur_arg], "all") == 0) {
697 set = 0;
698 break;
699 }
Willy Tarreau72faef32021-06-15 08:36:30 +0200700 if (parse_process_number(args[cur_arg], &set, 1, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100701 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
702 err_code |= ERR_ALERT | ERR_FATAL;
703 goto out;
704 }
705 cur_arg++;
706 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200707 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
708 file, linenum, args[0]);
709 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100710 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100711 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200712 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
713 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100714 err_code |= ERR_ALERT | ERR_FATAL;
715 goto out;
716 }
717
718 err = invalid_char(args[1]);
719 if (err) {
720 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
721 file, linenum, *err, args[1]);
722 err_code |= ERR_ALERT | ERR_FATAL;
723 goto out;
724 }
725
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100726 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100727 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100728 "logical disjunction within a condition.\n",
729 file, linenum, args[1]);
730 err_code |= ERR_ALERT | ERR_FATAL;
731 goto out;
732 }
733
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100734 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
735 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
736 file, linenum, args[1], errmsg);
737 err_code |= ERR_ALERT | ERR_FATAL;
738 goto out;
739 }
740 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100741 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100742
743 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
744 err_code |= ERR_WARN;
745
746 if (*(args[1]) == 0) {
747 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
748 file, linenum, args[0]);
749 err_code |= ERR_ALERT | ERR_FATAL;
750 goto out;
751 }
752 free(curproxy->dyncookie_key);
753 curproxy->dyncookie_key = strdup(args[1]);
754 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100755 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100756 int cur_arg;
757
758 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
759 err_code |= ERR_WARN;
760
761 if (*(args[1]) == 0) {
762 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
763 file, linenum, args[0]);
764 err_code |= ERR_ALERT | ERR_FATAL;
765 goto out;
766 }
767
768 curproxy->ck_opts = 0;
769 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100770 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100771 free(curproxy->cookie_name);
772 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200773 if (!curproxy->cookie_name)
774 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100775 curproxy->cookie_len = strlen(curproxy->cookie_name);
776
777 cur_arg = 2;
778 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100779 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100780 curproxy->ck_opts |= PR_CK_RW;
781 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100782 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100783 curproxy->ck_opts |= PR_CK_IND;
784 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100785 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100786 curproxy->ck_opts |= PR_CK_INS;
787 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100788 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100789 curproxy->ck_opts |= PR_CK_NOC;
790 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100791 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100792 curproxy->ck_opts |= PR_CK_POST;
793 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100794 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100795 curproxy->ck_opts |= PR_CK_PSV;
796 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100797 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100798 curproxy->ck_opts |= PR_CK_PFX;
799 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100800 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100801 curproxy->ck_opts |= PR_CK_HTTPONLY;
802 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100803 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100804 curproxy->ck_opts |= PR_CK_SECURE;
805 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100806 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100807 if (!*args[cur_arg + 1]) {
808 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
809 file, linenum, args[cur_arg]);
810 err_code |= ERR_ALERT | ERR_FATAL;
811 goto out;
812 }
813
Joao Moraise1583752019-10-30 21:04:00 -0300814 if (!strchr(args[cur_arg + 1], '.')) {
815 /* rfc6265, 5.2.3 The Domain Attribute */
816 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
817 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100818 file, linenum, args[cur_arg + 1]);
819 err_code |= ERR_WARN;
820 }
821
822 err = invalid_domainchar(args[cur_arg + 1]);
823 if (err) {
824 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
825 file, linenum, *err, args[cur_arg + 1]);
826 err_code |= ERR_ALERT | ERR_FATAL;
827 goto out;
828 }
829
830 if (!curproxy->cookie_domain) {
831 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
832 } else {
833 /* one domain was already specified, add another one by
834 * building the string which will be returned along with
835 * the cookie.
836 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200837 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
838 }
839
Christopher Fauletb15625a2021-04-12 21:31:45 +0200840 if (!curproxy->cookie_domain)
841 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100842 cur_arg++;
843 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100844 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100845 unsigned int maxidle;
846 const char *res;
847
848 if (!*args[cur_arg + 1]) {
849 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
850 file, linenum, args[cur_arg]);
851 err_code |= ERR_ALERT | ERR_FATAL;
852 goto out;
853 }
854
855 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200856 if (res == PARSE_TIME_OVER) {
857 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
858 file, linenum, args[cur_arg+1], args[cur_arg]);
859 err_code |= ERR_ALERT | ERR_FATAL;
860 goto out;
861 }
862 else if (res == PARSE_TIME_UNDER) {
863 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
864 file, linenum, args[cur_arg+1], args[cur_arg]);
865 err_code |= ERR_ALERT | ERR_FATAL;
866 goto out;
867 }
868 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100869 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
870 file, linenum, *res, args[cur_arg]);
871 err_code |= ERR_ALERT | ERR_FATAL;
872 goto out;
873 }
874 curproxy->cookie_maxidle = maxidle;
875 cur_arg++;
876 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100877 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100878 unsigned int maxlife;
879 const char *res;
880
881 if (!*args[cur_arg + 1]) {
882 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
883 file, linenum, args[cur_arg]);
884 err_code |= ERR_ALERT | ERR_FATAL;
885 goto out;
886 }
887
Willy Tarreau9faebe32019-06-07 19:00:37 +0200888
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100889 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200890 if (res == PARSE_TIME_OVER) {
891 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
892 file, linenum, args[cur_arg+1], args[cur_arg]);
893 err_code |= ERR_ALERT | ERR_FATAL;
894 goto out;
895 }
896 else if (res == PARSE_TIME_UNDER) {
897 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
898 file, linenum, args[cur_arg+1], args[cur_arg]);
899 err_code |= ERR_ALERT | ERR_FATAL;
900 goto out;
901 }
902 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100903 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
904 file, linenum, *res, args[cur_arg]);
905 err_code |= ERR_ALERT | ERR_FATAL;
906 goto out;
907 }
908 curproxy->cookie_maxlife = maxlife;
909 cur_arg++;
910 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100911 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100912
913 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
914 err_code |= ERR_WARN;
915 curproxy->ck_opts |= PR_CK_DYNAMIC;
916 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100917 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100918 char *val;
919 if (!*args[cur_arg + 1]) {
920 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
921 file, linenum, args[cur_arg]);
922 err_code |= ERR_ALERT | ERR_FATAL;
923 goto out;
924 }
925 val = args[cur_arg + 1];
926 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100927 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100928 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
929 file, linenum, *val);
930 err_code |= ERR_ALERT | ERR_FATAL;
931 goto out;
932 }
933 val++;
934 }
935 /* don't add ';' for the first attribute */
936 if (!curproxy->cookie_attrs)
937 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
938 else
939 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200940
Christopher Fauletb15625a2021-04-12 21:31:45 +0200941 if (!curproxy->cookie_attrs)
942 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100943 cur_arg++;
944 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100945
946 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100947 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 +0100948 file, linenum, args[0]);
949 err_code |= ERR_ALERT | ERR_FATAL;
950 goto out;
951 }
952 cur_arg++;
953 }
954 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
955 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
956 file, linenum);
957 err_code |= ERR_ALERT | ERR_FATAL;
958 }
959
960 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
961 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
962 file, linenum);
963 err_code |= ERR_ALERT | ERR_FATAL;
964 }
965
966 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
967 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
968 file, linenum);
969 err_code |= ERR_ALERT | ERR_FATAL;
970 }
971 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100972 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100973 if (*(args[1]) == 0) {
974 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
975 file, linenum, args[0]);
976 err_code |= ERR_ALERT | ERR_FATAL;
977 goto out;
978 }
979
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100980 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100981 if (*(args[1]) == 0) {
982 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
983 file, linenum, args[1]);
984 err_code |= ERR_ALERT | ERR_FATAL;
985 goto out;
986 }
987 free(curproxy->email_alert.from);
988 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200989 if (!curproxy->email_alert.from)
990 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100991 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100992 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100993 if (*(args[1]) == 0) {
994 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
995 file, linenum, args[1]);
996 err_code |= ERR_ALERT | ERR_FATAL;
997 goto out;
998 }
999 free(curproxy->email_alert.mailers.name);
1000 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001001 if (!curproxy->email_alert.mailers.name)
1002 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001003 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001004 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001005 if (*(args[1]) == 0) {
1006 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1007 file, linenum, args[1]);
1008 err_code |= ERR_ALERT | ERR_FATAL;
1009 goto out;
1010 }
1011 free(curproxy->email_alert.myhostname);
1012 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001013 if (!curproxy->email_alert.myhostname)
1014 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001015 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001016 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001017 curproxy->email_alert.level = get_log_level(args[2]);
1018 if (curproxy->email_alert.level < 0) {
1019 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1020 file, linenum, args[1], args[2]);
1021 err_code |= ERR_ALERT | ERR_FATAL;
1022 goto out;
1023 }
1024 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001025 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001026 if (*(args[1]) == 0) {
1027 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1028 file, linenum, args[1]);
1029 err_code |= ERR_ALERT | ERR_FATAL;
1030 goto out;
1031 }
1032 free(curproxy->email_alert.to);
1033 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001034 if (!curproxy->email_alert.to)
1035 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001036 }
1037 else {
1038 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1039 file, linenum, args[1]);
1040 err_code |= ERR_ALERT | ERR_FATAL;
1041 goto out;
1042 }
1043 /* Indicate that the email_alert is at least partially configured */
1044 curproxy->email_alert.set = 1;
1045 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001046 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001047 if (*(args[1]) == 0) {
1048 ha_alert("parsing [%s:%d] : missing persist method.\n",
1049 file, linenum);
1050 err_code |= ERR_ALERT | ERR_FATAL;
1051 goto out;
1052 }
1053
1054 if (!strncmp(args[1], "rdp-cookie", 10)) {
1055 curproxy->options2 |= PR_O2_RDPC_PRST;
1056
1057 if (*(args[1] + 10) == '(') { /* cookie name */
1058 const char *beg, *end;
1059
1060 beg = args[1] + 11;
1061 end = strchr(beg, ')');
1062
1063 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1064 goto out;
1065
1066 if (!end || end == beg) {
1067 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1068 file, linenum);
1069 err_code |= ERR_ALERT | ERR_FATAL;
1070 goto out;
1071 }
1072
1073 free(curproxy->rdp_cookie_name);
1074 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001075 if (!curproxy->rdp_cookie_name)
1076 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001077 curproxy->rdp_cookie_len = end-beg;
1078 }
1079 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1080 free(curproxy->rdp_cookie_name);
1081 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +02001082 if (!curproxy->rdp_cookie_name)
1083 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001084 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1085 }
1086 else { /* syntax */
1087 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1088 file, linenum);
1089 err_code |= ERR_ALERT | ERR_FATAL;
1090 goto out;
1091 }
1092 }
1093 else {
1094 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1095 file, linenum);
1096 err_code |= ERR_ALERT | ERR_FATAL;
1097 goto out;
1098 }
1099 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001100 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001101 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 +01001102 err_code |= ERR_ALERT | ERR_FATAL;
1103 goto out;
1104 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001105 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001106 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1107 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001108 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001109 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1110 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001111 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 +01001112 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1113 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001114 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001115 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1116 }
1117 else {
1118 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1119 file, linenum, args[0], args[1]);
1120 err_code |= ERR_ALERT | ERR_FATAL;
1121 goto out;
1122 }
1123 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001124 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001125 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1126 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001127 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001128 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001129
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001130 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001131
1132 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001133 curproxy->server_state_file_name = strdup(curproxy->id);
1134 else
1135 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001136
Christopher Fauletb15625a2021-04-12 21:31:45 +02001137 if (!curproxy->server_state_file_name)
1138 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001139 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001140 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001141 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1142 err_code |= ERR_WARN;
1143 if (*(args[1]) == 0) {
1144 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1145 file, linenum, args[0]);
1146 err_code |= ERR_ALERT | ERR_FATAL;
1147 goto out;
1148 }
1149 curproxy->max_out_conns = atoi(args[1]);
1150 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001151 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001152 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1153 err_code |= ERR_WARN;
1154
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001155 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
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[4]) == 0) {
1166 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1167 file, linenum, args[0]);
1168 err_code |= ERR_ALERT | ERR_FATAL;
1169 goto out;
1170 }
1171 free(curproxy->capture_name);
1172 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001173 if (!curproxy->capture_name)
1174 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001175 curproxy->capture_namelen = strlen(curproxy->capture_name);
1176 curproxy->capture_len = atol(args[4]);
1177 curproxy->to_log |= LW_COOKIE;
1178 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001179 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001180 struct cap_hdr *hdr;
1181
Willy Tarreau5d095c22021-02-12 10:15:59 +01001182 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001183 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1184 err_code |= ERR_ALERT | ERR_FATAL;
1185 goto out;
1186 }
1187
1188 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1189 goto out;
1190
1191 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1192 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1193 file, linenum, args[0], args[1]);
1194 err_code |= ERR_ALERT | ERR_FATAL;
1195 goto out;
1196 }
1197
1198 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001199 if (!hdr)
1200 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001201 hdr->next = curproxy->req_cap;
1202 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001203 if (!hdr->name)
1204 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001205 hdr->namelen = strlen(args[3]);
1206 hdr->len = atol(args[5]);
1207 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001208 if (!hdr->pool) {
1209 req_caphdr_alloc_error:
1210 if (hdr)
1211 ha_free(&hdr->name);
1212 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001213 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001214 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001215 hdr->index = curproxy->nb_req_cap++;
1216 curproxy->req_cap = hdr;
1217 curproxy->to_log |= LW_REQHDR;
1218 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001219 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001220 struct cap_hdr *hdr;
1221
Willy Tarreau5d095c22021-02-12 10:15:59 +01001222 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001223 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1224 err_code |= ERR_ALERT | ERR_FATAL;
1225 goto out;
1226 }
1227
1228 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1229 goto out;
1230
1231 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1232 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1233 file, linenum, args[0], args[1]);
1234 err_code |= ERR_ALERT | ERR_FATAL;
1235 goto out;
1236 }
1237 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001238 if (!hdr)
1239 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001240 hdr->next = curproxy->rsp_cap;
1241 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001242 if (!hdr->name)
1243 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001244 hdr->namelen = strlen(args[3]);
1245 hdr->len = atol(args[5]);
1246 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001247 if (!hdr->pool) {
1248 res_caphdr_alloc_error:
1249 if (hdr)
1250 ha_free(&hdr->name);
1251 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001252 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001253 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001254 hdr->index = curproxy->nb_rsp_cap++;
1255 curproxy->rsp_cap = hdr;
1256 curproxy->to_log |= LW_RSPHDR;
1257 }
1258 else {
1259 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1260 file, linenum, args[0]);
1261 err_code |= ERR_ALERT | ERR_FATAL;
1262 goto out;
1263 }
1264 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001265 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001266 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1267 err_code |= ERR_WARN;
1268
1269 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1270 goto out;
1271
1272 if (*(args[1]) == 0) {
1273 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1274 file, linenum, args[0]);
1275 err_code |= ERR_ALERT | ERR_FATAL;
1276 goto out;
1277 }
1278 curproxy->conn_retries = atol(args[1]);
1279 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001280 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001281 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001282 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001283
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001284 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1285 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
1289
1290 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1291 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001292 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001293 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1294 file, linenum, args[0]);
1295 err_code |= ERR_WARN;
1296 }
1297
1298 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1299
1300 if (!rule) {
1301 err_code |= ERR_ALERT | ERR_ABORT;
1302 goto out;
1303 }
1304
1305 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001306
1307 if (curproxy->cap & PR_CAP_FE)
1308 where |= SMP_VAL_FE_HRQ_HDR;
1309 if (curproxy->cap & PR_CAP_BE)
1310 where |= SMP_VAL_BE_HRQ_HDR;
1311 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001312
Willy Tarreau2b718102021-04-21 07:32:39 +02001313 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001314 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001315 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001316 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001317 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001318
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001319 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1320 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001321 err_code |= ERR_ALERT | ERR_FATAL;
1322 goto out;
1323 }
1324
1325 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1326 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001327 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001328 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1329 file, linenum, args[0]);
1330 err_code |= ERR_WARN;
1331 }
1332
1333 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1334
1335 if (!rule) {
1336 err_code |= ERR_ALERT | ERR_ABORT;
1337 goto out;
1338 }
1339
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001340 if (curproxy->cap & PR_CAP_FE)
1341 where |= SMP_VAL_FE_HRS_HDR;
1342 if (curproxy->cap & PR_CAP_BE)
1343 where |= SMP_VAL_BE_HRS_HDR;
1344 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001345
Willy Tarreau2b718102021-04-21 07:32:39 +02001346 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001347 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001348 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001349 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001350 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001351 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1352 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001353 err_code |= ERR_ALERT | ERR_FATAL;
1354 goto out;
1355 }
1356
1357 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1358 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1359 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1360 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1361 file, linenum, args[0]);
1362 err_code |= ERR_WARN;
1363 }
1364
1365 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1366
1367 if (!rule) {
1368 err_code |= ERR_ALERT | ERR_ABORT;
1369 goto out;
1370 }
1371
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001372 if (curproxy->cap & PR_CAP_FE)
1373 where |= SMP_VAL_FE_HRS_HDR;
1374 if (curproxy->cap & PR_CAP_BE)
1375 where |= SMP_VAL_BE_HRS_HDR;
1376 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001377
Willy Tarreau2b718102021-04-21 07:32:39 +02001378 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001379 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001380 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001381 /* set the header name and length into the proxy structure */
1382 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1383 err_code |= ERR_WARN;
1384
1385 if (!*args[1]) {
1386 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1387 file, linenum, args[0]);
1388 err_code |= ERR_ALERT | ERR_FATAL;
1389 goto out;
1390 }
1391
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001392 /* set the desired header name, in lower case */
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001393 istfree(&curproxy->server_id_hdr_name);
1394 curproxy->server_id_hdr_name = istdup(ist(args[1]));
1395 if (!isttest(curproxy->server_id_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02001396 goto alloc_error;
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001397 ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001398 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001399 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001400 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 +01001401
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001402 err_code |= ERR_ALERT | ERR_FATAL;
1403 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001404 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001405 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001406 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001407 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001408
Willy Tarreau5d095c22021-02-12 10:15:59 +01001409 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001410 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1411 err_code |= ERR_ALERT | ERR_FATAL;
1412 goto out;
1413 }
1414
1415 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1416 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1417 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1418 err_code |= ERR_ALERT | ERR_FATAL;
1419 goto out;
1420 }
1421
Willy Tarreau2b718102021-04-21 07:32:39 +02001422 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001423 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001424
1425 if (curproxy->cap & PR_CAP_FE)
1426 where |= SMP_VAL_FE_HRQ_HDR;
1427 if (curproxy->cap & PR_CAP_BE)
1428 where |= SMP_VAL_BE_HRQ_HDR;
1429 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001430 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001431 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001432 struct switching_rule *rule;
1433
Willy Tarreau5d095c22021-02-12 10:15:59 +01001434 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001435 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1436 err_code |= ERR_ALERT | ERR_FATAL;
1437 goto out;
1438 }
1439
1440 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1441 err_code |= ERR_WARN;
1442
1443 if (*(args[1]) == 0) {
1444 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1445 err_code |= ERR_ALERT | ERR_FATAL;
1446 goto out;
1447 }
1448
1449 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1450 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1451 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1452 file, linenum, errmsg);
1453 err_code |= ERR_ALERT | ERR_FATAL;
1454 goto out;
1455 }
1456
1457 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1458 }
1459 else if (*args[2]) {
1460 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1461 file, linenum, args[2]);
1462 err_code |= ERR_ALERT | ERR_FATAL;
1463 goto out;
1464 }
1465
1466 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001467 if (!rule)
1468 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001469 rule->cond = cond;
1470 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001471 if (!rule->be.name)
1472 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001473 rule->line = linenum;
1474 rule->file = strdup(file);
1475 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001476 use_backend_alloc_error:
1477 if (cond)
1478 prune_acl_cond(cond);
1479 ha_free(&cond);
1480 if (rule)
1481 ha_free(&(rule->be.name));
1482 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001483 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001484 }
1485 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001486 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001487 }
1488 else if (strcmp(args[0], "use-server") == 0) {
1489 struct server_rule *rule;
1490
Willy Tarreau5d095c22021-02-12 10:15:59 +01001491 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001492 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1493 err_code |= ERR_ALERT | ERR_FATAL;
1494 goto out;
1495 }
1496
1497 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1498 err_code |= ERR_WARN;
1499
1500 if (*(args[1]) == 0) {
1501 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1502 err_code |= ERR_ALERT | ERR_FATAL;
1503 goto out;
1504 }
1505
1506 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1507 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1508 file, linenum, args[0]);
1509 err_code |= ERR_ALERT | ERR_FATAL;
1510 goto out;
1511 }
1512
1513 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1514 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1515 file, linenum, errmsg);
1516 err_code |= ERR_ALERT | ERR_FATAL;
1517 goto out;
1518 }
1519
1520 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1521
1522 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001523 if (!rule)
1524 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001525 rule->cond = cond;
1526 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001527 if (!rule->srv.name)
1528 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001529 rule->line = linenum;
1530 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001531 if (!rule->file) {
1532 use_server_alloc_error:
1533 if (cond)
1534 prune_acl_cond(cond);
1535 ha_free(&cond);
1536 if (rule)
1537 ha_free(&(rule->srv.name));
1538 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001539 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001540 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001541 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001542 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001543 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1544 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001545 else if ((strcmp(args[0], "force-persist") == 0) ||
1546 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001547 struct persist_rule *rule;
1548
Willy Tarreau5d095c22021-02-12 10:15:59 +01001549 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001550 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1551 err_code |= ERR_ALERT | ERR_FATAL;
1552 goto out;
1553 }
1554
1555 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1556 err_code |= ERR_WARN;
1557
1558 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1559 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1560 file, linenum, args[0]);
1561 err_code |= ERR_ALERT | ERR_FATAL;
1562 goto out;
1563 }
1564
1565 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1566 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1567 file, linenum, args[0], errmsg);
1568 err_code |= ERR_ALERT | ERR_FATAL;
1569 goto out;
1570 }
1571
1572 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1573 * where force-persist is applied.
1574 */
1575 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1576
1577 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001578 if (!rule) {
1579 if (cond)
1580 prune_acl_cond(cond);
1581 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001582 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001583 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001584 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001585 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001586 rule->type = PERSIST_TYPE_FORCE;
1587 } else {
1588 rule->type = PERSIST_TYPE_IGNORE;
1589 }
1590 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001591 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001592 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001593 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001594 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001595
Willy Tarreau5d095c22021-02-12 10:15:59 +01001596 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001597 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1598 file, linenum);
1599 err_code |= ERR_ALERT | ERR_FATAL;
1600 goto out;
1601 }
1602
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001603 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001604 if (other) {
1605 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 +01001606 file, linenum, curproxy->id,
1607 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1608 other->proxy ? other->id : other->peers.p->id,
1609 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001610 err_code |= ERR_ALERT | ERR_FATAL;
1611 goto out;
1612 }
1613
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001614 curproxy->table = calloc(1, sizeof *curproxy->table);
1615 if (!curproxy->table) {
1616 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1617 file, linenum, args[0], args[1]);
1618 err_code |= ERR_ALERT | ERR_FATAL;
1619 goto out;
1620 }
1621
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001622 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1623 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001624 if (err_code & ERR_FATAL) {
1625 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001626 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001627 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001628
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001629 /* Store the proxy in the stick-table. */
1630 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001631
1632 stktable_store_name(curproxy->table);
1633 curproxy->table->next = stktables_list;
1634 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001635
1636 /* Add this proxy to the list of proxies which refer to its stick-table. */
1637 if (curproxy->table->proxies_list != curproxy) {
1638 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1639 curproxy->table->proxies_list = curproxy;
1640 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001641 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001642 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001643 struct sticking_rule *rule;
1644 struct sample_expr *expr;
1645 int myidx = 0;
1646 const char *name = NULL;
1647 int flags;
1648
Willy Tarreau5d095c22021-02-12 10:15:59 +01001649 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001650 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1651 err_code |= ERR_ALERT | ERR_FATAL;
1652 goto out;
1653 }
1654
1655 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1656 err_code |= ERR_WARN;
1657 goto out;
1658 }
1659
1660 myidx++;
1661 if ((strcmp(args[myidx], "store") == 0) ||
1662 (strcmp(args[myidx], "store-request") == 0)) {
1663 myidx++;
1664 flags = STK_IS_STORE;
1665 }
1666 else if (strcmp(args[myidx], "store-response") == 0) {
1667 myidx++;
1668 flags = STK_IS_STORE | STK_ON_RSP;
1669 }
1670 else if (strcmp(args[myidx], "match") == 0) {
1671 myidx++;
1672 flags = STK_IS_MATCH;
1673 }
1674 else if (strcmp(args[myidx], "on") == 0) {
1675 myidx++;
1676 flags = STK_IS_MATCH | STK_IS_STORE;
1677 }
1678 else {
1679 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1680 err_code |= ERR_ALERT | ERR_FATAL;
1681 goto out;
1682 }
1683
1684 if (*(args[myidx]) == 0) {
1685 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1686 err_code |= ERR_ALERT | ERR_FATAL;
1687 goto out;
1688 }
1689
1690 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001691 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001692 if (!expr) {
1693 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1694 err_code |= ERR_ALERT | ERR_FATAL;
1695 goto out;
1696 }
1697
1698 if (flags & STK_ON_RSP) {
1699 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1700 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1701 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1702 err_code |= ERR_ALERT | ERR_FATAL;
1703 free(expr);
1704 goto out;
1705 }
1706 } else {
1707 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1708 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1709 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1710 err_code |= ERR_ALERT | ERR_FATAL;
1711 free(expr);
1712 goto out;
1713 }
1714 }
1715
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001716 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001717 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1718
1719 if (strcmp(args[myidx], "table") == 0) {
1720 myidx++;
1721 name = args[myidx++];
1722 }
1723
1724 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1725 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1726 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1727 file, linenum, args[0], errmsg);
1728 err_code |= ERR_ALERT | ERR_FATAL;
1729 free(expr);
1730 goto out;
1731 }
1732 }
1733 else if (*(args[myidx])) {
1734 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1735 file, linenum, args[0], args[myidx]);
1736 err_code |= ERR_ALERT | ERR_FATAL;
1737 free(expr);
1738 goto out;
1739 }
1740 if (flags & STK_ON_RSP)
1741 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1742 else
1743 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1744
1745 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001746 if (!rule) {
1747 if (cond)
1748 prune_acl_cond(cond);
1749 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001750 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001751 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001752 rule->cond = cond;
1753 rule->expr = expr;
1754 rule->flags = flags;
1755 rule->table.name = name ? strdup(name) : NULL;
1756 LIST_INIT(&rule->list);
1757 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001758 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001759 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001760 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001761 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001762 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001763 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001764 curproxy->uri_auth = NULL; /* we must detach from the default config */
1765
1766 if (!*args[1]) {
1767 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001768 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001769 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001770 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001771
Willy Tarreau5d095c22021-02-12 10:15:59 +01001772 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001773 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1774 err_code |= ERR_ALERT | ERR_FATAL;
1775 goto out;
1776 }
1777
Christopher Fauletb15625a2021-04-12 21:31:45 +02001778 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1779 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001780
1781 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1782 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1783 file, linenum, args[0], args[1]);
1784 err_code |= ERR_ALERT | ERR_FATAL;
1785 goto out;
1786 }
1787 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1788 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1789 file, linenum, args[0], args[1], errmsg);
1790 err_code |= ERR_ALERT | ERR_FATAL;
1791 goto out;
1792 }
1793
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001794 if (curproxy->cap & PR_CAP_FE)
1795 where |= SMP_VAL_FE_HRQ_HDR;
1796 if (curproxy->cap & PR_CAP_BE)
1797 where |= SMP_VAL_BE_HRQ_HDR;
1798 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001799
1800 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001801 if (!rule) {
1802 if (cond)
1803 prune_acl_cond(cond);
1804 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001805 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001806 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001807 rule->cond = cond;
1808 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001809 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001810 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001811 if (*(args[2]) == 0) {
1812 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1813 err_code |= ERR_ALERT | ERR_FATAL;
1814 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001815 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1816 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001817 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001818 if (*(args[2]) == 0) {
1819 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1820 err_code |= ERR_ALERT | ERR_FATAL;
1821 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001822 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1823 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001824 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001825 unsigned interval;
1826
1827 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001828 if (err == PARSE_TIME_OVER) {
1829 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1830 file, linenum, args[2]);
1831 err_code |= ERR_ALERT | ERR_FATAL;
1832 goto out;
1833 }
1834 else if (err == PARSE_TIME_UNDER) {
1835 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1836 file, linenum, args[2]);
1837 err_code |= ERR_ALERT | ERR_FATAL;
1838 goto out;
1839 }
1840 else if (err) {
1841 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001842 file, linenum, *err);
1843 err_code |= ERR_ALERT | ERR_FATAL;
1844 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001845 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1846 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001847 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001848 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001849 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001850
Willy Tarreau5d095c22021-02-12 10:15:59 +01001851 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001852 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1853 err_code |= ERR_ALERT | ERR_FATAL;
1854 goto out;
1855 }
1856
Christopher Fauletb15625a2021-04-12 21:31:45 +02001857 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1858 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001859
1860 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1861 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1862 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1863 file, linenum, args[0]);
1864 err_code |= ERR_WARN;
1865 }
1866
1867 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1868
1869 if (!rule) {
1870 err_code |= ERR_ALERT | ERR_ABORT;
1871 goto out;
1872 }
1873
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001874 if (curproxy->cap & PR_CAP_FE)
1875 where |= SMP_VAL_FE_HRQ_HDR;
1876 if (curproxy->cap & PR_CAP_BE)
1877 where |= SMP_VAL_BE_HRQ_HDR;
1878 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001879 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001880
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001881 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001882 if (*(args[2]) == 0) {
1883 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1884 err_code |= ERR_ALERT | ERR_FATAL;
1885 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001886 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1887 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001888 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001889 if (*(args[2]) == 0) {
1890 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1891 err_code |= ERR_ALERT | ERR_FATAL;
1892 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001893 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1894 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001895 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001896 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1897 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001898 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001899 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1900 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001901 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001902 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1903 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001904 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001905 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1906 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001907 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001908
1909 if (*args[2]) {
1910 int i;
1911 char c;
1912
1913 for (i=0; args[2][i]; i++) {
1914 c = args[2][i];
1915 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1916 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1917 break;
1918 }
1919
1920 if (!i || args[2][i]) {
1921 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1922 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1923 file, linenum, args[0], args[1]);
1924 err_code |= ERR_ALERT | ERR_FATAL;
1925 goto out;
1926 }
1927 }
1928
Christopher Fauletb15625a2021-04-12 21:31:45 +02001929 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1930 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001931 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001932 char *desc = NULL;
1933
1934 if (*args[2]) {
1935 int i, len=0;
1936 char *d;
1937
1938 for (i = 2; *args[i]; i++)
1939 len += strlen(args[i]) + 1;
1940
1941 desc = d = calloc(1, len);
1942
1943 d += snprintf(d, desc + len - d, "%s", args[2]);
1944 for (i = 3; *args[i]; i++)
1945 d += snprintf(d, desc + len - d, " %s", args[i]);
1946 }
1947
1948 if (!*args[2] && !global.desc)
1949 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1950 file, linenum, args[1]);
1951 else {
1952 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1953 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001954 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001955 }
1956 free(desc);
1957 }
1958 } else {
1959stats_error_parsing:
1960 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1961 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1962 err_code |= ERR_ALERT | ERR_FATAL;
1963 goto out;
1964 }
1965 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001966 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001967 int optnum;
1968
1969 if (*(args[1]) == '\0') {
1970 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1971 file, linenum, args[0]);
1972 err_code |= ERR_ALERT | ERR_FATAL;
1973 goto out;
1974 }
1975
1976 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001977 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001978 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1979 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1980 file, linenum, cfg_opts[optnum].name);
1981 err_code |= ERR_ALERT | ERR_FATAL;
1982 goto out;
1983 }
1984 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1985 goto out;
1986
1987 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1988 err_code |= ERR_WARN;
1989 goto out;
1990 }
1991
1992 curproxy->no_options &= ~cfg_opts[optnum].val;
1993 curproxy->options &= ~cfg_opts[optnum].val;
1994
1995 switch (kwm) {
1996 case KWM_STD:
1997 curproxy->options |= cfg_opts[optnum].val;
1998 break;
1999 case KWM_NO:
2000 curproxy->no_options |= cfg_opts[optnum].val;
2001 break;
2002 case KWM_DEF: /* already cleared */
2003 break;
2004 }
2005
2006 goto out;
2007 }
2008 }
2009
2010 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002011 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002012 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2013 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2014 file, linenum, cfg_opts2[optnum].name);
2015 err_code |= ERR_ALERT | ERR_FATAL;
2016 goto out;
2017 }
2018 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2019 goto out;
2020 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2021 err_code |= ERR_WARN;
2022 goto out;
2023 }
2024
2025 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2026 curproxy->options2 &= ~cfg_opts2[optnum].val;
2027
2028 switch (kwm) {
2029 case KWM_STD:
2030 curproxy->options2 |= cfg_opts2[optnum].val;
2031 break;
2032 case KWM_NO:
2033 curproxy->no_options2 |= cfg_opts2[optnum].val;
2034 break;
2035 case KWM_DEF: /* already cleared */
2036 break;
2037 }
2038 goto out;
2039 }
2040 }
2041
2042 /* HTTP options override each other. They can be cancelled using
2043 * "no option xxx" which only switches to default mode if the mode
2044 * was this one (useful for cancelling options set in defaults
2045 * sections).
2046 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02002047 if (strcmp(args[1], "forceclose") == 0) {
2048 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",
2049 file, linenum, args[1]);
2050 err_code |= ERR_ALERT | ERR_FATAL;
2051 goto out;
2052 }
2053 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002054 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2055 goto out;
2056 if (kwm == KWM_STD) {
2057 curproxy->options &= ~PR_O_HTTP_MODE;
2058 curproxy->options |= PR_O_HTTP_CLO;
2059 goto out;
2060 }
2061 else if (kwm == KWM_NO) {
2062 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2063 curproxy->options &= ~PR_O_HTTP_MODE;
2064 goto out;
2065 }
2066 }
2067 else if (strcmp(args[1], "http-server-close") == 0) {
2068 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2069 goto out;
2070 if (kwm == KWM_STD) {
2071 curproxy->options &= ~PR_O_HTTP_MODE;
2072 curproxy->options |= PR_O_HTTP_SCL;
2073 goto out;
2074 }
2075 else if (kwm == KWM_NO) {
2076 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2077 curproxy->options &= ~PR_O_HTTP_MODE;
2078 goto out;
2079 }
2080 }
2081 else if (strcmp(args[1], "http-keep-alive") == 0) {
2082 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2083 goto out;
2084 if (kwm == KWM_STD) {
2085 curproxy->options &= ~PR_O_HTTP_MODE;
2086 curproxy->options |= PR_O_HTTP_KAL;
2087 goto out;
2088 }
2089 else if (kwm == KWM_NO) {
2090 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2091 curproxy->options &= ~PR_O_HTTP_MODE;
2092 goto out;
2093 }
2094 }
2095 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002096 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 +02002097 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002098 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002099 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002100 }
2101
2102 /* Redispatch can take an integer argument that control when the
2103 * resispatch occurs. All values are relative to the retries option.
2104 * This can be cancelled using "no option xxx".
2105 */
2106 if (strcmp(args[1], "redispatch") == 0) {
2107 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2108 err_code |= ERR_WARN;
2109 goto out;
2110 }
2111
2112 curproxy->no_options &= ~PR_O_REDISP;
2113 curproxy->options &= ~PR_O_REDISP;
2114
2115 switch (kwm) {
2116 case KWM_STD:
2117 curproxy->options |= PR_O_REDISP;
2118 curproxy->redispatch_after = -1;
2119 if(*args[2]) {
2120 curproxy->redispatch_after = atol(args[2]);
2121 }
2122 break;
2123 case KWM_NO:
2124 curproxy->no_options |= PR_O_REDISP;
2125 curproxy->redispatch_after = 0;
2126 break;
2127 case KWM_DEF: /* already cleared */
2128 break;
2129 }
2130 goto out;
2131 }
2132
Willy Tarreau25241232021-07-18 19:18:56 +02002133 if (strcmp(args[1], "http_proxy") == 0) {
2134 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",
2135 file, linenum, args[1]);
2136 err_code |= ERR_ALERT | ERR_FATAL;
2137 goto out;
2138 }
2139
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002140 if (kwm != KWM_STD) {
2141 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2142 file, linenum, args[1]);
2143 err_code |= ERR_ALERT | ERR_FATAL;
2144 goto out;
2145 }
2146
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002147 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002148 char *logformat;
2149 /* generate a complete HTTP log */
2150 logformat = default_http_log_format;
2151 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002152 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002153 curproxy->options2 |= PR_O2_CLFLOG;
2154 logformat = clf_http_log_format;
2155 } else {
2156 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2157 err_code |= ERR_ALERT | ERR_FATAL;
2158 goto out;
2159 }
2160 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2161 goto out;
2162 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002163 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002164 char *oldlogformat = "log-format";
2165 char *clflogformat = "";
2166
2167 if (curproxy->conf.logformat_string == default_http_log_format)
2168 oldlogformat = "option httplog";
2169 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2170 oldlogformat = "option tcplog";
2171 else if (curproxy->conf.logformat_string == clf_http_log_format)
2172 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002173 else if (curproxy->conf.logformat_string == default_https_log_format)
2174 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002175 if (logformat == clf_http_log_format)
2176 clflogformat = " clf";
2177 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2178 file, linenum, clflogformat, oldlogformat);
2179 }
2180 if (curproxy->conf.logformat_string != default_http_log_format &&
2181 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002182 curproxy->conf.logformat_string != clf_http_log_format &&
2183 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002184 free(curproxy->conf.logformat_string);
2185 curproxy->conf.logformat_string = logformat;
2186
2187 free(curproxy->conf.lfs_file);
2188 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2189 curproxy->conf.lfs_line = curproxy->conf.args.line;
2190
Willy Tarreau5d095c22021-02-12 10:15:59 +01002191 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002192 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2193 file, linenum, curproxy->id);
2194 err_code |= ERR_WARN;
2195 }
2196 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002197 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002198 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002199 char *oldlogformat = "log-format";
2200
2201 if (curproxy->conf.logformat_string == default_http_log_format)
2202 oldlogformat = "option httplog";
2203 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2204 oldlogformat = "option tcplog";
2205 else if (curproxy->conf.logformat_string == clf_http_log_format)
2206 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002207 else if (curproxy->conf.logformat_string == default_https_log_format)
2208 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002209 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2210 file, linenum, oldlogformat);
2211 }
2212 /* generate a detailed TCP log */
2213 if (curproxy->conf.logformat_string != default_http_log_format &&
2214 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002215 curproxy->conf.logformat_string != clf_http_log_format &&
2216 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002217 free(curproxy->conf.logformat_string);
2218 curproxy->conf.logformat_string = default_tcp_log_format;
2219
2220 free(curproxy->conf.lfs_file);
2221 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2222 curproxy->conf.lfs_line = curproxy->conf.args.line;
2223
2224 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2225 goto out;
2226
Willy Tarreau5d095c22021-02-12 10:15:59 +01002227 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002228 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2229 file, linenum, curproxy->id);
2230 err_code |= ERR_WARN;
2231 }
2232 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002233 else if (strcmp(args[1], "httpslog") == 0) {
2234 char *logformat;
2235 /* generate a complete HTTP log */
2236 logformat = default_https_log_format;
2237 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2238 char *oldlogformat = "log-format";
2239
2240 if (curproxy->conf.logformat_string == default_http_log_format)
2241 oldlogformat = "option httplog";
2242 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2243 oldlogformat = "option tcplog";
2244 else if (curproxy->conf.logformat_string == clf_http_log_format)
2245 oldlogformat = "option httplog clf";
2246 else if (curproxy->conf.logformat_string == default_https_log_format)
2247 oldlogformat = "option httpslog";
2248 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2249 file, linenum, oldlogformat);
2250 }
2251 if (curproxy->conf.logformat_string != default_http_log_format &&
2252 curproxy->conf.logformat_string != default_tcp_log_format &&
2253 curproxy->conf.logformat_string != clf_http_log_format &&
2254 curproxy->conf.logformat_string != default_https_log_format)
2255 free(curproxy->conf.logformat_string);
2256 curproxy->conf.logformat_string = logformat;
2257
2258 free(curproxy->conf.lfs_file);
2259 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2260 curproxy->conf.lfs_line = curproxy->conf.args.line;
2261
2262 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2263 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2264 file, linenum, curproxy->id);
2265 err_code |= ERR_WARN;
2266 }
2267 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002268 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 /* enable TCP keep-alives on client and server streams */
2270 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2271 err_code |= ERR_WARN;
2272
2273 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2274 goto out;
2275
2276 if (curproxy->cap & PR_CAP_FE)
2277 curproxy->options |= PR_O_TCP_CLI_KA;
2278 if (curproxy->cap & PR_CAP_BE)
2279 curproxy->options |= PR_O_TCP_SRV_KA;
2280 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002281 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002282 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002283 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002284 goto out;
2285 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002286 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002287 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002288 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002289 goto out;
2290 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002291 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002292 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002293 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002294 goto out;
2295 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002296 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002297 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002298 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002299 goto out;
2300 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002301 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002302 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002303 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002304 goto out;
2305 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002306 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002307 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002308 if (err_code & ERR_FATAL)
2309 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002310 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002311 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002312 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002313 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002314 goto out;
2315 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002316 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002317 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002318 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002319 goto out;
2320 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002321 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002322 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002323 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002324 goto out;
2325 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002326 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002327 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002328 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002329 goto out;
2330 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002331 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002332 int cur_arg;
2333
2334 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002335 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002336 */
2337
2338 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2339
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002340 istfree(&curproxy->fwdfor_hdr_name);
2341 curproxy->fwdfor_hdr_name = istdup(ist(DEF_XFORWARDFOR_HDR));
2342 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002343 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002344 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002345
2346 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2347 cur_arg = 2;
2348 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002349 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002350 unsigned char mask;
2351 int i;
2352
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002353 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002354 if (*(args[cur_arg+1]) &&
2355 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2356 curproxy->except_xff_net.family = AF_INET;
2357 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2358 }
2359 else if (*(args[cur_arg+1]) &&
2360 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2361 curproxy->except_xff_net.family = AF_INET6;
2362 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2363 for (i = 0; i < 16; i++)
2364 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2365 }
2366 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002367 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2368 file, linenum, args[0], args[1], args[cur_arg]);
2369 err_code |= ERR_ALERT | ERR_FATAL;
2370 goto out;
2371 }
2372 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002373 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002374 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002375 /* suboption header - needs additional argument for it */
2376 if (*(args[cur_arg+1]) == 0) {
2377 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2378 file, linenum, args[0], args[1], args[cur_arg]);
2379 err_code |= ERR_ALERT | ERR_FATAL;
2380 goto out;
2381 }
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002382 istfree(&curproxy->fwdfor_hdr_name);
2383 curproxy->fwdfor_hdr_name = istdup(ist(args[cur_arg+1]));
2384 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002385 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002386 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002387 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002388 curproxy->options &= ~PR_O_FF_ALWAYS;
2389 cur_arg += 1;
2390 } else {
2391 /* unknown suboption - catchall */
2392 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2393 file, linenum, args[0], args[1]);
2394 err_code |= ERR_ALERT | ERR_FATAL;
2395 goto out;
2396 }
2397 } /* end while loop */
2398 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002399 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002400 int cur_arg;
2401
2402 /* insert x-original-to field, but not for the IP address listed as an except.
2403 * set default options (ie: bitfield, header name, etc)
2404 */
2405
2406 curproxy->options |= PR_O_ORGTO;
2407
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002408 istfree(&curproxy->orgto_hdr_name);
2409 curproxy->orgto_hdr_name = istdup(ist(DEF_XORIGINALTO_HDR));
2410 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002411 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002412 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002413
2414 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2415 cur_arg = 2;
2416 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002417 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002418 unsigned char mask;
2419 int i;
2420
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002421 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002422 if (*(args[cur_arg+1]) &&
2423 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2424 curproxy->except_xot_net.family = AF_INET;
2425 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2426 }
2427 else if (*(args[cur_arg+1]) &&
2428 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2429 curproxy->except_xot_net.family = AF_INET6;
2430 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2431 for (i = 0; i < 16; i++)
2432 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2433 }
2434 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002435 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2436 file, linenum, args[0], args[1], args[cur_arg]);
2437 err_code |= ERR_ALERT | ERR_FATAL;
2438 goto out;
2439 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002440 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002441 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002442 /* suboption header - needs additional argument for it */
2443 if (*(args[cur_arg+1]) == 0) {
2444 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2445 file, linenum, args[0], args[1], args[cur_arg]);
2446 err_code |= ERR_ALERT | ERR_FATAL;
2447 goto out;
2448 }
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002449 istfree(&curproxy->orgto_hdr_name);
2450 curproxy->orgto_hdr_name = istdup(ist(args[cur_arg+1]));
2451 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002452 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002453 cur_arg += 2;
2454 } else {
2455 /* unknown suboption - catchall */
2456 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2457 file, linenum, args[0], args[1]);
2458 err_code |= ERR_ALERT | ERR_FATAL;
2459 goto out;
2460 }
2461 } /* end while loop */
2462 }
2463 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002464 const char *best = proxy_find_best_option(args[1], common_options);
2465
2466 if (best)
2467 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2468 else
2469 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2470
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002471 err_code |= ERR_ALERT | ERR_FATAL;
2472 goto out;
2473 }
2474 goto out;
2475 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002476 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002477 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2478 err_code |= ERR_WARN;
2479
2480 if (*(args[1]) == 0) {
2481 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2482 err_code |= ERR_ALERT | ERR_FATAL;
2483 goto out;
2484 }
2485 free(curproxy->defbe.name);
2486 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002487 if (!curproxy->defbe.name)
2488 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002489
2490 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2491 goto out;
2492 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002493 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002494 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 +01002495
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002496 err_code |= ERR_ALERT | ERR_FATAL;
2497 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002498 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002499 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002500 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2501 err_code |= ERR_WARN;
2502
2503 if (strcmp(args[1], "never") == 0) {
2504 /* enable a graceful server shutdown on an HTTP 404 response */
2505 curproxy->options &= ~PR_O_REUSE_MASK;
2506 curproxy->options |= PR_O_REUSE_NEVR;
2507 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2508 goto out;
2509 }
2510 else if (strcmp(args[1], "safe") == 0) {
2511 /* enable a graceful server shutdown on an HTTP 404 response */
2512 curproxy->options &= ~PR_O_REUSE_MASK;
2513 curproxy->options |= PR_O_REUSE_SAFE;
2514 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2515 goto out;
2516 }
2517 else if (strcmp(args[1], "aggressive") == 0) {
2518 curproxy->options &= ~PR_O_REUSE_MASK;
2519 curproxy->options |= PR_O_REUSE_AGGR;
2520 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2521 goto out;
2522 }
2523 else if (strcmp(args[1], "always") == 0) {
2524 /* enable a graceful server shutdown on an HTTP 404 response */
2525 curproxy->options &= ~PR_O_REUSE_MASK;
2526 curproxy->options |= PR_O_REUSE_ALWS;
2527 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2528 goto out;
2529 }
2530 else {
2531 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2532 err_code |= ERR_ALERT | ERR_FATAL;
2533 goto out;
2534 }
2535 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002536 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002537 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002538 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2539 err_code |= ERR_ALERT | ERR_FATAL;
2540 goto out;
2541 }
2542
2543 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2544 err_code |= ERR_WARN;
2545
2546 if (strcmp(args[1], "fail") == 0) {
2547 /* add a condition to fail monitor requests */
2548 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2549 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2550 file, linenum, args[0], args[1]);
2551 err_code |= ERR_ALERT | ERR_FATAL;
2552 goto out;
2553 }
2554
2555 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2556 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2557 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2558 file, linenum, args[0], args[1], errmsg);
2559 err_code |= ERR_ALERT | ERR_FATAL;
2560 goto out;
2561 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002562 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002563 }
2564 else {
2565 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2566 err_code |= ERR_ALERT | ERR_FATAL;
2567 goto out;
2568 }
2569 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002570#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002571 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002572 /* enable transparent proxy connections */
2573 curproxy->options |= PR_O_TRANSP;
2574 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2575 goto out;
2576 }
2577#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002578 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002579 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2580 err_code |= ERR_WARN;
2581
2582 if (*(args[1]) == 0) {
2583 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2584 err_code |= ERR_ALERT | ERR_FATAL;
2585 goto out;
2586 }
2587 curproxy->maxconn = atol(args[1]);
2588 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2589 goto out;
2590 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002591 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002592 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2593 err_code |= ERR_WARN;
2594
2595 if (*(args[1]) == 0) {
2596 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2597 err_code |= ERR_ALERT | ERR_FATAL;
2598 goto out;
2599 }
2600 curproxy->backlog = atol(args[1]);
2601 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2602 goto out;
2603 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002604 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002605 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2606 err_code |= ERR_WARN;
2607
2608 if (*(args[1]) == 0) {
2609 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2610 err_code |= ERR_ALERT | ERR_FATAL;
2611 goto out;
2612 }
2613 curproxy->fullconn = atol(args[1]);
2614 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2615 goto out;
2616 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002617 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002618 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 +02002619 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002620 err_code |= ERR_ALERT | ERR_FATAL;
2621 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002622 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002623 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002624 struct sockaddr_storage *sk;
2625 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002626
Willy Tarreau5d095c22021-02-12 10:15:59 +01002627 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002628 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2629 err_code |= ERR_ALERT | ERR_FATAL;
2630 goto out;
2631 }
2632 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2633 err_code |= ERR_WARN;
2634
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002635 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2636 &errmsg, NULL, NULL,
2637 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 +01002638 if (!sk) {
2639 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2640 err_code |= ERR_ALERT | ERR_FATAL;
2641 goto out;
2642 }
2643
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002644 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2645 goto out;
2646
2647 curproxy->dispatch_addr = *sk;
2648 curproxy->options |= PR_O_DISPATCH;
2649 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002650 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002651 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2652 err_code |= ERR_WARN;
2653
2654 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2655 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2656 err_code |= ERR_ALERT | ERR_FATAL;
2657 goto out;
2658 }
2659 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002660 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002661 /**
2662 * The syntax for hash-type config element is
2663 * hash-type {map-based|consistent} [[<algo>] avalanche]
2664 *
2665 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2666 */
2667 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2668
2669 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2670 err_code |= ERR_WARN;
2671
2672 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2673 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2674 }
2675 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2676 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2677 }
2678 else if (strcmp(args[1], "avalanche") == 0) {
2679 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]);
2680 err_code |= ERR_ALERT | ERR_FATAL;
2681 goto out;
2682 }
2683 else {
2684 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2685 err_code |= ERR_ALERT | ERR_FATAL;
2686 goto out;
2687 }
2688
2689 /* set the hash function to use */
2690 if (!*args[2]) {
2691 /* the default algo is sdbm */
2692 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2693
2694 /* if consistent with no argument, then avalanche modifier is also applied */
2695 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2696 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2697 } else {
2698 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002699 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002700 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2701 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002702 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002703 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2704 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002705 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002706 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2707 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002708 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002709 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2710 }
2711 else {
2712 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2713 err_code |= ERR_ALERT | ERR_FATAL;
2714 goto out;
2715 }
2716
2717 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002718 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002719 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2720 }
2721 else if (*args[3]) {
2722 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2723 err_code |= ERR_ALERT | ERR_FATAL;
2724 goto out;
2725 }
2726 }
2727 }
2728 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2729 if (*(args[1]) == 0) {
2730 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2731 err_code |= ERR_ALERT | ERR_FATAL;
2732 goto out;
2733 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002734 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2735 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002736 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2737 err_code |= ERR_ALERT | ERR_FATAL;
2738 goto out;
2739 }
2740 }
2741 else if (strcmp(args[0], "unique-id-format") == 0) {
2742 if (!*(args[1])) {
2743 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2744 err_code |= ERR_ALERT | ERR_FATAL;
2745 goto out;
2746 }
2747 if (*(args[2])) {
2748 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2749 err_code |= ERR_ALERT | ERR_FATAL;
2750 goto out;
2751 }
2752 free(curproxy->conf.uniqueid_format_string);
2753 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002754 if (!curproxy->conf.uniqueid_format_string)
2755 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002756
2757 free(curproxy->conf.uif_file);
2758 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2759 curproxy->conf.uif_line = curproxy->conf.args.line;
2760 }
2761
2762 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002763 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002764 if (!*(args[1])) {
2765 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2766 err_code |= ERR_ALERT | ERR_FATAL;
2767 goto out;
2768 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002769 copy = strdup(args[1]);
2770 if (copy == NULL) {
2771 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2772 err_code |= ERR_ALERT | ERR_FATAL;
2773 goto out;
2774 }
2775
2776 istfree(&curproxy->header_unique_id);
2777 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002778 }
2779
2780 else if (strcmp(args[0], "log-format") == 0) {
2781 if (!*(args[1])) {
2782 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2783 err_code |= ERR_ALERT | ERR_FATAL;
2784 goto out;
2785 }
2786 if (*(args[2])) {
2787 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2788 err_code |= ERR_ALERT | ERR_FATAL;
2789 goto out;
2790 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002791 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002792 char *oldlogformat = "log-format";
2793
2794 if (curproxy->conf.logformat_string == default_http_log_format)
2795 oldlogformat = "option httplog";
2796 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2797 oldlogformat = "option tcplog";
2798 else if (curproxy->conf.logformat_string == clf_http_log_format)
2799 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002800 else if (curproxy->conf.logformat_string == default_https_log_format)
2801 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002802 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2803 file, linenum, oldlogformat);
2804 }
2805 if (curproxy->conf.logformat_string != default_http_log_format &&
2806 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002807 curproxy->conf.logformat_string != clf_http_log_format &&
2808 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002809 free(curproxy->conf.logformat_string);
2810 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002811 if (!curproxy->conf.logformat_string)
2812 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002813
2814 free(curproxy->conf.lfs_file);
2815 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2816 curproxy->conf.lfs_line = curproxy->conf.args.line;
2817
2818 /* get a chance to improve log-format error reporting by
2819 * reporting the correct line-number when possible.
2820 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002821 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002822 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2823 file, linenum, curproxy->id);
2824 err_code |= ERR_WARN;
2825 }
2826 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002827 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002828 if (!*(args[1])) {
2829 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2830 err_code |= ERR_ALERT | ERR_FATAL;
2831 goto out;
2832 }
2833 if (*(args[2])) {
2834 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2835 err_code |= ERR_ALERT | ERR_FATAL;
2836 goto out;
2837 }
2838
2839 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2840 free(curproxy->conf.logformat_sd_string);
2841 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002842 if (!curproxy->conf.logformat_sd_string)
2843 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002844
2845 free(curproxy->conf.lfsd_file);
2846 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2847 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2848
2849 /* get a chance to improve log-format-sd error reporting by
2850 * reporting the correct line-number when possible.
2851 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002852 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002853 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2854 file, linenum, curproxy->id);
2855 err_code |= ERR_WARN;
2856 }
2857 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002858 else if (strcmp(args[0], "error-log-format") == 0) {
2859 if (!*(args[1])) {
2860 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2861 err_code |= ERR_ALERT | ERR_FATAL;
2862 goto out;
2863 }
2864 if (*(args[2])) {
2865 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2866 err_code |= ERR_ALERT | ERR_FATAL;
2867 goto out;
2868 }
2869 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2870 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2871 file, linenum);
2872 }
2873 free(curproxy->conf.error_logformat_string);
2874 curproxy->conf.error_logformat_string = strdup(args[1]);
2875 if (!curproxy->conf.error_logformat_string)
2876 goto alloc_error;
2877
2878 free(curproxy->conf.elfs_file);
2879 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2880 curproxy->conf.elfs_line = curproxy->conf.args.line;
2881
2882 /* get a chance to improve log-format error reporting by
2883 * reporting the correct line-number when possible.
2884 */
2885 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2886 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2887 file, linenum, curproxy->id);
2888 err_code |= ERR_WARN;
2889 }
2890 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002891 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002892 if (*(args[1]) == 0) {
2893 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2894 err_code |= ERR_ALERT | ERR_FATAL;
2895 goto out;
2896 }
2897 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002898 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2899 if (b_orig(&curproxy->log_tag) == NULL) {
2900 chunk_destroy(&curproxy->log_tag);
2901 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2902 err_code |= ERR_ALERT | ERR_FATAL;
2903 goto out;
2904 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002905 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002906 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002907 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002908 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2909 err_code |= ERR_ALERT | ERR_FATAL;
2910 goto out;
2911 }
2912 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002913 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002914 int cur_arg;
2915 int port1, port2;
2916 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002917
2918 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2919 err_code |= ERR_WARN;
2920
2921 if (!*args[1]) {
2922 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2923 file, linenum, "source", "usesrc", "interface");
2924 err_code |= ERR_ALERT | ERR_FATAL;
2925 goto out;
2926 }
2927
Christopher Faulet31930372019-07-15 10:16:58 +02002928 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002929 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002930 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002931 curproxy->conn_src.iface_len = 0;
2932
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002933 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2934 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002935 if (!sk) {
2936 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2937 file, linenum, args[0], args[1], errmsg);
2938 err_code |= ERR_ALERT | ERR_FATAL;
2939 goto out;
2940 }
2941
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002942 curproxy->conn_src.source_addr = *sk;
2943 curproxy->conn_src.opts |= CO_SRC_BIND;
2944
2945 cur_arg = 2;
2946 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002947 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002948#if defined(CONFIG_HAP_TRANSPARENT)
2949 if (!*args[cur_arg + 1]) {
2950 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2951 file, linenum, "usesrc");
2952 err_code |= ERR_ALERT | ERR_FATAL;
2953 goto out;
2954 }
2955
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002956 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002957 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2958 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002959 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002960 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2961 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2962 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2963 char *name, *end;
2964
2965 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002966 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002967 name++;
2968
2969 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002970 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002971 end++;
2972
2973 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2974 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002975 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002976 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002977 if (!curproxy->conn_src.bind_hdr_name)
2978 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002979 curproxy->conn_src.bind_hdr_len = end - name;
2980 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2981 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2982 curproxy->conn_src.bind_hdr_occ = -1;
2983
2984 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002985 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002986 end++;
2987 if (*end == ',') {
2988 end++;
2989 name = end;
2990 if (*end == '-')
2991 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002992 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002993 end++;
2994 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2995 }
2996
2997 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2998 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2999 " occurrences values smaller than %d.\n",
3000 file, linenum, MAX_HDR_HISTORY);
3001 err_code |= ERR_ALERT | ERR_FATAL;
3002 goto out;
3003 }
3004 } else {
3005 struct sockaddr_storage *sk;
3006
Willy Tarreau65ec4e32020-09-16 19:17:08 +02003007 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
3008 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003009 if (!sk) {
3010 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
3011 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
3012 err_code |= ERR_ALERT | ERR_FATAL;
3013 goto out;
3014 }
3015
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003016 curproxy->conn_src.tproxy_addr = *sk;
3017 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3018 }
3019 global.last_checks |= LSTCHK_NETADM;
3020#else /* no TPROXY support */
3021 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3022 file, linenum, "usesrc");
3023 err_code |= ERR_ALERT | ERR_FATAL;
3024 goto out;
3025#endif
3026 cur_arg += 2;
3027 continue;
3028 }
3029
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003030 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003031#ifdef SO_BINDTODEVICE
3032 if (!*args[cur_arg + 1]) {
3033 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3034 file, linenum, args[0]);
3035 err_code |= ERR_ALERT | ERR_FATAL;
3036 goto out;
3037 }
3038 free(curproxy->conn_src.iface_name);
3039 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02003040 if (!curproxy->conn_src.iface_name)
3041 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003042 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3043 global.last_checks |= LSTCHK_NETADM;
3044#else
3045 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3046 file, linenum, args[0], args[cur_arg]);
3047 err_code |= ERR_ALERT | ERR_FATAL;
3048 goto out;
3049#endif
3050 cur_arg += 2;
3051 continue;
3052 }
3053 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3054 file, linenum, args[0], "interface", "usesrc");
3055 err_code |= ERR_ALERT | ERR_FATAL;
3056 goto out;
3057 }
3058 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003059 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003060 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3061 file, linenum, "usesrc", "source");
3062 err_code |= ERR_ALERT | ERR_FATAL;
3063 goto out;
3064 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003065 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 +02003066 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003067 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003068 file, linenum, args[0]);
3069 err_code |= ERR_ALERT | ERR_FATAL;
3070 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003071 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003072 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003073 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3074 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3075 err_code |= ERR_ALERT | ERR_FATAL;
3076 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003077 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003078 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003079 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3080 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3081 err_code |= ERR_ALERT | ERR_FATAL;
3082 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003083 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003084 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003085 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3086 err_code |= ERR_ALERT | ERR_FATAL;
3087 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003088 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003089 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003090 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3091 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3092 err_code |= ERR_ALERT | ERR_FATAL;
3093 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003094 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003095 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003096 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3097 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3098 err_code |= ERR_ALERT | ERR_FATAL;
3099 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003100 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003101 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003102 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3103 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3104 err_code |= ERR_ALERT | ERR_FATAL;
3105 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003106 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003107 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003108 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3109 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3110 err_code |= ERR_ALERT | ERR_FATAL;
3111 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003112 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003113 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 +02003114 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3115 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3116 err_code |= ERR_ALERT | ERR_FATAL;
3117 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003118 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003119 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003120 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3121 err_code |= ERR_ALERT | ERR_FATAL;
3122 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003123 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003124 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 +02003125 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3126 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3127 err_code |= ERR_ALERT | ERR_FATAL;
3128 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003129 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003130 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 +02003131 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3132 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3133 err_code |= ERR_ALERT | ERR_FATAL;
3134 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003135 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003136 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003137 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3138 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3139 err_code |= ERR_ALERT | ERR_FATAL;
3140 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003141 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003142 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 +02003143 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3144 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3145 err_code |= ERR_ALERT | ERR_FATAL;
3146 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003147 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003148 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003149 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3150 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3151 err_code |= ERR_ALERT | ERR_FATAL;
3152 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003153 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003154 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003155 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3156 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3157 err_code |= ERR_ALERT | ERR_FATAL;
3158 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003159 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003160 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303161 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003162 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3163 err_code |= ERR_ALERT | ERR_FATAL;
3164 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003165 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003166 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003167 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3168 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3169 err_code |= ERR_ALERT | ERR_FATAL;
3170 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003171 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003172 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003173 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3174 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3175 err_code |= ERR_ALERT | ERR_FATAL;
3176 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003177 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003178 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003179 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3180 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3181 err_code |= ERR_ALERT | ERR_FATAL;
3182 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003183 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003184 else {
3185 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003186 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003187 int index;
3188
3189 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3190 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3191 if (kwl->kw[index].section != CFG_LISTEN)
3192 continue;
3193 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003194 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003195 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003196 err_code |= ERR_ALERT | ERR_FATAL;
3197 goto out;
3198 }
3199
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003200 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003201 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003202 if (rc < 0) {
3203 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3204 err_code |= ERR_ALERT | ERR_FATAL;
3205 goto out;
3206 }
3207 else if (rc > 0) {
3208 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3209 err_code |= ERR_WARN;
3210 goto out;
3211 }
3212 goto out;
3213 }
3214 }
3215 }
3216
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003217 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3218 if (best)
3219 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3220 else
3221 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003222 err_code |= ERR_ALERT | ERR_FATAL;
3223 goto out;
3224 }
3225 out:
3226 free(errmsg);
3227 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003228
3229 alloc_error:
3230 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3231 err_code |= ERR_ALERT | ERR_ABORT;
3232 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003233}