blob: c4b33f75e22d854bc724ab7354cefebf4ddf38b5 [file] [log] [blame]
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010011#include <unistd.h>
12
Willy Tarreaudcc048a2020-06-04 19:11:43 +020013#include <haproxy/acl.h>
Eric Salama7cea6062020-10-02 11:58:19 +020014#include <haproxy/buf.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020015#include <haproxy/capture-t.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020016#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020017#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020018#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020019#include <haproxy/connection.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020020#include <haproxy/extcheck.h>
Willy Tarreaub7fc4c42021-10-06 18:56:42 +020021#include <haproxy/http_ana.h>
Willy Tarreau87735332020-06-04 09:08:41 +020022#include <haproxy/http_htx.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020023#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020024#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020025#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020026#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020027#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020028#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020029#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020030#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020031#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020032#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/tcpcheck.h>
Willy Tarreaue9dcb3c2021-05-08 13:00:23 +020034#include <haproxy/tools.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020035#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010036
Willy Tarreauc0ff6792021-03-12 09:14:19 +010037/* some keywords that are still being parsed using strcmp() and are not
38 * registered anywhere. They are used as suggestions for mistyped words.
39 */
40static const char *common_kw_list[] = {
41 "listen", "frontend", "backend", "defaults", "server",
42 "default-server", "server-template", "bind", "monitor-net",
43 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
44 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
45 "persist", "appsession", "load-server-state-from-file",
46 "server-state-file-name", "max-session-srv-conns", "capture",
47 "retries", "http-request", "http-response", "http-after-response",
48 "http-send-name-header", "block", "redirect", "use_backend",
49 "use-server", "force-persist", "ignore-persist", "force-persist",
50 "stick-table", "stick", "stats", "option", "default_backend",
51 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
Willy Tarreaueb778242021-06-11 16:27:10 +020052 "fullconn", "dispatch", "balance", "hash-type",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010053 "hash-balance-factor", "unique-id-format", "unique-id-header",
54 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +020055 "error-log-format",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010056 NULL /* must be last */
57};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010058
Willy Tarreau31a3cea2021-03-15 11:11:55 +010059static const char *common_options[] = {
Willy Tarreau6ba69842021-06-11 16:01:50 +020060 "httpclose", "http-server-close", "http-keep-alive",
Willy Tarreaud2f25372021-06-11 16:06:29 +020061 "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010062 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
63 "mysql-check", "ldap-check", "spop-check", "tcp-check",
64 "external-check", "forwardfor", "original-to",
65 NULL /* must be last */
66};
67
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010068/* Report a warning if a rule is placed after a 'tcp-request session' rule.
69 * Return 1 if the warning has been emitted, otherwise 0.
70 */
71int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
72{
73 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
74 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
75 file, line, arg);
76 return 1;
77 }
78 return 0;
79}
80
81/* Report a warning if a rule is placed after a 'tcp-request content' rule.
82 * Return 1 if the warning has been emitted, otherwise 0.
83 */
84int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
85{
86 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
87 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
88 file, line, arg);
89 return 1;
90 }
91 return 0;
92}
93
94/* Report a warning if a rule is placed after a 'monitor fail' rule.
95 * Return 1 if the warning has been emitted, otherwise 0.
96 */
97int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
98{
99 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
100 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
101 file, line, arg);
102 return 1;
103 }
104 return 0;
105}
106
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100107/* Report a warning if a rule is placed after an 'http_request' rule.
108 * Return 1 if the warning has been emitted, otherwise 0.
109 */
110int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
111{
112 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
113 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
114 file, line, arg);
115 return 1;
116 }
117 return 0;
118}
119
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100120/* Report a warning if a rule is placed after a redirect rule.
121 * Return 1 if the warning has been emitted, otherwise 0.
122 */
123int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
124{
125 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
126 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
127 file, line, arg);
128 return 1;
129 }
130 return 0;
131}
132
133/* Report a warning if a rule is placed after a 'use_backend' rule.
134 * Return 1 if the warning has been emitted, otherwise 0.
135 */
136int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
137{
138 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
139 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
140 file, line, arg);
141 return 1;
142 }
143 return 0;
144}
145
146/* Report a warning if a rule is placed after a 'use-server' rule.
147 * Return 1 if the warning has been emitted, otherwise 0.
148 */
149int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
150{
151 if (!LIST_ISEMPTY(&proxy->server_rules)) {
152 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
153 file, line, arg);
154 return 1;
155 }
156 return 0;
157}
158
159/* report a warning if a redirect rule is dangerously placed */
160int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
161{
162 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
163 warnif_rule_after_use_server(proxy, file, line, arg);
164}
165
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100166/* report a warning if an http-request rule is dangerously placed */
167int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
168{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200169 return warnif_rule_after_redirect(proxy, file, line, arg) ||
170 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100171}
172
173/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200174int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100175{
176 return warnif_rule_after_http_req(proxy, file, line, arg) ||
177 warnif_misplaced_http_req(proxy, file, line, arg);
178}
179
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100180/* report a warning if a "tcp request content" rule is dangerously placed */
181int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
182{
183 return warnif_rule_after_monitor(proxy, file, line, arg) ||
184 warnif_misplaced_monitor(proxy, file, line, arg);
185}
186
187/* report a warning if a "tcp request session" rule is dangerously placed */
188int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
189{
190 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
191 warnif_misplaced_tcp_cont(proxy, file, line, arg);
192}
193
194/* report a warning if a "tcp request connection" rule is dangerously placed */
195int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
196{
197 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
198 warnif_misplaced_tcp_sess(proxy, file, line, arg);
199}
200
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100201int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
202{
203 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100204 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100205 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100206 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 int rc;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100208 int err_code = 0;
209 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100210 char *errmsg = NULL;
211 struct bind_conf *bind_conf;
212
Willy Tarreaue90904d2021-02-12 14:08:31 +0100213 if (!last_defproxy) {
214 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100215 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
216 proxy_preset_defaults(last_defproxy);
217
Willy Tarreaue90904d2021-02-12 14:08:31 +0100218 curr_defproxy = last_defproxy;
219 if (!last_defproxy) {
220 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
221 err_code |= ERR_ALERT | ERR_ABORT;
222 goto out;
223 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100224 }
225
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100226 if (strcmp(args[0], "listen") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200227 rc = PR_CAP_LISTEN | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100228 else if (strcmp(args[0], "frontend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200229 rc = PR_CAP_FE | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100230 else if (strcmp(args[0], "backend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200231 rc = PR_CAP_BE | PR_CAP_LB;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100232 else if (strcmp(args[0], "defaults") == 0) {
233 /* "defaults" must first delete the last no-name defaults if any */
Willy Tarreaue90904d2021-02-12 14:08:31 +0100234 curr_defproxy = NULL;
235 rc = PR_CAP_DEF | PR_CAP_LISTEN;
236 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100237 else
238 rc = PR_CAP_NONE;
239
Willy Tarreaue90904d2021-02-12 14:08:31 +0100240 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100241 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100242 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100243 file, linenum, args[0]);
244 err_code |= ERR_ALERT | ERR_ABORT;
245 goto out;
246 }
247
248 err = invalid_char(args[1]);
249 if (err) {
250 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
251 file, linenum, *err, args[0], args[1]);
252 err_code |= ERR_ALERT | ERR_FATAL;
253 }
254
255 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
256 if (curproxy) {
257 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
258 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
259 curproxy->id, curproxy->conf.file, curproxy->conf.line);
260 err_code |= ERR_ALERT | ERR_FATAL;
261 }
262
Emeric Brunb0c331f2020-10-07 17:05:59 +0200263 curproxy = log_forward_by_name(args[1]);
264 if (curproxy) {
265 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
266 file, linenum, proxy_cap_str(rc), args[1],
267 curproxy->id, curproxy->conf.file, curproxy->conf.line);
268 err_code |= ERR_ALERT | ERR_FATAL;
269 }
270
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100271 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
272 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100273 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100274 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
275 goto out;
276 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100277 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100278
Willy Tarreaue90904d2021-02-12 14:08:31 +0100279 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100280 const char *name = args[1];
281 int arg = 2;
282
283 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
284 // also support "defaults from blah" (no name then)
285 arg = 1;
286 name = "";
287 }
288
289 /* only regular proxies inherit from the previous defaults section */
290 if (!(rc & PR_CAP_DEF))
291 curr_defproxy = last_defproxy;
292
293 if (strcmp(args[arg], "from") == 0) {
294 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
295
296 if (!curr_defproxy) {
297 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
298 err_code |= ERR_ALERT | ERR_ABORT;
299 goto out;
300 }
301
302 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
303 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
304
305 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
306 file, linenum, args[arg+1], proxy_cap_str(rc), name,
307 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
308 err_code |= ERR_ALERT | ERR_FATAL;
309 }
310
311 err = invalid_char(args[arg+1]);
312 if (err) {
313 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",
314 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
315 err_code |= ERR_ALERT | ERR_FATAL;
316 }
Christopher Fauletb4054202021-10-12 18:57:43 +0200317 curr_defproxy->flags |= PR_FL_EXPLICIT_REF;
318 }
319 else if (curr_defproxy)
320 curr_defproxy->flags |= PR_FL_IMPLICIT_REF;
321
322 if (curr_defproxy && (curr_defproxy->flags & (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) == (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) {
323 ha_alert("parsing [%s:%d] : defaults section '%s' (declared at %s:%d) is explicitly referenced by another proxy and implicitly used here."
324 " To avoid any ambiguity don't mix both usage. Add a last defaults section not explicitly used or always use explicit references.\n",
325 file, linenum, curr_defproxy->id, curr_defproxy->conf.file, curr_defproxy->conf.line);
326 err_code |= ERR_WARN;
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100327 }
328
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100329 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100330 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100331 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100332 goto out;
333 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100334
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200335 if (curr_defproxy && (!LIST_ISEMPTY(&curr_defproxy->http_req_rules) ||
336 !LIST_ISEMPTY(&curr_defproxy->http_res_rules) ||
337 !LIST_ISEMPTY(&curr_defproxy->http_after_res_rules) ||
338 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
339 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules) ||
340 !LIST_ISEMPTY(&curr_defproxy->tcp_req.inspect_rules) ||
341 !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules))) {
342 /* If the current default proxy defines TCP/HTTP rules, the
343 * current proxy will keep a reference on it. But some sanity
344 * checks are performed first:
345 *
346 * - It cannot be used to init a defaults section
347 * - It cannot be used to init a listen section
348 * - It cannot be used to init backend and frontend sections at
349 * same time. It can be used to init several sections of the
350 * same type only.
351 * - It cannot define L4/L5 TCP rules if it is used to init
352 * backend sections.
353 * - It cannot define 'tcp-response content' rules if it
354 * is used to init frontend sections.
355 *
356 * If no error is found, refcount of the default proxy is incremented.
357 */
358
359 /* Note: Add tcpcheck_rules too if unresolve args become allowed in defaults section */
360 if (rc & PR_CAP_DEF) {
361 ha_alert("parsing [%s:%d]: a defaults section cannot inherit from a defaults section defining TCP/HTTP rules (defaults section at %s:%d).\n",
362 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
363 err_code |= ERR_ALERT | ERR_ABORT;
364 }
365 else if ((rc & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
366 ha_alert("parsing [%s:%d]: a listen section cannot inherit from a defaults section defining TCP/HTTP rules.\n",
367 file, linenum);
368 err_code |= ERR_ALERT | ERR_ABORT;
369 }
370 else {
371 char defcap = (curr_defproxy->cap & PR_CAP_LISTEN);
372
373 if ((defcap == PR_CAP_BE || defcap == PR_CAP_FE) && (rc & PR_CAP_LISTEN) != defcap) {
374 ha_alert("parsing [%s:%d]: frontends and backends cannot inherit from the same defaults section"
375 " if it defines TCP/HTTP rules (defaults section at %s:%d).\n",
376 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
377 err_code |= ERR_ALERT | ERR_ABORT;
378 }
379 else if (!(rc & PR_CAP_FE) && (!LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
380 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules))) {
381 ha_alert("parsing [%s:%d]: a backend section cannot inherit from a defaults section defining"
382 " 'tcp-request connection' or 'tcp-request session' rules (defaults section at %s:%d).\n",
383 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
384 err_code |= ERR_ALERT | ERR_ABORT;
385 }
386 else if (!(rc & PR_CAP_BE) && !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules)) {
387 ha_alert("parsing [%s:%d]: a frontend section cannot inherit from a defaults section defining"
388 " 'tcp-response content' rules (defaults section at %s:%d).\n",
389 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
390 err_code |= ERR_ALERT | ERR_ABORT;
391 }
392 else {
393 curr_defproxy->cap = (curr_defproxy->cap & ~PR_CAP_LISTEN) | (rc & PR_CAP_LISTEN);
394 proxy_ref_defaults(curproxy, curr_defproxy);
395 }
396 }
397 }
398
Christopher Faulet6ff7de52021-10-13 15:18:36 +0200399 if (curr_defproxy && (curr_defproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) &&
400 (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_BE) {
401 /* If the current default proxy defines tcpcheck rules, the
402 * current proxy will keep a reference on it. but only if the
403 * current proxy has the backend capability.
404 */
405 proxy_ref_defaults(curproxy, curr_defproxy);
406 }
407
Christopher Faulet6c10f5c2022-04-25 14:24:56 +0200408 if ((rc & PR_CAP_BE) && curr_defproxy && (curr_defproxy->nb_req_cap || curr_defproxy->nb_rsp_cap)) {
409 ha_alert("parsing [%s:%d]: backend or defaults sections cannot inherit from a defaults section defining"
410 " capptures (defaults section at %s:%d).\n",
411 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
412 err_code |= ERR_ALERT | ERR_ABORT;
413 }
414
Willy Tarreaue90904d2021-02-12 14:08:31 +0100415 if (rc & PR_CAP_DEF) {
416 /* last and current proxies must be updated to this one */
417 curr_defproxy = last_defproxy = curproxy;
418 } else {
419 /* regular proxies are in a list */
420 curproxy->next = proxies_list;
421 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100422 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100423 goto out;
424 }
425 else if (curproxy == NULL) {
426 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
427 err_code |= ERR_ALERT | ERR_FATAL;
428 goto out;
429 }
430
431 /* update the current file and line being parsed */
432 curproxy->conf.args.file = curproxy->conf.file;
433 curproxy->conf.args.line = linenum;
434
435 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100436 if ((strcmp(args[0], "server") == 0)) {
437 err_code |= parse_server(file, linenum, args,
438 curproxy, curr_defproxy,
439 SRV_PARSE_PARSE_ADDR);
440
441 if (err_code & ERR_FATAL)
442 goto out;
443 }
444 else if (strcmp(args[0], "default-server") == 0) {
445 err_code |= parse_server(file, linenum, args,
446 curproxy, curr_defproxy,
447 SRV_PARSE_DEFAULT_SERVER);
448
449 if (err_code & ERR_FATAL)
450 goto out;
451 }
452 else if (strcmp(args[0], "server-template") == 0) {
453 err_code |= parse_server(file, linenum, args,
454 curproxy, curr_defproxy,
455 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
456
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100457 if (err_code & ERR_FATAL)
458 goto out;
459 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100460 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100461 struct listener *l;
462 int cur_arg;
463
Willy Tarreau5d095c22021-02-12 10:15:59 +0100464 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100465 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
466 err_code |= ERR_ALERT | ERR_FATAL;
467 goto out;
468 }
469 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
470 err_code |= ERR_WARN;
471
472 if (!*(args[1])) {
473 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
474 file, linenum, args[0]);
475 err_code |= ERR_ALERT | ERR_FATAL;
476 goto out;
477 }
478
479 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200480 if (!bind_conf)
481 goto alloc_error;
482
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100483 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200484 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
485 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
486 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100487
488 /* NOTE: the following line might create several listeners if there
489 * are comma-separated IPs or port ranges. So all further processing
490 * will have to be applied to all listeners created after last_listen.
491 */
492 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
493 if (errmsg && *errmsg) {
494 indent_msg(&errmsg, 2);
495 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
496 }
497 else
498 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
499 file, linenum, args[0], args[1]);
500 err_code |= ERR_ALERT | ERR_FATAL;
501 goto out;
502 }
503
504 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
505 /* Set default global rights and owner for unix bind */
506 global.maxsock++;
507 }
508
509 cur_arg = 2;
Willy Tarreau55f0f7b2022-05-20 15:44:17 +0200510 err_code |= bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100511 goto out;
512 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100513 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200514 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]);
515 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100516 goto out;
517 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100518 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100519 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
520 err_code |= ERR_WARN;
521
522 if (alertif_too_many_args(1, file, linenum, args, &err_code))
523 goto out;
524
525 if (!*args[1]) {
526 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
527 file, linenum, args[0]);
528 err_code |= ERR_ALERT | ERR_FATAL;
529 goto out;
530 }
531
Tim Duesterhus4b1fcaa2022-03-05 00:52:40 +0100532 istfree(&curproxy->monitor_uri);
533 curproxy->monitor_uri = istdup(ist(args[1]));
534 if (!isttest(curproxy->monitor_uri))
Christopher Fauletb15625a2021-04-12 21:31:45 +0200535 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100536
537 goto out;
538 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100539 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100540 if (alertif_too_many_args(1, file, linenum, args, &err_code))
541 goto out;
542
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100543 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
544 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
545 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200546 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
547 err_code |= ERR_ALERT | ERR_FATAL;
548 goto out;
549 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100550 else {
551 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
552 err_code |= ERR_ALERT | ERR_FATAL;
553 goto out;
554 }
555 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100556 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100557 struct eb32_node *node;
558
Willy Tarreau5d095c22021-02-12 10:15:59 +0100559 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100560 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
561 file, linenum, args[0]);
562 err_code |= ERR_ALERT | ERR_FATAL;
563 goto out;
564 }
565
566 if (alertif_too_many_args(1, file, linenum, args, &err_code))
567 goto out;
568
569 if (!*args[1]) {
570 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
571 file, linenum, args[0]);
572 err_code |= ERR_ALERT | ERR_FATAL;
573 goto out;
574 }
575
576 curproxy->uuid = atol(args[1]);
577 curproxy->conf.id.key = curproxy->uuid;
578 curproxy->options |= PR_O_FORCED_ID;
579
580 if (curproxy->uuid <= 0) {
581 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
582 file, linenum);
583 err_code |= ERR_ALERT | ERR_FATAL;
584 goto out;
585 }
586
587 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
588 if (node) {
589 struct proxy *target = container_of(node, struct proxy, conf.id);
590 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
591 file, linenum, proxy_type_str(curproxy), curproxy->id,
592 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
593 err_code |= ERR_ALERT | ERR_FATAL;
594 goto out;
595 }
596 eb32_insert(&used_proxy_id, &curproxy->conf.id);
597 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100598 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100599 int i, len=0;
600 char *d;
601
Willy Tarreau5d095c22021-02-12 10:15:59 +0100602 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100603 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
604 file, linenum, args[0]);
605 err_code |= ERR_ALERT | ERR_FATAL;
606 goto out;
607 }
608
609 if (!*args[1]) {
610 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
611 file, linenum, args[0]);
612 return -1;
613 }
614
615 for (i = 1; *args[i]; i++)
616 len += strlen(args[i]) + 1;
617
618 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200619 if (!d)
620 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100621 curproxy->desc = d;
622
623 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
624 for (i = 2; *args[i]; i++)
625 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
626
627 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100628 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100629 if (alertif_too_many_args(0, file, linenum, args, &err_code))
630 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200631 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100632 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100633 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100634 if (alertif_too_many_args(0, file, linenum, args, &err_code))
635 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200636 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100637 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100638 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100639 int cur_arg = 1;
640 unsigned long set = 0;
641
642 while (*args[cur_arg]) {
643 if (strcmp(args[cur_arg], "all") == 0) {
644 set = 0;
645 break;
646 }
Willy Tarreau72faef32021-06-15 08:36:30 +0200647 if (parse_process_number(args[cur_arg], &set, 1, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100648 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
649 err_code |= ERR_ALERT | ERR_FATAL;
650 goto out;
651 }
652 cur_arg++;
653 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200654 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
655 file, linenum, args[0]);
656 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100657 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100658 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200659 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
660 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100661 err_code |= ERR_ALERT | ERR_FATAL;
662 goto out;
663 }
664
665 err = invalid_char(args[1]);
666 if (err) {
667 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
668 file, linenum, *err, args[1]);
669 err_code |= ERR_ALERT | ERR_FATAL;
670 goto out;
671 }
672
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100673 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100674 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100675 "logical disjunction within a condition.\n",
676 file, linenum, args[1]);
677 err_code |= ERR_ALERT | ERR_FATAL;
678 goto out;
679 }
680
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100681 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
682 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
683 file, linenum, args[1], errmsg);
684 err_code |= ERR_ALERT | ERR_FATAL;
685 goto out;
686 }
687 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100688 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100689
690 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
691 err_code |= ERR_WARN;
692
693 if (*(args[1]) == 0) {
694 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
695 file, linenum, args[0]);
696 err_code |= ERR_ALERT | ERR_FATAL;
697 goto out;
698 }
699 free(curproxy->dyncookie_key);
700 curproxy->dyncookie_key = strdup(args[1]);
701 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100702 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100703 int cur_arg;
704
705 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
706 err_code |= ERR_WARN;
707
708 if (*(args[1]) == 0) {
709 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
710 file, linenum, args[0]);
711 err_code |= ERR_ALERT | ERR_FATAL;
712 goto out;
713 }
714
715 curproxy->ck_opts = 0;
716 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100717 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100718 free(curproxy->cookie_name);
719 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200720 if (!curproxy->cookie_name)
721 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100722 curproxy->cookie_len = strlen(curproxy->cookie_name);
723
724 cur_arg = 2;
725 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100726 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100727 curproxy->ck_opts |= PR_CK_RW;
728 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100729 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100730 curproxy->ck_opts |= PR_CK_IND;
731 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100732 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100733 curproxy->ck_opts |= PR_CK_INS;
734 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100735 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100736 curproxy->ck_opts |= PR_CK_NOC;
737 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100738 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100739 curproxy->ck_opts |= PR_CK_POST;
740 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100741 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100742 curproxy->ck_opts |= PR_CK_PSV;
743 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100744 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100745 curproxy->ck_opts |= PR_CK_PFX;
746 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100747 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100748 curproxy->ck_opts |= PR_CK_HTTPONLY;
749 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100750 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100751 curproxy->ck_opts |= PR_CK_SECURE;
752 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100753 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100754 if (!*args[cur_arg + 1]) {
755 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
756 file, linenum, args[cur_arg]);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760
Joao Moraise1583752019-10-30 21:04:00 -0300761 if (!strchr(args[cur_arg + 1], '.')) {
762 /* rfc6265, 5.2.3 The Domain Attribute */
763 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
764 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100765 file, linenum, args[cur_arg + 1]);
766 err_code |= ERR_WARN;
767 }
768
769 err = invalid_domainchar(args[cur_arg + 1]);
770 if (err) {
771 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
772 file, linenum, *err, args[cur_arg + 1]);
773 err_code |= ERR_ALERT | ERR_FATAL;
774 goto out;
775 }
776
777 if (!curproxy->cookie_domain) {
778 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
779 } else {
780 /* one domain was already specified, add another one by
781 * building the string which will be returned along with
782 * the cookie.
783 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200784 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
785 }
786
Christopher Fauletb15625a2021-04-12 21:31:45 +0200787 if (!curproxy->cookie_domain)
788 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100789 cur_arg++;
790 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100791 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100792 unsigned int maxidle;
793 const char *res;
794
795 if (!*args[cur_arg + 1]) {
796 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
797 file, linenum, args[cur_arg]);
798 err_code |= ERR_ALERT | ERR_FATAL;
799 goto out;
800 }
801
802 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200803 if (res == PARSE_TIME_OVER) {
804 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
805 file, linenum, args[cur_arg+1], args[cur_arg]);
806 err_code |= ERR_ALERT | ERR_FATAL;
807 goto out;
808 }
809 else if (res == PARSE_TIME_UNDER) {
810 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
811 file, linenum, args[cur_arg+1], args[cur_arg]);
812 err_code |= ERR_ALERT | ERR_FATAL;
813 goto out;
814 }
815 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100816 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
817 file, linenum, *res, args[cur_arg]);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821 curproxy->cookie_maxidle = maxidle;
822 cur_arg++;
823 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100824 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100825 unsigned int maxlife;
826 const char *res;
827
828 if (!*args[cur_arg + 1]) {
829 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
830 file, linenum, args[cur_arg]);
831 err_code |= ERR_ALERT | ERR_FATAL;
832 goto out;
833 }
834
Willy Tarreau9faebe32019-06-07 19:00:37 +0200835
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100836 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200837 if (res == PARSE_TIME_OVER) {
838 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
839 file, linenum, args[cur_arg+1], args[cur_arg]);
840 err_code |= ERR_ALERT | ERR_FATAL;
841 goto out;
842 }
843 else if (res == PARSE_TIME_UNDER) {
844 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
845 file, linenum, args[cur_arg+1], args[cur_arg]);
846 err_code |= ERR_ALERT | ERR_FATAL;
847 goto out;
848 }
849 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100850 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
851 file, linenum, *res, args[cur_arg]);
852 err_code |= ERR_ALERT | ERR_FATAL;
853 goto out;
854 }
855 curproxy->cookie_maxlife = maxlife;
856 cur_arg++;
857 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100858 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100859
860 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
861 err_code |= ERR_WARN;
862 curproxy->ck_opts |= PR_CK_DYNAMIC;
863 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100864 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100865 char *val;
866 if (!*args[cur_arg + 1]) {
867 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
868 file, linenum, args[cur_arg]);
869 err_code |= ERR_ALERT | ERR_FATAL;
870 goto out;
871 }
872 val = args[cur_arg + 1];
873 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100874 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100875 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
876 file, linenum, *val);
877 err_code |= ERR_ALERT | ERR_FATAL;
878 goto out;
879 }
880 val++;
881 }
882 /* don't add ';' for the first attribute */
883 if (!curproxy->cookie_attrs)
884 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
885 else
886 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200887
Christopher Fauletb15625a2021-04-12 21:31:45 +0200888 if (!curproxy->cookie_attrs)
889 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100890 cur_arg++;
891 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100892
893 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100894 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 +0100895 file, linenum, args[0]);
896 err_code |= ERR_ALERT | ERR_FATAL;
897 goto out;
898 }
899 cur_arg++;
900 }
901 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
902 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
903 file, linenum);
904 err_code |= ERR_ALERT | ERR_FATAL;
905 }
906
907 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
908 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
909 file, linenum);
910 err_code |= ERR_ALERT | ERR_FATAL;
911 }
912
913 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
914 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
915 file, linenum);
916 err_code |= ERR_ALERT | ERR_FATAL;
917 }
918 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100919 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100920 if (*(args[1]) == 0) {
921 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
922 file, linenum, args[0]);
923 err_code |= ERR_ALERT | ERR_FATAL;
924 goto out;
925 }
926
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100927 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100928 if (*(args[1]) == 0) {
929 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
930 file, linenum, args[1]);
931 err_code |= ERR_ALERT | ERR_FATAL;
932 goto out;
933 }
934 free(curproxy->email_alert.from);
935 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200936 if (!curproxy->email_alert.from)
937 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100938 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100939 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100940 if (*(args[1]) == 0) {
941 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
942 file, linenum, args[1]);
943 err_code |= ERR_ALERT | ERR_FATAL;
944 goto out;
945 }
946 free(curproxy->email_alert.mailers.name);
947 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200948 if (!curproxy->email_alert.mailers.name)
949 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100950 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100951 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100952 if (*(args[1]) == 0) {
953 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
954 file, linenum, args[1]);
955 err_code |= ERR_ALERT | ERR_FATAL;
956 goto out;
957 }
958 free(curproxy->email_alert.myhostname);
959 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200960 if (!curproxy->email_alert.myhostname)
961 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100962 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100963 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100964 curproxy->email_alert.level = get_log_level(args[2]);
965 if (curproxy->email_alert.level < 0) {
966 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
967 file, linenum, args[1], args[2]);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 goto out;
970 }
971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100972 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100973 if (*(args[1]) == 0) {
974 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
975 file, linenum, args[1]);
976 err_code |= ERR_ALERT | ERR_FATAL;
977 goto out;
978 }
979 free(curproxy->email_alert.to);
980 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200981 if (!curproxy->email_alert.to)
982 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100983 }
984 else {
985 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
986 file, linenum, args[1]);
987 err_code |= ERR_ALERT | ERR_FATAL;
988 goto out;
989 }
990 /* Indicate that the email_alert is at least partially configured */
991 curproxy->email_alert.set = 1;
992 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100993 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100994 if (*(args[1]) == 0) {
995 ha_alert("parsing [%s:%d] : missing persist method.\n",
996 file, linenum);
997 err_code |= ERR_ALERT | ERR_FATAL;
998 goto out;
999 }
1000
1001 if (!strncmp(args[1], "rdp-cookie", 10)) {
1002 curproxy->options2 |= PR_O2_RDPC_PRST;
1003
1004 if (*(args[1] + 10) == '(') { /* cookie name */
1005 const char *beg, *end;
1006
1007 beg = args[1] + 11;
1008 end = strchr(beg, ')');
1009
1010 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1011 goto out;
1012
1013 if (!end || end == beg) {
1014 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1015 file, linenum);
1016 err_code |= ERR_ALERT | ERR_FATAL;
1017 goto out;
1018 }
1019
1020 free(curproxy->rdp_cookie_name);
1021 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001022 if (!curproxy->rdp_cookie_name)
1023 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001024 curproxy->rdp_cookie_len = end-beg;
1025 }
1026 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1027 free(curproxy->rdp_cookie_name);
1028 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +02001029 if (!curproxy->rdp_cookie_name)
1030 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001031 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1032 }
1033 else { /* syntax */
1034 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1035 file, linenum);
1036 err_code |= ERR_ALERT | ERR_FATAL;
1037 goto out;
1038 }
1039 }
1040 else {
1041 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1042 file, linenum);
1043 err_code |= ERR_ALERT | ERR_FATAL;
1044 goto out;
1045 }
1046 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001047 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001048 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 +01001049 err_code |= ERR_ALERT | ERR_FATAL;
1050 goto out;
1051 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001052 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001053 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1054 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001055 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001056 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1057 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001058 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 +01001059 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1060 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001061 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001062 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1063 }
1064 else {
1065 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1066 file, linenum, args[0], args[1]);
1067 err_code |= ERR_ALERT | ERR_FATAL;
1068 goto out;
1069 }
1070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001071 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001072 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1073 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001074 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001075 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001076
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001077 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001078
1079 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001080 curproxy->server_state_file_name = strdup(curproxy->id);
1081 else
1082 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001083
Christopher Fauletb15625a2021-04-12 21:31:45 +02001084 if (!curproxy->server_state_file_name)
1085 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001086 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001087 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001088 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1089 err_code |= ERR_WARN;
1090 if (*(args[1]) == 0) {
1091 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1092 file, linenum, args[0]);
1093 err_code |= ERR_ALERT | ERR_FATAL;
1094 goto out;
1095 }
1096 curproxy->max_out_conns = atoi(args[1]);
1097 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001098 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001099 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1100 err_code |= ERR_WARN;
1101
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001102 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001103 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001104 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1105 err_code |= ERR_ALERT | ERR_FATAL;
1106 goto out;
1107 }
1108
1109 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1110 goto out;
1111
1112 if (*(args[4]) == 0) {
1113 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1114 file, linenum, args[0]);
1115 err_code |= ERR_ALERT | ERR_FATAL;
1116 goto out;
1117 }
1118 free(curproxy->capture_name);
1119 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001120 if (!curproxy->capture_name)
1121 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001122 curproxy->capture_namelen = strlen(curproxy->capture_name);
1123 curproxy->capture_len = atol(args[4]);
1124 curproxy->to_log |= LW_COOKIE;
1125 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001126 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001127 struct cap_hdr *hdr;
1128
Willy Tarreau5d095c22021-02-12 10:15:59 +01001129 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001130 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1131 err_code |= ERR_ALERT | ERR_FATAL;
1132 goto out;
1133 }
1134
1135 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1136 goto out;
1137
1138 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1139 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1140 file, linenum, args[0], args[1]);
1141 err_code |= ERR_ALERT | ERR_FATAL;
1142 goto out;
1143 }
1144
1145 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001146 if (!hdr)
1147 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001148 hdr->next = curproxy->req_cap;
1149 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001150 if (!hdr->name)
1151 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001152 hdr->namelen = strlen(args[3]);
1153 hdr->len = atol(args[5]);
1154 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001155 if (!hdr->pool) {
1156 req_caphdr_alloc_error:
1157 if (hdr)
1158 ha_free(&hdr->name);
1159 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001160 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001161 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001162 hdr->index = curproxy->nb_req_cap++;
1163 curproxy->req_cap = hdr;
1164 curproxy->to_log |= LW_REQHDR;
1165 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001166 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001167 struct cap_hdr *hdr;
1168
Willy Tarreau5d095c22021-02-12 10:15:59 +01001169 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001170 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1171 err_code |= ERR_ALERT | ERR_FATAL;
1172 goto out;
1173 }
1174
1175 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1176 goto out;
1177
1178 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1179 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1180 file, linenum, args[0], args[1]);
1181 err_code |= ERR_ALERT | ERR_FATAL;
1182 goto out;
1183 }
1184 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001185 if (!hdr)
1186 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001187 hdr->next = curproxy->rsp_cap;
1188 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001189 if (!hdr->name)
1190 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001191 hdr->namelen = strlen(args[3]);
1192 hdr->len = atol(args[5]);
1193 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001194 if (!hdr->pool) {
1195 res_caphdr_alloc_error:
1196 if (hdr)
1197 ha_free(&hdr->name);
1198 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001199 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001200 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001201 hdr->index = curproxy->nb_rsp_cap++;
1202 curproxy->rsp_cap = hdr;
1203 curproxy->to_log |= LW_RSPHDR;
1204 }
1205 else {
1206 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1207 file, linenum, args[0]);
1208 err_code |= ERR_ALERT | ERR_FATAL;
1209 goto out;
1210 }
1211 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001212 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001213 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1214 err_code |= ERR_WARN;
1215
1216 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1217 goto out;
1218
1219 if (*(args[1]) == 0) {
1220 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1221 file, linenum, args[0]);
1222 err_code |= ERR_ALERT | ERR_FATAL;
1223 goto out;
1224 }
1225 curproxy->conn_retries = atol(args[1]);
1226 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001227 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001228 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001229 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001230
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001231 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1232 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001233 err_code |= ERR_ALERT | ERR_FATAL;
1234 goto out;
1235 }
1236
1237 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1238 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001239 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001240 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1241 file, linenum, args[0]);
1242 err_code |= ERR_WARN;
1243 }
1244
1245 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1246
1247 if (!rule) {
1248 err_code |= ERR_ALERT | ERR_ABORT;
1249 goto out;
1250 }
1251
1252 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001253
1254 if (curproxy->cap & PR_CAP_FE)
1255 where |= SMP_VAL_FE_HRQ_HDR;
1256 if (curproxy->cap & PR_CAP_BE)
1257 where |= SMP_VAL_BE_HRQ_HDR;
1258 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001259
Willy Tarreau2b718102021-04-21 07:32:39 +02001260 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001261 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001262 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001263 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001264 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001265
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001266 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1267 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001268 err_code |= ERR_ALERT | ERR_FATAL;
1269 goto out;
1270 }
1271
1272 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1273 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001274 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001275 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1276 file, linenum, args[0]);
1277 err_code |= ERR_WARN;
1278 }
1279
1280 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1281
1282 if (!rule) {
1283 err_code |= ERR_ALERT | ERR_ABORT;
1284 goto out;
1285 }
1286
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001287 if (curproxy->cap & PR_CAP_FE)
1288 where |= SMP_VAL_FE_HRS_HDR;
1289 if (curproxy->cap & PR_CAP_BE)
1290 where |= SMP_VAL_BE_HRS_HDR;
1291 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001292
Willy Tarreau2b718102021-04-21 07:32:39 +02001293 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001294 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001295 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001296 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001297 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001298 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1299 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001300 err_code |= ERR_ALERT | ERR_FATAL;
1301 goto out;
1302 }
1303
1304 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1305 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1306 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1307 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1308 file, linenum, args[0]);
1309 err_code |= ERR_WARN;
1310 }
1311
1312 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1313
1314 if (!rule) {
1315 err_code |= ERR_ALERT | ERR_ABORT;
1316 goto out;
1317 }
1318
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001319 if (curproxy->cap & PR_CAP_FE)
1320 where |= SMP_VAL_FE_HRS_HDR;
1321 if (curproxy->cap & PR_CAP_BE)
1322 where |= SMP_VAL_BE_HRS_HDR;
1323 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001324
Willy Tarreau2b718102021-04-21 07:32:39 +02001325 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001326 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001327 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001328 /* set the header name and length into the proxy structure */
1329 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1330 err_code |= ERR_WARN;
1331
1332 if (!*args[1]) {
1333 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1334 file, linenum, args[0]);
1335 err_code |= ERR_ALERT | ERR_FATAL;
1336 goto out;
1337 }
1338
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001339 /* set the desired header name, in lower case */
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001340 istfree(&curproxy->server_id_hdr_name);
1341 curproxy->server_id_hdr_name = istdup(ist(args[1]));
1342 if (!isttest(curproxy->server_id_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02001343 goto alloc_error;
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001344 ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001345 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001346 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001347 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 +01001348
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001349 err_code |= ERR_ALERT | ERR_FATAL;
1350 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001351 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001352 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001353 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001354 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001355
Willy Tarreau5d095c22021-02-12 10:15:59 +01001356 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001357 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1358 err_code |= ERR_ALERT | ERR_FATAL;
1359 goto out;
1360 }
1361
1362 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1363 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1364 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1365 err_code |= ERR_ALERT | ERR_FATAL;
1366 goto out;
1367 }
1368
Willy Tarreau2b718102021-04-21 07:32:39 +02001369 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001370 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001371
1372 if (curproxy->cap & PR_CAP_FE)
1373 where |= SMP_VAL_FE_HRQ_HDR;
1374 if (curproxy->cap & PR_CAP_BE)
1375 where |= SMP_VAL_BE_HRQ_HDR;
1376 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001377 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001378 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001379 struct switching_rule *rule;
1380
Willy Tarreau5d095c22021-02-12 10:15:59 +01001381 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001382 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1383 err_code |= ERR_ALERT | ERR_FATAL;
1384 goto out;
1385 }
1386
1387 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1388 err_code |= ERR_WARN;
1389
1390 if (*(args[1]) == 0) {
1391 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1392 err_code |= ERR_ALERT | ERR_FATAL;
1393 goto out;
1394 }
1395
1396 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1397 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1398 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1399 file, linenum, errmsg);
1400 err_code |= ERR_ALERT | ERR_FATAL;
1401 goto out;
1402 }
1403
1404 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1405 }
1406 else if (*args[2]) {
1407 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1408 file, linenum, args[2]);
1409 err_code |= ERR_ALERT | ERR_FATAL;
1410 goto out;
1411 }
1412
1413 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001414 if (!rule)
1415 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001416 rule->cond = cond;
1417 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001418 if (!rule->be.name)
1419 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001420 rule->line = linenum;
1421 rule->file = strdup(file);
1422 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001423 use_backend_alloc_error:
1424 if (cond)
1425 prune_acl_cond(cond);
1426 ha_free(&cond);
1427 if (rule)
1428 ha_free(&(rule->be.name));
1429 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001430 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001431 }
1432 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001433 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001434 }
1435 else if (strcmp(args[0], "use-server") == 0) {
1436 struct server_rule *rule;
1437
Willy Tarreau5d095c22021-02-12 10:15:59 +01001438 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001439 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1440 err_code |= ERR_ALERT | ERR_FATAL;
1441 goto out;
1442 }
1443
1444 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1445 err_code |= ERR_WARN;
1446
1447 if (*(args[1]) == 0) {
1448 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1449 err_code |= ERR_ALERT | ERR_FATAL;
1450 goto out;
1451 }
1452
1453 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1454 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1455 file, linenum, args[0]);
1456 err_code |= ERR_ALERT | ERR_FATAL;
1457 goto out;
1458 }
1459
1460 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1461 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1462 file, linenum, errmsg);
1463 err_code |= ERR_ALERT | ERR_FATAL;
1464 goto out;
1465 }
1466
1467 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1468
1469 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001470 if (!rule)
1471 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001472 rule->cond = cond;
1473 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001474 if (!rule->srv.name)
1475 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001476 rule->line = linenum;
1477 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001478 if (!rule->file) {
1479 use_server_alloc_error:
1480 if (cond)
1481 prune_acl_cond(cond);
1482 ha_free(&cond);
1483 if (rule)
1484 ha_free(&(rule->srv.name));
1485 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001486 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001487 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001488 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001489 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001490 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1491 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001492 else if ((strcmp(args[0], "force-persist") == 0) ||
1493 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001494 struct persist_rule *rule;
1495
Willy Tarreau5d095c22021-02-12 10:15:59 +01001496 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001497 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1498 err_code |= ERR_ALERT | ERR_FATAL;
1499 goto out;
1500 }
1501
1502 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1503 err_code |= ERR_WARN;
1504
1505 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1506 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1507 file, linenum, args[0]);
1508 err_code |= ERR_ALERT | ERR_FATAL;
1509 goto out;
1510 }
1511
1512 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1513 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1514 file, linenum, args[0], errmsg);
1515 err_code |= ERR_ALERT | ERR_FATAL;
1516 goto out;
1517 }
1518
1519 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1520 * where force-persist is applied.
1521 */
1522 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1523
1524 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001525 if (!rule) {
1526 if (cond)
1527 prune_acl_cond(cond);
1528 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001529 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001530 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001531 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001532 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001533 rule->type = PERSIST_TYPE_FORCE;
1534 } else {
1535 rule->type = PERSIST_TYPE_IGNORE;
1536 }
1537 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001538 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001539 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001540 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001541 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001542
Willy Tarreau5d095c22021-02-12 10:15:59 +01001543 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001544 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1545 file, linenum);
1546 err_code |= ERR_ALERT | ERR_FATAL;
1547 goto out;
1548 }
1549
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001550 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001551 if (other) {
1552 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 +01001553 file, linenum, curproxy->id,
1554 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1555 other->proxy ? other->id : other->peers.p->id,
1556 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001557 err_code |= ERR_ALERT | ERR_FATAL;
1558 goto out;
1559 }
1560
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001561 curproxy->table = calloc(1, sizeof *curproxy->table);
1562 if (!curproxy->table) {
1563 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1564 file, linenum, args[0], args[1]);
1565 err_code |= ERR_ALERT | ERR_FATAL;
1566 goto out;
1567 }
1568
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001569 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1570 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001571 if (err_code & ERR_FATAL) {
1572 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001573 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001574 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001575
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001576 /* Store the proxy in the stick-table. */
1577 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001578
1579 stktable_store_name(curproxy->table);
1580 curproxy->table->next = stktables_list;
1581 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001582
1583 /* Add this proxy to the list of proxies which refer to its stick-table. */
1584 if (curproxy->table->proxies_list != curproxy) {
1585 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1586 curproxy->table->proxies_list = curproxy;
1587 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001588 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001589 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001590 struct sticking_rule *rule;
1591 struct sample_expr *expr;
1592 int myidx = 0;
1593 const char *name = NULL;
1594 int flags;
1595
Willy Tarreau5d095c22021-02-12 10:15:59 +01001596 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001597 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1598 err_code |= ERR_ALERT | ERR_FATAL;
1599 goto out;
1600 }
1601
1602 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1603 err_code |= ERR_WARN;
1604 goto out;
1605 }
1606
1607 myidx++;
1608 if ((strcmp(args[myidx], "store") == 0) ||
1609 (strcmp(args[myidx], "store-request") == 0)) {
1610 myidx++;
1611 flags = STK_IS_STORE;
1612 }
1613 else if (strcmp(args[myidx], "store-response") == 0) {
1614 myidx++;
1615 flags = STK_IS_STORE | STK_ON_RSP;
1616 }
1617 else if (strcmp(args[myidx], "match") == 0) {
1618 myidx++;
1619 flags = STK_IS_MATCH;
1620 }
1621 else if (strcmp(args[myidx], "on") == 0) {
1622 myidx++;
1623 flags = STK_IS_MATCH | STK_IS_STORE;
1624 }
1625 else {
1626 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1627 err_code |= ERR_ALERT | ERR_FATAL;
1628 goto out;
1629 }
1630
1631 if (*(args[myidx]) == 0) {
1632 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1633 err_code |= ERR_ALERT | ERR_FATAL;
1634 goto out;
1635 }
1636
1637 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001638 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001639 if (!expr) {
1640 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1641 err_code |= ERR_ALERT | ERR_FATAL;
1642 goto out;
1643 }
1644
1645 if (flags & STK_ON_RSP) {
1646 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1647 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1648 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1649 err_code |= ERR_ALERT | ERR_FATAL;
1650 free(expr);
1651 goto out;
1652 }
1653 } else {
1654 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1655 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1656 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1657 err_code |= ERR_ALERT | ERR_FATAL;
1658 free(expr);
1659 goto out;
1660 }
1661 }
1662
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001663 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001664 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1665
1666 if (strcmp(args[myidx], "table") == 0) {
1667 myidx++;
1668 name = args[myidx++];
1669 }
1670
1671 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1672 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1673 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1674 file, linenum, args[0], errmsg);
1675 err_code |= ERR_ALERT | ERR_FATAL;
1676 free(expr);
1677 goto out;
1678 }
1679 }
1680 else if (*(args[myidx])) {
1681 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1682 file, linenum, args[0], args[myidx]);
1683 err_code |= ERR_ALERT | ERR_FATAL;
1684 free(expr);
1685 goto out;
1686 }
1687 if (flags & STK_ON_RSP)
1688 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1689 else
1690 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1691
1692 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001693 if (!rule) {
1694 if (cond)
1695 prune_acl_cond(cond);
1696 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001697 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001698 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001699 rule->cond = cond;
1700 rule->expr = expr;
1701 rule->flags = flags;
1702 rule->table.name = name ? strdup(name) : NULL;
1703 LIST_INIT(&rule->list);
1704 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001705 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001707 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001708 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001709 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001710 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001711 curproxy->uri_auth = NULL; /* we must detach from the default config */
1712
1713 if (!*args[1]) {
1714 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001715 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001716 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001717 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001718
Willy Tarreau5d095c22021-02-12 10:15:59 +01001719 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001720 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1721 err_code |= ERR_ALERT | ERR_FATAL;
1722 goto out;
1723 }
1724
Christopher Fauletb15625a2021-04-12 21:31:45 +02001725 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1726 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001727
1728 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1729 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1730 file, linenum, args[0], args[1]);
1731 err_code |= ERR_ALERT | ERR_FATAL;
1732 goto out;
1733 }
1734 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1735 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1736 file, linenum, args[0], args[1], errmsg);
1737 err_code |= ERR_ALERT | ERR_FATAL;
1738 goto out;
1739 }
1740
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001741 if (curproxy->cap & PR_CAP_FE)
1742 where |= SMP_VAL_FE_HRQ_HDR;
1743 if (curproxy->cap & PR_CAP_BE)
1744 where |= SMP_VAL_BE_HRQ_HDR;
1745 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001746
1747 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001748 if (!rule) {
1749 if (cond)
1750 prune_acl_cond(cond);
1751 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001752 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001753 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001754 rule->cond = cond;
1755 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001756 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001757 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001758 if (*(args[2]) == 0) {
1759 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1760 err_code |= ERR_ALERT | ERR_FATAL;
1761 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001762 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1763 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001764 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001765 if (*(args[2]) == 0) {
1766 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1767 err_code |= ERR_ALERT | ERR_FATAL;
1768 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001769 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1770 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001771 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001772 unsigned interval;
1773
1774 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001775 if (err == PARSE_TIME_OVER) {
1776 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1777 file, linenum, args[2]);
1778 err_code |= ERR_ALERT | ERR_FATAL;
1779 goto out;
1780 }
1781 else if (err == PARSE_TIME_UNDER) {
1782 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1783 file, linenum, args[2]);
1784 err_code |= ERR_ALERT | ERR_FATAL;
1785 goto out;
1786 }
1787 else if (err) {
1788 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001789 file, linenum, *err);
1790 err_code |= ERR_ALERT | ERR_FATAL;
1791 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001792 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1793 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001794 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001795 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001796 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001797
Willy Tarreau5d095c22021-02-12 10:15:59 +01001798 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001799 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1800 err_code |= ERR_ALERT | ERR_FATAL;
1801 goto out;
1802 }
1803
Christopher Fauletb15625a2021-04-12 21:31:45 +02001804 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1805 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001806
1807 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1808 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1809 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1810 file, linenum, args[0]);
1811 err_code |= ERR_WARN;
1812 }
1813
1814 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1815
1816 if (!rule) {
1817 err_code |= ERR_ALERT | ERR_ABORT;
1818 goto out;
1819 }
1820
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001821 if (curproxy->cap & PR_CAP_FE)
1822 where |= SMP_VAL_FE_HRQ_HDR;
1823 if (curproxy->cap & PR_CAP_BE)
1824 where |= SMP_VAL_BE_HRQ_HDR;
1825 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001826 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001827
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001828 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001829 if (*(args[2]) == 0) {
1830 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1831 err_code |= ERR_ALERT | ERR_FATAL;
1832 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001833 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1834 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001835 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001836 if (*(args[2]) == 0) {
1837 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1838 err_code |= ERR_ALERT | ERR_FATAL;
1839 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001840 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1841 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001842 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001843 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1844 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001845 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001846 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1847 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001848 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001849 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1850 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001851 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001852 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1853 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001854 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001855
1856 if (*args[2]) {
1857 int i;
1858 char c;
1859
1860 for (i=0; args[2][i]; i++) {
1861 c = args[2][i];
1862 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1863 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1864 break;
1865 }
1866
1867 if (!i || args[2][i]) {
1868 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1869 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1870 file, linenum, args[0], args[1]);
1871 err_code |= ERR_ALERT | ERR_FATAL;
1872 goto out;
1873 }
1874 }
1875
Christopher Fauletb15625a2021-04-12 21:31:45 +02001876 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1877 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001878 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001879 char *desc = NULL;
1880
1881 if (*args[2]) {
1882 int i, len=0;
1883 char *d;
1884
1885 for (i = 2; *args[i]; i++)
1886 len += strlen(args[i]) + 1;
1887
1888 desc = d = calloc(1, len);
1889
1890 d += snprintf(d, desc + len - d, "%s", args[2]);
1891 for (i = 3; *args[i]; i++)
1892 d += snprintf(d, desc + len - d, " %s", args[i]);
1893 }
1894
1895 if (!*args[2] && !global.desc)
1896 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1897 file, linenum, args[1]);
1898 else {
1899 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1900 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001901 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001902 }
1903 free(desc);
1904 }
1905 } else {
1906stats_error_parsing:
1907 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1908 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1909 err_code |= ERR_ALERT | ERR_FATAL;
1910 goto out;
1911 }
1912 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001913 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001914 int optnum;
1915
1916 if (*(args[1]) == '\0') {
1917 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1918 file, linenum, args[0]);
1919 err_code |= ERR_ALERT | ERR_FATAL;
1920 goto out;
1921 }
1922
1923 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001924 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001925 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1926 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1927 file, linenum, cfg_opts[optnum].name);
1928 err_code |= ERR_ALERT | ERR_FATAL;
1929 goto out;
1930 }
1931 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1932 goto out;
1933
1934 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1935 err_code |= ERR_WARN;
1936 goto out;
1937 }
1938
1939 curproxy->no_options &= ~cfg_opts[optnum].val;
1940 curproxy->options &= ~cfg_opts[optnum].val;
1941
1942 switch (kwm) {
1943 case KWM_STD:
1944 curproxy->options |= cfg_opts[optnum].val;
1945 break;
1946 case KWM_NO:
1947 curproxy->no_options |= cfg_opts[optnum].val;
1948 break;
1949 case KWM_DEF: /* already cleared */
1950 break;
1951 }
1952
1953 goto out;
1954 }
1955 }
1956
1957 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001958 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001959 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1960 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1961 file, linenum, cfg_opts2[optnum].name);
1962 err_code |= ERR_ALERT | ERR_FATAL;
1963 goto out;
1964 }
1965 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1966 goto out;
1967 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1968 err_code |= ERR_WARN;
1969 goto out;
1970 }
1971
1972 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1973 curproxy->options2 &= ~cfg_opts2[optnum].val;
1974
1975 switch (kwm) {
1976 case KWM_STD:
1977 curproxy->options2 |= cfg_opts2[optnum].val;
1978 break;
1979 case KWM_NO:
1980 curproxy->no_options2 |= cfg_opts2[optnum].val;
1981 break;
1982 case KWM_DEF: /* already cleared */
1983 break;
1984 }
1985 goto out;
1986 }
1987 }
1988
1989 /* HTTP options override each other. They can be cancelled using
1990 * "no option xxx" which only switches to default mode if the mode
1991 * was this one (useful for cancelling options set in defaults
1992 * sections).
1993 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001994 if (strcmp(args[1], "forceclose") == 0) {
1995 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",
1996 file, linenum, args[1]);
1997 err_code |= ERR_ALERT | ERR_FATAL;
1998 goto out;
1999 }
2000 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002001 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2002 goto out;
2003 if (kwm == KWM_STD) {
2004 curproxy->options &= ~PR_O_HTTP_MODE;
2005 curproxy->options |= PR_O_HTTP_CLO;
2006 goto out;
2007 }
2008 else if (kwm == KWM_NO) {
2009 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2010 curproxy->options &= ~PR_O_HTTP_MODE;
2011 goto out;
2012 }
2013 }
2014 else if (strcmp(args[1], "http-server-close") == 0) {
2015 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2016 goto out;
2017 if (kwm == KWM_STD) {
2018 curproxy->options &= ~PR_O_HTTP_MODE;
2019 curproxy->options |= PR_O_HTTP_SCL;
2020 goto out;
2021 }
2022 else if (kwm == KWM_NO) {
2023 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2024 curproxy->options &= ~PR_O_HTTP_MODE;
2025 goto out;
2026 }
2027 }
2028 else if (strcmp(args[1], "http-keep-alive") == 0) {
2029 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2030 goto out;
2031 if (kwm == KWM_STD) {
2032 curproxy->options &= ~PR_O_HTTP_MODE;
2033 curproxy->options |= PR_O_HTTP_KAL;
2034 goto out;
2035 }
2036 else if (kwm == KWM_NO) {
2037 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2038 curproxy->options &= ~PR_O_HTTP_MODE;
2039 goto out;
2040 }
2041 }
2042 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002043 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 +02002044 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002045 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002046 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002047 }
2048
2049 /* Redispatch can take an integer argument that control when the
2050 * resispatch occurs. All values are relative to the retries option.
2051 * This can be cancelled using "no option xxx".
2052 */
2053 if (strcmp(args[1], "redispatch") == 0) {
2054 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2055 err_code |= ERR_WARN;
2056 goto out;
2057 }
2058
2059 curproxy->no_options &= ~PR_O_REDISP;
2060 curproxy->options &= ~PR_O_REDISP;
2061
2062 switch (kwm) {
2063 case KWM_STD:
2064 curproxy->options |= PR_O_REDISP;
2065 curproxy->redispatch_after = -1;
2066 if(*args[2]) {
2067 curproxy->redispatch_after = atol(args[2]);
2068 }
2069 break;
2070 case KWM_NO:
2071 curproxy->no_options |= PR_O_REDISP;
2072 curproxy->redispatch_after = 0;
2073 break;
2074 case KWM_DEF: /* already cleared */
2075 break;
2076 }
2077 goto out;
2078 }
2079
Willy Tarreau25241232021-07-18 19:18:56 +02002080 if (strcmp(args[1], "http_proxy") == 0) {
2081 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",
2082 file, linenum, args[1]);
2083 err_code |= ERR_ALERT | ERR_FATAL;
2084 goto out;
2085 }
2086
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002087 if (kwm != KWM_STD) {
2088 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2089 file, linenum, args[1]);
2090 err_code |= ERR_ALERT | ERR_FATAL;
2091 goto out;
2092 }
2093
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002094 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002095 char *logformat;
2096 /* generate a complete HTTP log */
2097 logformat = default_http_log_format;
2098 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002099 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002100 curproxy->options2 |= PR_O2_CLFLOG;
2101 logformat = clf_http_log_format;
2102 } else {
2103 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2104 err_code |= ERR_ALERT | ERR_FATAL;
2105 goto out;
2106 }
2107 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2108 goto out;
2109 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002110 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002111 char *oldlogformat = "log-format";
2112 char *clflogformat = "";
2113
2114 if (curproxy->conf.logformat_string == default_http_log_format)
2115 oldlogformat = "option httplog";
2116 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2117 oldlogformat = "option tcplog";
2118 else if (curproxy->conf.logformat_string == clf_http_log_format)
2119 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002120 else if (curproxy->conf.logformat_string == default_https_log_format)
2121 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002122 if (logformat == clf_http_log_format)
2123 clflogformat = " clf";
2124 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2125 file, linenum, clflogformat, oldlogformat);
2126 }
2127 if (curproxy->conf.logformat_string != default_http_log_format &&
2128 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002129 curproxy->conf.logformat_string != clf_http_log_format &&
2130 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002131 free(curproxy->conf.logformat_string);
2132 curproxy->conf.logformat_string = logformat;
2133
2134 free(curproxy->conf.lfs_file);
2135 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2136 curproxy->conf.lfs_line = curproxy->conf.args.line;
2137
Willy Tarreau5d095c22021-02-12 10:15:59 +01002138 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002139 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2140 file, linenum, curproxy->id);
2141 err_code |= ERR_WARN;
2142 }
2143 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002144 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002145 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002146 char *oldlogformat = "log-format";
2147
2148 if (curproxy->conf.logformat_string == default_http_log_format)
2149 oldlogformat = "option httplog";
2150 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2151 oldlogformat = "option tcplog";
2152 else if (curproxy->conf.logformat_string == clf_http_log_format)
2153 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002154 else if (curproxy->conf.logformat_string == default_https_log_format)
2155 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002156 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2157 file, linenum, oldlogformat);
2158 }
2159 /* generate a detailed TCP log */
2160 if (curproxy->conf.logformat_string != default_http_log_format &&
2161 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002162 curproxy->conf.logformat_string != clf_http_log_format &&
2163 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002164 free(curproxy->conf.logformat_string);
2165 curproxy->conf.logformat_string = default_tcp_log_format;
2166
2167 free(curproxy->conf.lfs_file);
2168 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2169 curproxy->conf.lfs_line = curproxy->conf.args.line;
2170
2171 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2172 goto out;
2173
Willy Tarreau5d095c22021-02-12 10:15:59 +01002174 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002175 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2176 file, linenum, curproxy->id);
2177 err_code |= ERR_WARN;
2178 }
2179 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002180 else if (strcmp(args[1], "httpslog") == 0) {
2181 char *logformat;
2182 /* generate a complete HTTP log */
2183 logformat = default_https_log_format;
2184 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2185 char *oldlogformat = "log-format";
2186
2187 if (curproxy->conf.logformat_string == default_http_log_format)
2188 oldlogformat = "option httplog";
2189 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2190 oldlogformat = "option tcplog";
2191 else if (curproxy->conf.logformat_string == clf_http_log_format)
2192 oldlogformat = "option httplog clf";
2193 else if (curproxy->conf.logformat_string == default_https_log_format)
2194 oldlogformat = "option httpslog";
2195 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2196 file, linenum, oldlogformat);
2197 }
2198 if (curproxy->conf.logformat_string != default_http_log_format &&
2199 curproxy->conf.logformat_string != default_tcp_log_format &&
2200 curproxy->conf.logformat_string != clf_http_log_format &&
2201 curproxy->conf.logformat_string != default_https_log_format)
2202 free(curproxy->conf.logformat_string);
2203 curproxy->conf.logformat_string = logformat;
2204
2205 free(curproxy->conf.lfs_file);
2206 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2207 curproxy->conf.lfs_line = curproxy->conf.args.line;
2208
2209 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2210 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2211 file, linenum, curproxy->id);
2212 err_code |= ERR_WARN;
2213 }
2214 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002215 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002216 /* enable TCP keep-alives on client and server streams */
2217 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2218 err_code |= ERR_WARN;
2219
2220 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2221 goto out;
2222
2223 if (curproxy->cap & PR_CAP_FE)
2224 curproxy->options |= PR_O_TCP_CLI_KA;
2225 if (curproxy->cap & PR_CAP_BE)
2226 curproxy->options |= PR_O_TCP_SRV_KA;
2227 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002228 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002229 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002230 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002231 goto out;
2232 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002233 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002234 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002235 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002236 goto out;
2237 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002238 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002239 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002240 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002241 goto out;
2242 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002243 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002244 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002245 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002246 goto out;
2247 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002248 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002249 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002250 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002251 goto out;
2252 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002253 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002254 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002255 if (err_code & ERR_FATAL)
2256 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002257 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002258 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002259 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002260 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002261 goto out;
2262 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002263 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002264 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002265 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002266 goto out;
2267 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002268 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002269 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002270 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002271 goto out;
2272 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002273 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002274 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002275 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002276 goto out;
2277 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002278 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002279 int cur_arg;
2280
2281 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002282 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002283 */
2284
2285 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2286
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002287 istfree(&curproxy->fwdfor_hdr_name);
2288 curproxy->fwdfor_hdr_name = istdup(ist(DEF_XFORWARDFOR_HDR));
2289 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002290 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002291 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002292
2293 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2294 cur_arg = 2;
2295 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002296 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002297 unsigned char mask;
2298 int i;
2299
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002300 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002301 if (*(args[cur_arg+1]) &&
2302 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2303 curproxy->except_xff_net.family = AF_INET;
2304 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2305 }
2306 else if (*(args[cur_arg+1]) &&
2307 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2308 curproxy->except_xff_net.family = AF_INET6;
2309 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2310 for (i = 0; i < 16; i++)
2311 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2312 }
2313 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002314 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2315 file, linenum, args[0], args[1], args[cur_arg]);
2316 err_code |= ERR_ALERT | ERR_FATAL;
2317 goto out;
2318 }
2319 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002320 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002321 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002322 /* suboption header - needs additional argument for it */
2323 if (*(args[cur_arg+1]) == 0) {
2324 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2325 file, linenum, args[0], args[1], args[cur_arg]);
2326 err_code |= ERR_ALERT | ERR_FATAL;
2327 goto out;
2328 }
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002329 istfree(&curproxy->fwdfor_hdr_name);
2330 curproxy->fwdfor_hdr_name = istdup(ist(args[cur_arg+1]));
2331 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002332 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002333 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002334 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002335 curproxy->options &= ~PR_O_FF_ALWAYS;
2336 cur_arg += 1;
2337 } else {
2338 /* unknown suboption - catchall */
2339 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2340 file, linenum, args[0], args[1]);
2341 err_code |= ERR_ALERT | ERR_FATAL;
2342 goto out;
2343 }
2344 } /* end while loop */
2345 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002346 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002347 int cur_arg;
2348
2349 /* insert x-original-to field, but not for the IP address listed as an except.
2350 * set default options (ie: bitfield, header name, etc)
2351 */
2352
2353 curproxy->options |= PR_O_ORGTO;
2354
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002355 istfree(&curproxy->orgto_hdr_name);
2356 curproxy->orgto_hdr_name = istdup(ist(DEF_XORIGINALTO_HDR));
2357 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002358 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002359 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002360
2361 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2362 cur_arg = 2;
2363 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002364 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002365 unsigned char mask;
2366 int i;
2367
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002368 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002369 if (*(args[cur_arg+1]) &&
2370 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2371 curproxy->except_xot_net.family = AF_INET;
2372 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2373 }
2374 else if (*(args[cur_arg+1]) &&
2375 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2376 curproxy->except_xot_net.family = AF_INET6;
2377 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2378 for (i = 0; i < 16; i++)
2379 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2380 }
2381 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002382 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2383 file, linenum, args[0], args[1], args[cur_arg]);
2384 err_code |= ERR_ALERT | ERR_FATAL;
2385 goto out;
2386 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002387 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002388 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002389 /* suboption header - needs additional argument for it */
2390 if (*(args[cur_arg+1]) == 0) {
2391 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2392 file, linenum, args[0], args[1], args[cur_arg]);
2393 err_code |= ERR_ALERT | ERR_FATAL;
2394 goto out;
2395 }
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002396 istfree(&curproxy->orgto_hdr_name);
2397 curproxy->orgto_hdr_name = istdup(ist(args[cur_arg+1]));
2398 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002399 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002400 cur_arg += 2;
2401 } else {
2402 /* unknown suboption - catchall */
2403 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2404 file, linenum, args[0], args[1]);
2405 err_code |= ERR_ALERT | ERR_FATAL;
2406 goto out;
2407 }
2408 } /* end while loop */
2409 }
Christopher Faulet18c13d32022-05-16 11:43:10 +02002410 else if (strcmp(args[1], "http-restrict-req-hdr-names") == 0) {
Christopher Faulet18c13d32022-05-16 11:43:10 +02002411 if (alertif_too_many_args(2, file, linenum, args, &err_code))
2412 goto out;
2413
2414 if (*(args[2]) == 0) {
2415 ha_alert("parsing [%s:%d] : missing parameter. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2416 file, linenum, args[1]);
2417 err_code |= ERR_ALERT | ERR_FATAL;
2418 goto out;
2419 }
2420
2421 curproxy->options2 &= ~PR_O2_RSTRICT_REQ_HDR_NAMES_MASK;
2422 if (strcmp(args[2], "preserve") == 0)
2423 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_NOOP;
2424 else if (strcmp(args[2], "reject") == 0)
2425 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_BLK;
2426 else if (strcmp(args[2], "delete") == 0)
2427 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_DEL;
2428 else {
2429 ha_alert("parsing [%s:%d] : invalid parameter '%s'. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2430 file, linenum, args[2], args[1]);
2431 err_code |= ERR_ALERT | ERR_FATAL;
2432 goto out;
2433 }
2434 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002435 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002436 const char *best = proxy_find_best_option(args[1], common_options);
2437
2438 if (best)
2439 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2440 else
2441 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2442
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002443 err_code |= ERR_ALERT | ERR_FATAL;
2444 goto out;
2445 }
2446 goto out;
2447 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002448 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002449 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2450 err_code |= ERR_WARN;
2451
2452 if (*(args[1]) == 0) {
2453 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2454 err_code |= ERR_ALERT | ERR_FATAL;
2455 goto out;
2456 }
2457 free(curproxy->defbe.name);
2458 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002459 if (!curproxy->defbe.name)
2460 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002461
2462 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2463 goto out;
2464 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002465 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002466 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 +01002467
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002468 err_code |= ERR_ALERT | ERR_FATAL;
2469 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002470 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002471 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002472 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2473 err_code |= ERR_WARN;
2474
2475 if (strcmp(args[1], "never") == 0) {
2476 /* enable a graceful server shutdown on an HTTP 404 response */
2477 curproxy->options &= ~PR_O_REUSE_MASK;
2478 curproxy->options |= PR_O_REUSE_NEVR;
2479 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2480 goto out;
2481 }
2482 else if (strcmp(args[1], "safe") == 0) {
2483 /* enable a graceful server shutdown on an HTTP 404 response */
2484 curproxy->options &= ~PR_O_REUSE_MASK;
2485 curproxy->options |= PR_O_REUSE_SAFE;
2486 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2487 goto out;
2488 }
2489 else if (strcmp(args[1], "aggressive") == 0) {
2490 curproxy->options &= ~PR_O_REUSE_MASK;
2491 curproxy->options |= PR_O_REUSE_AGGR;
2492 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2493 goto out;
2494 }
2495 else if (strcmp(args[1], "always") == 0) {
2496 /* enable a graceful server shutdown on an HTTP 404 response */
2497 curproxy->options &= ~PR_O_REUSE_MASK;
2498 curproxy->options |= PR_O_REUSE_ALWS;
2499 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2500 goto out;
2501 }
2502 else {
2503 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2504 err_code |= ERR_ALERT | ERR_FATAL;
2505 goto out;
2506 }
2507 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002508 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002509 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002510 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2511 err_code |= ERR_ALERT | ERR_FATAL;
2512 goto out;
2513 }
2514
2515 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2516 err_code |= ERR_WARN;
2517
2518 if (strcmp(args[1], "fail") == 0) {
2519 /* add a condition to fail monitor requests */
2520 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2521 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2522 file, linenum, args[0], args[1]);
2523 err_code |= ERR_ALERT | ERR_FATAL;
2524 goto out;
2525 }
2526
2527 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2528 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2529 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2530 file, linenum, args[0], args[1], errmsg);
2531 err_code |= ERR_ALERT | ERR_FATAL;
2532 goto out;
2533 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002534 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002535 }
2536 else {
2537 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2538 err_code |= ERR_ALERT | ERR_FATAL;
2539 goto out;
2540 }
2541 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002542#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002543 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002544 /* enable transparent proxy connections */
2545 curproxy->options |= PR_O_TRANSP;
2546 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2547 goto out;
2548 }
2549#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002550 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002551 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2552 err_code |= ERR_WARN;
2553
2554 if (*(args[1]) == 0) {
2555 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2556 err_code |= ERR_ALERT | ERR_FATAL;
2557 goto out;
2558 }
2559 curproxy->maxconn = atol(args[1]);
2560 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2561 goto out;
2562 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002563 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002564 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2565 err_code |= ERR_WARN;
2566
2567 if (*(args[1]) == 0) {
2568 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2569 err_code |= ERR_ALERT | ERR_FATAL;
2570 goto out;
2571 }
2572 curproxy->backlog = atol(args[1]);
2573 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2574 goto out;
2575 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002576 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002577 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2578 err_code |= ERR_WARN;
2579
2580 if (*(args[1]) == 0) {
2581 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2582 err_code |= ERR_ALERT | ERR_FATAL;
2583 goto out;
2584 }
2585 curproxy->fullconn = atol(args[1]);
2586 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2587 goto out;
2588 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002589 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002590 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 +02002591 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002592 err_code |= ERR_ALERT | ERR_FATAL;
2593 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002594 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002595 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002596 struct sockaddr_storage *sk;
2597 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002598
Willy Tarreau5d095c22021-02-12 10:15:59 +01002599 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002600 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2601 err_code |= ERR_ALERT | ERR_FATAL;
2602 goto out;
2603 }
2604 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2605 err_code |= ERR_WARN;
2606
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002607 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2608 &errmsg, NULL, NULL,
2609 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 +01002610 if (!sk) {
2611 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2612 err_code |= ERR_ALERT | ERR_FATAL;
2613 goto out;
2614 }
2615
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002616 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2617 goto out;
2618
2619 curproxy->dispatch_addr = *sk;
2620 curproxy->options |= PR_O_DISPATCH;
2621 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002622 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002623 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2624 err_code |= ERR_WARN;
2625
2626 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2627 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2628 err_code |= ERR_ALERT | ERR_FATAL;
2629 goto out;
2630 }
2631 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002632 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002633 /**
2634 * The syntax for hash-type config element is
2635 * hash-type {map-based|consistent} [[<algo>] avalanche]
2636 *
2637 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2638 */
2639 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2640
2641 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2642 err_code |= ERR_WARN;
2643
2644 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2645 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2646 }
2647 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2648 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2649 }
2650 else if (strcmp(args[1], "avalanche") == 0) {
2651 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]);
2652 err_code |= ERR_ALERT | ERR_FATAL;
2653 goto out;
2654 }
2655 else {
2656 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2657 err_code |= ERR_ALERT | ERR_FATAL;
2658 goto out;
2659 }
2660
2661 /* set the hash function to use */
2662 if (!*args[2]) {
2663 /* the default algo is sdbm */
2664 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2665
2666 /* if consistent with no argument, then avalanche modifier is also applied */
2667 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2668 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2669 } else {
2670 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002671 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002672 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2673 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002674 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002675 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2676 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002677 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002678 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2679 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002680 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002681 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2682 }
2683 else {
2684 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2685 err_code |= ERR_ALERT | ERR_FATAL;
2686 goto out;
2687 }
2688
2689 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002690 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002691 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2692 }
2693 else if (*args[3]) {
2694 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2695 err_code |= ERR_ALERT | ERR_FATAL;
2696 goto out;
2697 }
2698 }
2699 }
2700 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2701 if (*(args[1]) == 0) {
2702 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2703 err_code |= ERR_ALERT | ERR_FATAL;
2704 goto out;
2705 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002706 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2707 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002708 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2709 err_code |= ERR_ALERT | ERR_FATAL;
2710 goto out;
2711 }
2712 }
2713 else if (strcmp(args[0], "unique-id-format") == 0) {
2714 if (!*(args[1])) {
2715 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2716 err_code |= ERR_ALERT | ERR_FATAL;
2717 goto out;
2718 }
2719 if (*(args[2])) {
2720 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2721 err_code |= ERR_ALERT | ERR_FATAL;
2722 goto out;
2723 }
2724 free(curproxy->conf.uniqueid_format_string);
2725 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002726 if (!curproxy->conf.uniqueid_format_string)
2727 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002728
2729 free(curproxy->conf.uif_file);
2730 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2731 curproxy->conf.uif_line = curproxy->conf.args.line;
2732 }
2733
2734 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002735 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002736 if (!*(args[1])) {
2737 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2738 err_code |= ERR_ALERT | ERR_FATAL;
2739 goto out;
2740 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002741 copy = strdup(args[1]);
2742 if (copy == NULL) {
2743 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2744 err_code |= ERR_ALERT | ERR_FATAL;
2745 goto out;
2746 }
2747
2748 istfree(&curproxy->header_unique_id);
2749 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002750 }
2751
2752 else if (strcmp(args[0], "log-format") == 0) {
2753 if (!*(args[1])) {
2754 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2755 err_code |= ERR_ALERT | ERR_FATAL;
2756 goto out;
2757 }
2758 if (*(args[2])) {
2759 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2760 err_code |= ERR_ALERT | ERR_FATAL;
2761 goto out;
2762 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002763 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002764 char *oldlogformat = "log-format";
2765
2766 if (curproxy->conf.logformat_string == default_http_log_format)
2767 oldlogformat = "option httplog";
2768 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2769 oldlogformat = "option tcplog";
2770 else if (curproxy->conf.logformat_string == clf_http_log_format)
2771 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002772 else if (curproxy->conf.logformat_string == default_https_log_format)
2773 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002774 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2775 file, linenum, oldlogformat);
2776 }
2777 if (curproxy->conf.logformat_string != default_http_log_format &&
2778 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002779 curproxy->conf.logformat_string != clf_http_log_format &&
2780 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002781 free(curproxy->conf.logformat_string);
2782 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002783 if (!curproxy->conf.logformat_string)
2784 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002785
2786 free(curproxy->conf.lfs_file);
2787 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2788 curproxy->conf.lfs_line = curproxy->conf.args.line;
2789
2790 /* get a chance to improve log-format error reporting by
2791 * reporting the correct line-number when possible.
2792 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002793 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002794 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2795 file, linenum, curproxy->id);
2796 err_code |= ERR_WARN;
2797 }
2798 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002799 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002800 if (!*(args[1])) {
2801 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2802 err_code |= ERR_ALERT | ERR_FATAL;
2803 goto out;
2804 }
2805 if (*(args[2])) {
2806 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2807 err_code |= ERR_ALERT | ERR_FATAL;
2808 goto out;
2809 }
2810
2811 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2812 free(curproxy->conf.logformat_sd_string);
2813 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002814 if (!curproxy->conf.logformat_sd_string)
2815 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002816
2817 free(curproxy->conf.lfsd_file);
2818 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2819 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2820
2821 /* get a chance to improve log-format-sd error reporting by
2822 * reporting the correct line-number when possible.
2823 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002824 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002825 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2826 file, linenum, curproxy->id);
2827 err_code |= ERR_WARN;
2828 }
2829 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002830 else if (strcmp(args[0], "error-log-format") == 0) {
2831 if (!*(args[1])) {
2832 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2833 err_code |= ERR_ALERT | ERR_FATAL;
2834 goto out;
2835 }
2836 if (*(args[2])) {
2837 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2838 err_code |= ERR_ALERT | ERR_FATAL;
2839 goto out;
2840 }
2841 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2842 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2843 file, linenum);
2844 }
2845 free(curproxy->conf.error_logformat_string);
2846 curproxy->conf.error_logformat_string = strdup(args[1]);
2847 if (!curproxy->conf.error_logformat_string)
2848 goto alloc_error;
2849
2850 free(curproxy->conf.elfs_file);
2851 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2852 curproxy->conf.elfs_line = curproxy->conf.args.line;
2853
2854 /* get a chance to improve log-format error reporting by
2855 * reporting the correct line-number when possible.
2856 */
2857 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2858 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2859 file, linenum, curproxy->id);
2860 err_code |= ERR_WARN;
2861 }
2862 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002863 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002864 if (*(args[1]) == 0) {
2865 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2866 err_code |= ERR_ALERT | ERR_FATAL;
2867 goto out;
2868 }
2869 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002870 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2871 if (b_orig(&curproxy->log_tag) == NULL) {
2872 chunk_destroy(&curproxy->log_tag);
2873 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2874 err_code |= ERR_ALERT | ERR_FATAL;
2875 goto out;
2876 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002877 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002878 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002879 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002880 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2881 err_code |= ERR_ALERT | ERR_FATAL;
2882 goto out;
2883 }
2884 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002885 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002886 int cur_arg;
2887 int port1, port2;
2888 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002889
2890 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2891 err_code |= ERR_WARN;
2892
2893 if (!*args[1]) {
2894 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2895 file, linenum, "source", "usesrc", "interface");
2896 err_code |= ERR_ALERT | ERR_FATAL;
2897 goto out;
2898 }
2899
Christopher Faulet31930372019-07-15 10:16:58 +02002900 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002901 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002902 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002903 curproxy->conn_src.iface_len = 0;
2904
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002905 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2906 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002907 if (!sk) {
2908 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2909 file, linenum, args[0], args[1], errmsg);
2910 err_code |= ERR_ALERT | ERR_FATAL;
2911 goto out;
2912 }
2913
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002914 curproxy->conn_src.source_addr = *sk;
2915 curproxy->conn_src.opts |= CO_SRC_BIND;
2916
2917 cur_arg = 2;
2918 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002919 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002920#if defined(CONFIG_HAP_TRANSPARENT)
2921 if (!*args[cur_arg + 1]) {
2922 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2923 file, linenum, "usesrc");
2924 err_code |= ERR_ALERT | ERR_FATAL;
2925 goto out;
2926 }
2927
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002928 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002929 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2930 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002931 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002932 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2933 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2934 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2935 char *name, *end;
2936
2937 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002938 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002939 name++;
2940
2941 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002942 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002943 end++;
2944
2945 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2946 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002947 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002948 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002949 if (!curproxy->conn_src.bind_hdr_name)
2950 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002951 curproxy->conn_src.bind_hdr_len = end - name;
2952 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2953 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2954 curproxy->conn_src.bind_hdr_occ = -1;
2955
2956 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002957 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002958 end++;
2959 if (*end == ',') {
2960 end++;
2961 name = end;
2962 if (*end == '-')
2963 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002964 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002965 end++;
2966 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2967 }
2968
2969 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2970 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2971 " occurrences values smaller than %d.\n",
2972 file, linenum, MAX_HDR_HISTORY);
2973 err_code |= ERR_ALERT | ERR_FATAL;
2974 goto out;
2975 }
2976 } else {
2977 struct sockaddr_storage *sk;
2978
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002979 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2980 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002981 if (!sk) {
2982 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2983 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2984 err_code |= ERR_ALERT | ERR_FATAL;
2985 goto out;
2986 }
2987
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002988 curproxy->conn_src.tproxy_addr = *sk;
2989 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2990 }
2991 global.last_checks |= LSTCHK_NETADM;
2992#else /* no TPROXY support */
2993 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2994 file, linenum, "usesrc");
2995 err_code |= ERR_ALERT | ERR_FATAL;
2996 goto out;
2997#endif
2998 cur_arg += 2;
2999 continue;
3000 }
3001
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003002 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003003#ifdef SO_BINDTODEVICE
3004 if (!*args[cur_arg + 1]) {
3005 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3006 file, linenum, args[0]);
3007 err_code |= ERR_ALERT | ERR_FATAL;
3008 goto out;
3009 }
3010 free(curproxy->conn_src.iface_name);
3011 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02003012 if (!curproxy->conn_src.iface_name)
3013 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003014 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3015 global.last_checks |= LSTCHK_NETADM;
3016#else
3017 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3018 file, linenum, args[0], args[cur_arg]);
3019 err_code |= ERR_ALERT | ERR_FATAL;
3020 goto out;
3021#endif
3022 cur_arg += 2;
3023 continue;
3024 }
3025 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3026 file, linenum, args[0], "interface", "usesrc");
3027 err_code |= ERR_ALERT | ERR_FATAL;
3028 goto out;
3029 }
3030 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003031 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003032 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3033 file, linenum, "usesrc", "source");
3034 err_code |= ERR_ALERT | ERR_FATAL;
3035 goto out;
3036 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003037 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 +02003038 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003039 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003040 file, linenum, args[0]);
3041 err_code |= ERR_ALERT | ERR_FATAL;
3042 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003043 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003044 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003045 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3046 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3047 err_code |= ERR_ALERT | ERR_FATAL;
3048 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003049 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003050 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003051 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3052 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3053 err_code |= ERR_ALERT | ERR_FATAL;
3054 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003055 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003056 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003057 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3058 err_code |= ERR_ALERT | ERR_FATAL;
3059 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003060 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003061 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003062 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3063 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3064 err_code |= ERR_ALERT | ERR_FATAL;
3065 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003066 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003067 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003068 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3069 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3070 err_code |= ERR_ALERT | ERR_FATAL;
3071 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003072 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003073 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003074 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3075 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3076 err_code |= ERR_ALERT | ERR_FATAL;
3077 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003078 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003079 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003080 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3081 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3082 err_code |= ERR_ALERT | ERR_FATAL;
3083 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003084 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003085 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 +02003086 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3087 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3088 err_code |= ERR_ALERT | ERR_FATAL;
3089 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003090 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003091 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003092 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3093 err_code |= ERR_ALERT | ERR_FATAL;
3094 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003095 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003096 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 +02003097 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3098 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3099 err_code |= ERR_ALERT | ERR_FATAL;
3100 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003101 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003102 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 +02003103 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3104 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3105 err_code |= ERR_ALERT | ERR_FATAL;
3106 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003107 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003108 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003109 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3110 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3111 err_code |= ERR_ALERT | ERR_FATAL;
3112 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003113 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003114 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 +02003115 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3116 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3117 err_code |= ERR_ALERT | ERR_FATAL;
3118 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003119 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003120 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003121 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3122 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3123 err_code |= ERR_ALERT | ERR_FATAL;
3124 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003125 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003126 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003127 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3128 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3129 err_code |= ERR_ALERT | ERR_FATAL;
3130 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003131 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003132 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303133 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003134 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3135 err_code |= ERR_ALERT | ERR_FATAL;
3136 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003137 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003138 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003139 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3140 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3141 err_code |= ERR_ALERT | ERR_FATAL;
3142 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003143 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003144 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003145 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3146 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3147 err_code |= ERR_ALERT | ERR_FATAL;
3148 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003149 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003150 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003151 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3152 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3153 err_code |= ERR_ALERT | ERR_FATAL;
3154 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003155 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003156 else {
3157 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003158 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003159 int index;
3160
3161 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3162 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3163 if (kwl->kw[index].section != CFG_LISTEN)
3164 continue;
3165 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003166 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003167 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003168 err_code |= ERR_ALERT | ERR_FATAL;
3169 goto out;
3170 }
3171
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003172 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003173 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003174 if (rc < 0) {
3175 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3176 err_code |= ERR_ALERT | ERR_FATAL;
3177 goto out;
3178 }
3179 else if (rc > 0) {
3180 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3181 err_code |= ERR_WARN;
3182 goto out;
3183 }
3184 goto out;
3185 }
3186 }
3187 }
3188
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003189 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3190 if (best)
3191 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3192 else
3193 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003194 err_code |= ERR_ALERT | ERR_FATAL;
3195 goto out;
3196 }
3197 out:
3198 free(errmsg);
3199 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003200
3201 alloc_error:
3202 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3203 err_code |= ERR_ALERT | ERR_ABORT;
3204 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003205}