blob: 258a3581ca63f62b7c1550ca1a4feaeffeadf2e0 [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",
Willy Tarreau94f763b2022-07-15 17:14:40 +020044 "acl", "dynamic-cookie-key", "cookie", "email-alert",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010045 "persist", "appsession", "load-server-state-from-file",
46 "server-state-file-name", "max-session-srv-conns", "capture",
47 "retries", "http-request", "http-response", "http-after-response",
48 "http-send-name-header", "block", "redirect", "use_backend",
49 "use-server", "force-persist", "ignore-persist", "force-persist",
50 "stick-table", "stick", "stats", "option", "default_backend",
51 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
Willy Tarreaueb778242021-06-11 16:27:10 +020052 "fullconn", "dispatch", "balance", "hash-type",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010053 "hash-balance-factor", "unique-id-format", "unique-id-header",
54 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +020055 "error-log-format",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010056 NULL /* must be last */
57};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010058
Willy Tarreau31a3cea2021-03-15 11:11:55 +010059static const char *common_options[] = {
Willy Tarreau6ba69842021-06-11 16:01:50 +020060 "httpclose", "http-server-close", "http-keep-alive",
Willy Tarreaud2f25372021-06-11 16:06:29 +020061 "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010062 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
63 "mysql-check", "ldap-check", "spop-check", "tcp-check",
64 "external-check", "forwardfor", "original-to",
65 NULL /* must be last */
66};
67
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010068/* Report a warning if a rule is placed after a 'tcp-request session' rule.
69 * Return 1 if the warning has been emitted, otherwise 0.
70 */
71int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
72{
73 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
74 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
75 file, line, arg);
76 return 1;
77 }
78 return 0;
79}
80
81/* Report a warning if a rule is placed after a 'tcp-request content' rule.
82 * Return 1 if the warning has been emitted, otherwise 0.
83 */
84int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
85{
86 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
87 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
88 file, line, arg);
89 return 1;
90 }
91 return 0;
92}
93
94/* Report a warning if a rule is placed after a 'monitor fail' rule.
95 * Return 1 if the warning has been emitted, otherwise 0.
96 */
97int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
98{
99 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
100 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
101 file, line, arg);
102 return 1;
103 }
104 return 0;
105}
106
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100107/* Report a warning if a rule is placed after an 'http_request' rule.
108 * Return 1 if the warning has been emitted, otherwise 0.
109 */
110int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
111{
112 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
113 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
114 file, line, arg);
115 return 1;
116 }
117 return 0;
118}
119
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100120/* Report a warning if a rule is placed after a redirect rule.
121 * Return 1 if the warning has been emitted, otherwise 0.
122 */
123int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
124{
125 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
126 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
127 file, line, arg);
128 return 1;
129 }
130 return 0;
131}
132
133/* Report a warning if a rule is placed after a 'use_backend' rule.
134 * Return 1 if the warning has been emitted, otherwise 0.
135 */
136int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
137{
138 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
139 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
140 file, line, arg);
141 return 1;
142 }
143 return 0;
144}
145
146/* Report a warning if a rule is placed after a 'use-server' rule.
147 * Return 1 if the warning has been emitted, otherwise 0.
148 */
149int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
150{
151 if (!LIST_ISEMPTY(&proxy->server_rules)) {
152 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
153 file, line, arg);
154 return 1;
155 }
156 return 0;
157}
158
159/* report a warning if a redirect rule is dangerously placed */
160int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
161{
162 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
163 warnif_rule_after_use_server(proxy, file, line, arg);
164}
165
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100166/* report a warning if an http-request rule is dangerously placed */
167int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
168{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200169 return warnif_rule_after_redirect(proxy, file, line, arg) ||
170 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100171}
172
173/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200174int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100175{
176 return warnif_rule_after_http_req(proxy, file, line, arg) ||
177 warnif_misplaced_http_req(proxy, file, line, arg);
178}
179
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100180/* report a warning if a "tcp request content" rule is dangerously placed */
181int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
182{
183 return warnif_rule_after_monitor(proxy, file, line, arg) ||
184 warnif_misplaced_monitor(proxy, file, line, arg);
185}
186
187/* report a warning if a "tcp request session" rule is dangerously placed */
188int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
189{
190 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
191 warnif_misplaced_tcp_cont(proxy, file, line, arg);
192}
193
194/* report a warning if a "tcp request connection" rule is dangerously placed */
195int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
196{
197 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
198 warnif_misplaced_tcp_sess(proxy, file, line, arg);
199}
200
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100201int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
202{
203 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100204 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100205 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100206 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 int rc;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100208 int err_code = 0;
209 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100210 char *errmsg = NULL;
211 struct bind_conf *bind_conf;
212
Willy Tarreaue90904d2021-02-12 14:08:31 +0100213 if (!last_defproxy) {
214 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100215 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
216 proxy_preset_defaults(last_defproxy);
217
Willy Tarreaue90904d2021-02-12 14:08:31 +0100218 curr_defproxy = last_defproxy;
219 if (!last_defproxy) {
220 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
221 err_code |= ERR_ALERT | ERR_ABORT;
222 goto out;
223 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100224 }
225
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100226 if (strcmp(args[0], "listen") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200227 rc = PR_CAP_LISTEN | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100228 else if (strcmp(args[0], "frontend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200229 rc = PR_CAP_FE | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100230 else if (strcmp(args[0], "backend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200231 rc = PR_CAP_BE | PR_CAP_LB;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100232 else if (strcmp(args[0], "defaults") == 0) {
233 /* "defaults" must first delete the last no-name defaults if any */
Willy Tarreaue90904d2021-02-12 14:08:31 +0100234 curr_defproxy = NULL;
235 rc = PR_CAP_DEF | PR_CAP_LISTEN;
236 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100237 else
238 rc = PR_CAP_NONE;
239
Willy Tarreaue90904d2021-02-12 14:08:31 +0100240 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100241 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100242 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100243 file, linenum, args[0]);
244 err_code |= ERR_ALERT | ERR_ABORT;
245 goto out;
246 }
247
248 err = invalid_char(args[1]);
249 if (err) {
250 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
251 file, linenum, *err, args[0], args[1]);
252 err_code |= ERR_ALERT | ERR_FATAL;
253 }
254
255 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
256 if (curproxy) {
257 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
258 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
259 curproxy->id, curproxy->conf.file, curproxy->conf.line);
260 err_code |= ERR_ALERT | ERR_FATAL;
261 }
262
Emeric Brunb0c331f2020-10-07 17:05:59 +0200263 curproxy = log_forward_by_name(args[1]);
264 if (curproxy) {
265 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
266 file, linenum, proxy_cap_str(rc), args[1],
267 curproxy->id, curproxy->conf.file, curproxy->conf.line);
268 err_code |= ERR_ALERT | ERR_FATAL;
269 }
270
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100271 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
272 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100273 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100274 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
275 goto out;
276 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100277 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100278
Willy Tarreaue90904d2021-02-12 14:08:31 +0100279 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100280 const char *name = args[1];
281 int arg = 2;
282
283 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
284 // also support "defaults from blah" (no name then)
285 arg = 1;
286 name = "";
287 }
288
289 /* only regular proxies inherit from the previous defaults section */
290 if (!(rc & PR_CAP_DEF))
291 curr_defproxy = last_defproxy;
292
293 if (strcmp(args[arg], "from") == 0) {
294 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
295
296 if (!curr_defproxy) {
297 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
298 err_code |= ERR_ALERT | ERR_ABORT;
299 goto out;
300 }
301
302 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
303 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
304
305 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
306 file, linenum, args[arg+1], proxy_cap_str(rc), name,
307 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
308 err_code |= ERR_ALERT | ERR_FATAL;
309 }
310
311 err = invalid_char(args[arg+1]);
312 if (err) {
313 ha_alert("parsing [%s:%d] : character '%c' is not permitted in defaults section name '%s' when designated by its name (section found at %s:%d).\n",
314 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
315 err_code |= ERR_ALERT | ERR_FATAL;
316 }
Christopher Fauletb4054202021-10-12 18:57:43 +0200317 curr_defproxy->flags |= PR_FL_EXPLICIT_REF;
318 }
319 else if (curr_defproxy)
320 curr_defproxy->flags |= PR_FL_IMPLICIT_REF;
321
322 if (curr_defproxy && (curr_defproxy->flags & (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) == (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) {
323 ha_alert("parsing [%s:%d] : defaults section '%s' (declared at %s:%d) is explicitly referenced by another proxy and implicitly used here."
324 " To avoid any ambiguity don't mix both usage. Add a last defaults section not explicitly used or always use explicit references.\n",
325 file, linenum, curr_defproxy->id, curr_defproxy->conf.file, curr_defproxy->conf.line);
326 err_code |= ERR_WARN;
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100327 }
328
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100329 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100330 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100331 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100332 goto out;
333 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100334
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200335 if (curr_defproxy && (!LIST_ISEMPTY(&curr_defproxy->http_req_rules) ||
336 !LIST_ISEMPTY(&curr_defproxy->http_res_rules) ||
337 !LIST_ISEMPTY(&curr_defproxy->http_after_res_rules) ||
338 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
339 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules) ||
340 !LIST_ISEMPTY(&curr_defproxy->tcp_req.inspect_rules) ||
341 !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules))) {
342 /* If the current default proxy defines TCP/HTTP rules, the
343 * current proxy will keep a reference on it. But some sanity
344 * checks are performed first:
345 *
346 * - It cannot be used to init a defaults section
347 * - It cannot be used to init a listen section
348 * - It cannot be used to init backend and frontend sections at
349 * same time. It can be used to init several sections of the
350 * same type only.
351 * - It cannot define L4/L5 TCP rules if it is used to init
352 * backend sections.
353 * - It cannot define 'tcp-response content' rules if it
354 * is used to init frontend sections.
355 *
356 * If no error is found, refcount of the default proxy is incremented.
357 */
358
359 /* Note: Add tcpcheck_rules too if unresolve args become allowed in defaults section */
360 if (rc & PR_CAP_DEF) {
361 ha_alert("parsing [%s:%d]: a defaults section cannot inherit from a defaults section defining TCP/HTTP rules (defaults section at %s:%d).\n",
362 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
363 err_code |= ERR_ALERT | ERR_ABORT;
364 }
365 else if ((rc & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
366 ha_alert("parsing [%s:%d]: a listen section cannot inherit from a defaults section defining TCP/HTTP rules.\n",
367 file, linenum);
368 err_code |= ERR_ALERT | ERR_ABORT;
369 }
370 else {
371 char defcap = (curr_defproxy->cap & PR_CAP_LISTEN);
372
373 if ((defcap == PR_CAP_BE || defcap == PR_CAP_FE) && (rc & PR_CAP_LISTEN) != defcap) {
374 ha_alert("parsing [%s:%d]: frontends and backends cannot inherit from the same defaults section"
375 " if it defines TCP/HTTP rules (defaults section at %s:%d).\n",
376 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
377 err_code |= ERR_ALERT | ERR_ABORT;
378 }
379 else if (!(rc & PR_CAP_FE) && (!LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
380 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules))) {
381 ha_alert("parsing [%s:%d]: a backend section cannot inherit from a defaults section defining"
382 " 'tcp-request connection' or 'tcp-request session' rules (defaults section at %s:%d).\n",
383 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
384 err_code |= ERR_ALERT | ERR_ABORT;
385 }
386 else if (!(rc & PR_CAP_BE) && !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules)) {
387 ha_alert("parsing [%s:%d]: a frontend section cannot inherit from a defaults section defining"
388 " 'tcp-response content' rules (defaults section at %s:%d).\n",
389 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
390 err_code |= ERR_ALERT | ERR_ABORT;
391 }
392 else {
393 curr_defproxy->cap = (curr_defproxy->cap & ~PR_CAP_LISTEN) | (rc & PR_CAP_LISTEN);
394 proxy_ref_defaults(curproxy, curr_defproxy);
395 }
396 }
397 }
398
Christopher Faulet6ff7de52021-10-13 15:18:36 +0200399 if (curr_defproxy && (curr_defproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) &&
400 (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_BE) {
401 /* If the current default proxy defines tcpcheck rules, the
402 * current proxy will keep a reference on it. but only if the
403 * current proxy has the backend capability.
404 */
405 proxy_ref_defaults(curproxy, curr_defproxy);
406 }
407
Christopher Faulet6c10f5c2022-04-25 14:24:56 +0200408 if ((rc & PR_CAP_BE) && curr_defproxy && (curr_defproxy->nb_req_cap || curr_defproxy->nb_rsp_cap)) {
409 ha_alert("parsing [%s:%d]: backend or defaults sections cannot inherit from a defaults section defining"
410 " capptures (defaults section at %s:%d).\n",
411 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
412 err_code |= ERR_ALERT | ERR_ABORT;
413 }
414
Willy Tarreaue90904d2021-02-12 14:08:31 +0100415 if (rc & PR_CAP_DEF) {
416 /* last and current proxies must be updated to this one */
417 curr_defproxy = last_defproxy = curproxy;
418 } else {
419 /* regular proxies are in a list */
420 curproxy->next = proxies_list;
421 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100422 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100423 goto out;
424 }
425 else if (curproxy == NULL) {
426 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
427 err_code |= ERR_ALERT | ERR_FATAL;
428 goto out;
429 }
430
431 /* update the current file and line being parsed */
432 curproxy->conf.args.file = curproxy->conf.file;
433 curproxy->conf.args.line = linenum;
434
435 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100436 if ((strcmp(args[0], "server") == 0)) {
437 err_code |= parse_server(file, linenum, args,
438 curproxy, curr_defproxy,
439 SRV_PARSE_PARSE_ADDR);
440
441 if (err_code & ERR_FATAL)
442 goto out;
443 }
444 else if (strcmp(args[0], "default-server") == 0) {
445 err_code |= parse_server(file, linenum, args,
446 curproxy, curr_defproxy,
447 SRV_PARSE_DEFAULT_SERVER);
448
449 if (err_code & ERR_FATAL)
450 goto out;
451 }
452 else if (strcmp(args[0], "server-template") == 0) {
453 err_code |= parse_server(file, linenum, args,
454 curproxy, curr_defproxy,
455 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
456
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100457 if (err_code & ERR_FATAL)
458 goto out;
459 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100460 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100461 struct listener *l;
462 int cur_arg;
463
Willy Tarreau5d095c22021-02-12 10:15:59 +0100464 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100465 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
466 err_code |= ERR_ALERT | ERR_FATAL;
467 goto out;
468 }
469 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
470 err_code |= ERR_WARN;
471
472 if (!*(args[1])) {
473 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
474 file, linenum, args[0]);
475 err_code |= ERR_ALERT | ERR_FATAL;
476 goto out;
477 }
478
479 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200480 if (!bind_conf)
481 goto alloc_error;
482
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100483 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200484 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
485 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
486 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100487
488 /* NOTE: the following line might create several listeners if there
489 * are comma-separated IPs or port ranges. So all further processing
490 * will have to be applied to all listeners created after last_listen.
491 */
492 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
493 if (errmsg && *errmsg) {
494 indent_msg(&errmsg, 2);
495 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
496 }
497 else
498 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
499 file, linenum, args[0], args[1]);
500 err_code |= ERR_ALERT | ERR_FATAL;
501 goto out;
502 }
503
504 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
505 /* Set default global rights and owner for unix bind */
506 global.maxsock++;
507 }
508
509 cur_arg = 2;
Willy Tarreau55f0f7b2022-05-20 15:44:17 +0200510 err_code |= bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100511 goto out;
512 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100513 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200514 ha_alert("parsing [%s:%d] : 'monitor-net' doesn't exist anymore. Please use 'http-request return status 200 if { src %s }' instead.\n", file, linenum, args[1]);
515 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100516 goto out;
517 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100518 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100519 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
520 err_code |= ERR_WARN;
521
522 if (alertif_too_many_args(1, file, linenum, args, &err_code))
523 goto out;
524
525 if (!*args[1]) {
526 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
527 file, linenum, args[0]);
528 err_code |= ERR_ALERT | ERR_FATAL;
529 goto out;
530 }
531
Tim Duesterhus4b1fcaa2022-03-05 00:52:40 +0100532 istfree(&curproxy->monitor_uri);
533 curproxy->monitor_uri = istdup(ist(args[1]));
534 if (!isttest(curproxy->monitor_uri))
Christopher Fauletb15625a2021-04-12 21:31:45 +0200535 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100536
537 goto out;
538 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100539 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100540 if (alertif_too_many_args(1, file, linenum, args, &err_code))
541 goto out;
542
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100543 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
544 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
545 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200546 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
547 err_code |= ERR_ALERT | ERR_FATAL;
548 goto out;
549 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100550 else {
551 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
552 err_code |= ERR_ALERT | ERR_FATAL;
553 goto out;
554 }
555 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100556 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100557 struct eb32_node *node;
558
Willy Tarreau5d095c22021-02-12 10:15:59 +0100559 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100560 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
561 file, linenum, args[0]);
562 err_code |= ERR_ALERT | ERR_FATAL;
563 goto out;
564 }
565
566 if (alertif_too_many_args(1, file, linenum, args, &err_code))
567 goto out;
568
569 if (!*args[1]) {
570 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
571 file, linenum, args[0]);
572 err_code |= ERR_ALERT | ERR_FATAL;
573 goto out;
574 }
575
576 curproxy->uuid = atol(args[1]);
577 curproxy->conf.id.key = curproxy->uuid;
578 curproxy->options |= PR_O_FORCED_ID;
579
580 if (curproxy->uuid <= 0) {
581 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
582 file, linenum);
583 err_code |= ERR_ALERT | ERR_FATAL;
584 goto out;
585 }
586
587 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
588 if (node) {
589 struct proxy *target = container_of(node, struct proxy, conf.id);
590 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
591 file, linenum, proxy_type_str(curproxy), curproxy->id,
592 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
593 err_code |= ERR_ALERT | ERR_FATAL;
594 goto out;
595 }
596 eb32_insert(&used_proxy_id, &curproxy->conf.id);
597 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100598 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100599 int i, len=0;
600 char *d;
601
Willy Tarreau5d095c22021-02-12 10:15:59 +0100602 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100603 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
604 file, linenum, args[0]);
605 err_code |= ERR_ALERT | ERR_FATAL;
606 goto out;
607 }
608
609 if (!*args[1]) {
610 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
611 file, linenum, args[0]);
612 return -1;
613 }
614
615 for (i = 1; *args[i]; i++)
616 len += strlen(args[i]) + 1;
617
618 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200619 if (!d)
620 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100621 curproxy->desc = d;
622
623 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
624 for (i = 2; *args[i]; i++)
625 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
626
627 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100628 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100629 if (alertif_too_many_args(0, file, linenum, args, &err_code))
630 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200631 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100632 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100633 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100634 if (alertif_too_many_args(0, file, linenum, args, &err_code))
635 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200636 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100637 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100638 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau94f763b2022-07-15 17:14:40 +0200639 ha_alert("parsing [%s:%d]: '%s' is not supported anymore.\n", file, linenum, args[0]);
640 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100641 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100642 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200643 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
644 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100645 err_code |= ERR_ALERT | ERR_FATAL;
646 goto out;
647 }
648
649 err = invalid_char(args[1]);
650 if (err) {
651 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
652 file, linenum, *err, args[1]);
653 err_code |= ERR_ALERT | ERR_FATAL;
654 goto out;
655 }
656
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100657 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100658 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100659 "logical disjunction within a condition.\n",
660 file, linenum, args[1]);
661 err_code |= ERR_ALERT | ERR_FATAL;
662 goto out;
663 }
664
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100665 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
666 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
667 file, linenum, args[1], errmsg);
668 err_code |= ERR_ALERT | ERR_FATAL;
669 goto out;
670 }
671 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100672 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100673
674 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
675 err_code |= ERR_WARN;
676
677 if (*(args[1]) == 0) {
678 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
679 file, linenum, args[0]);
680 err_code |= ERR_ALERT | ERR_FATAL;
681 goto out;
682 }
683 free(curproxy->dyncookie_key);
684 curproxy->dyncookie_key = strdup(args[1]);
685 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100686 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100687 int cur_arg;
688
689 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
690 err_code |= ERR_WARN;
691
692 if (*(args[1]) == 0) {
693 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
694 file, linenum, args[0]);
695 err_code |= ERR_ALERT | ERR_FATAL;
696 goto out;
697 }
698
699 curproxy->ck_opts = 0;
700 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100701 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100702 free(curproxy->cookie_name);
703 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200704 if (!curproxy->cookie_name)
705 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100706 curproxy->cookie_len = strlen(curproxy->cookie_name);
707
708 cur_arg = 2;
709 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100710 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100711 curproxy->ck_opts |= PR_CK_RW;
712 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100713 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100714 curproxy->ck_opts |= PR_CK_IND;
715 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100716 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100717 curproxy->ck_opts |= PR_CK_INS;
718 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100719 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100720 curproxy->ck_opts |= PR_CK_NOC;
721 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100722 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100723 curproxy->ck_opts |= PR_CK_POST;
724 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100725 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100726 curproxy->ck_opts |= PR_CK_PSV;
727 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100728 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100729 curproxy->ck_opts |= PR_CK_PFX;
730 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100731 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100732 curproxy->ck_opts |= PR_CK_HTTPONLY;
733 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100734 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100735 curproxy->ck_opts |= PR_CK_SECURE;
736 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100737 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100738 if (!*args[cur_arg + 1]) {
739 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
740 file, linenum, args[cur_arg]);
741 err_code |= ERR_ALERT | ERR_FATAL;
742 goto out;
743 }
744
Joao Moraise1583752019-10-30 21:04:00 -0300745 if (!strchr(args[cur_arg + 1], '.')) {
746 /* rfc6265, 5.2.3 The Domain Attribute */
747 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
748 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100749 file, linenum, args[cur_arg + 1]);
750 err_code |= ERR_WARN;
751 }
752
753 err = invalid_domainchar(args[cur_arg + 1]);
754 if (err) {
755 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
756 file, linenum, *err, args[cur_arg + 1]);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760
761 if (!curproxy->cookie_domain) {
762 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
763 } else {
764 /* one domain was already specified, add another one by
765 * building the string which will be returned along with
766 * the cookie.
767 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200768 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
769 }
770
Christopher Fauletb15625a2021-04-12 21:31:45 +0200771 if (!curproxy->cookie_domain)
772 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100773 cur_arg++;
774 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100775 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100776 unsigned int maxidle;
777 const char *res;
778
779 if (!*args[cur_arg + 1]) {
780 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
781 file, linenum, args[cur_arg]);
782 err_code |= ERR_ALERT | ERR_FATAL;
783 goto out;
784 }
785
786 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200787 if (res == PARSE_TIME_OVER) {
788 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
789 file, linenum, args[cur_arg+1], args[cur_arg]);
790 err_code |= ERR_ALERT | ERR_FATAL;
791 goto out;
792 }
793 else if (res == PARSE_TIME_UNDER) {
794 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
795 file, linenum, args[cur_arg+1], args[cur_arg]);
796 err_code |= ERR_ALERT | ERR_FATAL;
797 goto out;
798 }
799 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100800 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
801 file, linenum, *res, args[cur_arg]);
802 err_code |= ERR_ALERT | ERR_FATAL;
803 goto out;
804 }
805 curproxy->cookie_maxidle = maxidle;
806 cur_arg++;
807 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100808 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100809 unsigned int maxlife;
810 const char *res;
811
812 if (!*args[cur_arg + 1]) {
813 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
814 file, linenum, args[cur_arg]);
815 err_code |= ERR_ALERT | ERR_FATAL;
816 goto out;
817 }
818
Willy Tarreau9faebe32019-06-07 19:00:37 +0200819
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100820 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200821 if (res == PARSE_TIME_OVER) {
822 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
823 file, linenum, args[cur_arg+1], args[cur_arg]);
824 err_code |= ERR_ALERT | ERR_FATAL;
825 goto out;
826 }
827 else if (res == PARSE_TIME_UNDER) {
828 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
829 file, linenum, args[cur_arg+1], args[cur_arg]);
830 err_code |= ERR_ALERT | ERR_FATAL;
831 goto out;
832 }
833 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100834 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
835 file, linenum, *res, args[cur_arg]);
836 err_code |= ERR_ALERT | ERR_FATAL;
837 goto out;
838 }
839 curproxy->cookie_maxlife = maxlife;
840 cur_arg++;
841 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100842 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100843
844 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
845 err_code |= ERR_WARN;
846 curproxy->ck_opts |= PR_CK_DYNAMIC;
847 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100848 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100849 char *val;
850 if (!*args[cur_arg + 1]) {
851 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
852 file, linenum, args[cur_arg]);
853 err_code |= ERR_ALERT | ERR_FATAL;
854 goto out;
855 }
856 val = args[cur_arg + 1];
857 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100858 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100859 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
860 file, linenum, *val);
861 err_code |= ERR_ALERT | ERR_FATAL;
862 goto out;
863 }
864 val++;
865 }
866 /* don't add ';' for the first attribute */
867 if (!curproxy->cookie_attrs)
868 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
869 else
870 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200871
Christopher Fauletb15625a2021-04-12 21:31:45 +0200872 if (!curproxy->cookie_attrs)
873 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100874 cur_arg++;
875 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100876
877 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100878 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 +0100879 file, linenum, args[0]);
880 err_code |= ERR_ALERT | ERR_FATAL;
881 goto out;
882 }
883 cur_arg++;
884 }
885 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
886 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
887 file, linenum);
888 err_code |= ERR_ALERT | ERR_FATAL;
889 }
890
891 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
892 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
893 file, linenum);
894 err_code |= ERR_ALERT | ERR_FATAL;
895 }
896
897 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
898 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
899 file, linenum);
900 err_code |= ERR_ALERT | ERR_FATAL;
901 }
902 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100903 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100904 if (*(args[1]) == 0) {
905 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
906 file, linenum, args[0]);
907 err_code |= ERR_ALERT | ERR_FATAL;
908 goto out;
909 }
910
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100911 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100912 if (*(args[1]) == 0) {
913 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
914 file, linenum, args[1]);
915 err_code |= ERR_ALERT | ERR_FATAL;
916 goto out;
917 }
918 free(curproxy->email_alert.from);
919 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200920 if (!curproxy->email_alert.from)
921 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100922 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100923 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100924 if (*(args[1]) == 0) {
925 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
926 file, linenum, args[1]);
927 err_code |= ERR_ALERT | ERR_FATAL;
928 goto out;
929 }
930 free(curproxy->email_alert.mailers.name);
931 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200932 if (!curproxy->email_alert.mailers.name)
933 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100934 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100935 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100936 if (*(args[1]) == 0) {
937 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
938 file, linenum, args[1]);
939 err_code |= ERR_ALERT | ERR_FATAL;
940 goto out;
941 }
942 free(curproxy->email_alert.myhostname);
943 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200944 if (!curproxy->email_alert.myhostname)
945 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100946 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100947 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100948 curproxy->email_alert.level = get_log_level(args[2]);
949 if (curproxy->email_alert.level < 0) {
950 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
951 file, linenum, args[1], args[2]);
952 err_code |= ERR_ALERT | ERR_FATAL;
953 goto out;
954 }
955 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100956 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100957 if (*(args[1]) == 0) {
958 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
959 file, linenum, args[1]);
960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
962 }
963 free(curproxy->email_alert.to);
964 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200965 if (!curproxy->email_alert.to)
966 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100967 }
968 else {
969 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
970 file, linenum, args[1]);
971 err_code |= ERR_ALERT | ERR_FATAL;
972 goto out;
973 }
974 /* Indicate that the email_alert is at least partially configured */
975 curproxy->email_alert.set = 1;
976 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100977 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100978 if (*(args[1]) == 0) {
979 ha_alert("parsing [%s:%d] : missing persist method.\n",
980 file, linenum);
981 err_code |= ERR_ALERT | ERR_FATAL;
982 goto out;
983 }
984
985 if (!strncmp(args[1], "rdp-cookie", 10)) {
986 curproxy->options2 |= PR_O2_RDPC_PRST;
987
988 if (*(args[1] + 10) == '(') { /* cookie name */
989 const char *beg, *end;
990
991 beg = args[1] + 11;
992 end = strchr(beg, ')');
993
994 if (alertif_too_many_args(1, file, linenum, args, &err_code))
995 goto out;
996
997 if (!end || end == beg) {
998 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
999 file, linenum);
1000 err_code |= ERR_ALERT | ERR_FATAL;
1001 goto out;
1002 }
1003
1004 free(curproxy->rdp_cookie_name);
1005 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001006 if (!curproxy->rdp_cookie_name)
1007 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001008 curproxy->rdp_cookie_len = end-beg;
1009 }
1010 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1011 free(curproxy->rdp_cookie_name);
1012 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +02001013 if (!curproxy->rdp_cookie_name)
1014 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001015 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1016 }
1017 else { /* syntax */
1018 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1019 file, linenum);
1020 err_code |= ERR_ALERT | ERR_FATAL;
1021 goto out;
1022 }
1023 }
1024 else {
1025 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1026 file, linenum);
1027 err_code |= ERR_ALERT | ERR_FATAL;
1028 goto out;
1029 }
1030 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001031 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001032 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 +01001033 err_code |= ERR_ALERT | ERR_FATAL;
1034 goto out;
1035 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001036 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001037 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1038 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001039 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001040 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1041 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001042 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 +01001043 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1044 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001045 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001046 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1047 }
1048 else {
1049 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1050 file, linenum, args[0], args[1]);
1051 err_code |= ERR_ALERT | ERR_FATAL;
1052 goto out;
1053 }
1054 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001055 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001056 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1057 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001058 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001059 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001060
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001061 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001062
1063 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001064 curproxy->server_state_file_name = strdup(curproxy->id);
1065 else
1066 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001067
Christopher Fauletb15625a2021-04-12 21:31:45 +02001068 if (!curproxy->server_state_file_name)
1069 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001071 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001072 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1073 err_code |= ERR_WARN;
1074 if (*(args[1]) == 0) {
1075 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1076 file, linenum, args[0]);
1077 err_code |= ERR_ALERT | ERR_FATAL;
1078 goto out;
1079 }
1080 curproxy->max_out_conns = atoi(args[1]);
1081 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001082 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001083 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1084 err_code |= ERR_WARN;
1085
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001086 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001087 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001088 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1089 err_code |= ERR_ALERT | ERR_FATAL;
1090 goto out;
1091 }
1092
1093 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1094 goto out;
1095
1096 if (*(args[4]) == 0) {
1097 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1098 file, linenum, args[0]);
1099 err_code |= ERR_ALERT | ERR_FATAL;
1100 goto out;
1101 }
1102 free(curproxy->capture_name);
1103 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001104 if (!curproxy->capture_name)
1105 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001106 curproxy->capture_namelen = strlen(curproxy->capture_name);
1107 curproxy->capture_len = atol(args[4]);
1108 curproxy->to_log |= LW_COOKIE;
1109 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001110 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001111 struct cap_hdr *hdr;
1112
Willy Tarreau5d095c22021-02-12 10:15:59 +01001113 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001114 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1115 err_code |= ERR_ALERT | ERR_FATAL;
1116 goto out;
1117 }
1118
1119 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1120 goto out;
1121
1122 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1123 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1124 file, linenum, args[0], args[1]);
1125 err_code |= ERR_ALERT | ERR_FATAL;
1126 goto out;
1127 }
1128
1129 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001130 if (!hdr)
1131 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001132 hdr->next = curproxy->req_cap;
1133 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001134 if (!hdr->name)
1135 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001136 hdr->namelen = strlen(args[3]);
1137 hdr->len = atol(args[5]);
1138 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001139 if (!hdr->pool) {
1140 req_caphdr_alloc_error:
1141 if (hdr)
1142 ha_free(&hdr->name);
1143 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001144 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001145 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001146 hdr->index = curproxy->nb_req_cap++;
1147 curproxy->req_cap = hdr;
1148 curproxy->to_log |= LW_REQHDR;
1149 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001150 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001151 struct cap_hdr *hdr;
1152
Willy Tarreau5d095c22021-02-12 10:15:59 +01001153 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001154 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1155 err_code |= ERR_ALERT | ERR_FATAL;
1156 goto out;
1157 }
1158
1159 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1160 goto out;
1161
1162 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1163 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1164 file, linenum, args[0], args[1]);
1165 err_code |= ERR_ALERT | ERR_FATAL;
1166 goto out;
1167 }
1168 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001169 if (!hdr)
1170 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001171 hdr->next = curproxy->rsp_cap;
1172 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001173 if (!hdr->name)
1174 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001175 hdr->namelen = strlen(args[3]);
1176 hdr->len = atol(args[5]);
1177 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001178 if (!hdr->pool) {
1179 res_caphdr_alloc_error:
1180 if (hdr)
1181 ha_free(&hdr->name);
1182 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001183 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001184 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001185 hdr->index = curproxy->nb_rsp_cap++;
1186 curproxy->rsp_cap = hdr;
1187 curproxy->to_log |= LW_RSPHDR;
1188 }
1189 else {
1190 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1191 file, linenum, args[0]);
1192 err_code |= ERR_ALERT | ERR_FATAL;
1193 goto out;
1194 }
1195 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001196 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001197 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1198 err_code |= ERR_WARN;
1199
1200 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1201 goto out;
1202
1203 if (*(args[1]) == 0) {
1204 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1205 file, linenum, args[0]);
1206 err_code |= ERR_ALERT | ERR_FATAL;
1207 goto out;
1208 }
1209 curproxy->conn_retries = atol(args[1]);
1210 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001211 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001212 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001213 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001214
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001215 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1216 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001217 err_code |= ERR_ALERT | ERR_FATAL;
1218 goto out;
1219 }
1220
1221 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1222 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001223 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001224 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1225 file, linenum, args[0]);
1226 err_code |= ERR_WARN;
1227 }
1228
1229 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1230
1231 if (!rule) {
1232 err_code |= ERR_ALERT | ERR_ABORT;
1233 goto out;
1234 }
1235
1236 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001237
1238 if (curproxy->cap & PR_CAP_FE)
1239 where |= SMP_VAL_FE_HRQ_HDR;
1240 if (curproxy->cap & PR_CAP_BE)
1241 where |= SMP_VAL_BE_HRQ_HDR;
1242 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001243
Willy Tarreau2b718102021-04-21 07:32:39 +02001244 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001245 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001246 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001247 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001248 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001249
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001250 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1251 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001252 err_code |= ERR_ALERT | ERR_FATAL;
1253 goto out;
1254 }
1255
1256 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1257 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001258 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001259 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1260 file, linenum, args[0]);
1261 err_code |= ERR_WARN;
1262 }
1263
1264 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1265
1266 if (!rule) {
1267 err_code |= ERR_ALERT | ERR_ABORT;
1268 goto out;
1269 }
1270
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001271 if (curproxy->cap & PR_CAP_FE)
1272 where |= SMP_VAL_FE_HRS_HDR;
1273 if (curproxy->cap & PR_CAP_BE)
1274 where |= SMP_VAL_BE_HRS_HDR;
1275 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001276
Willy Tarreau2b718102021-04-21 07:32:39 +02001277 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001278 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001279 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001280 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001281 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001282 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1283 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001284 err_code |= ERR_ALERT | ERR_FATAL;
1285 goto out;
1286 }
1287
1288 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1289 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1290 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1291 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1292 file, linenum, args[0]);
1293 err_code |= ERR_WARN;
1294 }
1295
1296 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1297
1298 if (!rule) {
1299 err_code |= ERR_ALERT | ERR_ABORT;
1300 goto out;
1301 }
1302
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001303 if (curproxy->cap & PR_CAP_FE)
1304 where |= SMP_VAL_FE_HRS_HDR;
1305 if (curproxy->cap & PR_CAP_BE)
1306 where |= SMP_VAL_BE_HRS_HDR;
1307 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001308
Willy Tarreau2b718102021-04-21 07:32:39 +02001309 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001310 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001311 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001312 /* set the header name and length into the proxy structure */
1313 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1314 err_code |= ERR_WARN;
1315
1316 if (!*args[1]) {
1317 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1318 file, linenum, args[0]);
1319 err_code |= ERR_ALERT | ERR_FATAL;
1320 goto out;
1321 }
1322
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001323 /* set the desired header name, in lower case */
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001324 istfree(&curproxy->server_id_hdr_name);
1325 curproxy->server_id_hdr_name = istdup(ist(args[1]));
1326 if (!isttest(curproxy->server_id_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02001327 goto alloc_error;
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001328 ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001329 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001330 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001331 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 +01001332
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001333 err_code |= ERR_ALERT | ERR_FATAL;
1334 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001335 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001336 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001337 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001338 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001339
Willy Tarreau5d095c22021-02-12 10:15:59 +01001340 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001341 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1342 err_code |= ERR_ALERT | ERR_FATAL;
1343 goto out;
1344 }
1345
1346 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1347 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1348 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1349 err_code |= ERR_ALERT | ERR_FATAL;
1350 goto out;
1351 }
1352
Willy Tarreau2b718102021-04-21 07:32:39 +02001353 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001354 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001355
1356 if (curproxy->cap & PR_CAP_FE)
1357 where |= SMP_VAL_FE_HRQ_HDR;
1358 if (curproxy->cap & PR_CAP_BE)
1359 where |= SMP_VAL_BE_HRQ_HDR;
1360 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001361 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001362 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001363 struct switching_rule *rule;
1364
Willy Tarreau5d095c22021-02-12 10:15:59 +01001365 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001366 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1367 err_code |= ERR_ALERT | ERR_FATAL;
1368 goto out;
1369 }
1370
1371 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1372 err_code |= ERR_WARN;
1373
1374 if (*(args[1]) == 0) {
1375 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1376 err_code |= ERR_ALERT | ERR_FATAL;
1377 goto out;
1378 }
1379
1380 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1381 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1382 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1383 file, linenum, errmsg);
1384 err_code |= ERR_ALERT | ERR_FATAL;
1385 goto out;
1386 }
1387
1388 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1389 }
1390 else if (*args[2]) {
1391 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1392 file, linenum, args[2]);
1393 err_code |= ERR_ALERT | ERR_FATAL;
1394 goto out;
1395 }
1396
1397 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001398 if (!rule)
1399 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001400 rule->cond = cond;
1401 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001402 if (!rule->be.name)
1403 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001404 rule->line = linenum;
1405 rule->file = strdup(file);
1406 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001407 use_backend_alloc_error:
1408 if (cond)
1409 prune_acl_cond(cond);
1410 ha_free(&cond);
1411 if (rule)
1412 ha_free(&(rule->be.name));
1413 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001414 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001415 }
1416 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001417 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001418 }
1419 else if (strcmp(args[0], "use-server") == 0) {
1420 struct server_rule *rule;
1421
Willy Tarreau5d095c22021-02-12 10:15:59 +01001422 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001423 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1424 err_code |= ERR_ALERT | ERR_FATAL;
1425 goto out;
1426 }
1427
1428 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1429 err_code |= ERR_WARN;
1430
1431 if (*(args[1]) == 0) {
1432 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1433 err_code |= ERR_ALERT | ERR_FATAL;
1434 goto out;
1435 }
1436
1437 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1438 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1439 file, linenum, args[0]);
1440 err_code |= ERR_ALERT | ERR_FATAL;
1441 goto out;
1442 }
1443
1444 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1445 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1446 file, linenum, errmsg);
1447 err_code |= ERR_ALERT | ERR_FATAL;
1448 goto out;
1449 }
1450
1451 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1452
1453 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001454 if (!rule)
1455 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001456 rule->cond = cond;
1457 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001458 if (!rule->srv.name)
1459 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001460 rule->line = linenum;
1461 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001462 if (!rule->file) {
1463 use_server_alloc_error:
1464 if (cond)
1465 prune_acl_cond(cond);
1466 ha_free(&cond);
1467 if (rule)
1468 ha_free(&(rule->srv.name));
1469 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001470 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001471 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001472 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001473 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001474 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1475 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001476 else if ((strcmp(args[0], "force-persist") == 0) ||
1477 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001478 struct persist_rule *rule;
1479
Willy Tarreau5d095c22021-02-12 10:15:59 +01001480 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001481 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1482 err_code |= ERR_ALERT | ERR_FATAL;
1483 goto out;
1484 }
1485
1486 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1487 err_code |= ERR_WARN;
1488
1489 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1490 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1491 file, linenum, args[0]);
1492 err_code |= ERR_ALERT | ERR_FATAL;
1493 goto out;
1494 }
1495
1496 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1497 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1498 file, linenum, args[0], errmsg);
1499 err_code |= ERR_ALERT | ERR_FATAL;
1500 goto out;
1501 }
1502
1503 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1504 * where force-persist is applied.
1505 */
1506 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1507
1508 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001509 if (!rule) {
1510 if (cond)
1511 prune_acl_cond(cond);
1512 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001513 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001514 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001515 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001516 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001517 rule->type = PERSIST_TYPE_FORCE;
1518 } else {
1519 rule->type = PERSIST_TYPE_IGNORE;
1520 }
1521 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001522 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001523 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001524 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001525 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001526
Willy Tarreau5d095c22021-02-12 10:15:59 +01001527 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001528 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1529 file, linenum);
1530 err_code |= ERR_ALERT | ERR_FATAL;
1531 goto out;
1532 }
1533
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001534 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001535 if (other) {
1536 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 +01001537 file, linenum, curproxy->id,
1538 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1539 other->proxy ? other->id : other->peers.p->id,
1540 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001541 err_code |= ERR_ALERT | ERR_FATAL;
1542 goto out;
1543 }
1544
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001545 curproxy->table = calloc(1, sizeof *curproxy->table);
1546 if (!curproxy->table) {
1547 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1548 file, linenum, args[0], args[1]);
1549 err_code |= ERR_ALERT | ERR_FATAL;
1550 goto out;
1551 }
1552
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001553 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1554 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001555 if (err_code & ERR_FATAL) {
1556 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001557 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001558 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001559
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001560 /* Store the proxy in the stick-table. */
1561 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001562
1563 stktable_store_name(curproxy->table);
1564 curproxy->table->next = stktables_list;
1565 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001566
1567 /* Add this proxy to the list of proxies which refer to its stick-table. */
1568 if (curproxy->table->proxies_list != curproxy) {
1569 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1570 curproxy->table->proxies_list = curproxy;
1571 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001572 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001573 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001574 struct sticking_rule *rule;
1575 struct sample_expr *expr;
1576 int myidx = 0;
1577 const char *name = NULL;
1578 int flags;
1579
Willy Tarreau5d095c22021-02-12 10:15:59 +01001580 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001581 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1582 err_code |= ERR_ALERT | ERR_FATAL;
1583 goto out;
1584 }
1585
1586 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1587 err_code |= ERR_WARN;
1588 goto out;
1589 }
1590
1591 myidx++;
1592 if ((strcmp(args[myidx], "store") == 0) ||
1593 (strcmp(args[myidx], "store-request") == 0)) {
1594 myidx++;
1595 flags = STK_IS_STORE;
1596 }
1597 else if (strcmp(args[myidx], "store-response") == 0) {
1598 myidx++;
1599 flags = STK_IS_STORE | STK_ON_RSP;
1600 }
1601 else if (strcmp(args[myidx], "match") == 0) {
1602 myidx++;
1603 flags = STK_IS_MATCH;
1604 }
1605 else if (strcmp(args[myidx], "on") == 0) {
1606 myidx++;
1607 flags = STK_IS_MATCH | STK_IS_STORE;
1608 }
1609 else {
1610 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1611 err_code |= ERR_ALERT | ERR_FATAL;
1612 goto out;
1613 }
1614
1615 if (*(args[myidx]) == 0) {
1616 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1617 err_code |= ERR_ALERT | ERR_FATAL;
1618 goto out;
1619 }
1620
1621 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001622 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001623 if (!expr) {
1624 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1625 err_code |= ERR_ALERT | ERR_FATAL;
1626 goto out;
1627 }
1628
1629 if (flags & STK_ON_RSP) {
1630 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1631 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1632 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1633 err_code |= ERR_ALERT | ERR_FATAL;
1634 free(expr);
1635 goto out;
1636 }
1637 } else {
1638 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1639 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1640 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1641 err_code |= ERR_ALERT | ERR_FATAL;
1642 free(expr);
1643 goto out;
1644 }
1645 }
1646
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001647 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001648 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1649
1650 if (strcmp(args[myidx], "table") == 0) {
1651 myidx++;
1652 name = args[myidx++];
1653 }
1654
1655 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1656 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1657 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1658 file, linenum, args[0], errmsg);
1659 err_code |= ERR_ALERT | ERR_FATAL;
1660 free(expr);
1661 goto out;
1662 }
1663 }
1664 else if (*(args[myidx])) {
1665 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1666 file, linenum, args[0], args[myidx]);
1667 err_code |= ERR_ALERT | ERR_FATAL;
1668 free(expr);
1669 goto out;
1670 }
1671 if (flags & STK_ON_RSP)
1672 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1673 else
1674 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1675
1676 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001677 if (!rule) {
1678 if (cond)
1679 prune_acl_cond(cond);
1680 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001681 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001682 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001683 rule->cond = cond;
1684 rule->expr = expr;
1685 rule->flags = flags;
1686 rule->table.name = name ? strdup(name) : NULL;
1687 LIST_INIT(&rule->list);
1688 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001689 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001690 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001691 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001692 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001693 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001694 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001695 curproxy->uri_auth = NULL; /* we must detach from the default config */
1696
1697 if (!*args[1]) {
1698 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001699 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001700 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001701 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001702
Willy Tarreau5d095c22021-02-12 10:15:59 +01001703 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001704 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1705 err_code |= ERR_ALERT | ERR_FATAL;
1706 goto out;
1707 }
1708
Christopher Fauletb15625a2021-04-12 21:31:45 +02001709 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1710 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001711
1712 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1713 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1714 file, linenum, args[0], args[1]);
1715 err_code |= ERR_ALERT | ERR_FATAL;
1716 goto out;
1717 }
1718 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1719 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1720 file, linenum, args[0], args[1], errmsg);
1721 err_code |= ERR_ALERT | ERR_FATAL;
1722 goto out;
1723 }
1724
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001725 if (curproxy->cap & PR_CAP_FE)
1726 where |= SMP_VAL_FE_HRQ_HDR;
1727 if (curproxy->cap & PR_CAP_BE)
1728 where |= SMP_VAL_BE_HRQ_HDR;
1729 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001730
1731 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001732 if (!rule) {
1733 if (cond)
1734 prune_acl_cond(cond);
1735 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001736 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001737 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001738 rule->cond = cond;
1739 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001740 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001741 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001742 if (*(args[2]) == 0) {
1743 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1744 err_code |= ERR_ALERT | ERR_FATAL;
1745 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001746 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1747 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001748 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001749 if (*(args[2]) == 0) {
1750 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1751 err_code |= ERR_ALERT | ERR_FATAL;
1752 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001753 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1754 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001755 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001756 unsigned interval;
1757
1758 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001759 if (err == PARSE_TIME_OVER) {
1760 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1761 file, linenum, args[2]);
1762 err_code |= ERR_ALERT | ERR_FATAL;
1763 goto out;
1764 }
1765 else if (err == PARSE_TIME_UNDER) {
1766 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1767 file, linenum, args[2]);
1768 err_code |= ERR_ALERT | ERR_FATAL;
1769 goto out;
1770 }
1771 else if (err) {
1772 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001773 file, linenum, *err);
1774 err_code |= ERR_ALERT | ERR_FATAL;
1775 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001776 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1777 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001778 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001779 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001780 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001781
Willy Tarreau5d095c22021-02-12 10:15:59 +01001782 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001783 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1784 err_code |= ERR_ALERT | ERR_FATAL;
1785 goto out;
1786 }
1787
Christopher Fauletb15625a2021-04-12 21:31:45 +02001788 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1789 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001790
1791 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1792 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1793 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1794 file, linenum, args[0]);
1795 err_code |= ERR_WARN;
1796 }
1797
1798 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1799
1800 if (!rule) {
1801 err_code |= ERR_ALERT | ERR_ABORT;
1802 goto out;
1803 }
1804
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001805 if (curproxy->cap & PR_CAP_FE)
1806 where |= SMP_VAL_FE_HRQ_HDR;
1807 if (curproxy->cap & PR_CAP_BE)
1808 where |= SMP_VAL_BE_HRQ_HDR;
1809 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001810 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001811
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001812 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001813 if (*(args[2]) == 0) {
1814 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1815 err_code |= ERR_ALERT | ERR_FATAL;
1816 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001817 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1818 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001819 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001820 if (*(args[2]) == 0) {
1821 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1822 err_code |= ERR_ALERT | ERR_FATAL;
1823 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001824 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1825 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001826 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001827 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1828 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001829 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001830 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1831 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001832 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001833 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1834 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001835 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001836 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1837 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001838 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001839
1840 if (*args[2]) {
1841 int i;
1842 char c;
1843
1844 for (i=0; args[2][i]; i++) {
1845 c = args[2][i];
1846 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1847 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1848 break;
1849 }
1850
1851 if (!i || args[2][i]) {
1852 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1853 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1854 file, linenum, args[0], args[1]);
1855 err_code |= ERR_ALERT | ERR_FATAL;
1856 goto out;
1857 }
1858 }
1859
Christopher Fauletb15625a2021-04-12 21:31:45 +02001860 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1861 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001862 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001863 char *desc = NULL;
1864
1865 if (*args[2]) {
1866 int i, len=0;
1867 char *d;
1868
1869 for (i = 2; *args[i]; i++)
1870 len += strlen(args[i]) + 1;
1871
1872 desc = d = calloc(1, len);
1873
1874 d += snprintf(d, desc + len - d, "%s", args[2]);
1875 for (i = 3; *args[i]; i++)
1876 d += snprintf(d, desc + len - d, " %s", args[i]);
1877 }
1878
1879 if (!*args[2] && !global.desc)
1880 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1881 file, linenum, args[1]);
1882 else {
1883 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1884 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001885 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001886 }
1887 free(desc);
1888 }
1889 } else {
1890stats_error_parsing:
1891 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1892 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1893 err_code |= ERR_ALERT | ERR_FATAL;
1894 goto out;
1895 }
1896 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001897 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001898 int optnum;
1899
1900 if (*(args[1]) == '\0') {
1901 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1902 file, linenum, args[0]);
1903 err_code |= ERR_ALERT | ERR_FATAL;
1904 goto out;
1905 }
1906
1907 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001908 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001909 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1910 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1911 file, linenum, cfg_opts[optnum].name);
1912 err_code |= ERR_ALERT | ERR_FATAL;
1913 goto out;
1914 }
1915 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1916 goto out;
1917
1918 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1919 err_code |= ERR_WARN;
1920 goto out;
1921 }
1922
1923 curproxy->no_options &= ~cfg_opts[optnum].val;
1924 curproxy->options &= ~cfg_opts[optnum].val;
1925
1926 switch (kwm) {
1927 case KWM_STD:
1928 curproxy->options |= cfg_opts[optnum].val;
1929 break;
1930 case KWM_NO:
1931 curproxy->no_options |= cfg_opts[optnum].val;
1932 break;
1933 case KWM_DEF: /* already cleared */
1934 break;
1935 }
1936
1937 goto out;
1938 }
1939 }
1940
1941 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001942 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001943 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1944 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1945 file, linenum, cfg_opts2[optnum].name);
1946 err_code |= ERR_ALERT | ERR_FATAL;
1947 goto out;
1948 }
1949 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1950 goto out;
1951 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1952 err_code |= ERR_WARN;
1953 goto out;
1954 }
1955
1956 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1957 curproxy->options2 &= ~cfg_opts2[optnum].val;
1958
1959 switch (kwm) {
1960 case KWM_STD:
1961 curproxy->options2 |= cfg_opts2[optnum].val;
1962 break;
1963 case KWM_NO:
1964 curproxy->no_options2 |= cfg_opts2[optnum].val;
1965 break;
1966 case KWM_DEF: /* already cleared */
1967 break;
1968 }
1969 goto out;
1970 }
1971 }
1972
1973 /* HTTP options override each other. They can be cancelled using
1974 * "no option xxx" which only switches to default mode if the mode
1975 * was this one (useful for cancelling options set in defaults
1976 * sections).
1977 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001978 if (strcmp(args[1], "forceclose") == 0) {
1979 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",
1980 file, linenum, args[1]);
1981 err_code |= ERR_ALERT | ERR_FATAL;
1982 goto out;
1983 }
1984 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001985 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1986 goto out;
1987 if (kwm == KWM_STD) {
1988 curproxy->options &= ~PR_O_HTTP_MODE;
1989 curproxy->options |= PR_O_HTTP_CLO;
1990 goto out;
1991 }
1992 else if (kwm == KWM_NO) {
1993 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1994 curproxy->options &= ~PR_O_HTTP_MODE;
1995 goto out;
1996 }
1997 }
1998 else if (strcmp(args[1], "http-server-close") == 0) {
1999 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2000 goto out;
2001 if (kwm == KWM_STD) {
2002 curproxy->options &= ~PR_O_HTTP_MODE;
2003 curproxy->options |= PR_O_HTTP_SCL;
2004 goto out;
2005 }
2006 else if (kwm == KWM_NO) {
2007 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2008 curproxy->options &= ~PR_O_HTTP_MODE;
2009 goto out;
2010 }
2011 }
2012 else if (strcmp(args[1], "http-keep-alive") == 0) {
2013 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2014 goto out;
2015 if (kwm == KWM_STD) {
2016 curproxy->options &= ~PR_O_HTTP_MODE;
2017 curproxy->options |= PR_O_HTTP_KAL;
2018 goto out;
2019 }
2020 else if (kwm == KWM_NO) {
2021 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2022 curproxy->options &= ~PR_O_HTTP_MODE;
2023 goto out;
2024 }
2025 }
2026 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002027 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 +02002028 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002029 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002030 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002031 }
2032
2033 /* Redispatch can take an integer argument that control when the
2034 * resispatch occurs. All values are relative to the retries option.
2035 * This can be cancelled using "no option xxx".
2036 */
2037 if (strcmp(args[1], "redispatch") == 0) {
2038 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2039 err_code |= ERR_WARN;
2040 goto out;
2041 }
2042
2043 curproxy->no_options &= ~PR_O_REDISP;
2044 curproxy->options &= ~PR_O_REDISP;
2045
2046 switch (kwm) {
2047 case KWM_STD:
2048 curproxy->options |= PR_O_REDISP;
2049 curproxy->redispatch_after = -1;
2050 if(*args[2]) {
2051 curproxy->redispatch_after = atol(args[2]);
2052 }
2053 break;
2054 case KWM_NO:
2055 curproxy->no_options |= PR_O_REDISP;
2056 curproxy->redispatch_after = 0;
2057 break;
2058 case KWM_DEF: /* already cleared */
2059 break;
2060 }
2061 goto out;
2062 }
2063
Willy Tarreau25241232021-07-18 19:18:56 +02002064 if (strcmp(args[1], "http_proxy") == 0) {
2065 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",
2066 file, linenum, args[1]);
2067 err_code |= ERR_ALERT | ERR_FATAL;
2068 goto out;
2069 }
2070
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002071 if (kwm != KWM_STD) {
2072 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2073 file, linenum, args[1]);
2074 err_code |= ERR_ALERT | ERR_FATAL;
2075 goto out;
2076 }
2077
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002078 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002079 char *logformat;
2080 /* generate a complete HTTP log */
2081 logformat = default_http_log_format;
2082 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002083 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002084 curproxy->options2 |= PR_O2_CLFLOG;
2085 logformat = clf_http_log_format;
2086 } else {
2087 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2088 err_code |= ERR_ALERT | ERR_FATAL;
2089 goto out;
2090 }
2091 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2092 goto out;
2093 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002094 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002095 char *oldlogformat = "log-format";
2096 char *clflogformat = "";
2097
2098 if (curproxy->conf.logformat_string == default_http_log_format)
2099 oldlogformat = "option httplog";
2100 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2101 oldlogformat = "option tcplog";
2102 else if (curproxy->conf.logformat_string == clf_http_log_format)
2103 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002104 else if (curproxy->conf.logformat_string == default_https_log_format)
2105 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002106 if (logformat == clf_http_log_format)
2107 clflogformat = " clf";
2108 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2109 file, linenum, clflogformat, oldlogformat);
2110 }
2111 if (curproxy->conf.logformat_string != default_http_log_format &&
2112 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002113 curproxy->conf.logformat_string != clf_http_log_format &&
2114 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002115 free(curproxy->conf.logformat_string);
2116 curproxy->conf.logformat_string = logformat;
2117
2118 free(curproxy->conf.lfs_file);
2119 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2120 curproxy->conf.lfs_line = curproxy->conf.args.line;
2121
Willy Tarreau5d095c22021-02-12 10:15:59 +01002122 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002123 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2124 file, linenum, curproxy->id);
2125 err_code |= ERR_WARN;
2126 }
2127 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002128 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002129 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002130 char *oldlogformat = "log-format";
2131
2132 if (curproxy->conf.logformat_string == default_http_log_format)
2133 oldlogformat = "option httplog";
2134 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2135 oldlogformat = "option tcplog";
2136 else if (curproxy->conf.logformat_string == clf_http_log_format)
2137 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002138 else if (curproxy->conf.logformat_string == default_https_log_format)
2139 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002140 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2141 file, linenum, oldlogformat);
2142 }
2143 /* generate a detailed TCP log */
2144 if (curproxy->conf.logformat_string != default_http_log_format &&
2145 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002146 curproxy->conf.logformat_string != clf_http_log_format &&
2147 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002148 free(curproxy->conf.logformat_string);
2149 curproxy->conf.logformat_string = default_tcp_log_format;
2150
2151 free(curproxy->conf.lfs_file);
2152 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2153 curproxy->conf.lfs_line = curproxy->conf.args.line;
2154
2155 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2156 goto out;
2157
Willy Tarreau5d095c22021-02-12 10:15:59 +01002158 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002159 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2160 file, linenum, curproxy->id);
2161 err_code |= ERR_WARN;
2162 }
2163 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002164 else if (strcmp(args[1], "httpslog") == 0) {
2165 char *logformat;
2166 /* generate a complete HTTP log */
2167 logformat = default_https_log_format;
2168 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2169 char *oldlogformat = "log-format";
2170
2171 if (curproxy->conf.logformat_string == default_http_log_format)
2172 oldlogformat = "option httplog";
2173 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2174 oldlogformat = "option tcplog";
2175 else if (curproxy->conf.logformat_string == clf_http_log_format)
2176 oldlogformat = "option httplog clf";
2177 else if (curproxy->conf.logformat_string == default_https_log_format)
2178 oldlogformat = "option httpslog";
2179 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2180 file, linenum, oldlogformat);
2181 }
2182 if (curproxy->conf.logformat_string != default_http_log_format &&
2183 curproxy->conf.logformat_string != default_tcp_log_format &&
2184 curproxy->conf.logformat_string != clf_http_log_format &&
2185 curproxy->conf.logformat_string != default_https_log_format)
2186 free(curproxy->conf.logformat_string);
2187 curproxy->conf.logformat_string = logformat;
2188
2189 free(curproxy->conf.lfs_file);
2190 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2191 curproxy->conf.lfs_line = curproxy->conf.args.line;
2192
2193 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2194 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2195 file, linenum, curproxy->id);
2196 err_code |= ERR_WARN;
2197 }
2198 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002199 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002200 /* enable TCP keep-alives on client and server streams */
2201 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2202 err_code |= ERR_WARN;
2203
2204 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2205 goto out;
2206
2207 if (curproxy->cap & PR_CAP_FE)
2208 curproxy->options |= PR_O_TCP_CLI_KA;
2209 if (curproxy->cap & PR_CAP_BE)
2210 curproxy->options |= PR_O_TCP_SRV_KA;
2211 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002212 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002213 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002214 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002215 goto out;
2216 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002217 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002218 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002219 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002220 goto out;
2221 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002222 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002223 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002224 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002225 goto out;
2226 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002227 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002228 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002229 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002230 goto out;
2231 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002232 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002233 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002234 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002235 goto out;
2236 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002237 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002238 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002239 if (err_code & ERR_FATAL)
2240 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002241 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002242 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002243 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002244 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002245 goto out;
2246 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002247 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002248 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002249 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002250 goto out;
2251 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002252 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002253 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002254 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002255 goto out;
2256 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002257 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002258 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002259 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002260 goto out;
2261 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002262 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002263 int cur_arg;
2264
2265 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002266 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002267 */
2268
2269 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2270
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002271 istfree(&curproxy->fwdfor_hdr_name);
2272 curproxy->fwdfor_hdr_name = istdup(ist(DEF_XFORWARDFOR_HDR));
2273 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002274 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002275 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002276
2277 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2278 cur_arg = 2;
2279 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002280 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002281 unsigned char mask;
2282 int i;
2283
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002284 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002285 if (*(args[cur_arg+1]) &&
2286 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2287 curproxy->except_xff_net.family = AF_INET;
2288 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2289 }
2290 else if (*(args[cur_arg+1]) &&
2291 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2292 curproxy->except_xff_net.family = AF_INET6;
2293 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2294 for (i = 0; i < 16; i++)
2295 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2296 }
2297 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002298 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2299 file, linenum, args[0], args[1], args[cur_arg]);
2300 err_code |= ERR_ALERT | ERR_FATAL;
2301 goto out;
2302 }
2303 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002304 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002305 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002306 /* suboption header - needs additional argument for it */
2307 if (*(args[cur_arg+1]) == 0) {
2308 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2309 file, linenum, args[0], args[1], args[cur_arg]);
2310 err_code |= ERR_ALERT | ERR_FATAL;
2311 goto out;
2312 }
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002313 istfree(&curproxy->fwdfor_hdr_name);
2314 curproxy->fwdfor_hdr_name = istdup(ist(args[cur_arg+1]));
2315 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002316 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002317 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002318 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002319 curproxy->options &= ~PR_O_FF_ALWAYS;
2320 cur_arg += 1;
2321 } else {
2322 /* unknown suboption - catchall */
2323 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2324 file, linenum, args[0], args[1]);
2325 err_code |= ERR_ALERT | ERR_FATAL;
2326 goto out;
2327 }
2328 } /* end while loop */
2329 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002330 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002331 int cur_arg;
2332
2333 /* insert x-original-to field, but not for the IP address listed as an except.
2334 * set default options (ie: bitfield, header name, etc)
2335 */
2336
2337 curproxy->options |= PR_O_ORGTO;
2338
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002339 istfree(&curproxy->orgto_hdr_name);
2340 curproxy->orgto_hdr_name = istdup(ist(DEF_XORIGINALTO_HDR));
2341 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002342 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002343 curproxy->except_xot_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" "originalto" */
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_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2355 curproxy->except_xot_net.family = AF_INET;
2356 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2357 }
2358 else if (*(args[cur_arg+1]) &&
2359 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2360 curproxy->except_xot_net.family = AF_INET6;
2361 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2362 for (i = 0; i < 16; i++)
2363 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_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 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002371 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002372 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002373 /* suboption header - needs additional argument for it */
2374 if (*(args[cur_arg+1]) == 0) {
2375 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2376 file, linenum, args[0], args[1], args[cur_arg]);
2377 err_code |= ERR_ALERT | ERR_FATAL;
2378 goto out;
2379 }
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002380 istfree(&curproxy->orgto_hdr_name);
2381 curproxy->orgto_hdr_name = istdup(ist(args[cur_arg+1]));
2382 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002383 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002384 cur_arg += 2;
2385 } else {
2386 /* unknown suboption - catchall */
2387 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2388 file, linenum, args[0], args[1]);
2389 err_code |= ERR_ALERT | ERR_FATAL;
2390 goto out;
2391 }
2392 } /* end while loop */
2393 }
Christopher Faulet18c13d32022-05-16 11:43:10 +02002394 else if (strcmp(args[1], "http-restrict-req-hdr-names") == 0) {
Christopher Faulet18c13d32022-05-16 11:43:10 +02002395 if (alertif_too_many_args(2, file, linenum, args, &err_code))
2396 goto out;
2397
2398 if (*(args[2]) == 0) {
2399 ha_alert("parsing [%s:%d] : missing parameter. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2400 file, linenum, args[1]);
2401 err_code |= ERR_ALERT | ERR_FATAL;
2402 goto out;
2403 }
2404
2405 curproxy->options2 &= ~PR_O2_RSTRICT_REQ_HDR_NAMES_MASK;
2406 if (strcmp(args[2], "preserve") == 0)
2407 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_NOOP;
2408 else if (strcmp(args[2], "reject") == 0)
2409 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_BLK;
2410 else if (strcmp(args[2], "delete") == 0)
2411 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_DEL;
2412 else {
2413 ha_alert("parsing [%s:%d] : invalid parameter '%s'. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2414 file, linenum, args[2], args[1]);
2415 err_code |= ERR_ALERT | ERR_FATAL;
2416 goto out;
2417 }
2418 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002419 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002420 const char *best = proxy_find_best_option(args[1], common_options);
2421
2422 if (best)
2423 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2424 else
2425 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2426
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002427 err_code |= ERR_ALERT | ERR_FATAL;
2428 goto out;
2429 }
2430 goto out;
2431 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002432 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002433 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2434 err_code |= ERR_WARN;
2435
2436 if (*(args[1]) == 0) {
2437 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2438 err_code |= ERR_ALERT | ERR_FATAL;
2439 goto out;
2440 }
2441 free(curproxy->defbe.name);
2442 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002443 if (!curproxy->defbe.name)
2444 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002445
2446 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2447 goto out;
2448 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002449 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002450 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 +01002451
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002452 err_code |= ERR_ALERT | ERR_FATAL;
2453 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002454 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002455 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002456 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2457 err_code |= ERR_WARN;
2458
2459 if (strcmp(args[1], "never") == 0) {
2460 /* enable a graceful server shutdown on an HTTP 404 response */
2461 curproxy->options &= ~PR_O_REUSE_MASK;
2462 curproxy->options |= PR_O_REUSE_NEVR;
2463 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2464 goto out;
2465 }
2466 else if (strcmp(args[1], "safe") == 0) {
2467 /* enable a graceful server shutdown on an HTTP 404 response */
2468 curproxy->options &= ~PR_O_REUSE_MASK;
2469 curproxy->options |= PR_O_REUSE_SAFE;
2470 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2471 goto out;
2472 }
2473 else if (strcmp(args[1], "aggressive") == 0) {
2474 curproxy->options &= ~PR_O_REUSE_MASK;
2475 curproxy->options |= PR_O_REUSE_AGGR;
2476 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2477 goto out;
2478 }
2479 else if (strcmp(args[1], "always") == 0) {
2480 /* enable a graceful server shutdown on an HTTP 404 response */
2481 curproxy->options &= ~PR_O_REUSE_MASK;
2482 curproxy->options |= PR_O_REUSE_ALWS;
2483 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2484 goto out;
2485 }
2486 else {
2487 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2488 err_code |= ERR_ALERT | ERR_FATAL;
2489 goto out;
2490 }
2491 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002492 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002493 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002494 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2495 err_code |= ERR_ALERT | ERR_FATAL;
2496 goto out;
2497 }
2498
2499 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2500 err_code |= ERR_WARN;
2501
2502 if (strcmp(args[1], "fail") == 0) {
2503 /* add a condition to fail monitor requests */
2504 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2505 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2506 file, linenum, args[0], args[1]);
2507 err_code |= ERR_ALERT | ERR_FATAL;
2508 goto out;
2509 }
2510
2511 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2512 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2513 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2514 file, linenum, args[0], args[1], errmsg);
2515 err_code |= ERR_ALERT | ERR_FATAL;
2516 goto out;
2517 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002518 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002519 }
2520 else {
2521 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2522 err_code |= ERR_ALERT | ERR_FATAL;
2523 goto out;
2524 }
2525 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002526#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002527 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002528 /* enable transparent proxy connections */
2529 curproxy->options |= PR_O_TRANSP;
2530 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2531 goto out;
2532 }
2533#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002534 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002535 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2536 err_code |= ERR_WARN;
2537
2538 if (*(args[1]) == 0) {
2539 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2540 err_code |= ERR_ALERT | ERR_FATAL;
2541 goto out;
2542 }
2543 curproxy->maxconn = atol(args[1]);
2544 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2545 goto out;
2546 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002547 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002548 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2549 err_code |= ERR_WARN;
2550
2551 if (*(args[1]) == 0) {
2552 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2553 err_code |= ERR_ALERT | ERR_FATAL;
2554 goto out;
2555 }
2556 curproxy->backlog = atol(args[1]);
2557 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2558 goto out;
2559 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002560 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002561 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2562 err_code |= ERR_WARN;
2563
2564 if (*(args[1]) == 0) {
2565 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2566 err_code |= ERR_ALERT | ERR_FATAL;
2567 goto out;
2568 }
2569 curproxy->fullconn = atol(args[1]);
2570 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2571 goto out;
2572 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002573 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002574 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 +02002575 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002576 err_code |= ERR_ALERT | ERR_FATAL;
2577 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002578 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002579 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002580 struct sockaddr_storage *sk;
2581 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002582
Willy Tarreau5d095c22021-02-12 10:15:59 +01002583 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002584 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2585 err_code |= ERR_ALERT | ERR_FATAL;
2586 goto out;
2587 }
2588 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2589 err_code |= ERR_WARN;
2590
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002591 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2592 &errmsg, NULL, NULL,
2593 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 +01002594 if (!sk) {
2595 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2596 err_code |= ERR_ALERT | ERR_FATAL;
2597 goto out;
2598 }
2599
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002600 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2601 goto out;
2602
2603 curproxy->dispatch_addr = *sk;
2604 curproxy->options |= PR_O_DISPATCH;
2605 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002606 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002607 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2608 err_code |= ERR_WARN;
2609
2610 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2611 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2612 err_code |= ERR_ALERT | ERR_FATAL;
2613 goto out;
2614 }
2615 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002616 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002617 /**
2618 * The syntax for hash-type config element is
2619 * hash-type {map-based|consistent} [[<algo>] avalanche]
2620 *
2621 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2622 */
2623 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2624
2625 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2626 err_code |= ERR_WARN;
2627
2628 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2629 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2630 }
2631 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2632 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2633 }
2634 else if (strcmp(args[1], "avalanche") == 0) {
2635 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]);
2636 err_code |= ERR_ALERT | ERR_FATAL;
2637 goto out;
2638 }
2639 else {
2640 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2641 err_code |= ERR_ALERT | ERR_FATAL;
2642 goto out;
2643 }
2644
2645 /* set the hash function to use */
2646 if (!*args[2]) {
2647 /* the default algo is sdbm */
2648 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2649
2650 /* if consistent with no argument, then avalanche modifier is also applied */
2651 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2652 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2653 } else {
2654 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002655 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002656 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2657 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002658 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002659 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2660 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002661 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002662 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2663 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002664 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002665 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2666 }
2667 else {
2668 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2669 err_code |= ERR_ALERT | ERR_FATAL;
2670 goto out;
2671 }
2672
2673 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002674 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002675 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2676 }
2677 else if (*args[3]) {
2678 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2679 err_code |= ERR_ALERT | ERR_FATAL;
2680 goto out;
2681 }
2682 }
2683 }
2684 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2685 if (*(args[1]) == 0) {
2686 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2687 err_code |= ERR_ALERT | ERR_FATAL;
2688 goto out;
2689 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002690 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2691 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002692 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2693 err_code |= ERR_ALERT | ERR_FATAL;
2694 goto out;
2695 }
2696 }
2697 else if (strcmp(args[0], "unique-id-format") == 0) {
2698 if (!*(args[1])) {
2699 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2700 err_code |= ERR_ALERT | ERR_FATAL;
2701 goto out;
2702 }
2703 if (*(args[2])) {
2704 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2705 err_code |= ERR_ALERT | ERR_FATAL;
2706 goto out;
2707 }
2708 free(curproxy->conf.uniqueid_format_string);
2709 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002710 if (!curproxy->conf.uniqueid_format_string)
2711 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002712
2713 free(curproxy->conf.uif_file);
2714 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2715 curproxy->conf.uif_line = curproxy->conf.args.line;
2716 }
2717
2718 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002719 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002720 if (!*(args[1])) {
2721 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2722 err_code |= ERR_ALERT | ERR_FATAL;
2723 goto out;
2724 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002725 copy = strdup(args[1]);
2726 if (copy == NULL) {
2727 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2728 err_code |= ERR_ALERT | ERR_FATAL;
2729 goto out;
2730 }
2731
2732 istfree(&curproxy->header_unique_id);
2733 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002734 }
2735
2736 else if (strcmp(args[0], "log-format") == 0) {
2737 if (!*(args[1])) {
2738 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2739 err_code |= ERR_ALERT | ERR_FATAL;
2740 goto out;
2741 }
2742 if (*(args[2])) {
2743 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2744 err_code |= ERR_ALERT | ERR_FATAL;
2745 goto out;
2746 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002747 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002748 char *oldlogformat = "log-format";
2749
2750 if (curproxy->conf.logformat_string == default_http_log_format)
2751 oldlogformat = "option httplog";
2752 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2753 oldlogformat = "option tcplog";
2754 else if (curproxy->conf.logformat_string == clf_http_log_format)
2755 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002756 else if (curproxy->conf.logformat_string == default_https_log_format)
2757 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002758 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2759 file, linenum, oldlogformat);
2760 }
2761 if (curproxy->conf.logformat_string != default_http_log_format &&
2762 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002763 curproxy->conf.logformat_string != clf_http_log_format &&
2764 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002765 free(curproxy->conf.logformat_string);
2766 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002767 if (!curproxy->conf.logformat_string)
2768 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002769
2770 free(curproxy->conf.lfs_file);
2771 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2772 curproxy->conf.lfs_line = curproxy->conf.args.line;
2773
2774 /* get a chance to improve log-format error reporting by
2775 * reporting the correct line-number when possible.
2776 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002777 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002778 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2779 file, linenum, curproxy->id);
2780 err_code |= ERR_WARN;
2781 }
2782 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002783 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002784 if (!*(args[1])) {
2785 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2786 err_code |= ERR_ALERT | ERR_FATAL;
2787 goto out;
2788 }
2789 if (*(args[2])) {
2790 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2791 err_code |= ERR_ALERT | ERR_FATAL;
2792 goto out;
2793 }
2794
2795 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2796 free(curproxy->conf.logformat_sd_string);
2797 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002798 if (!curproxy->conf.logformat_sd_string)
2799 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002800
2801 free(curproxy->conf.lfsd_file);
2802 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2803 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2804
2805 /* get a chance to improve log-format-sd error reporting by
2806 * reporting the correct line-number when possible.
2807 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002808 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002809 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2810 file, linenum, curproxy->id);
2811 err_code |= ERR_WARN;
2812 }
2813 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002814 else if (strcmp(args[0], "error-log-format") == 0) {
2815 if (!*(args[1])) {
2816 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2817 err_code |= ERR_ALERT | ERR_FATAL;
2818 goto out;
2819 }
2820 if (*(args[2])) {
2821 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2822 err_code |= ERR_ALERT | ERR_FATAL;
2823 goto out;
2824 }
2825 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2826 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2827 file, linenum);
2828 }
2829 free(curproxy->conf.error_logformat_string);
2830 curproxy->conf.error_logformat_string = strdup(args[1]);
2831 if (!curproxy->conf.error_logformat_string)
2832 goto alloc_error;
2833
2834 free(curproxy->conf.elfs_file);
2835 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2836 curproxy->conf.elfs_line = curproxy->conf.args.line;
2837
2838 /* get a chance to improve log-format error reporting by
2839 * reporting the correct line-number when possible.
2840 */
2841 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2842 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2843 file, linenum, curproxy->id);
2844 err_code |= ERR_WARN;
2845 }
2846 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002847 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002848 if (*(args[1]) == 0) {
2849 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2850 err_code |= ERR_ALERT | ERR_FATAL;
2851 goto out;
2852 }
2853 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002854 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2855 if (b_orig(&curproxy->log_tag) == NULL) {
2856 chunk_destroy(&curproxy->log_tag);
2857 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2858 err_code |= ERR_ALERT | ERR_FATAL;
2859 goto out;
2860 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002861 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002862 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002863 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002864 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2865 err_code |= ERR_ALERT | ERR_FATAL;
2866 goto out;
2867 }
2868 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002869 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002870 int cur_arg;
2871 int port1, port2;
2872 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002873
2874 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2875 err_code |= ERR_WARN;
2876
2877 if (!*args[1]) {
2878 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2879 file, linenum, "source", "usesrc", "interface");
2880 err_code |= ERR_ALERT | ERR_FATAL;
2881 goto out;
2882 }
2883
Christopher Faulet31930372019-07-15 10:16:58 +02002884 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002885 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002886 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002887 curproxy->conn_src.iface_len = 0;
2888
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002889 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2890 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002891 if (!sk) {
2892 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2893 file, linenum, args[0], args[1], errmsg);
2894 err_code |= ERR_ALERT | ERR_FATAL;
2895 goto out;
2896 }
2897
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002898 curproxy->conn_src.source_addr = *sk;
2899 curproxy->conn_src.opts |= CO_SRC_BIND;
2900
2901 cur_arg = 2;
2902 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002903 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002904#if defined(CONFIG_HAP_TRANSPARENT)
2905 if (!*args[cur_arg + 1]) {
2906 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2907 file, linenum, "usesrc");
2908 err_code |= ERR_ALERT | ERR_FATAL;
2909 goto out;
2910 }
2911
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002912 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002913 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2914 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002915 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002916 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2917 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2918 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2919 char *name, *end;
2920
2921 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002922 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002923 name++;
2924
2925 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002926 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002927 end++;
2928
2929 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2930 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002931 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002932 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002933 if (!curproxy->conn_src.bind_hdr_name)
2934 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002935 curproxy->conn_src.bind_hdr_len = end - name;
2936 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2937 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2938 curproxy->conn_src.bind_hdr_occ = -1;
2939
2940 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002941 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002942 end++;
2943 if (*end == ',') {
2944 end++;
2945 name = end;
2946 if (*end == '-')
2947 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002948 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002949 end++;
2950 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2951 }
2952
2953 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2954 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2955 " occurrences values smaller than %d.\n",
2956 file, linenum, MAX_HDR_HISTORY);
2957 err_code |= ERR_ALERT | ERR_FATAL;
2958 goto out;
2959 }
2960 } else {
2961 struct sockaddr_storage *sk;
2962
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002963 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2964 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002965 if (!sk) {
2966 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2967 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2968 err_code |= ERR_ALERT | ERR_FATAL;
2969 goto out;
2970 }
2971
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002972 curproxy->conn_src.tproxy_addr = *sk;
2973 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2974 }
2975 global.last_checks |= LSTCHK_NETADM;
2976#else /* no TPROXY support */
2977 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2978 file, linenum, "usesrc");
2979 err_code |= ERR_ALERT | ERR_FATAL;
2980 goto out;
2981#endif
2982 cur_arg += 2;
2983 continue;
2984 }
2985
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002986 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002987#ifdef SO_BINDTODEVICE
2988 if (!*args[cur_arg + 1]) {
2989 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2990 file, linenum, args[0]);
2991 err_code |= ERR_ALERT | ERR_FATAL;
2992 goto out;
2993 }
2994 free(curproxy->conn_src.iface_name);
2995 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002996 if (!curproxy->conn_src.iface_name)
2997 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002998 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2999 global.last_checks |= LSTCHK_NETADM;
3000#else
3001 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3002 file, linenum, args[0], args[cur_arg]);
3003 err_code |= ERR_ALERT | ERR_FATAL;
3004 goto out;
3005#endif
3006 cur_arg += 2;
3007 continue;
3008 }
3009 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3010 file, linenum, args[0], "interface", "usesrc");
3011 err_code |= ERR_ALERT | ERR_FATAL;
3012 goto out;
3013 }
3014 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003015 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003016 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3017 file, linenum, "usesrc", "source");
3018 err_code |= ERR_ALERT | ERR_FATAL;
3019 goto out;
3020 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003021 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 +02003022 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003023 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003024 file, linenum, args[0]);
3025 err_code |= ERR_ALERT | ERR_FATAL;
3026 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003027 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003028 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003029 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3030 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3031 err_code |= ERR_ALERT | ERR_FATAL;
3032 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003033 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003034 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003035 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3036 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3037 err_code |= ERR_ALERT | ERR_FATAL;
3038 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003039 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003040 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003041 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3042 err_code |= ERR_ALERT | ERR_FATAL;
3043 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003044 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003045 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003046 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3047 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3048 err_code |= ERR_ALERT | ERR_FATAL;
3049 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003050 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003051 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003052 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3053 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3054 err_code |= ERR_ALERT | ERR_FATAL;
3055 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003056 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003057 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003058 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3059 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3060 err_code |= ERR_ALERT | ERR_FATAL;
3061 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003062 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003063 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003064 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3065 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3066 err_code |= ERR_ALERT | ERR_FATAL;
3067 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003068 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003069 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 +02003070 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3071 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3072 err_code |= ERR_ALERT | ERR_FATAL;
3073 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003074 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003075 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003076 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3077 err_code |= ERR_ALERT | ERR_FATAL;
3078 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003079 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003080 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 +02003081 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3082 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3083 err_code |= ERR_ALERT | ERR_FATAL;
3084 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003085 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003086 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 +02003087 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3088 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3089 err_code |= ERR_ALERT | ERR_FATAL;
3090 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003092 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003093 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3094 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3095 err_code |= ERR_ALERT | ERR_FATAL;
3096 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003097 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003098 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 +02003099 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3100 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3101 err_code |= ERR_ALERT | ERR_FATAL;
3102 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003103 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003104 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003105 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3106 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3107 err_code |= ERR_ALERT | ERR_FATAL;
3108 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003109 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003110 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003111 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3112 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3113 err_code |= ERR_ALERT | ERR_FATAL;
3114 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003115 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003116 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303117 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003118 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3119 err_code |= ERR_ALERT | ERR_FATAL;
3120 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003121 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003122 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003123 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3124 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3125 err_code |= ERR_ALERT | ERR_FATAL;
3126 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003127 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003128 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003129 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3130 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3131 err_code |= ERR_ALERT | ERR_FATAL;
3132 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003133 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003134 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003135 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3136 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3137 err_code |= ERR_ALERT | ERR_FATAL;
3138 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003139 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003140 else {
3141 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003142 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003143 int index;
3144
3145 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3146 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3147 if (kwl->kw[index].section != CFG_LISTEN)
3148 continue;
3149 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003150 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003151 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003152 err_code |= ERR_ALERT | ERR_FATAL;
3153 goto out;
3154 }
3155
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003156 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003157 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003158 if (rc < 0) {
3159 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3160 err_code |= ERR_ALERT | ERR_FATAL;
3161 goto out;
3162 }
3163 else if (rc > 0) {
3164 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3165 err_code |= ERR_WARN;
3166 goto out;
3167 }
3168 goto out;
3169 }
3170 }
3171 }
3172
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003173 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3174 if (best)
3175 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3176 else
3177 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003178 err_code |= ERR_ALERT | ERR_FATAL;
3179 goto out;
3180 }
3181 out:
3182 free(errmsg);
3183 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003184
3185 alloc_error:
3186 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3187 err_code |= ERR_ALERT | ERR_ABORT;
3188 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003189}