blob: 216e6d8d577fc7c9f2917465964bf781da7948e7 [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
Willy Tarreaue90904d2021-02-12 14:08:31 +0100409 if (rc & PR_CAP_DEF) {
410 /* last and current proxies must be updated to this one */
411 curr_defproxy = last_defproxy = curproxy;
412 } else {
413 /* regular proxies are in a list */
414 curproxy->next = proxies_list;
415 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100416 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100417 goto out;
418 }
419 else if (curproxy == NULL) {
420 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
421 err_code |= ERR_ALERT | ERR_FATAL;
422 goto out;
423 }
424
425 /* update the current file and line being parsed */
426 curproxy->conf.args.file = curproxy->conf.file;
427 curproxy->conf.args.line = linenum;
428
429 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100430 if ((strcmp(args[0], "server") == 0)) {
431 err_code |= parse_server(file, linenum, args,
432 curproxy, curr_defproxy,
433 SRV_PARSE_PARSE_ADDR);
434
435 if (err_code & ERR_FATAL)
436 goto out;
437 }
438 else if (strcmp(args[0], "default-server") == 0) {
439 err_code |= parse_server(file, linenum, args,
440 curproxy, curr_defproxy,
441 SRV_PARSE_DEFAULT_SERVER);
442
443 if (err_code & ERR_FATAL)
444 goto out;
445 }
446 else if (strcmp(args[0], "server-template") == 0) {
447 err_code |= parse_server(file, linenum, args,
448 curproxy, curr_defproxy,
449 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
450
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100451 if (err_code & ERR_FATAL)
452 goto out;
453 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100454 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100455 struct listener *l;
456 int cur_arg;
457
Willy Tarreau5d095c22021-02-12 10:15:59 +0100458 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100459 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
460 err_code |= ERR_ALERT | ERR_FATAL;
461 goto out;
462 }
463 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
464 err_code |= ERR_WARN;
465
466 if (!*(args[1])) {
467 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
468 file, linenum, args[0]);
469 err_code |= ERR_ALERT | ERR_FATAL;
470 goto out;
471 }
472
473 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200474 if (!bind_conf)
475 goto alloc_error;
476
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100477 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200478 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
479 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
480 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100481
482 /* NOTE: the following line might create several listeners if there
483 * are comma-separated IPs or port ranges. So all further processing
484 * will have to be applied to all listeners created after last_listen.
485 */
486 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
487 if (errmsg && *errmsg) {
488 indent_msg(&errmsg, 2);
489 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
490 }
491 else
492 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
493 file, linenum, args[0], args[1]);
494 err_code |= ERR_ALERT | ERR_FATAL;
495 goto out;
496 }
497
498 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
499 /* Set default global rights and owner for unix bind */
500 global.maxsock++;
501 }
502
503 cur_arg = 2;
504 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100505 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100506 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100507
508 kw = bind_find_kw(args[cur_arg]);
509 if (kw) {
510 char *err = NULL;
511 int code;
512
513 if (!kw->parse) {
514 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
515 file, linenum, args[0], args[1], args[cur_arg]);
516 cur_arg += 1 + kw->skip ;
517 err_code |= ERR_ALERT | ERR_FATAL;
518 goto out;
519 }
520
521 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
522 err_code |= code;
523
524 if (code) {
525 if (err && *err) {
526 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200527 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
528 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
529 else
530 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100531 }
532 else
533 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
534 file, linenum, args[0], args[1], args[cur_arg]);
535 if (code & ERR_FATAL) {
536 free(err);
537 cur_arg += 1 + kw->skip;
538 goto out;
539 }
540 }
541 free(err);
542 cur_arg += 1 + kw->skip;
543 continue;
544 }
545
Willy Tarreau433b05f2021-03-12 10:14:07 +0100546 best = bind_find_best_kw(args[cur_arg]);
547 if (best)
548 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
549 file, linenum, args[0], args[1], args[cur_arg], best);
550 else
551 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
552 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100553
554 err_code |= ERR_ALERT | ERR_FATAL;
555 goto out;
556 }
557 goto out;
558 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100559 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200560 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]);
561 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100562 goto out;
563 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100564 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100565 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
566 err_code |= ERR_WARN;
567
568 if (alertif_too_many_args(1, file, linenum, args, &err_code))
569 goto out;
570
571 if (!*args[1]) {
572 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
573 file, linenum, args[0]);
574 err_code |= ERR_ALERT | ERR_FATAL;
575 goto out;
576 }
577
Tim Duesterhus4b1fcaa2022-03-05 00:52:40 +0100578 istfree(&curproxy->monitor_uri);
579 curproxy->monitor_uri = istdup(ist(args[1]));
580 if (!isttest(curproxy->monitor_uri))
Christopher Fauletb15625a2021-04-12 21:31:45 +0200581 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100582
583 goto out;
584 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100585 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100586 if (alertif_too_many_args(1, file, linenum, args, &err_code))
587 goto out;
588
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100589 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
590 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
591 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200592 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
593 err_code |= ERR_ALERT | ERR_FATAL;
594 goto out;
595 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100596 else {
597 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
598 err_code |= ERR_ALERT | ERR_FATAL;
599 goto out;
600 }
601 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100602 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100603 struct eb32_node *node;
604
Willy Tarreau5d095c22021-02-12 10:15:59 +0100605 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100606 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
607 file, linenum, args[0]);
608 err_code |= ERR_ALERT | ERR_FATAL;
609 goto out;
610 }
611
612 if (alertif_too_many_args(1, file, linenum, args, &err_code))
613 goto out;
614
615 if (!*args[1]) {
616 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
617 file, linenum, args[0]);
618 err_code |= ERR_ALERT | ERR_FATAL;
619 goto out;
620 }
621
622 curproxy->uuid = atol(args[1]);
623 curproxy->conf.id.key = curproxy->uuid;
624 curproxy->options |= PR_O_FORCED_ID;
625
626 if (curproxy->uuid <= 0) {
627 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
628 file, linenum);
629 err_code |= ERR_ALERT | ERR_FATAL;
630 goto out;
631 }
632
633 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
634 if (node) {
635 struct proxy *target = container_of(node, struct proxy, conf.id);
636 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
637 file, linenum, proxy_type_str(curproxy), curproxy->id,
638 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
639 err_code |= ERR_ALERT | ERR_FATAL;
640 goto out;
641 }
642 eb32_insert(&used_proxy_id, &curproxy->conf.id);
643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100644 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100645 int i, len=0;
646 char *d;
647
Willy Tarreau5d095c22021-02-12 10:15:59 +0100648 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100649 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
650 file, linenum, args[0]);
651 err_code |= ERR_ALERT | ERR_FATAL;
652 goto out;
653 }
654
655 if (!*args[1]) {
656 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
657 file, linenum, args[0]);
658 return -1;
659 }
660
661 for (i = 1; *args[i]; i++)
662 len += strlen(args[i]) + 1;
663
664 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200665 if (!d)
666 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100667 curproxy->desc = d;
668
669 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
670 for (i = 2; *args[i]; i++)
671 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
672
673 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100674 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100675 if (alertif_too_many_args(0, file, linenum, args, &err_code))
676 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200677 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100678 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100679 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100680 if (alertif_too_many_args(0, file, linenum, args, &err_code))
681 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200682 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100683 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100684 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100685 int cur_arg = 1;
686 unsigned long set = 0;
687
688 while (*args[cur_arg]) {
689 if (strcmp(args[cur_arg], "all") == 0) {
690 set = 0;
691 break;
692 }
Willy Tarreau72faef32021-06-15 08:36:30 +0200693 if (parse_process_number(args[cur_arg], &set, 1, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100694 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
695 err_code |= ERR_ALERT | ERR_FATAL;
696 goto out;
697 }
698 cur_arg++;
699 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200700 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
701 file, linenum, args[0]);
702 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100704 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200705 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
706 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100707 err_code |= ERR_ALERT | ERR_FATAL;
708 goto out;
709 }
710
711 err = invalid_char(args[1]);
712 if (err) {
713 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
714 file, linenum, *err, args[1]);
715 err_code |= ERR_ALERT | ERR_FATAL;
716 goto out;
717 }
718
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100719 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100720 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100721 "logical disjunction within a condition.\n",
722 file, linenum, args[1]);
723 err_code |= ERR_ALERT | ERR_FATAL;
724 goto out;
725 }
726
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100727 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
728 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
729 file, linenum, args[1], errmsg);
730 err_code |= ERR_ALERT | ERR_FATAL;
731 goto out;
732 }
733 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100734 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100735
736 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
737 err_code |= ERR_WARN;
738
739 if (*(args[1]) == 0) {
740 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
741 file, linenum, args[0]);
742 err_code |= ERR_ALERT | ERR_FATAL;
743 goto out;
744 }
745 free(curproxy->dyncookie_key);
746 curproxy->dyncookie_key = strdup(args[1]);
747 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100748 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100749 int cur_arg;
750
751 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
752 err_code |= ERR_WARN;
753
754 if (*(args[1]) == 0) {
755 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
756 file, linenum, args[0]);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760
761 curproxy->ck_opts = 0;
762 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100763 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100764 free(curproxy->cookie_name);
765 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200766 if (!curproxy->cookie_name)
767 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100768 curproxy->cookie_len = strlen(curproxy->cookie_name);
769
770 cur_arg = 2;
771 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100772 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100773 curproxy->ck_opts |= PR_CK_RW;
774 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100775 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100776 curproxy->ck_opts |= PR_CK_IND;
777 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100778 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100779 curproxy->ck_opts |= PR_CK_INS;
780 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100781 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100782 curproxy->ck_opts |= PR_CK_NOC;
783 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100784 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100785 curproxy->ck_opts |= PR_CK_POST;
786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100788 curproxy->ck_opts |= PR_CK_PSV;
789 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100790 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100791 curproxy->ck_opts |= PR_CK_PFX;
792 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100793 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100794 curproxy->ck_opts |= PR_CK_HTTPONLY;
795 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100796 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100797 curproxy->ck_opts |= PR_CK_SECURE;
798 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100799 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100800 if (!*args[cur_arg + 1]) {
801 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
802 file, linenum, args[cur_arg]);
803 err_code |= ERR_ALERT | ERR_FATAL;
804 goto out;
805 }
806
Joao Moraise1583752019-10-30 21:04:00 -0300807 if (!strchr(args[cur_arg + 1], '.')) {
808 /* rfc6265, 5.2.3 The Domain Attribute */
809 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
810 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100811 file, linenum, args[cur_arg + 1]);
812 err_code |= ERR_WARN;
813 }
814
815 err = invalid_domainchar(args[cur_arg + 1]);
816 if (err) {
817 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
818 file, linenum, *err, args[cur_arg + 1]);
819 err_code |= ERR_ALERT | ERR_FATAL;
820 goto out;
821 }
822
823 if (!curproxy->cookie_domain) {
824 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
825 } else {
826 /* one domain was already specified, add another one by
827 * building the string which will be returned along with
828 * the cookie.
829 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200830 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
831 }
832
Christopher Fauletb15625a2021-04-12 21:31:45 +0200833 if (!curproxy->cookie_domain)
834 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100835 cur_arg++;
836 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100837 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100838 unsigned int maxidle;
839 const char *res;
840
841 if (!*args[cur_arg + 1]) {
842 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
843 file, linenum, args[cur_arg]);
844 err_code |= ERR_ALERT | ERR_FATAL;
845 goto out;
846 }
847
848 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200849 if (res == PARSE_TIME_OVER) {
850 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
851 file, linenum, args[cur_arg+1], args[cur_arg]);
852 err_code |= ERR_ALERT | ERR_FATAL;
853 goto out;
854 }
855 else if (res == PARSE_TIME_UNDER) {
856 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
857 file, linenum, args[cur_arg+1], args[cur_arg]);
858 err_code |= ERR_ALERT | ERR_FATAL;
859 goto out;
860 }
861 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100862 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
863 file, linenum, *res, args[cur_arg]);
864 err_code |= ERR_ALERT | ERR_FATAL;
865 goto out;
866 }
867 curproxy->cookie_maxidle = maxidle;
868 cur_arg++;
869 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100870 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100871 unsigned int maxlife;
872 const char *res;
873
874 if (!*args[cur_arg + 1]) {
875 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
876 file, linenum, args[cur_arg]);
877 err_code |= ERR_ALERT | ERR_FATAL;
878 goto out;
879 }
880
Willy Tarreau9faebe32019-06-07 19:00:37 +0200881
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100882 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200883 if (res == PARSE_TIME_OVER) {
884 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
885 file, linenum, args[cur_arg+1], args[cur_arg]);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto out;
888 }
889 else if (res == PARSE_TIME_UNDER) {
890 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
891 file, linenum, args[cur_arg+1], args[cur_arg]);
892 err_code |= ERR_ALERT | ERR_FATAL;
893 goto out;
894 }
895 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100896 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
897 file, linenum, *res, args[cur_arg]);
898 err_code |= ERR_ALERT | ERR_FATAL;
899 goto out;
900 }
901 curproxy->cookie_maxlife = maxlife;
902 cur_arg++;
903 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100904 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100905
906 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
907 err_code |= ERR_WARN;
908 curproxy->ck_opts |= PR_CK_DYNAMIC;
909 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100910 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100911 char *val;
912 if (!*args[cur_arg + 1]) {
913 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
914 file, linenum, args[cur_arg]);
915 err_code |= ERR_ALERT | ERR_FATAL;
916 goto out;
917 }
918 val = args[cur_arg + 1];
919 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100920 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100921 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
922 file, linenum, *val);
923 err_code |= ERR_ALERT | ERR_FATAL;
924 goto out;
925 }
926 val++;
927 }
928 /* don't add ';' for the first attribute */
929 if (!curproxy->cookie_attrs)
930 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
931 else
932 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200933
Christopher Fauletb15625a2021-04-12 21:31:45 +0200934 if (!curproxy->cookie_attrs)
935 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100936 cur_arg++;
937 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100938
939 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100940 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 +0100941 file, linenum, args[0]);
942 err_code |= ERR_ALERT | ERR_FATAL;
943 goto out;
944 }
945 cur_arg++;
946 }
947 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
948 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
949 file, linenum);
950 err_code |= ERR_ALERT | ERR_FATAL;
951 }
952
953 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
954 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
955 file, linenum);
956 err_code |= ERR_ALERT | ERR_FATAL;
957 }
958
959 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
960 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
961 file, linenum);
962 err_code |= ERR_ALERT | ERR_FATAL;
963 }
964 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100965 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100966 if (*(args[1]) == 0) {
967 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
968 file, linenum, args[0]);
969 err_code |= ERR_ALERT | ERR_FATAL;
970 goto out;
971 }
972
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100973 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100974 if (*(args[1]) == 0) {
975 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
976 file, linenum, args[1]);
977 err_code |= ERR_ALERT | ERR_FATAL;
978 goto out;
979 }
980 free(curproxy->email_alert.from);
981 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200982 if (!curproxy->email_alert.from)
983 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100984 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100985 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100986 if (*(args[1]) == 0) {
987 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
988 file, linenum, args[1]);
989 err_code |= ERR_ALERT | ERR_FATAL;
990 goto out;
991 }
992 free(curproxy->email_alert.mailers.name);
993 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200994 if (!curproxy->email_alert.mailers.name)
995 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100996 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100997 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100998 if (*(args[1]) == 0) {
999 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1000 file, linenum, args[1]);
1001 err_code |= ERR_ALERT | ERR_FATAL;
1002 goto out;
1003 }
1004 free(curproxy->email_alert.myhostname);
1005 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001006 if (!curproxy->email_alert.myhostname)
1007 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001008 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001009 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001010 curproxy->email_alert.level = get_log_level(args[2]);
1011 if (curproxy->email_alert.level < 0) {
1012 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1013 file, linenum, args[1], args[2]);
1014 err_code |= ERR_ALERT | ERR_FATAL;
1015 goto out;
1016 }
1017 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001018 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001019 if (*(args[1]) == 0) {
1020 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1021 file, linenum, args[1]);
1022 err_code |= ERR_ALERT | ERR_FATAL;
1023 goto out;
1024 }
1025 free(curproxy->email_alert.to);
1026 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001027 if (!curproxy->email_alert.to)
1028 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001029 }
1030 else {
1031 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1032 file, linenum, args[1]);
1033 err_code |= ERR_ALERT | ERR_FATAL;
1034 goto out;
1035 }
1036 /* Indicate that the email_alert is at least partially configured */
1037 curproxy->email_alert.set = 1;
1038 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001039 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001040 if (*(args[1]) == 0) {
1041 ha_alert("parsing [%s:%d] : missing persist method.\n",
1042 file, linenum);
1043 err_code |= ERR_ALERT | ERR_FATAL;
1044 goto out;
1045 }
1046
1047 if (!strncmp(args[1], "rdp-cookie", 10)) {
1048 curproxy->options2 |= PR_O2_RDPC_PRST;
1049
1050 if (*(args[1] + 10) == '(') { /* cookie name */
1051 const char *beg, *end;
1052
1053 beg = args[1] + 11;
1054 end = strchr(beg, ')');
1055
1056 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1057 goto out;
1058
1059 if (!end || end == beg) {
1060 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1061 file, linenum);
1062 err_code |= ERR_ALERT | ERR_FATAL;
1063 goto out;
1064 }
1065
1066 free(curproxy->rdp_cookie_name);
1067 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001068 if (!curproxy->rdp_cookie_name)
1069 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001070 curproxy->rdp_cookie_len = end-beg;
1071 }
1072 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1073 free(curproxy->rdp_cookie_name);
1074 curproxy->rdp_cookie_name = strdup("msts");
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 = strlen(curproxy->rdp_cookie_name);
1078 }
1079 else { /* syntax */
1080 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1081 file, linenum);
1082 err_code |= ERR_ALERT | ERR_FATAL;
1083 goto out;
1084 }
1085 }
1086 else {
1087 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1088 file, linenum);
1089 err_code |= ERR_ALERT | ERR_FATAL;
1090 goto out;
1091 }
1092 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001093 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001094 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 +01001095 err_code |= ERR_ALERT | ERR_FATAL;
1096 goto out;
1097 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001098 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001099 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1100 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001101 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001102 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1103 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001104 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 +01001105 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1106 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001107 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001108 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1109 }
1110 else {
1111 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1112 file, linenum, args[0], args[1]);
1113 err_code |= ERR_ALERT | ERR_FATAL;
1114 goto out;
1115 }
1116 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001117 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001118 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1119 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001120 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001121 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001122
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001123 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001124
1125 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001126 curproxy->server_state_file_name = strdup(curproxy->id);
1127 else
1128 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001129
Christopher Fauletb15625a2021-04-12 21:31:45 +02001130 if (!curproxy->server_state_file_name)
1131 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001132 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001133 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001134 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1135 err_code |= ERR_WARN;
1136 if (*(args[1]) == 0) {
1137 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1138 file, linenum, args[0]);
1139 err_code |= ERR_ALERT | ERR_FATAL;
1140 goto out;
1141 }
1142 curproxy->max_out_conns = atoi(args[1]);
1143 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001144 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001145 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1146 err_code |= ERR_WARN;
1147
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001148 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001149 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001150 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1151 err_code |= ERR_ALERT | ERR_FATAL;
1152 goto out;
1153 }
1154
1155 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1156 goto out;
1157
1158 if (*(args[4]) == 0) {
1159 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1160 file, linenum, args[0]);
1161 err_code |= ERR_ALERT | ERR_FATAL;
1162 goto out;
1163 }
1164 free(curproxy->capture_name);
1165 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001166 if (!curproxy->capture_name)
1167 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001168 curproxy->capture_namelen = strlen(curproxy->capture_name);
1169 curproxy->capture_len = atol(args[4]);
1170 curproxy->to_log |= LW_COOKIE;
1171 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001172 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001173 struct cap_hdr *hdr;
1174
Willy Tarreau5d095c22021-02-12 10:15:59 +01001175 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001176 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1177 err_code |= ERR_ALERT | ERR_FATAL;
1178 goto out;
1179 }
1180
1181 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1182 goto out;
1183
1184 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1185 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1186 file, linenum, args[0], args[1]);
1187 err_code |= ERR_ALERT | ERR_FATAL;
1188 goto out;
1189 }
1190
1191 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001192 if (!hdr)
1193 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001194 hdr->next = curproxy->req_cap;
1195 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001196 if (!hdr->name)
1197 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001198 hdr->namelen = strlen(args[3]);
1199 hdr->len = atol(args[5]);
1200 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001201 if (!hdr->pool) {
1202 req_caphdr_alloc_error:
1203 if (hdr)
1204 ha_free(&hdr->name);
1205 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001206 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001207 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001208 hdr->index = curproxy->nb_req_cap++;
1209 curproxy->req_cap = hdr;
1210 curproxy->to_log |= LW_REQHDR;
1211 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001212 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001213 struct cap_hdr *hdr;
1214
Willy Tarreau5d095c22021-02-12 10:15:59 +01001215 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001216 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1217 err_code |= ERR_ALERT | ERR_FATAL;
1218 goto out;
1219 }
1220
1221 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1222 goto out;
1223
1224 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1225 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1226 file, linenum, args[0], args[1]);
1227 err_code |= ERR_ALERT | ERR_FATAL;
1228 goto out;
1229 }
1230 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001231 if (!hdr)
1232 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001233 hdr->next = curproxy->rsp_cap;
1234 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001235 if (!hdr->name)
1236 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001237 hdr->namelen = strlen(args[3]);
1238 hdr->len = atol(args[5]);
1239 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001240 if (!hdr->pool) {
1241 res_caphdr_alloc_error:
1242 if (hdr)
1243 ha_free(&hdr->name);
1244 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001245 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001246 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001247 hdr->index = curproxy->nb_rsp_cap++;
1248 curproxy->rsp_cap = hdr;
1249 curproxy->to_log |= LW_RSPHDR;
1250 }
1251 else {
1252 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1253 file, linenum, args[0]);
1254 err_code |= ERR_ALERT | ERR_FATAL;
1255 goto out;
1256 }
1257 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001258 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001259 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1260 err_code |= ERR_WARN;
1261
1262 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1263 goto out;
1264
1265 if (*(args[1]) == 0) {
1266 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1267 file, linenum, args[0]);
1268 err_code |= ERR_ALERT | ERR_FATAL;
1269 goto out;
1270 }
1271 curproxy->conn_retries = atol(args[1]);
1272 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001273 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001274 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001275 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001276
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001277 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1278 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001279 err_code |= ERR_ALERT | ERR_FATAL;
1280 goto out;
1281 }
1282
1283 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1284 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001285 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001286 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1287 file, linenum, args[0]);
1288 err_code |= ERR_WARN;
1289 }
1290
1291 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1292
1293 if (!rule) {
1294 err_code |= ERR_ALERT | ERR_ABORT;
1295 goto out;
1296 }
1297
1298 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001299
1300 if (curproxy->cap & PR_CAP_FE)
1301 where |= SMP_VAL_FE_HRQ_HDR;
1302 if (curproxy->cap & PR_CAP_BE)
1303 where |= SMP_VAL_BE_HRQ_HDR;
1304 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001305
Willy Tarreau2b718102021-04-21 07:32:39 +02001306 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001307 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001308 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001309 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001310 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001311
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001312 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1313 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001314 err_code |= ERR_ALERT | ERR_FATAL;
1315 goto out;
1316 }
1317
1318 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1319 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001320 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001321 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1322 file, linenum, args[0]);
1323 err_code |= ERR_WARN;
1324 }
1325
1326 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1327
1328 if (!rule) {
1329 err_code |= ERR_ALERT | ERR_ABORT;
1330 goto out;
1331 }
1332
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001333 if (curproxy->cap & PR_CAP_FE)
1334 where |= SMP_VAL_FE_HRS_HDR;
1335 if (curproxy->cap & PR_CAP_BE)
1336 where |= SMP_VAL_BE_HRS_HDR;
1337 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001338
Willy Tarreau2b718102021-04-21 07:32:39 +02001339 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001340 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001341 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001342 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001343 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001344 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1345 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001346 err_code |= ERR_ALERT | ERR_FATAL;
1347 goto out;
1348 }
1349
1350 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1351 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1352 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1353 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1354 file, linenum, args[0]);
1355 err_code |= ERR_WARN;
1356 }
1357
1358 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1359
1360 if (!rule) {
1361 err_code |= ERR_ALERT | ERR_ABORT;
1362 goto out;
1363 }
1364
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001365 if (curproxy->cap & PR_CAP_FE)
1366 where |= SMP_VAL_FE_HRS_HDR;
1367 if (curproxy->cap & PR_CAP_BE)
1368 where |= SMP_VAL_BE_HRS_HDR;
1369 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001370
Willy Tarreau2b718102021-04-21 07:32:39 +02001371 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001372 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001373 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001374 /* set the header name and length into the proxy structure */
1375 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1376 err_code |= ERR_WARN;
1377
1378 if (!*args[1]) {
1379 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1380 file, linenum, args[0]);
1381 err_code |= ERR_ALERT | ERR_FATAL;
1382 goto out;
1383 }
1384
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001385 /* set the desired header name, in lower case */
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001386 istfree(&curproxy->server_id_hdr_name);
1387 curproxy->server_id_hdr_name = istdup(ist(args[1]));
1388 if (!isttest(curproxy->server_id_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02001389 goto alloc_error;
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001390 ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001391 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001392 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001393 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 +01001394
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001395 err_code |= ERR_ALERT | ERR_FATAL;
1396 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001397 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001398 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001399 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001400 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001401
Willy Tarreau5d095c22021-02-12 10:15:59 +01001402 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001403 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1404 err_code |= ERR_ALERT | ERR_FATAL;
1405 goto out;
1406 }
1407
1408 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1409 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1410 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1411 err_code |= ERR_ALERT | ERR_FATAL;
1412 goto out;
1413 }
1414
Willy Tarreau2b718102021-04-21 07:32:39 +02001415 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001416 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001417
1418 if (curproxy->cap & PR_CAP_FE)
1419 where |= SMP_VAL_FE_HRQ_HDR;
1420 if (curproxy->cap & PR_CAP_BE)
1421 where |= SMP_VAL_BE_HRQ_HDR;
1422 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001423 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001424 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001425 struct switching_rule *rule;
1426
Willy Tarreau5d095c22021-02-12 10:15:59 +01001427 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001428 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1429 err_code |= ERR_ALERT | ERR_FATAL;
1430 goto out;
1431 }
1432
1433 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1434 err_code |= ERR_WARN;
1435
1436 if (*(args[1]) == 0) {
1437 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1438 err_code |= ERR_ALERT | ERR_FATAL;
1439 goto out;
1440 }
1441
1442 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1443 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1444 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1445 file, linenum, errmsg);
1446 err_code |= ERR_ALERT | ERR_FATAL;
1447 goto out;
1448 }
1449
1450 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1451 }
1452 else if (*args[2]) {
1453 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1454 file, linenum, args[2]);
1455 err_code |= ERR_ALERT | ERR_FATAL;
1456 goto out;
1457 }
1458
1459 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001460 if (!rule)
1461 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001462 rule->cond = cond;
1463 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001464 if (!rule->be.name)
1465 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001466 rule->line = linenum;
1467 rule->file = strdup(file);
1468 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001469 use_backend_alloc_error:
1470 if (cond)
1471 prune_acl_cond(cond);
1472 ha_free(&cond);
1473 if (rule)
1474 ha_free(&(rule->be.name));
1475 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001476 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001477 }
1478 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001479 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001480 }
1481 else if (strcmp(args[0], "use-server") == 0) {
1482 struct server_rule *rule;
1483
Willy Tarreau5d095c22021-02-12 10:15:59 +01001484 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001485 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1486 err_code |= ERR_ALERT | ERR_FATAL;
1487 goto out;
1488 }
1489
1490 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1491 err_code |= ERR_WARN;
1492
1493 if (*(args[1]) == 0) {
1494 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1495 err_code |= ERR_ALERT | ERR_FATAL;
1496 goto out;
1497 }
1498
1499 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1500 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1501 file, linenum, args[0]);
1502 err_code |= ERR_ALERT | ERR_FATAL;
1503 goto out;
1504 }
1505
1506 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1507 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1508 file, linenum, errmsg);
1509 err_code |= ERR_ALERT | ERR_FATAL;
1510 goto out;
1511 }
1512
1513 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1514
1515 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001516 if (!rule)
1517 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001518 rule->cond = cond;
1519 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001520 if (!rule->srv.name)
1521 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001522 rule->line = linenum;
1523 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001524 if (!rule->file) {
1525 use_server_alloc_error:
1526 if (cond)
1527 prune_acl_cond(cond);
1528 ha_free(&cond);
1529 if (rule)
1530 ha_free(&(rule->srv.name));
1531 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001532 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001533 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001534 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001535 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001536 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1537 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001538 else if ((strcmp(args[0], "force-persist") == 0) ||
1539 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001540 struct persist_rule *rule;
1541
Willy Tarreau5d095c22021-02-12 10:15:59 +01001542 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001543 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1544 err_code |= ERR_ALERT | ERR_FATAL;
1545 goto out;
1546 }
1547
1548 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1549 err_code |= ERR_WARN;
1550
1551 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1552 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1553 file, linenum, args[0]);
1554 err_code |= ERR_ALERT | ERR_FATAL;
1555 goto out;
1556 }
1557
1558 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1559 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1560 file, linenum, args[0], errmsg);
1561 err_code |= ERR_ALERT | ERR_FATAL;
1562 goto out;
1563 }
1564
1565 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1566 * where force-persist is applied.
1567 */
1568 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1569
1570 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001571 if (!rule) {
1572 if (cond)
1573 prune_acl_cond(cond);
1574 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001575 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001576 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001577 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001578 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001579 rule->type = PERSIST_TYPE_FORCE;
1580 } else {
1581 rule->type = PERSIST_TYPE_IGNORE;
1582 }
1583 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001584 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001585 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001586 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001587 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001588
Willy Tarreau5d095c22021-02-12 10:15:59 +01001589 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001590 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1591 file, linenum);
1592 err_code |= ERR_ALERT | ERR_FATAL;
1593 goto out;
1594 }
1595
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001596 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001597 if (other) {
1598 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 +01001599 file, linenum, curproxy->id,
1600 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1601 other->proxy ? other->id : other->peers.p->id,
1602 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001603 err_code |= ERR_ALERT | ERR_FATAL;
1604 goto out;
1605 }
1606
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001607 curproxy->table = calloc(1, sizeof *curproxy->table);
1608 if (!curproxy->table) {
1609 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1610 file, linenum, args[0], args[1]);
1611 err_code |= ERR_ALERT | ERR_FATAL;
1612 goto out;
1613 }
1614
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001615 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1616 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001617 if (err_code & ERR_FATAL) {
1618 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001619 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001620 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001621
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001622 /* Store the proxy in the stick-table. */
1623 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001624
1625 stktable_store_name(curproxy->table);
1626 curproxy->table->next = stktables_list;
1627 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001628
1629 /* Add this proxy to the list of proxies which refer to its stick-table. */
1630 if (curproxy->table->proxies_list != curproxy) {
1631 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1632 curproxy->table->proxies_list = curproxy;
1633 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001634 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001635 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001636 struct sticking_rule *rule;
1637 struct sample_expr *expr;
1638 int myidx = 0;
1639 const char *name = NULL;
1640 int flags;
1641
Willy Tarreau5d095c22021-02-12 10:15:59 +01001642 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001643 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1644 err_code |= ERR_ALERT | ERR_FATAL;
1645 goto out;
1646 }
1647
1648 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1649 err_code |= ERR_WARN;
1650 goto out;
1651 }
1652
1653 myidx++;
1654 if ((strcmp(args[myidx], "store") == 0) ||
1655 (strcmp(args[myidx], "store-request") == 0)) {
1656 myidx++;
1657 flags = STK_IS_STORE;
1658 }
1659 else if (strcmp(args[myidx], "store-response") == 0) {
1660 myidx++;
1661 flags = STK_IS_STORE | STK_ON_RSP;
1662 }
1663 else if (strcmp(args[myidx], "match") == 0) {
1664 myidx++;
1665 flags = STK_IS_MATCH;
1666 }
1667 else if (strcmp(args[myidx], "on") == 0) {
1668 myidx++;
1669 flags = STK_IS_MATCH | STK_IS_STORE;
1670 }
1671 else {
1672 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1673 err_code |= ERR_ALERT | ERR_FATAL;
1674 goto out;
1675 }
1676
1677 if (*(args[myidx]) == 0) {
1678 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1679 err_code |= ERR_ALERT | ERR_FATAL;
1680 goto out;
1681 }
1682
1683 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001684 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001685 if (!expr) {
1686 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1687 err_code |= ERR_ALERT | ERR_FATAL;
1688 goto out;
1689 }
1690
1691 if (flags & STK_ON_RSP) {
1692 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1693 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1694 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1695 err_code |= ERR_ALERT | ERR_FATAL;
1696 free(expr);
1697 goto out;
1698 }
1699 } else {
1700 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1701 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1702 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1703 err_code |= ERR_ALERT | ERR_FATAL;
1704 free(expr);
1705 goto out;
1706 }
1707 }
1708
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001709 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001710 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1711
1712 if (strcmp(args[myidx], "table") == 0) {
1713 myidx++;
1714 name = args[myidx++];
1715 }
1716
1717 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1718 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1719 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1720 file, linenum, args[0], errmsg);
1721 err_code |= ERR_ALERT | ERR_FATAL;
1722 free(expr);
1723 goto out;
1724 }
1725 }
1726 else if (*(args[myidx])) {
1727 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1728 file, linenum, args[0], args[myidx]);
1729 err_code |= ERR_ALERT | ERR_FATAL;
1730 free(expr);
1731 goto out;
1732 }
1733 if (flags & STK_ON_RSP)
1734 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1735 else
1736 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1737
1738 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001739 if (!rule) {
1740 if (cond)
1741 prune_acl_cond(cond);
1742 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001743 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001744 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001745 rule->cond = cond;
1746 rule->expr = expr;
1747 rule->flags = flags;
1748 rule->table.name = name ? strdup(name) : NULL;
1749 LIST_INIT(&rule->list);
1750 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001751 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001752 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001753 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001754 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001755 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001756 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001757 curproxy->uri_auth = NULL; /* we must detach from the default config */
1758
1759 if (!*args[1]) {
1760 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001761 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001762 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001763 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001764
Willy Tarreau5d095c22021-02-12 10:15:59 +01001765 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001766 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1767 err_code |= ERR_ALERT | ERR_FATAL;
1768 goto out;
1769 }
1770
Christopher Fauletb15625a2021-04-12 21:31:45 +02001771 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1772 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001773
1774 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1775 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1776 file, linenum, args[0], args[1]);
1777 err_code |= ERR_ALERT | ERR_FATAL;
1778 goto out;
1779 }
1780 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1781 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1782 file, linenum, args[0], args[1], errmsg);
1783 err_code |= ERR_ALERT | ERR_FATAL;
1784 goto out;
1785 }
1786
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001787 if (curproxy->cap & PR_CAP_FE)
1788 where |= SMP_VAL_FE_HRQ_HDR;
1789 if (curproxy->cap & PR_CAP_BE)
1790 where |= SMP_VAL_BE_HRQ_HDR;
1791 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001792
1793 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001794 if (!rule) {
1795 if (cond)
1796 prune_acl_cond(cond);
1797 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001798 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001799 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001800 rule->cond = cond;
1801 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001802 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001803 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001804 if (*(args[2]) == 0) {
1805 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1806 err_code |= ERR_ALERT | ERR_FATAL;
1807 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001808 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1809 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001810 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001811 if (*(args[2]) == 0) {
1812 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\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_realm(&curproxy->uri_auth, args[2]))
1816 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001817 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001818 unsigned interval;
1819
1820 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001821 if (err == PARSE_TIME_OVER) {
1822 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1823 file, linenum, args[2]);
1824 err_code |= ERR_ALERT | ERR_FATAL;
1825 goto out;
1826 }
1827 else if (err == PARSE_TIME_UNDER) {
1828 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1829 file, linenum, args[2]);
1830 err_code |= ERR_ALERT | ERR_FATAL;
1831 goto out;
1832 }
1833 else if (err) {
1834 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001835 file, linenum, *err);
1836 err_code |= ERR_ALERT | ERR_FATAL;
1837 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001838 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1839 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001840 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001841 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001842 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001843
Willy Tarreau5d095c22021-02-12 10:15:59 +01001844 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001845 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1846 err_code |= ERR_ALERT | ERR_FATAL;
1847 goto out;
1848 }
1849
Christopher Fauletb15625a2021-04-12 21:31:45 +02001850 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1851 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001852
1853 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1854 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1855 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1856 file, linenum, args[0]);
1857 err_code |= ERR_WARN;
1858 }
1859
1860 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1861
1862 if (!rule) {
1863 err_code |= ERR_ALERT | ERR_ABORT;
1864 goto out;
1865 }
1866
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001867 if (curproxy->cap & PR_CAP_FE)
1868 where |= SMP_VAL_FE_HRQ_HDR;
1869 if (curproxy->cap & PR_CAP_BE)
1870 where |= SMP_VAL_BE_HRQ_HDR;
1871 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001872 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001873
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001874 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001875 if (*(args[2]) == 0) {
1876 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1877 err_code |= ERR_ALERT | ERR_FATAL;
1878 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001879 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1880 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001881 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001882 if (*(args[2]) == 0) {
1883 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\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_scope(&curproxy->uri_auth, args[2]))
1887 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001888 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001889 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1890 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001891 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001892 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1893 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001894 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001895 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1896 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001897 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001898 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1899 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001900 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001901
1902 if (*args[2]) {
1903 int i;
1904 char c;
1905
1906 for (i=0; args[2][i]; i++) {
1907 c = args[2][i];
1908 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1909 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1910 break;
1911 }
1912
1913 if (!i || args[2][i]) {
1914 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1915 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1916 file, linenum, args[0], args[1]);
1917 err_code |= ERR_ALERT | ERR_FATAL;
1918 goto out;
1919 }
1920 }
1921
Christopher Fauletb15625a2021-04-12 21:31:45 +02001922 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1923 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001924 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001925 char *desc = NULL;
1926
1927 if (*args[2]) {
1928 int i, len=0;
1929 char *d;
1930
1931 for (i = 2; *args[i]; i++)
1932 len += strlen(args[i]) + 1;
1933
1934 desc = d = calloc(1, len);
1935
1936 d += snprintf(d, desc + len - d, "%s", args[2]);
1937 for (i = 3; *args[i]; i++)
1938 d += snprintf(d, desc + len - d, " %s", args[i]);
1939 }
1940
1941 if (!*args[2] && !global.desc)
1942 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1943 file, linenum, args[1]);
1944 else {
1945 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1946 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001947 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001948 }
1949 free(desc);
1950 }
1951 } else {
1952stats_error_parsing:
1953 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1954 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1955 err_code |= ERR_ALERT | ERR_FATAL;
1956 goto out;
1957 }
1958 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001959 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001960 int optnum;
1961
1962 if (*(args[1]) == '\0') {
1963 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1964 file, linenum, args[0]);
1965 err_code |= ERR_ALERT | ERR_FATAL;
1966 goto out;
1967 }
1968
1969 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001970 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001971 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1972 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1973 file, linenum, cfg_opts[optnum].name);
1974 err_code |= ERR_ALERT | ERR_FATAL;
1975 goto out;
1976 }
1977 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1978 goto out;
1979
1980 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1981 err_code |= ERR_WARN;
1982 goto out;
1983 }
1984
1985 curproxy->no_options &= ~cfg_opts[optnum].val;
1986 curproxy->options &= ~cfg_opts[optnum].val;
1987
1988 switch (kwm) {
1989 case KWM_STD:
1990 curproxy->options |= cfg_opts[optnum].val;
1991 break;
1992 case KWM_NO:
1993 curproxy->no_options |= cfg_opts[optnum].val;
1994 break;
1995 case KWM_DEF: /* already cleared */
1996 break;
1997 }
1998
1999 goto out;
2000 }
2001 }
2002
2003 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002004 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002005 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2006 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2007 file, linenum, cfg_opts2[optnum].name);
2008 err_code |= ERR_ALERT | ERR_FATAL;
2009 goto out;
2010 }
2011 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2012 goto out;
2013 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2014 err_code |= ERR_WARN;
2015 goto out;
2016 }
2017
2018 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2019 curproxy->options2 &= ~cfg_opts2[optnum].val;
2020
2021 switch (kwm) {
2022 case KWM_STD:
2023 curproxy->options2 |= cfg_opts2[optnum].val;
2024 break;
2025 case KWM_NO:
2026 curproxy->no_options2 |= cfg_opts2[optnum].val;
2027 break;
2028 case KWM_DEF: /* already cleared */
2029 break;
2030 }
2031 goto out;
2032 }
2033 }
2034
2035 /* HTTP options override each other. They can be cancelled using
2036 * "no option xxx" which only switches to default mode if the mode
2037 * was this one (useful for cancelling options set in defaults
2038 * sections).
2039 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02002040 if (strcmp(args[1], "forceclose") == 0) {
2041 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",
2042 file, linenum, args[1]);
2043 err_code |= ERR_ALERT | ERR_FATAL;
2044 goto out;
2045 }
2046 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002047 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2048 goto out;
2049 if (kwm == KWM_STD) {
2050 curproxy->options &= ~PR_O_HTTP_MODE;
2051 curproxy->options |= PR_O_HTTP_CLO;
2052 goto out;
2053 }
2054 else if (kwm == KWM_NO) {
2055 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2056 curproxy->options &= ~PR_O_HTTP_MODE;
2057 goto out;
2058 }
2059 }
2060 else if (strcmp(args[1], "http-server-close") == 0) {
2061 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2062 goto out;
2063 if (kwm == KWM_STD) {
2064 curproxy->options &= ~PR_O_HTTP_MODE;
2065 curproxy->options |= PR_O_HTTP_SCL;
2066 goto out;
2067 }
2068 else if (kwm == KWM_NO) {
2069 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2070 curproxy->options &= ~PR_O_HTTP_MODE;
2071 goto out;
2072 }
2073 }
2074 else if (strcmp(args[1], "http-keep-alive") == 0) {
2075 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2076 goto out;
2077 if (kwm == KWM_STD) {
2078 curproxy->options &= ~PR_O_HTTP_MODE;
2079 curproxy->options |= PR_O_HTTP_KAL;
2080 goto out;
2081 }
2082 else if (kwm == KWM_NO) {
2083 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2084 curproxy->options &= ~PR_O_HTTP_MODE;
2085 goto out;
2086 }
2087 }
2088 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002089 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 +02002090 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002091 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002092 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002093 }
2094
2095 /* Redispatch can take an integer argument that control when the
2096 * resispatch occurs. All values are relative to the retries option.
2097 * This can be cancelled using "no option xxx".
2098 */
2099 if (strcmp(args[1], "redispatch") == 0) {
2100 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2101 err_code |= ERR_WARN;
2102 goto out;
2103 }
2104
2105 curproxy->no_options &= ~PR_O_REDISP;
2106 curproxy->options &= ~PR_O_REDISP;
2107
2108 switch (kwm) {
2109 case KWM_STD:
2110 curproxy->options |= PR_O_REDISP;
2111 curproxy->redispatch_after = -1;
2112 if(*args[2]) {
2113 curproxy->redispatch_after = atol(args[2]);
2114 }
2115 break;
2116 case KWM_NO:
2117 curproxy->no_options |= PR_O_REDISP;
2118 curproxy->redispatch_after = 0;
2119 break;
2120 case KWM_DEF: /* already cleared */
2121 break;
2122 }
2123 goto out;
2124 }
2125
Willy Tarreau25241232021-07-18 19:18:56 +02002126 if (strcmp(args[1], "http_proxy") == 0) {
2127 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",
2128 file, linenum, args[1]);
2129 err_code |= ERR_ALERT | ERR_FATAL;
2130 goto out;
2131 }
2132
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002133 if (kwm != KWM_STD) {
2134 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2135 file, linenum, args[1]);
2136 err_code |= ERR_ALERT | ERR_FATAL;
2137 goto out;
2138 }
2139
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002140 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002141 char *logformat;
2142 /* generate a complete HTTP log */
2143 logformat = default_http_log_format;
2144 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002145 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002146 curproxy->options2 |= PR_O2_CLFLOG;
2147 logformat = clf_http_log_format;
2148 } else {
2149 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2150 err_code |= ERR_ALERT | ERR_FATAL;
2151 goto out;
2152 }
2153 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2154 goto out;
2155 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002156 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002157 char *oldlogformat = "log-format";
2158 char *clflogformat = "";
2159
2160 if (curproxy->conf.logformat_string == default_http_log_format)
2161 oldlogformat = "option httplog";
2162 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2163 oldlogformat = "option tcplog";
2164 else if (curproxy->conf.logformat_string == clf_http_log_format)
2165 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002166 else if (curproxy->conf.logformat_string == default_https_log_format)
2167 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002168 if (logformat == clf_http_log_format)
2169 clflogformat = " clf";
2170 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2171 file, linenum, clflogformat, oldlogformat);
2172 }
2173 if (curproxy->conf.logformat_string != default_http_log_format &&
2174 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002175 curproxy->conf.logformat_string != clf_http_log_format &&
2176 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002177 free(curproxy->conf.logformat_string);
2178 curproxy->conf.logformat_string = logformat;
2179
2180 free(curproxy->conf.lfs_file);
2181 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2182 curproxy->conf.lfs_line = curproxy->conf.args.line;
2183
Willy Tarreau5d095c22021-02-12 10:15:59 +01002184 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002185 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2186 file, linenum, curproxy->id);
2187 err_code |= ERR_WARN;
2188 }
2189 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002190 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002191 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002192 char *oldlogformat = "log-format";
2193
2194 if (curproxy->conf.logformat_string == default_http_log_format)
2195 oldlogformat = "option httplog";
2196 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2197 oldlogformat = "option tcplog";
2198 else if (curproxy->conf.logformat_string == clf_http_log_format)
2199 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002200 else if (curproxy->conf.logformat_string == default_https_log_format)
2201 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002202 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2203 file, linenum, oldlogformat);
2204 }
2205 /* generate a detailed TCP log */
2206 if (curproxy->conf.logformat_string != default_http_log_format &&
2207 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002208 curproxy->conf.logformat_string != clf_http_log_format &&
2209 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002210 free(curproxy->conf.logformat_string);
2211 curproxy->conf.logformat_string = default_tcp_log_format;
2212
2213 free(curproxy->conf.lfs_file);
2214 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2215 curproxy->conf.lfs_line = curproxy->conf.args.line;
2216
2217 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2218 goto out;
2219
Willy Tarreau5d095c22021-02-12 10:15:59 +01002220 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002221 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2222 file, linenum, curproxy->id);
2223 err_code |= ERR_WARN;
2224 }
2225 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002226 else if (strcmp(args[1], "httpslog") == 0) {
2227 char *logformat;
2228 /* generate a complete HTTP log */
2229 logformat = default_https_log_format;
2230 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2231 char *oldlogformat = "log-format";
2232
2233 if (curproxy->conf.logformat_string == default_http_log_format)
2234 oldlogformat = "option httplog";
2235 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2236 oldlogformat = "option tcplog";
2237 else if (curproxy->conf.logformat_string == clf_http_log_format)
2238 oldlogformat = "option httplog clf";
2239 else if (curproxy->conf.logformat_string == default_https_log_format)
2240 oldlogformat = "option httpslog";
2241 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2242 file, linenum, oldlogformat);
2243 }
2244 if (curproxy->conf.logformat_string != default_http_log_format &&
2245 curproxy->conf.logformat_string != default_tcp_log_format &&
2246 curproxy->conf.logformat_string != clf_http_log_format &&
2247 curproxy->conf.logformat_string != default_https_log_format)
2248 free(curproxy->conf.logformat_string);
2249 curproxy->conf.logformat_string = logformat;
2250
2251 free(curproxy->conf.lfs_file);
2252 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2253 curproxy->conf.lfs_line = curproxy->conf.args.line;
2254
2255 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2256 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2257 file, linenum, curproxy->id);
2258 err_code |= ERR_WARN;
2259 }
2260 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002261 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002262 /* enable TCP keep-alives on client and server streams */
2263 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2264 err_code |= ERR_WARN;
2265
2266 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2267 goto out;
2268
2269 if (curproxy->cap & PR_CAP_FE)
2270 curproxy->options |= PR_O_TCP_CLI_KA;
2271 if (curproxy->cap & PR_CAP_BE)
2272 curproxy->options |= PR_O_TCP_SRV_KA;
2273 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002274 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002275 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002276 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002277 goto out;
2278 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002279 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002280 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002281 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002282 goto out;
2283 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002284 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002285 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002286 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002287 goto out;
2288 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002289 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002290 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002291 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002292 goto out;
2293 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002294 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002295 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002296 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002297 goto out;
2298 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002299 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002300 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002301 if (err_code & ERR_FATAL)
2302 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002303 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002304 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002305 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002306 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002307 goto out;
2308 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002309 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002310 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002311 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002312 goto out;
2313 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002314 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002315 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002316 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002317 goto out;
2318 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002319 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002320 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002321 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002322 goto out;
2323 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002324 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002325 int cur_arg;
2326
2327 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002328 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002329 */
2330
2331 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2332
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002333 istfree(&curproxy->fwdfor_hdr_name);
2334 curproxy->fwdfor_hdr_name = istdup(ist(DEF_XFORWARDFOR_HDR));
2335 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002336 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002337 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002338
2339 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2340 cur_arg = 2;
2341 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002342 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002343 unsigned char mask;
2344 int i;
2345
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002346 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002347 if (*(args[cur_arg+1]) &&
2348 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2349 curproxy->except_xff_net.family = AF_INET;
2350 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2351 }
2352 else if (*(args[cur_arg+1]) &&
2353 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2354 curproxy->except_xff_net.family = AF_INET6;
2355 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2356 for (i = 0; i < 16; i++)
2357 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2358 }
2359 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002360 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2361 file, linenum, args[0], args[1], args[cur_arg]);
2362 err_code |= ERR_ALERT | ERR_FATAL;
2363 goto out;
2364 }
2365 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002366 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002367 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002368 /* suboption header - needs additional argument for it */
2369 if (*(args[cur_arg+1]) == 0) {
2370 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2371 file, linenum, args[0], args[1], args[cur_arg]);
2372 err_code |= ERR_ALERT | ERR_FATAL;
2373 goto out;
2374 }
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002375 istfree(&curproxy->fwdfor_hdr_name);
2376 curproxy->fwdfor_hdr_name = istdup(ist(args[cur_arg+1]));
2377 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002378 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002379 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002380 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002381 curproxy->options &= ~PR_O_FF_ALWAYS;
2382 cur_arg += 1;
2383 } else {
2384 /* unknown suboption - catchall */
2385 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2386 file, linenum, args[0], args[1]);
2387 err_code |= ERR_ALERT | ERR_FATAL;
2388 goto out;
2389 }
2390 } /* end while loop */
2391 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002392 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002393 int cur_arg;
2394
2395 /* insert x-original-to field, but not for the IP address listed as an except.
2396 * set default options (ie: bitfield, header name, etc)
2397 */
2398
2399 curproxy->options |= PR_O_ORGTO;
2400
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002401 istfree(&curproxy->orgto_hdr_name);
2402 curproxy->orgto_hdr_name = istdup(ist(DEF_XORIGINALTO_HDR));
2403 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002404 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002405 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002406
2407 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2408 cur_arg = 2;
2409 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002410 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002411 unsigned char mask;
2412 int i;
2413
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002414 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002415 if (*(args[cur_arg+1]) &&
2416 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2417 curproxy->except_xot_net.family = AF_INET;
2418 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2419 }
2420 else if (*(args[cur_arg+1]) &&
2421 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2422 curproxy->except_xot_net.family = AF_INET6;
2423 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2424 for (i = 0; i < 16; i++)
2425 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2426 }
2427 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002428 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2429 file, linenum, args[0], args[1], args[cur_arg]);
2430 err_code |= ERR_ALERT | ERR_FATAL;
2431 goto out;
2432 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002433 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002434 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002435 /* suboption header - needs additional argument for it */
2436 if (*(args[cur_arg+1]) == 0) {
2437 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2438 file, linenum, args[0], args[1], args[cur_arg]);
2439 err_code |= ERR_ALERT | ERR_FATAL;
2440 goto out;
2441 }
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002442 istfree(&curproxy->orgto_hdr_name);
2443 curproxy->orgto_hdr_name = istdup(ist(args[cur_arg+1]));
2444 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002445 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002446 cur_arg += 2;
2447 } else {
2448 /* unknown suboption - catchall */
2449 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2450 file, linenum, args[0], args[1]);
2451 err_code |= ERR_ALERT | ERR_FATAL;
2452 goto out;
2453 }
2454 } /* end while loop */
2455 }
2456 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002457 const char *best = proxy_find_best_option(args[1], common_options);
2458
2459 if (best)
2460 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2461 else
2462 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2463
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002464 err_code |= ERR_ALERT | ERR_FATAL;
2465 goto out;
2466 }
2467 goto out;
2468 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002469 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002470 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2471 err_code |= ERR_WARN;
2472
2473 if (*(args[1]) == 0) {
2474 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2475 err_code |= ERR_ALERT | ERR_FATAL;
2476 goto out;
2477 }
2478 free(curproxy->defbe.name);
2479 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002480 if (!curproxy->defbe.name)
2481 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002482
2483 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2484 goto out;
2485 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002486 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002487 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 +01002488
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002489 err_code |= ERR_ALERT | ERR_FATAL;
2490 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002491 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002492 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002493 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2494 err_code |= ERR_WARN;
2495
2496 if (strcmp(args[1], "never") == 0) {
2497 /* enable a graceful server shutdown on an HTTP 404 response */
2498 curproxy->options &= ~PR_O_REUSE_MASK;
2499 curproxy->options |= PR_O_REUSE_NEVR;
2500 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2501 goto out;
2502 }
2503 else if (strcmp(args[1], "safe") == 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_SAFE;
2507 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2508 goto out;
2509 }
2510 else if (strcmp(args[1], "aggressive") == 0) {
2511 curproxy->options &= ~PR_O_REUSE_MASK;
2512 curproxy->options |= PR_O_REUSE_AGGR;
2513 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2514 goto out;
2515 }
2516 else if (strcmp(args[1], "always") == 0) {
2517 /* enable a graceful server shutdown on an HTTP 404 response */
2518 curproxy->options &= ~PR_O_REUSE_MASK;
2519 curproxy->options |= PR_O_REUSE_ALWS;
2520 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2521 goto out;
2522 }
2523 else {
2524 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2525 err_code |= ERR_ALERT | ERR_FATAL;
2526 goto out;
2527 }
2528 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002529 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002530 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002531 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2532 err_code |= ERR_ALERT | ERR_FATAL;
2533 goto out;
2534 }
2535
2536 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2537 err_code |= ERR_WARN;
2538
2539 if (strcmp(args[1], "fail") == 0) {
2540 /* add a condition to fail monitor requests */
2541 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2542 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2543 file, linenum, args[0], args[1]);
2544 err_code |= ERR_ALERT | ERR_FATAL;
2545 goto out;
2546 }
2547
2548 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2549 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2550 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2551 file, linenum, args[0], args[1], errmsg);
2552 err_code |= ERR_ALERT | ERR_FATAL;
2553 goto out;
2554 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002555 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002556 }
2557 else {
2558 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2559 err_code |= ERR_ALERT | ERR_FATAL;
2560 goto out;
2561 }
2562 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002563#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002564 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002565 /* enable transparent proxy connections */
2566 curproxy->options |= PR_O_TRANSP;
2567 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2568 goto out;
2569 }
2570#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002571 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002572 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2573 err_code |= ERR_WARN;
2574
2575 if (*(args[1]) == 0) {
2576 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2577 err_code |= ERR_ALERT | ERR_FATAL;
2578 goto out;
2579 }
2580 curproxy->maxconn = atol(args[1]);
2581 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2582 goto out;
2583 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002584 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002585 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2586 err_code |= ERR_WARN;
2587
2588 if (*(args[1]) == 0) {
2589 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2590 err_code |= ERR_ALERT | ERR_FATAL;
2591 goto out;
2592 }
2593 curproxy->backlog = atol(args[1]);
2594 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2595 goto out;
2596 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002597 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002598 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2599 err_code |= ERR_WARN;
2600
2601 if (*(args[1]) == 0) {
2602 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2603 err_code |= ERR_ALERT | ERR_FATAL;
2604 goto out;
2605 }
2606 curproxy->fullconn = atol(args[1]);
2607 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2608 goto out;
2609 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002610 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002611 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 +02002612 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002613 err_code |= ERR_ALERT | ERR_FATAL;
2614 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002615 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002616 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002617 struct sockaddr_storage *sk;
2618 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002619
Willy Tarreau5d095c22021-02-12 10:15:59 +01002620 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002621 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2622 err_code |= ERR_ALERT | ERR_FATAL;
2623 goto out;
2624 }
2625 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2626 err_code |= ERR_WARN;
2627
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002628 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2629 &errmsg, NULL, NULL,
2630 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 +01002631 if (!sk) {
2632 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2633 err_code |= ERR_ALERT | ERR_FATAL;
2634 goto out;
2635 }
2636
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002637 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2638 goto out;
2639
2640 curproxy->dispatch_addr = *sk;
2641 curproxy->options |= PR_O_DISPATCH;
2642 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002643 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002644 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2645 err_code |= ERR_WARN;
2646
2647 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2648 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2649 err_code |= ERR_ALERT | ERR_FATAL;
2650 goto out;
2651 }
2652 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002653 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002654 /**
2655 * The syntax for hash-type config element is
2656 * hash-type {map-based|consistent} [[<algo>] avalanche]
2657 *
2658 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2659 */
2660 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2661
2662 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2663 err_code |= ERR_WARN;
2664
2665 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2666 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2667 }
2668 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2669 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2670 }
2671 else if (strcmp(args[1], "avalanche") == 0) {
2672 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]);
2673 err_code |= ERR_ALERT | ERR_FATAL;
2674 goto out;
2675 }
2676 else {
2677 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2678 err_code |= ERR_ALERT | ERR_FATAL;
2679 goto out;
2680 }
2681
2682 /* set the hash function to use */
2683 if (!*args[2]) {
2684 /* the default algo is sdbm */
2685 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2686
2687 /* if consistent with no argument, then avalanche modifier is also applied */
2688 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2689 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2690 } else {
2691 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002692 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002693 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2694 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002695 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002696 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2697 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002698 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002699 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2700 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002701 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002702 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2703 }
2704 else {
2705 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2706 err_code |= ERR_ALERT | ERR_FATAL;
2707 goto out;
2708 }
2709
2710 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002711 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002712 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2713 }
2714 else if (*args[3]) {
2715 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2716 err_code |= ERR_ALERT | ERR_FATAL;
2717 goto out;
2718 }
2719 }
2720 }
2721 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2722 if (*(args[1]) == 0) {
2723 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2724 err_code |= ERR_ALERT | ERR_FATAL;
2725 goto out;
2726 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002727 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2728 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002729 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2730 err_code |= ERR_ALERT | ERR_FATAL;
2731 goto out;
2732 }
2733 }
2734 else if (strcmp(args[0], "unique-id-format") == 0) {
2735 if (!*(args[1])) {
2736 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2737 err_code |= ERR_ALERT | ERR_FATAL;
2738 goto out;
2739 }
2740 if (*(args[2])) {
2741 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2742 err_code |= ERR_ALERT | ERR_FATAL;
2743 goto out;
2744 }
2745 free(curproxy->conf.uniqueid_format_string);
2746 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002747 if (!curproxy->conf.uniqueid_format_string)
2748 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002749
2750 free(curproxy->conf.uif_file);
2751 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2752 curproxy->conf.uif_line = curproxy->conf.args.line;
2753 }
2754
2755 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002756 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002757 if (!*(args[1])) {
2758 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2759 err_code |= ERR_ALERT | ERR_FATAL;
2760 goto out;
2761 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002762 copy = strdup(args[1]);
2763 if (copy == NULL) {
2764 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2765 err_code |= ERR_ALERT | ERR_FATAL;
2766 goto out;
2767 }
2768
2769 istfree(&curproxy->header_unique_id);
2770 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002771 }
2772
2773 else if (strcmp(args[0], "log-format") == 0) {
2774 if (!*(args[1])) {
2775 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2776 err_code |= ERR_ALERT | ERR_FATAL;
2777 goto out;
2778 }
2779 if (*(args[2])) {
2780 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2781 err_code |= ERR_ALERT | ERR_FATAL;
2782 goto out;
2783 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002784 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002785 char *oldlogformat = "log-format";
2786
2787 if (curproxy->conf.logformat_string == default_http_log_format)
2788 oldlogformat = "option httplog";
2789 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2790 oldlogformat = "option tcplog";
2791 else if (curproxy->conf.logformat_string == clf_http_log_format)
2792 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002793 else if (curproxy->conf.logformat_string == default_https_log_format)
2794 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002795 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2796 file, linenum, oldlogformat);
2797 }
2798 if (curproxy->conf.logformat_string != default_http_log_format &&
2799 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002800 curproxy->conf.logformat_string != clf_http_log_format &&
2801 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002802 free(curproxy->conf.logformat_string);
2803 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002804 if (!curproxy->conf.logformat_string)
2805 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002806
2807 free(curproxy->conf.lfs_file);
2808 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2809 curproxy->conf.lfs_line = curproxy->conf.args.line;
2810
2811 /* get a chance to improve log-format error reporting by
2812 * reporting the correct line-number when possible.
2813 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002814 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002815 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2816 file, linenum, curproxy->id);
2817 err_code |= ERR_WARN;
2818 }
2819 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002820 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002821 if (!*(args[1])) {
2822 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2823 err_code |= ERR_ALERT | ERR_FATAL;
2824 goto out;
2825 }
2826 if (*(args[2])) {
2827 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2828 err_code |= ERR_ALERT | ERR_FATAL;
2829 goto out;
2830 }
2831
2832 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2833 free(curproxy->conf.logformat_sd_string);
2834 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002835 if (!curproxy->conf.logformat_sd_string)
2836 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002837
2838 free(curproxy->conf.lfsd_file);
2839 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2840 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2841
2842 /* get a chance to improve log-format-sd error reporting by
2843 * reporting the correct line-number when possible.
2844 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002845 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002846 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2847 file, linenum, curproxy->id);
2848 err_code |= ERR_WARN;
2849 }
2850 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002851 else if (strcmp(args[0], "error-log-format") == 0) {
2852 if (!*(args[1])) {
2853 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2854 err_code |= ERR_ALERT | ERR_FATAL;
2855 goto out;
2856 }
2857 if (*(args[2])) {
2858 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2859 err_code |= ERR_ALERT | ERR_FATAL;
2860 goto out;
2861 }
2862 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2863 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2864 file, linenum);
2865 }
2866 free(curproxy->conf.error_logformat_string);
2867 curproxy->conf.error_logformat_string = strdup(args[1]);
2868 if (!curproxy->conf.error_logformat_string)
2869 goto alloc_error;
2870
2871 free(curproxy->conf.elfs_file);
2872 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2873 curproxy->conf.elfs_line = curproxy->conf.args.line;
2874
2875 /* get a chance to improve log-format error reporting by
2876 * reporting the correct line-number when possible.
2877 */
2878 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2879 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2880 file, linenum, curproxy->id);
2881 err_code |= ERR_WARN;
2882 }
2883 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002884 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002885 if (*(args[1]) == 0) {
2886 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2887 err_code |= ERR_ALERT | ERR_FATAL;
2888 goto out;
2889 }
2890 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002891 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2892 if (b_orig(&curproxy->log_tag) == NULL) {
2893 chunk_destroy(&curproxy->log_tag);
2894 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2895 err_code |= ERR_ALERT | ERR_FATAL;
2896 goto out;
2897 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002898 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002899 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002900 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002901 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2902 err_code |= ERR_ALERT | ERR_FATAL;
2903 goto out;
2904 }
2905 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002906 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002907 int cur_arg;
2908 int port1, port2;
2909 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002910
2911 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2912 err_code |= ERR_WARN;
2913
2914 if (!*args[1]) {
2915 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2916 file, linenum, "source", "usesrc", "interface");
2917 err_code |= ERR_ALERT | ERR_FATAL;
2918 goto out;
2919 }
2920
Christopher Faulet31930372019-07-15 10:16:58 +02002921 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002922 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002923 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002924 curproxy->conn_src.iface_len = 0;
2925
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002926 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2927 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002928 if (!sk) {
2929 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2930 file, linenum, args[0], args[1], errmsg);
2931 err_code |= ERR_ALERT | ERR_FATAL;
2932 goto out;
2933 }
2934
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002935 curproxy->conn_src.source_addr = *sk;
2936 curproxy->conn_src.opts |= CO_SRC_BIND;
2937
2938 cur_arg = 2;
2939 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002940 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002941#if defined(CONFIG_HAP_TRANSPARENT)
2942 if (!*args[cur_arg + 1]) {
2943 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2944 file, linenum, "usesrc");
2945 err_code |= ERR_ALERT | ERR_FATAL;
2946 goto out;
2947 }
2948
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002949 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002950 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2951 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002952 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002953 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2954 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2955 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2956 char *name, *end;
2957
2958 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002959 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002960 name++;
2961
2962 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002963 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002964 end++;
2965
2966 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2967 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002968 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002969 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002970 if (!curproxy->conn_src.bind_hdr_name)
2971 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002972 curproxy->conn_src.bind_hdr_len = end - name;
2973 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2974 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2975 curproxy->conn_src.bind_hdr_occ = -1;
2976
2977 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002978 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002979 end++;
2980 if (*end == ',') {
2981 end++;
2982 name = end;
2983 if (*end == '-')
2984 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002985 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002986 end++;
2987 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2988 }
2989
2990 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2991 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2992 " occurrences values smaller than %d.\n",
2993 file, linenum, MAX_HDR_HISTORY);
2994 err_code |= ERR_ALERT | ERR_FATAL;
2995 goto out;
2996 }
2997 } else {
2998 struct sockaddr_storage *sk;
2999
Willy Tarreau65ec4e32020-09-16 19:17:08 +02003000 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
3001 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003002 if (!sk) {
3003 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
3004 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
3005 err_code |= ERR_ALERT | ERR_FATAL;
3006 goto out;
3007 }
3008
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003009 curproxy->conn_src.tproxy_addr = *sk;
3010 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3011 }
3012 global.last_checks |= LSTCHK_NETADM;
3013#else /* no TPROXY support */
3014 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3015 file, linenum, "usesrc");
3016 err_code |= ERR_ALERT | ERR_FATAL;
3017 goto out;
3018#endif
3019 cur_arg += 2;
3020 continue;
3021 }
3022
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003023 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003024#ifdef SO_BINDTODEVICE
3025 if (!*args[cur_arg + 1]) {
3026 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3027 file, linenum, args[0]);
3028 err_code |= ERR_ALERT | ERR_FATAL;
3029 goto out;
3030 }
3031 free(curproxy->conn_src.iface_name);
3032 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02003033 if (!curproxy->conn_src.iface_name)
3034 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003035 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3036 global.last_checks |= LSTCHK_NETADM;
3037#else
3038 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3039 file, linenum, args[0], args[cur_arg]);
3040 err_code |= ERR_ALERT | ERR_FATAL;
3041 goto out;
3042#endif
3043 cur_arg += 2;
3044 continue;
3045 }
3046 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3047 file, linenum, args[0], "interface", "usesrc");
3048 err_code |= ERR_ALERT | ERR_FATAL;
3049 goto out;
3050 }
3051 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003052 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003053 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3054 file, linenum, "usesrc", "source");
3055 err_code |= ERR_ALERT | ERR_FATAL;
3056 goto out;
3057 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003058 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 +02003059 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003060 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003061 file, linenum, args[0]);
3062 err_code |= ERR_ALERT | ERR_FATAL;
3063 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003064 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003065 else if (strcmp(args[0], "reqdel") == 0) { /* delete 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. "
3067 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3068 err_code |= ERR_ALERT | ERR_FATAL;
3069 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003071 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003072 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3073 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3074 err_code |= ERR_ALERT | ERR_FATAL;
3075 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003076 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003077 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003078 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3079 err_code |= ERR_ALERT | ERR_FATAL;
3080 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003081 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003082 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003083 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3084 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3085 err_code |= ERR_ALERT | ERR_FATAL;
3086 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003087 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003088 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003089 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3090 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3091 err_code |= ERR_ALERT | ERR_FATAL;
3092 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003093 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003094 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003095 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3096 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3097 err_code |= ERR_ALERT | ERR_FATAL;
3098 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003099 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003100 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003101 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3102 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003105 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003106 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 +02003107 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3108 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3109 err_code |= ERR_ALERT | ERR_FATAL;
3110 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003111 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003112 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003113 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3114 err_code |= ERR_ALERT | ERR_FATAL;
3115 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003116 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003117 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 +02003118 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3119 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3120 err_code |= ERR_ALERT | ERR_FATAL;
3121 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003123 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 +02003124 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3125 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3126 err_code |= ERR_ALERT | ERR_FATAL;
3127 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003128 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003129 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003130 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3131 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3132 err_code |= ERR_ALERT | ERR_FATAL;
3133 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003134 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003135 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 +02003136 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3137 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3138 err_code |= ERR_ALERT | ERR_FATAL;
3139 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003140 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003141 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003142 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3143 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3144 err_code |= ERR_ALERT | ERR_FATAL;
3145 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003147 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003148 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3149 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3150 err_code |= ERR_ALERT | ERR_FATAL;
3151 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003152 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003153 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303154 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003155 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3156 err_code |= ERR_ALERT | ERR_FATAL;
3157 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003158 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003159 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003160 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3161 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3162 err_code |= ERR_ALERT | ERR_FATAL;
3163 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003164 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003165 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003166 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3167 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3168 err_code |= ERR_ALERT | ERR_FATAL;
3169 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003170 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003171 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003172 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3173 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3174 err_code |= ERR_ALERT | ERR_FATAL;
3175 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003176 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003177 else {
3178 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003179 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003180 int index;
3181
3182 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3183 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3184 if (kwl->kw[index].section != CFG_LISTEN)
3185 continue;
3186 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003187 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003188 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003189 err_code |= ERR_ALERT | ERR_FATAL;
3190 goto out;
3191 }
3192
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003193 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003194 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003195 if (rc < 0) {
3196 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3197 err_code |= ERR_ALERT | ERR_FATAL;
3198 goto out;
3199 }
3200 else if (rc > 0) {
3201 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3202 err_code |= ERR_WARN;
3203 goto out;
3204 }
3205 goto out;
3206 }
3207 }
3208 }
3209
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003210 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3211 if (best)
3212 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3213 else
3214 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003215 err_code |= ERR_ALERT | ERR_FATAL;
3216 goto out;
3217 }
3218 out:
3219 free(errmsg);
3220 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003221
3222 alloc_error:
3223 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3224 err_code |= ERR_ALERT | ERR_ABORT;
3225 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003226}