blob: d8902953edb0597415e2e2435e78b606478f34ce [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;
510 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100511 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100512 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100513
514 kw = bind_find_kw(args[cur_arg]);
515 if (kw) {
516 char *err = NULL;
517 int code;
518
519 if (!kw->parse) {
520 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
521 file, linenum, args[0], args[1], args[cur_arg]);
522 cur_arg += 1 + kw->skip ;
523 err_code |= ERR_ALERT | ERR_FATAL;
524 goto out;
525 }
526
527 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
528 err_code |= code;
529
530 if (code) {
531 if (err && *err) {
532 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200533 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
534 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
535 else
536 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100537 }
538 else
539 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
540 file, linenum, args[0], args[1], args[cur_arg]);
541 if (code & ERR_FATAL) {
542 free(err);
543 cur_arg += 1 + kw->skip;
544 goto out;
545 }
546 }
547 free(err);
548 cur_arg += 1 + kw->skip;
549 continue;
550 }
551
Willy Tarreau433b05f2021-03-12 10:14:07 +0100552 best = bind_find_best_kw(args[cur_arg]);
553 if (best)
554 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
555 file, linenum, args[0], args[1], args[cur_arg], best);
556 else
557 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
558 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100559
560 err_code |= ERR_ALERT | ERR_FATAL;
561 goto out;
562 }
563 goto out;
564 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100565 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200566 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]);
567 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100568 goto out;
569 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100570 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100571 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
572 err_code |= ERR_WARN;
573
574 if (alertif_too_many_args(1, file, linenum, args, &err_code))
575 goto out;
576
577 if (!*args[1]) {
578 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
579 file, linenum, args[0]);
580 err_code |= ERR_ALERT | ERR_FATAL;
581 goto out;
582 }
583
Tim Duesterhus4b1fcaa2022-03-05 00:52:40 +0100584 istfree(&curproxy->monitor_uri);
585 curproxy->monitor_uri = istdup(ist(args[1]));
586 if (!isttest(curproxy->monitor_uri))
Christopher Fauletb15625a2021-04-12 21:31:45 +0200587 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100588
589 goto out;
590 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100591 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100592 if (alertif_too_many_args(1, file, linenum, args, &err_code))
593 goto out;
594
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100595 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
596 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
597 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200598 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
599 err_code |= ERR_ALERT | ERR_FATAL;
600 goto out;
601 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100602 else {
603 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
604 err_code |= ERR_ALERT | ERR_FATAL;
605 goto out;
606 }
607 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100608 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100609 struct eb32_node *node;
610
Willy Tarreau5d095c22021-02-12 10:15:59 +0100611 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100612 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
613 file, linenum, args[0]);
614 err_code |= ERR_ALERT | ERR_FATAL;
615 goto out;
616 }
617
618 if (alertif_too_many_args(1, file, linenum, args, &err_code))
619 goto out;
620
621 if (!*args[1]) {
622 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
623 file, linenum, args[0]);
624 err_code |= ERR_ALERT | ERR_FATAL;
625 goto out;
626 }
627
628 curproxy->uuid = atol(args[1]);
629 curproxy->conf.id.key = curproxy->uuid;
630 curproxy->options |= PR_O_FORCED_ID;
631
632 if (curproxy->uuid <= 0) {
633 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
634 file, linenum);
635 err_code |= ERR_ALERT | ERR_FATAL;
636 goto out;
637 }
638
639 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
640 if (node) {
641 struct proxy *target = container_of(node, struct proxy, conf.id);
642 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
643 file, linenum, proxy_type_str(curproxy), curproxy->id,
644 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
645 err_code |= ERR_ALERT | ERR_FATAL;
646 goto out;
647 }
648 eb32_insert(&used_proxy_id, &curproxy->conf.id);
649 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100650 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100651 int i, len=0;
652 char *d;
653
Willy Tarreau5d095c22021-02-12 10:15:59 +0100654 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100655 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
656 file, linenum, args[0]);
657 err_code |= ERR_ALERT | ERR_FATAL;
658 goto out;
659 }
660
661 if (!*args[1]) {
662 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
663 file, linenum, args[0]);
664 return -1;
665 }
666
667 for (i = 1; *args[i]; i++)
668 len += strlen(args[i]) + 1;
669
670 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200671 if (!d)
672 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100673 curproxy->desc = d;
674
675 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
676 for (i = 2; *args[i]; i++)
677 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
678
679 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100680 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100681 if (alertif_too_many_args(0, file, linenum, args, &err_code))
682 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200683 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100684 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100685 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100686 if (alertif_too_many_args(0, file, linenum, args, &err_code))
687 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200688 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100689 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100690 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100691 int cur_arg = 1;
692 unsigned long set = 0;
693
694 while (*args[cur_arg]) {
695 if (strcmp(args[cur_arg], "all") == 0) {
696 set = 0;
697 break;
698 }
Willy Tarreau72faef32021-06-15 08:36:30 +0200699 if (parse_process_number(args[cur_arg], &set, 1, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100700 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
701 err_code |= ERR_ALERT | ERR_FATAL;
702 goto out;
703 }
704 cur_arg++;
705 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200706 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
707 file, linenum, args[0]);
708 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100709 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100710 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200711 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
712 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100713 err_code |= ERR_ALERT | ERR_FATAL;
714 goto out;
715 }
716
717 err = invalid_char(args[1]);
718 if (err) {
719 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
720 file, linenum, *err, args[1]);
721 err_code |= ERR_ALERT | ERR_FATAL;
722 goto out;
723 }
724
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100725 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100726 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100727 "logical disjunction within a condition.\n",
728 file, linenum, args[1]);
729 err_code |= ERR_ALERT | ERR_FATAL;
730 goto out;
731 }
732
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100733 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
734 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
735 file, linenum, args[1], errmsg);
736 err_code |= ERR_ALERT | ERR_FATAL;
737 goto out;
738 }
739 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100740 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100741
742 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
743 err_code |= ERR_WARN;
744
745 if (*(args[1]) == 0) {
746 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
747 file, linenum, args[0]);
748 err_code |= ERR_ALERT | ERR_FATAL;
749 goto out;
750 }
751 free(curproxy->dyncookie_key);
752 curproxy->dyncookie_key = strdup(args[1]);
753 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100754 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100755 int cur_arg;
756
757 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
758 err_code |= ERR_WARN;
759
760 if (*(args[1]) == 0) {
761 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
762 file, linenum, args[0]);
763 err_code |= ERR_ALERT | ERR_FATAL;
764 goto out;
765 }
766
767 curproxy->ck_opts = 0;
768 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100769 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100770 free(curproxy->cookie_name);
771 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200772 if (!curproxy->cookie_name)
773 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100774 curproxy->cookie_len = strlen(curproxy->cookie_name);
775
776 cur_arg = 2;
777 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100778 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100779 curproxy->ck_opts |= PR_CK_RW;
780 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100781 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100782 curproxy->ck_opts |= PR_CK_IND;
783 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100784 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100785 curproxy->ck_opts |= PR_CK_INS;
786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100788 curproxy->ck_opts |= PR_CK_NOC;
789 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100790 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100791 curproxy->ck_opts |= PR_CK_POST;
792 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100793 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100794 curproxy->ck_opts |= PR_CK_PSV;
795 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100796 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100797 curproxy->ck_opts |= PR_CK_PFX;
798 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100799 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100800 curproxy->ck_opts |= PR_CK_HTTPONLY;
801 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100802 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100803 curproxy->ck_opts |= PR_CK_SECURE;
804 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100805 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100806 if (!*args[cur_arg + 1]) {
807 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
808 file, linenum, args[cur_arg]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812
Joao Moraise1583752019-10-30 21:04:00 -0300813 if (!strchr(args[cur_arg + 1], '.')) {
814 /* rfc6265, 5.2.3 The Domain Attribute */
815 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
816 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100817 file, linenum, args[cur_arg + 1]);
818 err_code |= ERR_WARN;
819 }
820
821 err = invalid_domainchar(args[cur_arg + 1]);
822 if (err) {
823 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
824 file, linenum, *err, args[cur_arg + 1]);
825 err_code |= ERR_ALERT | ERR_FATAL;
826 goto out;
827 }
828
829 if (!curproxy->cookie_domain) {
830 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
831 } else {
832 /* one domain was already specified, add another one by
833 * building the string which will be returned along with
834 * the cookie.
835 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200836 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
837 }
838
Christopher Fauletb15625a2021-04-12 21:31:45 +0200839 if (!curproxy->cookie_domain)
840 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100841 cur_arg++;
842 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100843 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100844 unsigned int maxidle;
845 const char *res;
846
847 if (!*args[cur_arg + 1]) {
848 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
849 file, linenum, args[cur_arg]);
850 err_code |= ERR_ALERT | ERR_FATAL;
851 goto out;
852 }
853
854 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200855 if (res == PARSE_TIME_OVER) {
856 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
857 file, linenum, args[cur_arg+1], args[cur_arg]);
858 err_code |= ERR_ALERT | ERR_FATAL;
859 goto out;
860 }
861 else if (res == PARSE_TIME_UNDER) {
862 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
863 file, linenum, args[cur_arg+1], args[cur_arg]);
864 err_code |= ERR_ALERT | ERR_FATAL;
865 goto out;
866 }
867 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100868 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
869 file, linenum, *res, args[cur_arg]);
870 err_code |= ERR_ALERT | ERR_FATAL;
871 goto out;
872 }
873 curproxy->cookie_maxidle = maxidle;
874 cur_arg++;
875 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100876 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100877 unsigned int maxlife;
878 const char *res;
879
880 if (!*args[cur_arg + 1]) {
881 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
882 file, linenum, args[cur_arg]);
883 err_code |= ERR_ALERT | ERR_FATAL;
884 goto out;
885 }
886
Willy Tarreau9faebe32019-06-07 19:00:37 +0200887
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100888 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200889 if (res == PARSE_TIME_OVER) {
890 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
891 file, linenum, args[cur_arg+1], args[cur_arg]);
892 err_code |= ERR_ALERT | ERR_FATAL;
893 goto out;
894 }
895 else if (res == PARSE_TIME_UNDER) {
896 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
897 file, linenum, args[cur_arg+1], args[cur_arg]);
898 err_code |= ERR_ALERT | ERR_FATAL;
899 goto out;
900 }
901 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100902 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
903 file, linenum, *res, args[cur_arg]);
904 err_code |= ERR_ALERT | ERR_FATAL;
905 goto out;
906 }
907 curproxy->cookie_maxlife = maxlife;
908 cur_arg++;
909 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100910 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100911
912 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
913 err_code |= ERR_WARN;
914 curproxy->ck_opts |= PR_CK_DYNAMIC;
915 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100916 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100917 char *val;
918 if (!*args[cur_arg + 1]) {
919 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
920 file, linenum, args[cur_arg]);
921 err_code |= ERR_ALERT | ERR_FATAL;
922 goto out;
923 }
924 val = args[cur_arg + 1];
925 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100926 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100927 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
928 file, linenum, *val);
929 err_code |= ERR_ALERT | ERR_FATAL;
930 goto out;
931 }
932 val++;
933 }
934 /* don't add ';' for the first attribute */
935 if (!curproxy->cookie_attrs)
936 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
937 else
938 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200939
Christopher Fauletb15625a2021-04-12 21:31:45 +0200940 if (!curproxy->cookie_attrs)
941 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100942 cur_arg++;
943 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100944
945 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100946 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 +0100947 file, linenum, args[0]);
948 err_code |= ERR_ALERT | ERR_FATAL;
949 goto out;
950 }
951 cur_arg++;
952 }
953 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
954 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
955 file, linenum);
956 err_code |= ERR_ALERT | ERR_FATAL;
957 }
958
959 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
960 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
961 file, linenum);
962 err_code |= ERR_ALERT | ERR_FATAL;
963 }
964
965 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
966 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
967 file, linenum);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 }
970 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100971 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100972 if (*(args[1]) == 0) {
973 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
974 file, linenum, args[0]);
975 err_code |= ERR_ALERT | ERR_FATAL;
976 goto out;
977 }
978
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100979 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100980 if (*(args[1]) == 0) {
981 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
982 file, linenum, args[1]);
983 err_code |= ERR_ALERT | ERR_FATAL;
984 goto out;
985 }
986 free(curproxy->email_alert.from);
987 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200988 if (!curproxy->email_alert.from)
989 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100990 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100991 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100992 if (*(args[1]) == 0) {
993 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
994 file, linenum, args[1]);
995 err_code |= ERR_ALERT | ERR_FATAL;
996 goto out;
997 }
998 free(curproxy->email_alert.mailers.name);
999 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001000 if (!curproxy->email_alert.mailers.name)
1001 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001002 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001003 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001004 if (*(args[1]) == 0) {
1005 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1006 file, linenum, args[1]);
1007 err_code |= ERR_ALERT | ERR_FATAL;
1008 goto out;
1009 }
1010 free(curproxy->email_alert.myhostname);
1011 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001012 if (!curproxy->email_alert.myhostname)
1013 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001014 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001015 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001016 curproxy->email_alert.level = get_log_level(args[2]);
1017 if (curproxy->email_alert.level < 0) {
1018 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1019 file, linenum, args[1], args[2]);
1020 err_code |= ERR_ALERT | ERR_FATAL;
1021 goto out;
1022 }
1023 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001024 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001025 if (*(args[1]) == 0) {
1026 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1027 file, linenum, args[1]);
1028 err_code |= ERR_ALERT | ERR_FATAL;
1029 goto out;
1030 }
1031 free(curproxy->email_alert.to);
1032 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001033 if (!curproxy->email_alert.to)
1034 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001035 }
1036 else {
1037 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1038 file, linenum, args[1]);
1039 err_code |= ERR_ALERT | ERR_FATAL;
1040 goto out;
1041 }
1042 /* Indicate that the email_alert is at least partially configured */
1043 curproxy->email_alert.set = 1;
1044 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001045 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001046 if (*(args[1]) == 0) {
1047 ha_alert("parsing [%s:%d] : missing persist method.\n",
1048 file, linenum);
1049 err_code |= ERR_ALERT | ERR_FATAL;
1050 goto out;
1051 }
1052
1053 if (!strncmp(args[1], "rdp-cookie", 10)) {
1054 curproxy->options2 |= PR_O2_RDPC_PRST;
1055
1056 if (*(args[1] + 10) == '(') { /* cookie name */
1057 const char *beg, *end;
1058
1059 beg = args[1] + 11;
1060 end = strchr(beg, ')');
1061
1062 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1063 goto out;
1064
1065 if (!end || end == beg) {
1066 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1067 file, linenum);
1068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071
1072 free(curproxy->rdp_cookie_name);
1073 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001074 if (!curproxy->rdp_cookie_name)
1075 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001076 curproxy->rdp_cookie_len = end-beg;
1077 }
1078 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1079 free(curproxy->rdp_cookie_name);
1080 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +02001081 if (!curproxy->rdp_cookie_name)
1082 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001083 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1084 }
1085 else { /* syntax */
1086 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1087 file, linenum);
1088 err_code |= ERR_ALERT | ERR_FATAL;
1089 goto out;
1090 }
1091 }
1092 else {
1093 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1094 file, linenum);
1095 err_code |= ERR_ALERT | ERR_FATAL;
1096 goto out;
1097 }
1098 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001099 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001100 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 +01001101 err_code |= ERR_ALERT | ERR_FATAL;
1102 goto out;
1103 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001104 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001105 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1106 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001107 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001108 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1109 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001110 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 +01001111 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1112 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001113 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001114 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1115 }
1116 else {
1117 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1118 file, linenum, args[0], args[1]);
1119 err_code |= ERR_ALERT | ERR_FATAL;
1120 goto out;
1121 }
1122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001123 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001124 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1125 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001126 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001127 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001128
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001129 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001130
1131 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001132 curproxy->server_state_file_name = strdup(curproxy->id);
1133 else
1134 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001135
Christopher Fauletb15625a2021-04-12 21:31:45 +02001136 if (!curproxy->server_state_file_name)
1137 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001138 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001139 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001140 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1141 err_code |= ERR_WARN;
1142 if (*(args[1]) == 0) {
1143 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1144 file, linenum, args[0]);
1145 err_code |= ERR_ALERT | ERR_FATAL;
1146 goto out;
1147 }
1148 curproxy->max_out_conns = atoi(args[1]);
1149 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001150 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001151 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1152 err_code |= ERR_WARN;
1153
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001154 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001155 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001156 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1157 err_code |= ERR_ALERT | ERR_FATAL;
1158 goto out;
1159 }
1160
1161 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1162 goto out;
1163
1164 if (*(args[4]) == 0) {
1165 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1166 file, linenum, args[0]);
1167 err_code |= ERR_ALERT | ERR_FATAL;
1168 goto out;
1169 }
1170 free(curproxy->capture_name);
1171 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001172 if (!curproxy->capture_name)
1173 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001174 curproxy->capture_namelen = strlen(curproxy->capture_name);
1175 curproxy->capture_len = atol(args[4]);
1176 curproxy->to_log |= LW_COOKIE;
1177 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001178 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001179 struct cap_hdr *hdr;
1180
Willy Tarreau5d095c22021-02-12 10:15:59 +01001181 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001182 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1183 err_code |= ERR_ALERT | ERR_FATAL;
1184 goto out;
1185 }
1186
1187 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1188 goto out;
1189
1190 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1191 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1192 file, linenum, args[0], args[1]);
1193 err_code |= ERR_ALERT | ERR_FATAL;
1194 goto out;
1195 }
1196
1197 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001198 if (!hdr)
1199 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001200 hdr->next = curproxy->req_cap;
1201 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001202 if (!hdr->name)
1203 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001204 hdr->namelen = strlen(args[3]);
1205 hdr->len = atol(args[5]);
1206 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001207 if (!hdr->pool) {
1208 req_caphdr_alloc_error:
1209 if (hdr)
1210 ha_free(&hdr->name);
1211 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001212 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001213 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001214 hdr->index = curproxy->nb_req_cap++;
1215 curproxy->req_cap = hdr;
1216 curproxy->to_log |= LW_REQHDR;
1217 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001218 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001219 struct cap_hdr *hdr;
1220
Willy Tarreau5d095c22021-02-12 10:15:59 +01001221 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001222 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1223 err_code |= ERR_ALERT | ERR_FATAL;
1224 goto out;
1225 }
1226
1227 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1228 goto out;
1229
1230 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1231 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1232 file, linenum, args[0], args[1]);
1233 err_code |= ERR_ALERT | ERR_FATAL;
1234 goto out;
1235 }
1236 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001237 if (!hdr)
1238 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001239 hdr->next = curproxy->rsp_cap;
1240 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001241 if (!hdr->name)
1242 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001243 hdr->namelen = strlen(args[3]);
1244 hdr->len = atol(args[5]);
1245 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001246 if (!hdr->pool) {
1247 res_caphdr_alloc_error:
1248 if (hdr)
1249 ha_free(&hdr->name);
1250 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001251 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001252 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001253 hdr->index = curproxy->nb_rsp_cap++;
1254 curproxy->rsp_cap = hdr;
1255 curproxy->to_log |= LW_RSPHDR;
1256 }
1257 else {
1258 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1259 file, linenum, args[0]);
1260 err_code |= ERR_ALERT | ERR_FATAL;
1261 goto out;
1262 }
1263 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001264 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001265 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1266 err_code |= ERR_WARN;
1267
1268 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1269 goto out;
1270
1271 if (*(args[1]) == 0) {
1272 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1273 file, linenum, args[0]);
1274 err_code |= ERR_ALERT | ERR_FATAL;
1275 goto out;
1276 }
1277 curproxy->conn_retries = atol(args[1]);
1278 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001279 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001280 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001281 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001282
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001283 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1284 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001285 err_code |= ERR_ALERT | ERR_FATAL;
1286 goto out;
1287 }
1288
1289 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1290 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001291 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001292 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1293 file, linenum, args[0]);
1294 err_code |= ERR_WARN;
1295 }
1296
1297 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1298
1299 if (!rule) {
1300 err_code |= ERR_ALERT | ERR_ABORT;
1301 goto out;
1302 }
1303
1304 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001305
1306 if (curproxy->cap & PR_CAP_FE)
1307 where |= SMP_VAL_FE_HRQ_HDR;
1308 if (curproxy->cap & PR_CAP_BE)
1309 where |= SMP_VAL_BE_HRQ_HDR;
1310 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001311
Willy Tarreau2b718102021-04-21 07:32:39 +02001312 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001313 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001314 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001315 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001316 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001317
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001318 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1319 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001320 err_code |= ERR_ALERT | ERR_FATAL;
1321 goto out;
1322 }
1323
1324 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1325 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001326 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001327 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1328 file, linenum, args[0]);
1329 err_code |= ERR_WARN;
1330 }
1331
1332 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1333
1334 if (!rule) {
1335 err_code |= ERR_ALERT | ERR_ABORT;
1336 goto out;
1337 }
1338
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001339 if (curproxy->cap & PR_CAP_FE)
1340 where |= SMP_VAL_FE_HRS_HDR;
1341 if (curproxy->cap & PR_CAP_BE)
1342 where |= SMP_VAL_BE_HRS_HDR;
1343 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001344
Willy Tarreau2b718102021-04-21 07:32:39 +02001345 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001346 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001347 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001348 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001349 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001350 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1351 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001352 err_code |= ERR_ALERT | ERR_FATAL;
1353 goto out;
1354 }
1355
1356 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1357 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1358 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1359 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1360 file, linenum, args[0]);
1361 err_code |= ERR_WARN;
1362 }
1363
1364 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1365
1366 if (!rule) {
1367 err_code |= ERR_ALERT | ERR_ABORT;
1368 goto out;
1369 }
1370
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001371 if (curproxy->cap & PR_CAP_FE)
1372 where |= SMP_VAL_FE_HRS_HDR;
1373 if (curproxy->cap & PR_CAP_BE)
1374 where |= SMP_VAL_BE_HRS_HDR;
1375 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001376
Willy Tarreau2b718102021-04-21 07:32:39 +02001377 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001378 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001379 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001380 /* set the header name and length into the proxy structure */
1381 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1382 err_code |= ERR_WARN;
1383
1384 if (!*args[1]) {
1385 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1386 file, linenum, args[0]);
1387 err_code |= ERR_ALERT | ERR_FATAL;
1388 goto out;
1389 }
1390
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001391 /* set the desired header name, in lower case */
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001392 istfree(&curproxy->server_id_hdr_name);
1393 curproxy->server_id_hdr_name = istdup(ist(args[1]));
1394 if (!isttest(curproxy->server_id_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02001395 goto alloc_error;
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001396 ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001397 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001398 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001399 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 +01001400
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001401 err_code |= ERR_ALERT | ERR_FATAL;
1402 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001403 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001404 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001405 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001406 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001407
Willy Tarreau5d095c22021-02-12 10:15:59 +01001408 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001409 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1410 err_code |= ERR_ALERT | ERR_FATAL;
1411 goto out;
1412 }
1413
1414 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1415 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1416 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1417 err_code |= ERR_ALERT | ERR_FATAL;
1418 goto out;
1419 }
1420
Willy Tarreau2b718102021-04-21 07:32:39 +02001421 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001422 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001423
1424 if (curproxy->cap & PR_CAP_FE)
1425 where |= SMP_VAL_FE_HRQ_HDR;
1426 if (curproxy->cap & PR_CAP_BE)
1427 where |= SMP_VAL_BE_HRQ_HDR;
1428 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001429 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001430 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001431 struct switching_rule *rule;
1432
Willy Tarreau5d095c22021-02-12 10:15:59 +01001433 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001434 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1435 err_code |= ERR_ALERT | ERR_FATAL;
1436 goto out;
1437 }
1438
1439 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1440 err_code |= ERR_WARN;
1441
1442 if (*(args[1]) == 0) {
1443 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1444 err_code |= ERR_ALERT | ERR_FATAL;
1445 goto out;
1446 }
1447
1448 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1449 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1450 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1451 file, linenum, errmsg);
1452 err_code |= ERR_ALERT | ERR_FATAL;
1453 goto out;
1454 }
1455
1456 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1457 }
1458 else if (*args[2]) {
1459 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1460 file, linenum, args[2]);
1461 err_code |= ERR_ALERT | ERR_FATAL;
1462 goto out;
1463 }
1464
1465 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001466 if (!rule)
1467 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001468 rule->cond = cond;
1469 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001470 if (!rule->be.name)
1471 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001472 rule->line = linenum;
1473 rule->file = strdup(file);
1474 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001475 use_backend_alloc_error:
1476 if (cond)
1477 prune_acl_cond(cond);
1478 ha_free(&cond);
1479 if (rule)
1480 ha_free(&(rule->be.name));
1481 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001482 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001483 }
1484 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001485 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001486 }
1487 else if (strcmp(args[0], "use-server") == 0) {
1488 struct server_rule *rule;
1489
Willy Tarreau5d095c22021-02-12 10:15:59 +01001490 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001491 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1492 err_code |= ERR_ALERT | ERR_FATAL;
1493 goto out;
1494 }
1495
1496 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1497 err_code |= ERR_WARN;
1498
1499 if (*(args[1]) == 0) {
1500 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1501 err_code |= ERR_ALERT | ERR_FATAL;
1502 goto out;
1503 }
1504
1505 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "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 + 2, &errmsg)) == NULL) {
1513 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1514 file, linenum, errmsg);
1515 err_code |= ERR_ALERT | ERR_FATAL;
1516 goto out;
1517 }
1518
1519 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1520
1521 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001522 if (!rule)
1523 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001524 rule->cond = cond;
1525 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001526 if (!rule->srv.name)
1527 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001528 rule->line = linenum;
1529 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001530 if (!rule->file) {
1531 use_server_alloc_error:
1532 if (cond)
1533 prune_acl_cond(cond);
1534 ha_free(&cond);
1535 if (rule)
1536 ha_free(&(rule->srv.name));
1537 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001538 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001539 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001540 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001541 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001542 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1543 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001544 else if ((strcmp(args[0], "force-persist") == 0) ||
1545 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001546 struct persist_rule *rule;
1547
Willy Tarreau5d095c22021-02-12 10:15:59 +01001548 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001549 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1550 err_code |= ERR_ALERT | ERR_FATAL;
1551 goto out;
1552 }
1553
1554 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1555 err_code |= ERR_WARN;
1556
1557 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1558 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1559 file, linenum, args[0]);
1560 err_code |= ERR_ALERT | ERR_FATAL;
1561 goto out;
1562 }
1563
1564 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1565 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1566 file, linenum, args[0], errmsg);
1567 err_code |= ERR_ALERT | ERR_FATAL;
1568 goto out;
1569 }
1570
1571 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1572 * where force-persist is applied.
1573 */
1574 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1575
1576 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001577 if (!rule) {
1578 if (cond)
1579 prune_acl_cond(cond);
1580 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001581 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001582 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001583 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001584 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001585 rule->type = PERSIST_TYPE_FORCE;
1586 } else {
1587 rule->type = PERSIST_TYPE_IGNORE;
1588 }
1589 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001590 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001591 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001592 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001593 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001594
Willy Tarreau5d095c22021-02-12 10:15:59 +01001595 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001596 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1597 file, linenum);
1598 err_code |= ERR_ALERT | ERR_FATAL;
1599 goto out;
1600 }
1601
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001602 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001603 if (other) {
1604 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 +01001605 file, linenum, curproxy->id,
1606 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1607 other->proxy ? other->id : other->peers.p->id,
1608 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001609 err_code |= ERR_ALERT | ERR_FATAL;
1610 goto out;
1611 }
1612
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001613 curproxy->table = calloc(1, sizeof *curproxy->table);
1614 if (!curproxy->table) {
1615 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1616 file, linenum, args[0], args[1]);
1617 err_code |= ERR_ALERT | ERR_FATAL;
1618 goto out;
1619 }
1620
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001621 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1622 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001623 if (err_code & ERR_FATAL) {
1624 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001625 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001626 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001627
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001628 /* Store the proxy in the stick-table. */
1629 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001630
1631 stktable_store_name(curproxy->table);
1632 curproxy->table->next = stktables_list;
1633 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001634
1635 /* Add this proxy to the list of proxies which refer to its stick-table. */
1636 if (curproxy->table->proxies_list != curproxy) {
1637 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1638 curproxy->table->proxies_list = curproxy;
1639 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001640 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001641 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001642 struct sticking_rule *rule;
1643 struct sample_expr *expr;
1644 int myidx = 0;
1645 const char *name = NULL;
1646 int flags;
1647
Willy Tarreau5d095c22021-02-12 10:15:59 +01001648 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001649 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1650 err_code |= ERR_ALERT | ERR_FATAL;
1651 goto out;
1652 }
1653
1654 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1655 err_code |= ERR_WARN;
1656 goto out;
1657 }
1658
1659 myidx++;
1660 if ((strcmp(args[myidx], "store") == 0) ||
1661 (strcmp(args[myidx], "store-request") == 0)) {
1662 myidx++;
1663 flags = STK_IS_STORE;
1664 }
1665 else if (strcmp(args[myidx], "store-response") == 0) {
1666 myidx++;
1667 flags = STK_IS_STORE | STK_ON_RSP;
1668 }
1669 else if (strcmp(args[myidx], "match") == 0) {
1670 myidx++;
1671 flags = STK_IS_MATCH;
1672 }
1673 else if (strcmp(args[myidx], "on") == 0) {
1674 myidx++;
1675 flags = STK_IS_MATCH | STK_IS_STORE;
1676 }
1677 else {
1678 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1679 err_code |= ERR_ALERT | ERR_FATAL;
1680 goto out;
1681 }
1682
1683 if (*(args[myidx]) == 0) {
1684 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1685 err_code |= ERR_ALERT | ERR_FATAL;
1686 goto out;
1687 }
1688
1689 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001690 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001691 if (!expr) {
1692 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1693 err_code |= ERR_ALERT | ERR_FATAL;
1694 goto out;
1695 }
1696
1697 if (flags & STK_ON_RSP) {
1698 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1699 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1700 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1701 err_code |= ERR_ALERT | ERR_FATAL;
1702 free(expr);
1703 goto out;
1704 }
1705 } else {
1706 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1707 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1708 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1709 err_code |= ERR_ALERT | ERR_FATAL;
1710 free(expr);
1711 goto out;
1712 }
1713 }
1714
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001715 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001716 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1717
1718 if (strcmp(args[myidx], "table") == 0) {
1719 myidx++;
1720 name = args[myidx++];
1721 }
1722
1723 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1724 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1725 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1726 file, linenum, args[0], errmsg);
1727 err_code |= ERR_ALERT | ERR_FATAL;
1728 free(expr);
1729 goto out;
1730 }
1731 }
1732 else if (*(args[myidx])) {
1733 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1734 file, linenum, args[0], args[myidx]);
1735 err_code |= ERR_ALERT | ERR_FATAL;
1736 free(expr);
1737 goto out;
1738 }
1739 if (flags & STK_ON_RSP)
1740 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1741 else
1742 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1743
1744 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001745 if (!rule) {
1746 if (cond)
1747 prune_acl_cond(cond);
1748 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001749 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001750 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001751 rule->cond = cond;
1752 rule->expr = expr;
1753 rule->flags = flags;
1754 rule->table.name = name ? strdup(name) : NULL;
1755 LIST_INIT(&rule->list);
1756 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001757 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001758 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001759 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001760 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001761 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001762 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001763 curproxy->uri_auth = NULL; /* we must detach from the default config */
1764
1765 if (!*args[1]) {
1766 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001767 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001768 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001769 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001770
Willy Tarreau5d095c22021-02-12 10:15:59 +01001771 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001772 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1773 err_code |= ERR_ALERT | ERR_FATAL;
1774 goto out;
1775 }
1776
Christopher Fauletb15625a2021-04-12 21:31:45 +02001777 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1778 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001779
1780 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1781 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1782 file, linenum, args[0], args[1]);
1783 err_code |= ERR_ALERT | ERR_FATAL;
1784 goto out;
1785 }
1786 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1787 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1788 file, linenum, args[0], args[1], errmsg);
1789 err_code |= ERR_ALERT | ERR_FATAL;
1790 goto out;
1791 }
1792
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001793 if (curproxy->cap & PR_CAP_FE)
1794 where |= SMP_VAL_FE_HRQ_HDR;
1795 if (curproxy->cap & PR_CAP_BE)
1796 where |= SMP_VAL_BE_HRQ_HDR;
1797 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001798
1799 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001800 if (!rule) {
1801 if (cond)
1802 prune_acl_cond(cond);
1803 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001804 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001805 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001806 rule->cond = cond;
1807 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001808 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001809 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001810 if (*(args[2]) == 0) {
1811 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1812 err_code |= ERR_ALERT | ERR_FATAL;
1813 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001814 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1815 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001816 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001817 if (*(args[2]) == 0) {
1818 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1819 err_code |= ERR_ALERT | ERR_FATAL;
1820 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001821 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1822 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001823 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001824 unsigned interval;
1825
1826 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001827 if (err == PARSE_TIME_OVER) {
1828 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1829 file, linenum, args[2]);
1830 err_code |= ERR_ALERT | ERR_FATAL;
1831 goto out;
1832 }
1833 else if (err == PARSE_TIME_UNDER) {
1834 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1835 file, linenum, args[2]);
1836 err_code |= ERR_ALERT | ERR_FATAL;
1837 goto out;
1838 }
1839 else if (err) {
1840 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001841 file, linenum, *err);
1842 err_code |= ERR_ALERT | ERR_FATAL;
1843 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001844 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1845 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001846 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001847 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001848 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001849
Willy Tarreau5d095c22021-02-12 10:15:59 +01001850 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001851 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1852 err_code |= ERR_ALERT | ERR_FATAL;
1853 goto out;
1854 }
1855
Christopher Fauletb15625a2021-04-12 21:31:45 +02001856 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1857 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001858
1859 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1860 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1861 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1862 file, linenum, args[0]);
1863 err_code |= ERR_WARN;
1864 }
1865
1866 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1867
1868 if (!rule) {
1869 err_code |= ERR_ALERT | ERR_ABORT;
1870 goto out;
1871 }
1872
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001873 if (curproxy->cap & PR_CAP_FE)
1874 where |= SMP_VAL_FE_HRQ_HDR;
1875 if (curproxy->cap & PR_CAP_BE)
1876 where |= SMP_VAL_BE_HRQ_HDR;
1877 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001878 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001879
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001880 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001881 if (*(args[2]) == 0) {
1882 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1883 err_code |= ERR_ALERT | ERR_FATAL;
1884 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001885 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1886 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001887 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001888 if (*(args[2]) == 0) {
1889 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1890 err_code |= ERR_ALERT | ERR_FATAL;
1891 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001892 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1893 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001894 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001895 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1896 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001897 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001898 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1899 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001900 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001901 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1902 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001903 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001904 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1905 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001906 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001907
1908 if (*args[2]) {
1909 int i;
1910 char c;
1911
1912 for (i=0; args[2][i]; i++) {
1913 c = args[2][i];
1914 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1915 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1916 break;
1917 }
1918
1919 if (!i || args[2][i]) {
1920 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1921 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1922 file, linenum, args[0], args[1]);
1923 err_code |= ERR_ALERT | ERR_FATAL;
1924 goto out;
1925 }
1926 }
1927
Christopher Fauletb15625a2021-04-12 21:31:45 +02001928 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1929 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001930 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001931 char *desc = NULL;
1932
1933 if (*args[2]) {
1934 int i, len=0;
1935 char *d;
1936
1937 for (i = 2; *args[i]; i++)
1938 len += strlen(args[i]) + 1;
1939
1940 desc = d = calloc(1, len);
1941
1942 d += snprintf(d, desc + len - d, "%s", args[2]);
1943 for (i = 3; *args[i]; i++)
1944 d += snprintf(d, desc + len - d, " %s", args[i]);
1945 }
1946
1947 if (!*args[2] && !global.desc)
1948 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1949 file, linenum, args[1]);
1950 else {
1951 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1952 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001953 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001954 }
1955 free(desc);
1956 }
1957 } else {
1958stats_error_parsing:
1959 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1960 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1961 err_code |= ERR_ALERT | ERR_FATAL;
1962 goto out;
1963 }
1964 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001965 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001966 int optnum;
1967
1968 if (*(args[1]) == '\0') {
1969 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1970 file, linenum, args[0]);
1971 err_code |= ERR_ALERT | ERR_FATAL;
1972 goto out;
1973 }
1974
1975 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001976 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001977 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1978 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1979 file, linenum, cfg_opts[optnum].name);
1980 err_code |= ERR_ALERT | ERR_FATAL;
1981 goto out;
1982 }
1983 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1984 goto out;
1985
1986 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1987 err_code |= ERR_WARN;
1988 goto out;
1989 }
1990
1991 curproxy->no_options &= ~cfg_opts[optnum].val;
1992 curproxy->options &= ~cfg_opts[optnum].val;
1993
1994 switch (kwm) {
1995 case KWM_STD:
1996 curproxy->options |= cfg_opts[optnum].val;
1997 break;
1998 case KWM_NO:
1999 curproxy->no_options |= cfg_opts[optnum].val;
2000 break;
2001 case KWM_DEF: /* already cleared */
2002 break;
2003 }
2004
2005 goto out;
2006 }
2007 }
2008
2009 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002010 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002011 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2012 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2013 file, linenum, cfg_opts2[optnum].name);
2014 err_code |= ERR_ALERT | ERR_FATAL;
2015 goto out;
2016 }
2017 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2018 goto out;
2019 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2020 err_code |= ERR_WARN;
2021 goto out;
2022 }
2023
2024 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2025 curproxy->options2 &= ~cfg_opts2[optnum].val;
2026
2027 switch (kwm) {
2028 case KWM_STD:
2029 curproxy->options2 |= cfg_opts2[optnum].val;
2030 break;
2031 case KWM_NO:
2032 curproxy->no_options2 |= cfg_opts2[optnum].val;
2033 break;
2034 case KWM_DEF: /* already cleared */
2035 break;
2036 }
2037 goto out;
2038 }
2039 }
2040
2041 /* HTTP options override each other. They can be cancelled using
2042 * "no option xxx" which only switches to default mode if the mode
2043 * was this one (useful for cancelling options set in defaults
2044 * sections).
2045 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02002046 if (strcmp(args[1], "forceclose") == 0) {
2047 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",
2048 file, linenum, args[1]);
2049 err_code |= ERR_ALERT | ERR_FATAL;
2050 goto out;
2051 }
2052 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002053 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2054 goto out;
2055 if (kwm == KWM_STD) {
2056 curproxy->options &= ~PR_O_HTTP_MODE;
2057 curproxy->options |= PR_O_HTTP_CLO;
2058 goto out;
2059 }
2060 else if (kwm == KWM_NO) {
2061 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2062 curproxy->options &= ~PR_O_HTTP_MODE;
2063 goto out;
2064 }
2065 }
2066 else if (strcmp(args[1], "http-server-close") == 0) {
2067 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2068 goto out;
2069 if (kwm == KWM_STD) {
2070 curproxy->options &= ~PR_O_HTTP_MODE;
2071 curproxy->options |= PR_O_HTTP_SCL;
2072 goto out;
2073 }
2074 else if (kwm == KWM_NO) {
2075 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2076 curproxy->options &= ~PR_O_HTTP_MODE;
2077 goto out;
2078 }
2079 }
2080 else if (strcmp(args[1], "http-keep-alive") == 0) {
2081 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2082 goto out;
2083 if (kwm == KWM_STD) {
2084 curproxy->options &= ~PR_O_HTTP_MODE;
2085 curproxy->options |= PR_O_HTTP_KAL;
2086 goto out;
2087 }
2088 else if (kwm == KWM_NO) {
2089 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2090 curproxy->options &= ~PR_O_HTTP_MODE;
2091 goto out;
2092 }
2093 }
2094 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002095 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 +02002096 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002097 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002098 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002099 }
2100
2101 /* Redispatch can take an integer argument that control when the
2102 * resispatch occurs. All values are relative to the retries option.
2103 * This can be cancelled using "no option xxx".
2104 */
2105 if (strcmp(args[1], "redispatch") == 0) {
2106 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2107 err_code |= ERR_WARN;
2108 goto out;
2109 }
2110
2111 curproxy->no_options &= ~PR_O_REDISP;
2112 curproxy->options &= ~PR_O_REDISP;
2113
2114 switch (kwm) {
2115 case KWM_STD:
2116 curproxy->options |= PR_O_REDISP;
2117 curproxy->redispatch_after = -1;
2118 if(*args[2]) {
2119 curproxy->redispatch_after = atol(args[2]);
2120 }
2121 break;
2122 case KWM_NO:
2123 curproxy->no_options |= PR_O_REDISP;
2124 curproxy->redispatch_after = 0;
2125 break;
2126 case KWM_DEF: /* already cleared */
2127 break;
2128 }
2129 goto out;
2130 }
2131
Willy Tarreau25241232021-07-18 19:18:56 +02002132 if (strcmp(args[1], "http_proxy") == 0) {
2133 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",
2134 file, linenum, args[1]);
2135 err_code |= ERR_ALERT | ERR_FATAL;
2136 goto out;
2137 }
2138
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002139 if (kwm != KWM_STD) {
2140 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2141 file, linenum, args[1]);
2142 err_code |= ERR_ALERT | ERR_FATAL;
2143 goto out;
2144 }
2145
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002146 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002147 char *logformat;
2148 /* generate a complete HTTP log */
2149 logformat = default_http_log_format;
2150 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002151 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002152 curproxy->options2 |= PR_O2_CLFLOG;
2153 logformat = clf_http_log_format;
2154 } else {
2155 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2156 err_code |= ERR_ALERT | ERR_FATAL;
2157 goto out;
2158 }
2159 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2160 goto out;
2161 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002162 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002163 char *oldlogformat = "log-format";
2164 char *clflogformat = "";
2165
2166 if (curproxy->conf.logformat_string == default_http_log_format)
2167 oldlogformat = "option httplog";
2168 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2169 oldlogformat = "option tcplog";
2170 else if (curproxy->conf.logformat_string == clf_http_log_format)
2171 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002172 else if (curproxy->conf.logformat_string == default_https_log_format)
2173 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002174 if (logformat == clf_http_log_format)
2175 clflogformat = " clf";
2176 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2177 file, linenum, clflogformat, oldlogformat);
2178 }
2179 if (curproxy->conf.logformat_string != default_http_log_format &&
2180 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002181 curproxy->conf.logformat_string != clf_http_log_format &&
2182 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002183 free(curproxy->conf.logformat_string);
2184 curproxy->conf.logformat_string = logformat;
2185
2186 free(curproxy->conf.lfs_file);
2187 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2188 curproxy->conf.lfs_line = curproxy->conf.args.line;
2189
Willy Tarreau5d095c22021-02-12 10:15:59 +01002190 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002191 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2192 file, linenum, curproxy->id);
2193 err_code |= ERR_WARN;
2194 }
2195 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002196 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002197 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002198 char *oldlogformat = "log-format";
2199
2200 if (curproxy->conf.logformat_string == default_http_log_format)
2201 oldlogformat = "option httplog";
2202 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2203 oldlogformat = "option tcplog";
2204 else if (curproxy->conf.logformat_string == clf_http_log_format)
2205 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002206 else if (curproxy->conf.logformat_string == default_https_log_format)
2207 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002208 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2209 file, linenum, oldlogformat);
2210 }
2211 /* generate a detailed TCP log */
2212 if (curproxy->conf.logformat_string != default_http_log_format &&
2213 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002214 curproxy->conf.logformat_string != clf_http_log_format &&
2215 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002216 free(curproxy->conf.logformat_string);
2217 curproxy->conf.logformat_string = default_tcp_log_format;
2218
2219 free(curproxy->conf.lfs_file);
2220 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2221 curproxy->conf.lfs_line = curproxy->conf.args.line;
2222
2223 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2224 goto out;
2225
Willy Tarreau5d095c22021-02-12 10:15:59 +01002226 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002227 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2228 file, linenum, curproxy->id);
2229 err_code |= ERR_WARN;
2230 }
2231 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002232 else if (strcmp(args[1], "httpslog") == 0) {
2233 char *logformat;
2234 /* generate a complete HTTP log */
2235 logformat = default_https_log_format;
2236 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2237 char *oldlogformat = "log-format";
2238
2239 if (curproxy->conf.logformat_string == default_http_log_format)
2240 oldlogformat = "option httplog";
2241 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2242 oldlogformat = "option tcplog";
2243 else if (curproxy->conf.logformat_string == clf_http_log_format)
2244 oldlogformat = "option httplog clf";
2245 else if (curproxy->conf.logformat_string == default_https_log_format)
2246 oldlogformat = "option httpslog";
2247 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2248 file, linenum, oldlogformat);
2249 }
2250 if (curproxy->conf.logformat_string != default_http_log_format &&
2251 curproxy->conf.logformat_string != default_tcp_log_format &&
2252 curproxy->conf.logformat_string != clf_http_log_format &&
2253 curproxy->conf.logformat_string != default_https_log_format)
2254 free(curproxy->conf.logformat_string);
2255 curproxy->conf.logformat_string = logformat;
2256
2257 free(curproxy->conf.lfs_file);
2258 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2259 curproxy->conf.lfs_line = curproxy->conf.args.line;
2260
2261 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2262 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2263 file, linenum, curproxy->id);
2264 err_code |= ERR_WARN;
2265 }
2266 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002267 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002268 /* enable TCP keep-alives on client and server streams */
2269 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2270 err_code |= ERR_WARN;
2271
2272 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2273 goto out;
2274
2275 if (curproxy->cap & PR_CAP_FE)
2276 curproxy->options |= PR_O_TCP_CLI_KA;
2277 if (curproxy->cap & PR_CAP_BE)
2278 curproxy->options |= PR_O_TCP_SRV_KA;
2279 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002280 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002281 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002282 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002283 goto out;
2284 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002285 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002286 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002287 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002288 goto out;
2289 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002290 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002291 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002292 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002293 goto out;
2294 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002295 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002296 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002297 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002298 goto out;
2299 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002300 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002301 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002302 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002303 goto out;
2304 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002305 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002306 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002307 if (err_code & ERR_FATAL)
2308 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002309 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002310 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002311 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002312 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002313 goto out;
2314 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002315 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002316 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002317 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002318 goto out;
2319 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002320 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002321 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002322 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002323 goto out;
2324 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002325 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002326 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002327 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002328 goto out;
2329 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002330 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002331 int cur_arg;
2332
2333 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002334 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002335 */
2336
2337 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2338
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002339 istfree(&curproxy->fwdfor_hdr_name);
2340 curproxy->fwdfor_hdr_name = istdup(ist(DEF_XFORWARDFOR_HDR));
2341 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002342 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002343 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002344
2345 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2346 cur_arg = 2;
2347 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002348 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002349 unsigned char mask;
2350 int i;
2351
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002352 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002353 if (*(args[cur_arg+1]) &&
2354 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2355 curproxy->except_xff_net.family = AF_INET;
2356 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2357 }
2358 else if (*(args[cur_arg+1]) &&
2359 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2360 curproxy->except_xff_net.family = AF_INET6;
2361 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2362 for (i = 0; i < 16; i++)
2363 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2364 }
2365 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002366 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2367 file, linenum, args[0], args[1], args[cur_arg]);
2368 err_code |= ERR_ALERT | ERR_FATAL;
2369 goto out;
2370 }
2371 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002372 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002373 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002374 /* suboption header - needs additional argument for it */
2375 if (*(args[cur_arg+1]) == 0) {
2376 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2377 file, linenum, args[0], args[1], args[cur_arg]);
2378 err_code |= ERR_ALERT | ERR_FATAL;
2379 goto out;
2380 }
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002381 istfree(&curproxy->fwdfor_hdr_name);
2382 curproxy->fwdfor_hdr_name = istdup(ist(args[cur_arg+1]));
2383 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002384 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002385 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002386 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002387 curproxy->options &= ~PR_O_FF_ALWAYS;
2388 cur_arg += 1;
2389 } else {
2390 /* unknown suboption - catchall */
2391 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2392 file, linenum, args[0], args[1]);
2393 err_code |= ERR_ALERT | ERR_FATAL;
2394 goto out;
2395 }
2396 } /* end while loop */
2397 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002398 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002399 int cur_arg;
2400
2401 /* insert x-original-to field, but not for the IP address listed as an except.
2402 * set default options (ie: bitfield, header name, etc)
2403 */
2404
2405 curproxy->options |= PR_O_ORGTO;
2406
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002407 istfree(&curproxy->orgto_hdr_name);
2408 curproxy->orgto_hdr_name = istdup(ist(DEF_XORIGINALTO_HDR));
2409 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002410 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002411 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002412
2413 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2414 cur_arg = 2;
2415 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002416 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002417 unsigned char mask;
2418 int i;
2419
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002420 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002421 if (*(args[cur_arg+1]) &&
2422 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2423 curproxy->except_xot_net.family = AF_INET;
2424 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2425 }
2426 else if (*(args[cur_arg+1]) &&
2427 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2428 curproxy->except_xot_net.family = AF_INET6;
2429 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2430 for (i = 0; i < 16; i++)
2431 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2432 }
2433 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002434 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2435 file, linenum, args[0], args[1], args[cur_arg]);
2436 err_code |= ERR_ALERT | ERR_FATAL;
2437 goto out;
2438 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002439 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002440 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002441 /* suboption header - needs additional argument for it */
2442 if (*(args[cur_arg+1]) == 0) {
2443 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2444 file, linenum, args[0], args[1], args[cur_arg]);
2445 err_code |= ERR_ALERT | ERR_FATAL;
2446 goto out;
2447 }
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002448 istfree(&curproxy->orgto_hdr_name);
2449 curproxy->orgto_hdr_name = istdup(ist(args[cur_arg+1]));
2450 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002451 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002452 cur_arg += 2;
2453 } else {
2454 /* unknown suboption - catchall */
2455 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2456 file, linenum, args[0], args[1]);
2457 err_code |= ERR_ALERT | ERR_FATAL;
2458 goto out;
2459 }
2460 } /* end while loop */
2461 }
2462 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002463 const char *best = proxy_find_best_option(args[1], common_options);
2464
2465 if (best)
2466 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2467 else
2468 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2469
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002470 err_code |= ERR_ALERT | ERR_FATAL;
2471 goto out;
2472 }
2473 goto out;
2474 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002475 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002476 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2477 err_code |= ERR_WARN;
2478
2479 if (*(args[1]) == 0) {
2480 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2481 err_code |= ERR_ALERT | ERR_FATAL;
2482 goto out;
2483 }
2484 free(curproxy->defbe.name);
2485 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002486 if (!curproxy->defbe.name)
2487 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002488
2489 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2490 goto out;
2491 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002492 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002493 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 +01002494
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002495 err_code |= ERR_ALERT | ERR_FATAL;
2496 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002497 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002498 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002499 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2500 err_code |= ERR_WARN;
2501
2502 if (strcmp(args[1], "never") == 0) {
2503 /* enable a graceful server shutdown on an HTTP 404 response */
2504 curproxy->options &= ~PR_O_REUSE_MASK;
2505 curproxy->options |= PR_O_REUSE_NEVR;
2506 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2507 goto out;
2508 }
2509 else if (strcmp(args[1], "safe") == 0) {
2510 /* enable a graceful server shutdown on an HTTP 404 response */
2511 curproxy->options &= ~PR_O_REUSE_MASK;
2512 curproxy->options |= PR_O_REUSE_SAFE;
2513 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2514 goto out;
2515 }
2516 else if (strcmp(args[1], "aggressive") == 0) {
2517 curproxy->options &= ~PR_O_REUSE_MASK;
2518 curproxy->options |= PR_O_REUSE_AGGR;
2519 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2520 goto out;
2521 }
2522 else if (strcmp(args[1], "always") == 0) {
2523 /* enable a graceful server shutdown on an HTTP 404 response */
2524 curproxy->options &= ~PR_O_REUSE_MASK;
2525 curproxy->options |= PR_O_REUSE_ALWS;
2526 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2527 goto out;
2528 }
2529 else {
2530 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2531 err_code |= ERR_ALERT | ERR_FATAL;
2532 goto out;
2533 }
2534 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002535 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002536 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002537 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2538 err_code |= ERR_ALERT | ERR_FATAL;
2539 goto out;
2540 }
2541
2542 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2543 err_code |= ERR_WARN;
2544
2545 if (strcmp(args[1], "fail") == 0) {
2546 /* add a condition to fail monitor requests */
2547 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2548 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2549 file, linenum, args[0], args[1]);
2550 err_code |= ERR_ALERT | ERR_FATAL;
2551 goto out;
2552 }
2553
2554 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2555 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2556 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2557 file, linenum, args[0], args[1], errmsg);
2558 err_code |= ERR_ALERT | ERR_FATAL;
2559 goto out;
2560 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002561 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002562 }
2563 else {
2564 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2565 err_code |= ERR_ALERT | ERR_FATAL;
2566 goto out;
2567 }
2568 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002569#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002570 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002571 /* enable transparent proxy connections */
2572 curproxy->options |= PR_O_TRANSP;
2573 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2574 goto out;
2575 }
2576#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002577 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002578 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2579 err_code |= ERR_WARN;
2580
2581 if (*(args[1]) == 0) {
2582 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2583 err_code |= ERR_ALERT | ERR_FATAL;
2584 goto out;
2585 }
2586 curproxy->maxconn = atol(args[1]);
2587 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2588 goto out;
2589 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002590 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002591 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2592 err_code |= ERR_WARN;
2593
2594 if (*(args[1]) == 0) {
2595 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2596 err_code |= ERR_ALERT | ERR_FATAL;
2597 goto out;
2598 }
2599 curproxy->backlog = atol(args[1]);
2600 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2601 goto out;
2602 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002603 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2605 err_code |= ERR_WARN;
2606
2607 if (*(args[1]) == 0) {
2608 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2609 err_code |= ERR_ALERT | ERR_FATAL;
2610 goto out;
2611 }
2612 curproxy->fullconn = atol(args[1]);
2613 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2614 goto out;
2615 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002616 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002617 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 +02002618 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002619 err_code |= ERR_ALERT | ERR_FATAL;
2620 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002621 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002622 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002623 struct sockaddr_storage *sk;
2624 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002625
Willy Tarreau5d095c22021-02-12 10:15:59 +01002626 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002627 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2628 err_code |= ERR_ALERT | ERR_FATAL;
2629 goto out;
2630 }
2631 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2632 err_code |= ERR_WARN;
2633
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002634 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2635 &errmsg, NULL, NULL,
2636 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 +01002637 if (!sk) {
2638 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2639 err_code |= ERR_ALERT | ERR_FATAL;
2640 goto out;
2641 }
2642
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002643 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2644 goto out;
2645
2646 curproxy->dispatch_addr = *sk;
2647 curproxy->options |= PR_O_DISPATCH;
2648 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002649 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002650 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2651 err_code |= ERR_WARN;
2652
2653 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2654 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2655 err_code |= ERR_ALERT | ERR_FATAL;
2656 goto out;
2657 }
2658 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002659 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002660 /**
2661 * The syntax for hash-type config element is
2662 * hash-type {map-based|consistent} [[<algo>] avalanche]
2663 *
2664 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2665 */
2666 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2667
2668 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2669 err_code |= ERR_WARN;
2670
2671 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2672 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2673 }
2674 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2675 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2676 }
2677 else if (strcmp(args[1], "avalanche") == 0) {
2678 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]);
2679 err_code |= ERR_ALERT | ERR_FATAL;
2680 goto out;
2681 }
2682 else {
2683 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2684 err_code |= ERR_ALERT | ERR_FATAL;
2685 goto out;
2686 }
2687
2688 /* set the hash function to use */
2689 if (!*args[2]) {
2690 /* the default algo is sdbm */
2691 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2692
2693 /* if consistent with no argument, then avalanche modifier is also applied */
2694 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2695 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2696 } else {
2697 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002698 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002699 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2700 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002701 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002702 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002704 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002705 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002707 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002708 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2709 }
2710 else {
2711 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2712 err_code |= ERR_ALERT | ERR_FATAL;
2713 goto out;
2714 }
2715
2716 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002717 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002718 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2719 }
2720 else if (*args[3]) {
2721 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2722 err_code |= ERR_ALERT | ERR_FATAL;
2723 goto out;
2724 }
2725 }
2726 }
2727 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2728 if (*(args[1]) == 0) {
2729 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2730 err_code |= ERR_ALERT | ERR_FATAL;
2731 goto out;
2732 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002733 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2734 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002735 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2736 err_code |= ERR_ALERT | ERR_FATAL;
2737 goto out;
2738 }
2739 }
2740 else if (strcmp(args[0], "unique-id-format") == 0) {
2741 if (!*(args[1])) {
2742 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2743 err_code |= ERR_ALERT | ERR_FATAL;
2744 goto out;
2745 }
2746 if (*(args[2])) {
2747 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2748 err_code |= ERR_ALERT | ERR_FATAL;
2749 goto out;
2750 }
2751 free(curproxy->conf.uniqueid_format_string);
2752 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002753 if (!curproxy->conf.uniqueid_format_string)
2754 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002755
2756 free(curproxy->conf.uif_file);
2757 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2758 curproxy->conf.uif_line = curproxy->conf.args.line;
2759 }
2760
2761 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002762 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002763 if (!*(args[1])) {
2764 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2765 err_code |= ERR_ALERT | ERR_FATAL;
2766 goto out;
2767 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002768 copy = strdup(args[1]);
2769 if (copy == NULL) {
2770 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2771 err_code |= ERR_ALERT | ERR_FATAL;
2772 goto out;
2773 }
2774
2775 istfree(&curproxy->header_unique_id);
2776 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002777 }
2778
2779 else if (strcmp(args[0], "log-format") == 0) {
2780 if (!*(args[1])) {
2781 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2782 err_code |= ERR_ALERT | ERR_FATAL;
2783 goto out;
2784 }
2785 if (*(args[2])) {
2786 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2787 err_code |= ERR_ALERT | ERR_FATAL;
2788 goto out;
2789 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002790 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002791 char *oldlogformat = "log-format";
2792
2793 if (curproxy->conf.logformat_string == default_http_log_format)
2794 oldlogformat = "option httplog";
2795 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2796 oldlogformat = "option tcplog";
2797 else if (curproxy->conf.logformat_string == clf_http_log_format)
2798 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002799 else if (curproxy->conf.logformat_string == default_https_log_format)
2800 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002801 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2802 file, linenum, oldlogformat);
2803 }
2804 if (curproxy->conf.logformat_string != default_http_log_format &&
2805 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002806 curproxy->conf.logformat_string != clf_http_log_format &&
2807 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002808 free(curproxy->conf.logformat_string);
2809 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002810 if (!curproxy->conf.logformat_string)
2811 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002812
2813 free(curproxy->conf.lfs_file);
2814 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2815 curproxy->conf.lfs_line = curproxy->conf.args.line;
2816
2817 /* get a chance to improve log-format error reporting by
2818 * reporting the correct line-number when possible.
2819 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002820 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002821 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2822 file, linenum, curproxy->id);
2823 err_code |= ERR_WARN;
2824 }
2825 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002826 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002827 if (!*(args[1])) {
2828 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2829 err_code |= ERR_ALERT | ERR_FATAL;
2830 goto out;
2831 }
2832 if (*(args[2])) {
2833 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2834 err_code |= ERR_ALERT | ERR_FATAL;
2835 goto out;
2836 }
2837
2838 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2839 free(curproxy->conf.logformat_sd_string);
2840 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002841 if (!curproxy->conf.logformat_sd_string)
2842 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002843
2844 free(curproxy->conf.lfsd_file);
2845 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2846 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2847
2848 /* get a chance to improve log-format-sd error reporting by
2849 * reporting the correct line-number when possible.
2850 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002851 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002852 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2853 file, linenum, curproxy->id);
2854 err_code |= ERR_WARN;
2855 }
2856 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002857 else if (strcmp(args[0], "error-log-format") == 0) {
2858 if (!*(args[1])) {
2859 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2860 err_code |= ERR_ALERT | ERR_FATAL;
2861 goto out;
2862 }
2863 if (*(args[2])) {
2864 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2865 err_code |= ERR_ALERT | ERR_FATAL;
2866 goto out;
2867 }
2868 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2869 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2870 file, linenum);
2871 }
2872 free(curproxy->conf.error_logformat_string);
2873 curproxy->conf.error_logformat_string = strdup(args[1]);
2874 if (!curproxy->conf.error_logformat_string)
2875 goto alloc_error;
2876
2877 free(curproxy->conf.elfs_file);
2878 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2879 curproxy->conf.elfs_line = curproxy->conf.args.line;
2880
2881 /* get a chance to improve log-format error reporting by
2882 * reporting the correct line-number when possible.
2883 */
2884 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2885 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2886 file, linenum, curproxy->id);
2887 err_code |= ERR_WARN;
2888 }
2889 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002890 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002891 if (*(args[1]) == 0) {
2892 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2893 err_code |= ERR_ALERT | ERR_FATAL;
2894 goto out;
2895 }
2896 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002897 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2898 if (b_orig(&curproxy->log_tag) == NULL) {
2899 chunk_destroy(&curproxy->log_tag);
2900 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2901 err_code |= ERR_ALERT | ERR_FATAL;
2902 goto out;
2903 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002904 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002905 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002906 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002907 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2908 err_code |= ERR_ALERT | ERR_FATAL;
2909 goto out;
2910 }
2911 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002912 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002913 int cur_arg;
2914 int port1, port2;
2915 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002916
2917 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2918 err_code |= ERR_WARN;
2919
2920 if (!*args[1]) {
2921 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2922 file, linenum, "source", "usesrc", "interface");
2923 err_code |= ERR_ALERT | ERR_FATAL;
2924 goto out;
2925 }
2926
Christopher Faulet31930372019-07-15 10:16:58 +02002927 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002928 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002929 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002930 curproxy->conn_src.iface_len = 0;
2931
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002932 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2933 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002934 if (!sk) {
2935 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2936 file, linenum, args[0], args[1], errmsg);
2937 err_code |= ERR_ALERT | ERR_FATAL;
2938 goto out;
2939 }
2940
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002941 curproxy->conn_src.source_addr = *sk;
2942 curproxy->conn_src.opts |= CO_SRC_BIND;
2943
2944 cur_arg = 2;
2945 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002946 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002947#if defined(CONFIG_HAP_TRANSPARENT)
2948 if (!*args[cur_arg + 1]) {
2949 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2950 file, linenum, "usesrc");
2951 err_code |= ERR_ALERT | ERR_FATAL;
2952 goto out;
2953 }
2954
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002955 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002956 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2957 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002958 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002959 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2960 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2961 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2962 char *name, *end;
2963
2964 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002965 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002966 name++;
2967
2968 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002969 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002970 end++;
2971
2972 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2973 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002974 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002975 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002976 if (!curproxy->conn_src.bind_hdr_name)
2977 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002978 curproxy->conn_src.bind_hdr_len = end - name;
2979 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2980 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2981 curproxy->conn_src.bind_hdr_occ = -1;
2982
2983 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002984 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002985 end++;
2986 if (*end == ',') {
2987 end++;
2988 name = end;
2989 if (*end == '-')
2990 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002991 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002992 end++;
2993 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2994 }
2995
2996 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2997 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2998 " occurrences values smaller than %d.\n",
2999 file, linenum, MAX_HDR_HISTORY);
3000 err_code |= ERR_ALERT | ERR_FATAL;
3001 goto out;
3002 }
3003 } else {
3004 struct sockaddr_storage *sk;
3005
Willy Tarreau65ec4e32020-09-16 19:17:08 +02003006 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
3007 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003008 if (!sk) {
3009 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
3010 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
3011 err_code |= ERR_ALERT | ERR_FATAL;
3012 goto out;
3013 }
3014
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003015 curproxy->conn_src.tproxy_addr = *sk;
3016 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3017 }
3018 global.last_checks |= LSTCHK_NETADM;
3019#else /* no TPROXY support */
3020 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3021 file, linenum, "usesrc");
3022 err_code |= ERR_ALERT | ERR_FATAL;
3023 goto out;
3024#endif
3025 cur_arg += 2;
3026 continue;
3027 }
3028
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003029 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003030#ifdef SO_BINDTODEVICE
3031 if (!*args[cur_arg + 1]) {
3032 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3033 file, linenum, args[0]);
3034 err_code |= ERR_ALERT | ERR_FATAL;
3035 goto out;
3036 }
3037 free(curproxy->conn_src.iface_name);
3038 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02003039 if (!curproxy->conn_src.iface_name)
3040 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003041 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3042 global.last_checks |= LSTCHK_NETADM;
3043#else
3044 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3045 file, linenum, args[0], args[cur_arg]);
3046 err_code |= ERR_ALERT | ERR_FATAL;
3047 goto out;
3048#endif
3049 cur_arg += 2;
3050 continue;
3051 }
3052 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3053 file, linenum, args[0], "interface", "usesrc");
3054 err_code |= ERR_ALERT | ERR_FATAL;
3055 goto out;
3056 }
3057 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003058 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003059 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3060 file, linenum, "usesrc", "source");
3061 err_code |= ERR_ALERT | ERR_FATAL;
3062 goto out;
3063 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003064 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 +02003065 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003066 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003067 file, linenum, args[0]);
3068 err_code |= ERR_ALERT | ERR_FATAL;
3069 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003071 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003072 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3073 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3074 err_code |= ERR_ALERT | ERR_FATAL;
3075 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003076 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003077 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003078 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3079 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3080 err_code |= ERR_ALERT | ERR_FATAL;
3081 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003082 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003083 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003084 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3085 err_code |= ERR_ALERT | ERR_FATAL;
3086 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003087 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003088 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003089 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3090 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3091 err_code |= ERR_ALERT | ERR_FATAL;
3092 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003093 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003094 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003095 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3096 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3097 err_code |= ERR_ALERT | ERR_FATAL;
3098 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003099 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003100 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003101 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3102 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003105 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003106 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003107 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3108 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3109 err_code |= ERR_ALERT | ERR_FATAL;
3110 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003111 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003112 else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003113 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3114 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3115 err_code |= ERR_ALERT | ERR_FATAL;
3116 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003117 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003118 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003119 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3120 err_code |= ERR_ALERT | ERR_FATAL;
3121 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003123 else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003124 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3125 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3126 err_code |= ERR_ALERT | ERR_FATAL;
3127 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003128 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003129 else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003130 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3131 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3132 err_code |= ERR_ALERT | ERR_FATAL;
3133 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003134 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003135 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003136 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3137 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3138 err_code |= ERR_ALERT | ERR_FATAL;
3139 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003140 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003141 else if (strcmp(args[0], "srvexp") == 0 || strcmp(args[0], "rsprep") == 0) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003142 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3143 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3144 err_code |= ERR_ALERT | ERR_FATAL;
3145 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003147 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003148 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3149 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3150 err_code |= ERR_ALERT | ERR_FATAL;
3151 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003152 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003153 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003154 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3155 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3156 err_code |= ERR_ALERT | ERR_FATAL;
3157 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003158 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003159 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303160 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003161 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3162 err_code |= ERR_ALERT | ERR_FATAL;
3163 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003164 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003165 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003166 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3167 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3168 err_code |= ERR_ALERT | ERR_FATAL;
3169 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003170 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003171 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003172 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3173 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3174 err_code |= ERR_ALERT | ERR_FATAL;
3175 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003176 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003177 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003178 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3179 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3180 err_code |= ERR_ALERT | ERR_FATAL;
3181 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003182 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003183 else {
3184 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003185 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003186 int index;
3187
3188 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3189 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3190 if (kwl->kw[index].section != CFG_LISTEN)
3191 continue;
3192 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003193 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003194 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003195 err_code |= ERR_ALERT | ERR_FATAL;
3196 goto out;
3197 }
3198
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003199 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003200 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003201 if (rc < 0) {
3202 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3203 err_code |= ERR_ALERT | ERR_FATAL;
3204 goto out;
3205 }
3206 else if (rc > 0) {
3207 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3208 err_code |= ERR_WARN;
3209 goto out;
3210 }
3211 goto out;
3212 }
3213 }
3214 }
3215
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003216 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3217 if (best)
3218 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3219 else
3220 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003221 err_code |= ERR_ALERT | ERR_FATAL;
3222 goto out;
3223 }
3224 out:
3225 free(errmsg);
3226 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003227
3228 alloc_error:
3229 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3230 err_code |= ERR_ALERT | ERR_ABORT;
3231 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003232}