blob: 258564404a9e9bbf84ea9839fa892611f6959c25 [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) {
Aurelien DARRAGON9dce88b2022-11-21 17:01:11 +0100294 struct ebpt_node *next_by_name;
295
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100296 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
297
298 if (!curr_defproxy) {
299 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
300 err_code |= ERR_ALERT | ERR_ABORT;
301 goto out;
302 }
303
Aurelien DARRAGON9dce88b2022-11-21 17:01:11 +0100304 if ((next_by_name = ebpt_next_dup(&curr_defproxy->conf.by_name))) {
305 struct proxy *px2 = container_of(next_by_name, struct proxy, conf.by_name);
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100306
307 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
308 file, linenum, args[arg+1], proxy_cap_str(rc), name,
309 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
310 err_code |= ERR_ALERT | ERR_FATAL;
311 }
312
313 err = invalid_char(args[arg+1]);
314 if (err) {
315 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",
316 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
317 err_code |= ERR_ALERT | ERR_FATAL;
318 }
Christopher Fauletb4054202021-10-12 18:57:43 +0200319 curr_defproxy->flags |= PR_FL_EXPLICIT_REF;
320 }
321 else if (curr_defproxy)
322 curr_defproxy->flags |= PR_FL_IMPLICIT_REF;
323
324 if (curr_defproxy && (curr_defproxy->flags & (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) == (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) {
325 ha_alert("parsing [%s:%d] : defaults section '%s' (declared at %s:%d) is explicitly referenced by another proxy and implicitly used here."
326 " To avoid any ambiguity don't mix both usage. Add a last defaults section not explicitly used or always use explicit references.\n",
327 file, linenum, curr_defproxy->id, curr_defproxy->conf.file, curr_defproxy->conf.line);
328 err_code |= ERR_WARN;
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100329 }
330
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100331 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100332 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100333 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100334 goto out;
335 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100336
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200337 if (curr_defproxy && (!LIST_ISEMPTY(&curr_defproxy->http_req_rules) ||
338 !LIST_ISEMPTY(&curr_defproxy->http_res_rules) ||
339 !LIST_ISEMPTY(&curr_defproxy->http_after_res_rules) ||
340 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
341 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules) ||
342 !LIST_ISEMPTY(&curr_defproxy->tcp_req.inspect_rules) ||
343 !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules))) {
344 /* If the current default proxy defines TCP/HTTP rules, the
345 * current proxy will keep a reference on it. But some sanity
346 * checks are performed first:
347 *
348 * - It cannot be used to init a defaults section
349 * - It cannot be used to init a listen section
350 * - It cannot be used to init backend and frontend sections at
351 * same time. It can be used to init several sections of the
352 * same type only.
353 * - It cannot define L4/L5 TCP rules if it is used to init
354 * backend sections.
355 * - It cannot define 'tcp-response content' rules if it
356 * is used to init frontend sections.
357 *
358 * If no error is found, refcount of the default proxy is incremented.
359 */
360
361 /* Note: Add tcpcheck_rules too if unresolve args become allowed in defaults section */
362 if (rc & PR_CAP_DEF) {
363 ha_alert("parsing [%s:%d]: a defaults section cannot inherit from a defaults section defining TCP/HTTP rules (defaults section at %s:%d).\n",
364 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
365 err_code |= ERR_ALERT | ERR_ABORT;
366 }
367 else if ((rc & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
368 ha_alert("parsing [%s:%d]: a listen section cannot inherit from a defaults section defining TCP/HTTP rules.\n",
369 file, linenum);
370 err_code |= ERR_ALERT | ERR_ABORT;
371 }
372 else {
373 char defcap = (curr_defproxy->cap & PR_CAP_LISTEN);
374
375 if ((defcap == PR_CAP_BE || defcap == PR_CAP_FE) && (rc & PR_CAP_LISTEN) != defcap) {
376 ha_alert("parsing [%s:%d]: frontends and backends cannot inherit from the same defaults section"
377 " if it defines TCP/HTTP rules (defaults section at %s:%d).\n",
378 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
379 err_code |= ERR_ALERT | ERR_ABORT;
380 }
381 else if (!(rc & PR_CAP_FE) && (!LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
382 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules))) {
383 ha_alert("parsing [%s:%d]: a backend section cannot inherit from a defaults section defining"
384 " 'tcp-request connection' or 'tcp-request session' rules (defaults section at %s:%d).\n",
385 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
386 err_code |= ERR_ALERT | ERR_ABORT;
387 }
388 else if (!(rc & PR_CAP_BE) && !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules)) {
389 ha_alert("parsing [%s:%d]: a frontend section cannot inherit from a defaults section defining"
390 " 'tcp-response content' rules (defaults section at %s:%d).\n",
391 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
392 err_code |= ERR_ALERT | ERR_ABORT;
393 }
394 else {
395 curr_defproxy->cap = (curr_defproxy->cap & ~PR_CAP_LISTEN) | (rc & PR_CAP_LISTEN);
396 proxy_ref_defaults(curproxy, curr_defproxy);
397 }
398 }
399 }
400
Christopher Faulet6ff7de52021-10-13 15:18:36 +0200401 if (curr_defproxy && (curr_defproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) &&
402 (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_BE) {
403 /* If the current default proxy defines tcpcheck rules, the
404 * current proxy will keep a reference on it. but only if the
405 * current proxy has the backend capability.
406 */
407 proxy_ref_defaults(curproxy, curr_defproxy);
408 }
409
Christopher Faulet6c10f5c2022-04-25 14:24:56 +0200410 if ((rc & PR_CAP_BE) && curr_defproxy && (curr_defproxy->nb_req_cap || curr_defproxy->nb_rsp_cap)) {
411 ha_alert("parsing [%s:%d]: backend or defaults sections cannot inherit from a defaults section defining"
412 " capptures (defaults section at %s:%d).\n",
413 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
414 err_code |= ERR_ALERT | ERR_ABORT;
415 }
416
Willy Tarreaue90904d2021-02-12 14:08:31 +0100417 if (rc & PR_CAP_DEF) {
418 /* last and current proxies must be updated to this one */
419 curr_defproxy = last_defproxy = curproxy;
420 } else {
421 /* regular proxies are in a list */
422 curproxy->next = proxies_list;
423 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100424 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100425 goto out;
426 }
427 else if (curproxy == NULL) {
428 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
429 err_code |= ERR_ALERT | ERR_FATAL;
430 goto out;
431 }
432
433 /* update the current file and line being parsed */
434 curproxy->conf.args.file = curproxy->conf.file;
435 curproxy->conf.args.line = linenum;
436
437 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100438 if ((strcmp(args[0], "server") == 0)) {
439 err_code |= parse_server(file, linenum, args,
440 curproxy, curr_defproxy,
441 SRV_PARSE_PARSE_ADDR);
442
443 if (err_code & ERR_FATAL)
444 goto out;
445 }
446 else if (strcmp(args[0], "default-server") == 0) {
447 err_code |= parse_server(file, linenum, args,
448 curproxy, curr_defproxy,
449 SRV_PARSE_DEFAULT_SERVER);
450
451 if (err_code & ERR_FATAL)
452 goto out;
453 }
454 else if (strcmp(args[0], "server-template") == 0) {
455 err_code |= parse_server(file, linenum, args,
456 curproxy, curr_defproxy,
457 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
458
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100459 if (err_code & ERR_FATAL)
460 goto out;
461 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100462 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100463 struct listener *l;
464 int cur_arg;
465
Willy Tarreau5d095c22021-02-12 10:15:59 +0100466 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100467 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
468 err_code |= ERR_ALERT | ERR_FATAL;
469 goto out;
470 }
471 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
472 err_code |= ERR_WARN;
473
474 if (!*(args[1])) {
475 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
476 file, linenum, args[0]);
477 err_code |= ERR_ALERT | ERR_FATAL;
478 goto out;
479 }
480
481 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200482 if (!bind_conf)
483 goto alloc_error;
484
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100485 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200486 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
487 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
488 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100489
490 /* NOTE: the following line might create several listeners if there
491 * are comma-separated IPs or port ranges. So all further processing
492 * will have to be applied to all listeners created after last_listen.
493 */
494 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
495 if (errmsg && *errmsg) {
496 indent_msg(&errmsg, 2);
497 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
498 }
499 else
500 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
501 file, linenum, args[0], args[1]);
502 err_code |= ERR_ALERT | ERR_FATAL;
503 goto out;
504 }
505
506 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
507 /* Set default global rights and owner for unix bind */
508 global.maxsock++;
509 }
510
511 cur_arg = 2;
Willy Tarreau55f0f7b2022-05-20 15:44:17 +0200512 err_code |= bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100513 goto out;
514 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100515 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200516 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]);
517 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100518 goto out;
519 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100520 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100521 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
522 err_code |= ERR_WARN;
523
524 if (alertif_too_many_args(1, file, linenum, args, &err_code))
525 goto out;
526
527 if (!*args[1]) {
528 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
529 file, linenum, args[0]);
530 err_code |= ERR_ALERT | ERR_FATAL;
531 goto out;
532 }
533
Tim Duesterhus4b1fcaa2022-03-05 00:52:40 +0100534 istfree(&curproxy->monitor_uri);
535 curproxy->monitor_uri = istdup(ist(args[1]));
536 if (!isttest(curproxy->monitor_uri))
Christopher Fauletb15625a2021-04-12 21:31:45 +0200537 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100538
539 goto out;
540 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100541 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100542 if (alertif_too_many_args(1, file, linenum, args, &err_code))
543 goto out;
544
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100545 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
546 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
547 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200548 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
549 err_code |= ERR_ALERT | ERR_FATAL;
550 goto out;
551 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100552 else {
553 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
554 err_code |= ERR_ALERT | ERR_FATAL;
555 goto out;
556 }
557 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100558 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100559 struct eb32_node *node;
560
Willy Tarreau5d095c22021-02-12 10:15:59 +0100561 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100562 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
563 file, linenum, args[0]);
564 err_code |= ERR_ALERT | ERR_FATAL;
565 goto out;
566 }
567
568 if (alertif_too_many_args(1, file, linenum, args, &err_code))
569 goto out;
570
571 if (!*args[1]) {
572 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
573 file, linenum, args[0]);
574 err_code |= ERR_ALERT | ERR_FATAL;
575 goto out;
576 }
577
578 curproxy->uuid = atol(args[1]);
579 curproxy->conf.id.key = curproxy->uuid;
580 curproxy->options |= PR_O_FORCED_ID;
581
582 if (curproxy->uuid <= 0) {
583 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
584 file, linenum);
585 err_code |= ERR_ALERT | ERR_FATAL;
586 goto out;
587 }
588
589 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
590 if (node) {
591 struct proxy *target = container_of(node, struct proxy, conf.id);
592 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
593 file, linenum, proxy_type_str(curproxy), curproxy->id,
594 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
595 err_code |= ERR_ALERT | ERR_FATAL;
596 goto out;
597 }
598 eb32_insert(&used_proxy_id, &curproxy->conf.id);
599 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100600 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100601 int i, len=0;
602 char *d;
603
Willy Tarreau5d095c22021-02-12 10:15:59 +0100604 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100605 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
606 file, linenum, args[0]);
607 err_code |= ERR_ALERT | ERR_FATAL;
608 goto out;
609 }
610
611 if (!*args[1]) {
612 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
613 file, linenum, args[0]);
614 return -1;
615 }
616
617 for (i = 1; *args[i]; i++)
618 len += strlen(args[i]) + 1;
619
620 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200621 if (!d)
622 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100623 curproxy->desc = d;
624
625 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
626 for (i = 2; *args[i]; i++)
627 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
628
629 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100630 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100631 if (alertif_too_many_args(0, file, linenum, args, &err_code))
632 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200633 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100634 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100635 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100636 if (alertif_too_many_args(0, file, linenum, args, &err_code))
637 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200638 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100639 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100640 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau94f763b2022-07-15 17:14:40 +0200641 ha_alert("parsing [%s:%d]: '%s' is not supported anymore.\n", file, linenum, args[0]);
642 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100644 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200645 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
646 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100647 err_code |= ERR_ALERT | ERR_FATAL;
648 goto out;
649 }
650
651 err = invalid_char(args[1]);
652 if (err) {
653 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
654 file, linenum, *err, args[1]);
655 err_code |= ERR_ALERT | ERR_FATAL;
656 goto out;
657 }
658
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100659 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100660 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100661 "logical disjunction within a condition.\n",
662 file, linenum, args[1]);
663 err_code |= ERR_ALERT | ERR_FATAL;
664 goto out;
665 }
666
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100667 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
668 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
669 file, linenum, args[1], errmsg);
670 err_code |= ERR_ALERT | ERR_FATAL;
671 goto out;
672 }
673 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100674 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100675
676 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
677 err_code |= ERR_WARN;
678
679 if (*(args[1]) == 0) {
680 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
681 file, linenum, args[0]);
682 err_code |= ERR_ALERT | ERR_FATAL;
683 goto out;
684 }
685 free(curproxy->dyncookie_key);
686 curproxy->dyncookie_key = strdup(args[1]);
687 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100688 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100689 int cur_arg;
690
691 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
692 err_code |= ERR_WARN;
693
694 if (*(args[1]) == 0) {
695 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
696 file, linenum, args[0]);
697 err_code |= ERR_ALERT | ERR_FATAL;
698 goto out;
699 }
700
701 curproxy->ck_opts = 0;
702 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100703 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100704 free(curproxy->cookie_name);
705 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200706 if (!curproxy->cookie_name)
707 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100708 curproxy->cookie_len = strlen(curproxy->cookie_name);
709
710 cur_arg = 2;
711 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100712 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100713 curproxy->ck_opts |= PR_CK_RW;
714 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100715 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100716 curproxy->ck_opts |= PR_CK_IND;
717 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100718 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100719 curproxy->ck_opts |= PR_CK_INS;
720 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100721 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100722 curproxy->ck_opts |= PR_CK_NOC;
723 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100724 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100725 curproxy->ck_opts |= PR_CK_POST;
726 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100727 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100728 curproxy->ck_opts |= PR_CK_PSV;
729 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100730 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100731 curproxy->ck_opts |= PR_CK_PFX;
732 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100733 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100734 curproxy->ck_opts |= PR_CK_HTTPONLY;
735 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100736 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100737 curproxy->ck_opts |= PR_CK_SECURE;
738 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100739 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100740 if (!*args[cur_arg + 1]) {
741 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
742 file, linenum, args[cur_arg]);
743 err_code |= ERR_ALERT | ERR_FATAL;
744 goto out;
745 }
746
Joao Moraise1583752019-10-30 21:04:00 -0300747 if (!strchr(args[cur_arg + 1], '.')) {
748 /* rfc6265, 5.2.3 The Domain Attribute */
749 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
750 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100751 file, linenum, args[cur_arg + 1]);
752 err_code |= ERR_WARN;
753 }
754
755 err = invalid_domainchar(args[cur_arg + 1]);
756 if (err) {
757 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
758 file, linenum, *err, args[cur_arg + 1]);
759 err_code |= ERR_ALERT | ERR_FATAL;
760 goto out;
761 }
762
763 if (!curproxy->cookie_domain) {
764 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
765 } else {
766 /* one domain was already specified, add another one by
767 * building the string which will be returned along with
768 * the cookie.
769 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200770 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
771 }
772
Christopher Fauletb15625a2021-04-12 21:31:45 +0200773 if (!curproxy->cookie_domain)
774 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100775 cur_arg++;
776 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100777 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100778 unsigned int maxidle;
779 const char *res;
780
781 if (!*args[cur_arg + 1]) {
782 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
783 file, linenum, args[cur_arg]);
784 err_code |= ERR_ALERT | ERR_FATAL;
785 goto out;
786 }
787
788 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200789 if (res == PARSE_TIME_OVER) {
790 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
791 file, linenum, args[cur_arg+1], args[cur_arg]);
792 err_code |= ERR_ALERT | ERR_FATAL;
793 goto out;
794 }
795 else if (res == PARSE_TIME_UNDER) {
796 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
797 file, linenum, args[cur_arg+1], args[cur_arg]);
798 err_code |= ERR_ALERT | ERR_FATAL;
799 goto out;
800 }
801 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100802 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
803 file, linenum, *res, args[cur_arg]);
804 err_code |= ERR_ALERT | ERR_FATAL;
805 goto out;
806 }
807 curproxy->cookie_maxidle = maxidle;
808 cur_arg++;
809 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100810 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100811 unsigned int maxlife;
812 const char *res;
813
814 if (!*args[cur_arg + 1]) {
815 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
816 file, linenum, args[cur_arg]);
817 err_code |= ERR_ALERT | ERR_FATAL;
818 goto out;
819 }
820
Willy Tarreau9faebe32019-06-07 19:00:37 +0200821
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100822 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200823 if (res == PARSE_TIME_OVER) {
824 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
825 file, linenum, args[cur_arg+1], args[cur_arg]);
826 err_code |= ERR_ALERT | ERR_FATAL;
827 goto out;
828 }
829 else if (res == PARSE_TIME_UNDER) {
830 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
831 file, linenum, args[cur_arg+1], args[cur_arg]);
832 err_code |= ERR_ALERT | ERR_FATAL;
833 goto out;
834 }
835 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100836 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
837 file, linenum, *res, args[cur_arg]);
838 err_code |= ERR_ALERT | ERR_FATAL;
839 goto out;
840 }
841 curproxy->cookie_maxlife = maxlife;
842 cur_arg++;
843 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100844 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100845
846 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
847 err_code |= ERR_WARN;
848 curproxy->ck_opts |= PR_CK_DYNAMIC;
849 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100850 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100851 char *val;
852 if (!*args[cur_arg + 1]) {
853 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
854 file, linenum, args[cur_arg]);
855 err_code |= ERR_ALERT | ERR_FATAL;
856 goto out;
857 }
858 val = args[cur_arg + 1];
859 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100860 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100861 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
862 file, linenum, *val);
863 err_code |= ERR_ALERT | ERR_FATAL;
864 goto out;
865 }
866 val++;
867 }
868 /* don't add ';' for the first attribute */
869 if (!curproxy->cookie_attrs)
870 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
871 else
872 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200873
Christopher Fauletb15625a2021-04-12 21:31:45 +0200874 if (!curproxy->cookie_attrs)
875 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100876 cur_arg++;
877 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100878
879 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100880 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 +0100881 file, linenum, args[0]);
882 err_code |= ERR_ALERT | ERR_FATAL;
883 goto out;
884 }
885 cur_arg++;
886 }
887 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
888 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
889 file, linenum);
890 err_code |= ERR_ALERT | ERR_FATAL;
891 }
892
893 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
894 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
895 file, linenum);
896 err_code |= ERR_ALERT | ERR_FATAL;
897 }
898
899 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
900 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
901 file, linenum);
902 err_code |= ERR_ALERT | ERR_FATAL;
903 }
904 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100905 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100906 if (*(args[1]) == 0) {
907 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
908 file, linenum, args[0]);
909 err_code |= ERR_ALERT | ERR_FATAL;
910 goto out;
911 }
912
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100913 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100914 if (*(args[1]) == 0) {
915 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
916 file, linenum, args[1]);
917 err_code |= ERR_ALERT | ERR_FATAL;
918 goto out;
919 }
920 free(curproxy->email_alert.from);
921 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200922 if (!curproxy->email_alert.from)
923 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100924 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100925 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100926 if (*(args[1]) == 0) {
927 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
928 file, linenum, args[1]);
929 err_code |= ERR_ALERT | ERR_FATAL;
930 goto out;
931 }
932 free(curproxy->email_alert.mailers.name);
933 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200934 if (!curproxy->email_alert.mailers.name)
935 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100936 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100937 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100938 if (*(args[1]) == 0) {
939 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
940 file, linenum, args[1]);
941 err_code |= ERR_ALERT | ERR_FATAL;
942 goto out;
943 }
944 free(curproxy->email_alert.myhostname);
945 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200946 if (!curproxy->email_alert.myhostname)
947 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100948 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100949 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100950 curproxy->email_alert.level = get_log_level(args[2]);
951 if (curproxy->email_alert.level < 0) {
952 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
953 file, linenum, args[1], args[2]);
954 err_code |= ERR_ALERT | ERR_FATAL;
955 goto out;
956 }
957 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100958 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100959 if (*(args[1]) == 0) {
960 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
961 file, linenum, args[1]);
962 err_code |= ERR_ALERT | ERR_FATAL;
963 goto out;
964 }
965 free(curproxy->email_alert.to);
966 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200967 if (!curproxy->email_alert.to)
968 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100969 }
970 else {
971 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
972 file, linenum, args[1]);
973 err_code |= ERR_ALERT | ERR_FATAL;
974 goto out;
975 }
976 /* Indicate that the email_alert is at least partially configured */
977 curproxy->email_alert.set = 1;
978 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100979 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100980 if (*(args[1]) == 0) {
981 ha_alert("parsing [%s:%d] : missing persist method.\n",
982 file, linenum);
983 err_code |= ERR_ALERT | ERR_FATAL;
984 goto out;
985 }
986
987 if (!strncmp(args[1], "rdp-cookie", 10)) {
988 curproxy->options2 |= PR_O2_RDPC_PRST;
989
990 if (*(args[1] + 10) == '(') { /* cookie name */
991 const char *beg, *end;
992
993 beg = args[1] + 11;
994 end = strchr(beg, ')');
995
996 if (alertif_too_many_args(1, file, linenum, args, &err_code))
997 goto out;
998
999 if (!end || end == beg) {
1000 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1001 file, linenum);
1002 err_code |= ERR_ALERT | ERR_FATAL;
1003 goto out;
1004 }
1005
1006 free(curproxy->rdp_cookie_name);
1007 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001008 if (!curproxy->rdp_cookie_name)
1009 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001010 curproxy->rdp_cookie_len = end-beg;
1011 }
1012 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1013 free(curproxy->rdp_cookie_name);
1014 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +02001015 if (!curproxy->rdp_cookie_name)
1016 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001017 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1018 }
1019 else { /* syntax */
1020 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1021 file, linenum);
1022 err_code |= ERR_ALERT | ERR_FATAL;
1023 goto out;
1024 }
1025 }
1026 else {
1027 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1028 file, linenum);
1029 err_code |= ERR_ALERT | ERR_FATAL;
1030 goto out;
1031 }
1032 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001033 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001034 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 +01001035 err_code |= ERR_ALERT | ERR_FATAL;
1036 goto out;
1037 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001038 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001039 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1040 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001041 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001042 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1043 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001044 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 +01001045 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1046 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001047 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001048 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1049 }
1050 else {
1051 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1052 file, linenum, args[0], args[1]);
1053 err_code |= ERR_ALERT | ERR_FATAL;
1054 goto out;
1055 }
1056 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001057 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001058 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1059 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001060 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001061 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001062
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001063 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001064
1065 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001066 curproxy->server_state_file_name = strdup(curproxy->id);
1067 else
1068 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001069
Christopher Fauletb15625a2021-04-12 21:31:45 +02001070 if (!curproxy->server_state_file_name)
1071 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001072 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001073 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001074 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1075 err_code |= ERR_WARN;
1076 if (*(args[1]) == 0) {
1077 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1078 file, linenum, args[0]);
1079 err_code |= ERR_ALERT | ERR_FATAL;
1080 goto out;
1081 }
1082 curproxy->max_out_conns = atoi(args[1]);
1083 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001084 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001085 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1086 err_code |= ERR_WARN;
1087
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001088 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001089 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001090 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1091 err_code |= ERR_ALERT | ERR_FATAL;
1092 goto out;
1093 }
1094
1095 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1096 goto out;
1097
1098 if (*(args[4]) == 0) {
1099 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1100 file, linenum, args[0]);
1101 err_code |= ERR_ALERT | ERR_FATAL;
1102 goto out;
1103 }
1104 free(curproxy->capture_name);
1105 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001106 if (!curproxy->capture_name)
1107 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001108 curproxy->capture_namelen = strlen(curproxy->capture_name);
1109 curproxy->capture_len = atol(args[4]);
1110 curproxy->to_log |= LW_COOKIE;
1111 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001112 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001113 struct cap_hdr *hdr;
1114
Willy Tarreau5d095c22021-02-12 10:15:59 +01001115 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001116 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1117 err_code |= ERR_ALERT | ERR_FATAL;
1118 goto out;
1119 }
1120
1121 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1122 goto out;
1123
1124 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1125 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1126 file, linenum, args[0], args[1]);
1127 err_code |= ERR_ALERT | ERR_FATAL;
1128 goto out;
1129 }
1130
1131 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001132 if (!hdr)
1133 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001134 hdr->next = curproxy->req_cap;
1135 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001136 if (!hdr->name)
1137 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001138 hdr->namelen = strlen(args[3]);
1139 hdr->len = atol(args[5]);
1140 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001141 if (!hdr->pool) {
1142 req_caphdr_alloc_error:
1143 if (hdr)
1144 ha_free(&hdr->name);
1145 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001146 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001147 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001148 hdr->index = curproxy->nb_req_cap++;
1149 curproxy->req_cap = hdr;
1150 curproxy->to_log |= LW_REQHDR;
1151 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001152 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001153 struct cap_hdr *hdr;
1154
Willy Tarreau5d095c22021-02-12 10:15:59 +01001155 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001156 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1157 err_code |= ERR_ALERT | ERR_FATAL;
1158 goto out;
1159 }
1160
1161 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1162 goto out;
1163
1164 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1165 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1166 file, linenum, args[0], args[1]);
1167 err_code |= ERR_ALERT | ERR_FATAL;
1168 goto out;
1169 }
1170 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001171 if (!hdr)
1172 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001173 hdr->next = curproxy->rsp_cap;
1174 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001175 if (!hdr->name)
1176 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001177 hdr->namelen = strlen(args[3]);
1178 hdr->len = atol(args[5]);
1179 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001180 if (!hdr->pool) {
1181 res_caphdr_alloc_error:
1182 if (hdr)
1183 ha_free(&hdr->name);
1184 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001185 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001186 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001187 hdr->index = curproxy->nb_rsp_cap++;
1188 curproxy->rsp_cap = hdr;
1189 curproxy->to_log |= LW_RSPHDR;
1190 }
1191 else {
1192 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1193 file, linenum, args[0]);
1194 err_code |= ERR_ALERT | ERR_FATAL;
1195 goto out;
1196 }
1197 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001198 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001199 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1200 err_code |= ERR_WARN;
1201
1202 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1203 goto out;
1204
1205 if (*(args[1]) == 0) {
1206 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1207 file, linenum, args[0]);
1208 err_code |= ERR_ALERT | ERR_FATAL;
1209 goto out;
1210 }
1211 curproxy->conn_retries = atol(args[1]);
1212 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001213 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001214 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001215 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001216
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001217 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1218 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001219 err_code |= ERR_ALERT | ERR_FATAL;
1220 goto out;
1221 }
1222
1223 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1224 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001225 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001226 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1227 file, linenum, args[0]);
1228 err_code |= ERR_WARN;
1229 }
1230
1231 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1232
1233 if (!rule) {
1234 err_code |= ERR_ALERT | ERR_ABORT;
1235 goto out;
1236 }
1237
1238 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001239
1240 if (curproxy->cap & PR_CAP_FE)
1241 where |= SMP_VAL_FE_HRQ_HDR;
1242 if (curproxy->cap & PR_CAP_BE)
1243 where |= SMP_VAL_BE_HRQ_HDR;
1244 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001245
Willy Tarreau2b718102021-04-21 07:32:39 +02001246 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001247 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001248 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001249 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001250 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001251
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001252 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1253 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001254 err_code |= ERR_ALERT | ERR_FATAL;
1255 goto out;
1256 }
1257
1258 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1259 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001260 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001261 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1262 file, linenum, args[0]);
1263 err_code |= ERR_WARN;
1264 }
1265
1266 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1267
1268 if (!rule) {
1269 err_code |= ERR_ALERT | ERR_ABORT;
1270 goto out;
1271 }
1272
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001273 if (curproxy->cap & PR_CAP_FE)
1274 where |= SMP_VAL_FE_HRS_HDR;
1275 if (curproxy->cap & PR_CAP_BE)
1276 where |= SMP_VAL_BE_HRS_HDR;
1277 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001278
Willy Tarreau2b718102021-04-21 07:32:39 +02001279 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001280 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001281 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001282 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001283 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001284 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1285 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
1289
1290 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1291 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1292 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1293 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1294 file, linenum, args[0]);
1295 err_code |= ERR_WARN;
1296 }
1297
1298 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1299
1300 if (!rule) {
1301 err_code |= ERR_ALERT | ERR_ABORT;
1302 goto out;
1303 }
1304
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001305 if (curproxy->cap & PR_CAP_FE)
1306 where |= SMP_VAL_FE_HRS_HDR;
1307 if (curproxy->cap & PR_CAP_BE)
1308 where |= SMP_VAL_BE_HRS_HDR;
1309 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001310
Willy Tarreau2b718102021-04-21 07:32:39 +02001311 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001312 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001313 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001314 /* set the header name and length into the proxy structure */
1315 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1316 err_code |= ERR_WARN;
1317
1318 if (!*args[1]) {
1319 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1320 file, linenum, args[0]);
1321 err_code |= ERR_ALERT | ERR_FATAL;
1322 goto out;
1323 }
1324
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001325 /* set the desired header name, in lower case */
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001326 istfree(&curproxy->server_id_hdr_name);
1327 curproxy->server_id_hdr_name = istdup(ist(args[1]));
1328 if (!isttest(curproxy->server_id_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02001329 goto alloc_error;
Tim Duesterhusb4b03772022-03-05 00:52:43 +01001330 ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001331 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001332 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001333 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 +01001334
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001335 err_code |= ERR_ALERT | ERR_FATAL;
1336 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001337 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001338 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001339 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001340 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001341
Willy Tarreau5d095c22021-02-12 10:15:59 +01001342 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001343 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1344 err_code |= ERR_ALERT | ERR_FATAL;
1345 goto out;
1346 }
1347
1348 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1349 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1350 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1351 err_code |= ERR_ALERT | ERR_FATAL;
1352 goto out;
1353 }
1354
Willy Tarreau2b718102021-04-21 07:32:39 +02001355 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001356 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001357
1358 if (curproxy->cap & PR_CAP_FE)
1359 where |= SMP_VAL_FE_HRQ_HDR;
1360 if (curproxy->cap & PR_CAP_BE)
1361 where |= SMP_VAL_BE_HRQ_HDR;
1362 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001363 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001364 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001365 struct switching_rule *rule;
1366
Willy Tarreau5d095c22021-02-12 10:15:59 +01001367 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001368 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1369 err_code |= ERR_ALERT | ERR_FATAL;
1370 goto out;
1371 }
1372
1373 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1374 err_code |= ERR_WARN;
1375
1376 if (*(args[1]) == 0) {
1377 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1378 err_code |= ERR_ALERT | ERR_FATAL;
1379 goto out;
1380 }
1381
1382 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1383 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1384 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1385 file, linenum, errmsg);
1386 err_code |= ERR_ALERT | ERR_FATAL;
1387 goto out;
1388 }
1389
1390 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1391 }
1392 else if (*args[2]) {
1393 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1394 file, linenum, args[2]);
1395 err_code |= ERR_ALERT | ERR_FATAL;
1396 goto out;
1397 }
1398
1399 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001400 if (!rule)
1401 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001402 rule->cond = cond;
1403 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001404 if (!rule->be.name)
1405 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001406 rule->line = linenum;
1407 rule->file = strdup(file);
1408 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001409 use_backend_alloc_error:
1410 if (cond)
1411 prune_acl_cond(cond);
1412 ha_free(&cond);
1413 if (rule)
1414 ha_free(&(rule->be.name));
1415 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001416 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001417 }
1418 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001419 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001420 }
1421 else if (strcmp(args[0], "use-server") == 0) {
1422 struct server_rule *rule;
1423
Willy Tarreau5d095c22021-02-12 10:15:59 +01001424 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001425 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1426 err_code |= ERR_ALERT | ERR_FATAL;
1427 goto out;
1428 }
1429
1430 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1431 err_code |= ERR_WARN;
1432
1433 if (*(args[1]) == 0) {
1434 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1435 err_code |= ERR_ALERT | ERR_FATAL;
1436 goto out;
1437 }
1438
1439 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1440 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1441 file, linenum, args[0]);
1442 err_code |= ERR_ALERT | ERR_FATAL;
1443 goto out;
1444 }
1445
1446 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1447 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1448 file, linenum, errmsg);
1449 err_code |= ERR_ALERT | ERR_FATAL;
1450 goto out;
1451 }
1452
1453 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1454
1455 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001456 if (!rule)
1457 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001458 rule->cond = cond;
1459 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001460 if (!rule->srv.name)
1461 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001462 rule->line = linenum;
1463 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001464 if (!rule->file) {
1465 use_server_alloc_error:
1466 if (cond)
1467 prune_acl_cond(cond);
1468 ha_free(&cond);
1469 if (rule)
1470 ha_free(&(rule->srv.name));
1471 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001472 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001473 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001474 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001475 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001476 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1477 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001478 else if ((strcmp(args[0], "force-persist") == 0) ||
1479 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001480 struct persist_rule *rule;
1481
Willy Tarreau5d095c22021-02-12 10:15:59 +01001482 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001483 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1484 err_code |= ERR_ALERT | ERR_FATAL;
1485 goto out;
1486 }
1487
1488 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1489 err_code |= ERR_WARN;
1490
1491 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1492 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1493 file, linenum, args[0]);
1494 err_code |= ERR_ALERT | ERR_FATAL;
1495 goto out;
1496 }
1497
1498 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1499 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1500 file, linenum, args[0], errmsg);
1501 err_code |= ERR_ALERT | ERR_FATAL;
1502 goto out;
1503 }
1504
1505 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1506 * where force-persist is applied.
1507 */
1508 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1509
1510 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001511 if (!rule) {
1512 if (cond)
1513 prune_acl_cond(cond);
1514 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001515 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001516 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001517 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001518 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001519 rule->type = PERSIST_TYPE_FORCE;
1520 } else {
1521 rule->type = PERSIST_TYPE_IGNORE;
1522 }
1523 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001524 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001525 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001526 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001527 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001528
Willy Tarreau5d095c22021-02-12 10:15:59 +01001529 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001530 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1531 file, linenum);
1532 err_code |= ERR_ALERT | ERR_FATAL;
1533 goto out;
1534 }
1535
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001536 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001537 if (other) {
1538 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 +01001539 file, linenum, curproxy->id,
1540 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1541 other->proxy ? other->id : other->peers.p->id,
1542 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001543 err_code |= ERR_ALERT | ERR_FATAL;
1544 goto out;
1545 }
1546
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001547 curproxy->table = calloc(1, sizeof *curproxy->table);
1548 if (!curproxy->table) {
1549 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1550 file, linenum, args[0], args[1]);
1551 err_code |= ERR_ALERT | ERR_FATAL;
1552 goto out;
1553 }
1554
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001555 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1556 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001557 if (err_code & ERR_FATAL) {
1558 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001559 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001560 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001561
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001562 /* Store the proxy in the stick-table. */
1563 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001564
1565 stktable_store_name(curproxy->table);
1566 curproxy->table->next = stktables_list;
1567 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001568
1569 /* Add this proxy to the list of proxies which refer to its stick-table. */
1570 if (curproxy->table->proxies_list != curproxy) {
1571 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1572 curproxy->table->proxies_list = curproxy;
1573 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001574 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001575 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001576 struct sticking_rule *rule;
1577 struct sample_expr *expr;
1578 int myidx = 0;
1579 const char *name = NULL;
1580 int flags;
1581
Willy Tarreau5d095c22021-02-12 10:15:59 +01001582 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001583 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1584 err_code |= ERR_ALERT | ERR_FATAL;
1585 goto out;
1586 }
1587
1588 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1589 err_code |= ERR_WARN;
1590 goto out;
1591 }
1592
1593 myidx++;
1594 if ((strcmp(args[myidx], "store") == 0) ||
1595 (strcmp(args[myidx], "store-request") == 0)) {
1596 myidx++;
1597 flags = STK_IS_STORE;
1598 }
1599 else if (strcmp(args[myidx], "store-response") == 0) {
1600 myidx++;
1601 flags = STK_IS_STORE | STK_ON_RSP;
1602 }
1603 else if (strcmp(args[myidx], "match") == 0) {
1604 myidx++;
1605 flags = STK_IS_MATCH;
1606 }
1607 else if (strcmp(args[myidx], "on") == 0) {
1608 myidx++;
1609 flags = STK_IS_MATCH | STK_IS_STORE;
1610 }
1611 else {
1612 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1613 err_code |= ERR_ALERT | ERR_FATAL;
1614 goto out;
1615 }
1616
1617 if (*(args[myidx]) == 0) {
1618 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1619 err_code |= ERR_ALERT | ERR_FATAL;
1620 goto out;
1621 }
1622
1623 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001624 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001625 if (!expr) {
1626 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1627 err_code |= ERR_ALERT | ERR_FATAL;
1628 goto out;
1629 }
1630
1631 if (flags & STK_ON_RSP) {
1632 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1633 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1634 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1635 err_code |= ERR_ALERT | ERR_FATAL;
1636 free(expr);
1637 goto out;
1638 }
1639 } else {
1640 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1641 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1642 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1643 err_code |= ERR_ALERT | ERR_FATAL;
1644 free(expr);
1645 goto out;
1646 }
1647 }
1648
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001649 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001650 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1651
1652 if (strcmp(args[myidx], "table") == 0) {
1653 myidx++;
1654 name = args[myidx++];
1655 }
1656
1657 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1658 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1659 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1660 file, linenum, args[0], errmsg);
1661 err_code |= ERR_ALERT | ERR_FATAL;
1662 free(expr);
1663 goto out;
1664 }
1665 }
1666 else if (*(args[myidx])) {
1667 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1668 file, linenum, args[0], args[myidx]);
1669 err_code |= ERR_ALERT | ERR_FATAL;
1670 free(expr);
1671 goto out;
1672 }
1673 if (flags & STK_ON_RSP)
1674 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1675 else
1676 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1677
1678 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001679 if (!rule) {
1680 if (cond)
1681 prune_acl_cond(cond);
1682 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001683 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001684 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001685 rule->cond = cond;
1686 rule->expr = expr;
1687 rule->flags = flags;
1688 rule->table.name = name ? strdup(name) : NULL;
1689 LIST_INIT(&rule->list);
1690 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001691 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001692 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001693 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001694 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001695 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001696 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001697 curproxy->uri_auth = NULL; /* we must detach from the default config */
1698
1699 if (!*args[1]) {
1700 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001701 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001702 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001703 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001704
Willy Tarreau5d095c22021-02-12 10:15:59 +01001705 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1707 err_code |= ERR_ALERT | ERR_FATAL;
1708 goto out;
1709 }
1710
Christopher Fauletb15625a2021-04-12 21:31:45 +02001711 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1712 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001713
1714 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1715 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1716 file, linenum, args[0], args[1]);
1717 err_code |= ERR_ALERT | ERR_FATAL;
1718 goto out;
1719 }
1720 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1721 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1722 file, linenum, args[0], args[1], errmsg);
1723 err_code |= ERR_ALERT | ERR_FATAL;
1724 goto out;
1725 }
1726
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001727 if (curproxy->cap & PR_CAP_FE)
1728 where |= SMP_VAL_FE_HRQ_HDR;
1729 if (curproxy->cap & PR_CAP_BE)
1730 where |= SMP_VAL_BE_HRQ_HDR;
1731 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001732
1733 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001734 if (!rule) {
1735 if (cond)
1736 prune_acl_cond(cond);
1737 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001738 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001739 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001740 rule->cond = cond;
1741 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001742 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001743 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001744 if (*(args[2]) == 0) {
1745 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1746 err_code |= ERR_ALERT | ERR_FATAL;
1747 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001748 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1749 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001750 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001751 if (*(args[2]) == 0) {
1752 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1753 err_code |= ERR_ALERT | ERR_FATAL;
1754 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001755 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1756 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001757 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001758 unsigned interval;
1759
1760 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001761 if (err == PARSE_TIME_OVER) {
1762 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1763 file, linenum, args[2]);
1764 err_code |= ERR_ALERT | ERR_FATAL;
1765 goto out;
1766 }
1767 else if (err == PARSE_TIME_UNDER) {
1768 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1769 file, linenum, args[2]);
1770 err_code |= ERR_ALERT | ERR_FATAL;
1771 goto out;
1772 }
1773 else if (err) {
1774 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001775 file, linenum, *err);
1776 err_code |= ERR_ALERT | ERR_FATAL;
1777 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001778 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1779 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001780 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001781 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001782 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001783
Willy Tarreau5d095c22021-02-12 10:15:59 +01001784 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001785 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1786 err_code |= ERR_ALERT | ERR_FATAL;
1787 goto out;
1788 }
1789
Christopher Fauletb15625a2021-04-12 21:31:45 +02001790 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1791 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001792
1793 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1794 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1795 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1796 file, linenum, args[0]);
1797 err_code |= ERR_WARN;
1798 }
1799
1800 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1801
1802 if (!rule) {
1803 err_code |= ERR_ALERT | ERR_ABORT;
1804 goto out;
1805 }
1806
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001807 if (curproxy->cap & PR_CAP_FE)
1808 where |= SMP_VAL_FE_HRQ_HDR;
1809 if (curproxy->cap & PR_CAP_BE)
1810 where |= SMP_VAL_BE_HRQ_HDR;
1811 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001812 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001813
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001814 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001815 if (*(args[2]) == 0) {
1816 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1817 err_code |= ERR_ALERT | ERR_FATAL;
1818 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001819 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1820 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001821 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001822 if (*(args[2]) == 0) {
1823 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1824 err_code |= ERR_ALERT | ERR_FATAL;
1825 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001826 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1827 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001828 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001829 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1830 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001831 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001832 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1833 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001834 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001835 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1836 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001837 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001838 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1839 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001840 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001841
1842 if (*args[2]) {
1843 int i;
1844 char c;
1845
1846 for (i=0; args[2][i]; i++) {
1847 c = args[2][i];
1848 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1849 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1850 break;
1851 }
1852
1853 if (!i || args[2][i]) {
1854 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1855 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1856 file, linenum, args[0], args[1]);
1857 err_code |= ERR_ALERT | ERR_FATAL;
1858 goto out;
1859 }
1860 }
1861
Christopher Fauletb15625a2021-04-12 21:31:45 +02001862 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1863 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001864 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001865 char *desc = NULL;
1866
1867 if (*args[2]) {
1868 int i, len=0;
1869 char *d;
1870
1871 for (i = 2; *args[i]; i++)
1872 len += strlen(args[i]) + 1;
1873
1874 desc = d = calloc(1, len);
1875
1876 d += snprintf(d, desc + len - d, "%s", args[2]);
1877 for (i = 3; *args[i]; i++)
1878 d += snprintf(d, desc + len - d, " %s", args[i]);
1879 }
1880
1881 if (!*args[2] && !global.desc)
1882 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1883 file, linenum, args[1]);
1884 else {
1885 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1886 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001887 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001888 }
1889 free(desc);
1890 }
1891 } else {
1892stats_error_parsing:
1893 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1894 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1895 err_code |= ERR_ALERT | ERR_FATAL;
1896 goto out;
1897 }
1898 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001899 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001900 int optnum;
1901
1902 if (*(args[1]) == '\0') {
1903 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1904 file, linenum, args[0]);
1905 err_code |= ERR_ALERT | ERR_FATAL;
1906 goto out;
1907 }
1908
1909 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001910 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001911 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1912 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1913 file, linenum, cfg_opts[optnum].name);
1914 err_code |= ERR_ALERT | ERR_FATAL;
1915 goto out;
1916 }
1917 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1918 goto out;
1919
1920 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1921 err_code |= ERR_WARN;
1922 goto out;
1923 }
1924
1925 curproxy->no_options &= ~cfg_opts[optnum].val;
1926 curproxy->options &= ~cfg_opts[optnum].val;
1927
1928 switch (kwm) {
1929 case KWM_STD:
1930 curproxy->options |= cfg_opts[optnum].val;
1931 break;
1932 case KWM_NO:
1933 curproxy->no_options |= cfg_opts[optnum].val;
1934 break;
1935 case KWM_DEF: /* already cleared */
1936 break;
1937 }
1938
1939 goto out;
1940 }
1941 }
1942
1943 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001944 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001945 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1946 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1947 file, linenum, cfg_opts2[optnum].name);
1948 err_code |= ERR_ALERT | ERR_FATAL;
1949 goto out;
1950 }
1951 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1952 goto out;
1953 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1954 err_code |= ERR_WARN;
1955 goto out;
1956 }
1957
1958 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1959 curproxy->options2 &= ~cfg_opts2[optnum].val;
1960
1961 switch (kwm) {
1962 case KWM_STD:
1963 curproxy->options2 |= cfg_opts2[optnum].val;
1964 break;
1965 case KWM_NO:
1966 curproxy->no_options2 |= cfg_opts2[optnum].val;
1967 break;
1968 case KWM_DEF: /* already cleared */
1969 break;
1970 }
1971 goto out;
1972 }
1973 }
1974
1975 /* HTTP options override each other. They can be cancelled using
1976 * "no option xxx" which only switches to default mode if the mode
1977 * was this one (useful for cancelling options set in defaults
1978 * sections).
1979 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001980 if (strcmp(args[1], "forceclose") == 0) {
1981 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",
1982 file, linenum, args[1]);
1983 err_code |= ERR_ALERT | ERR_FATAL;
1984 goto out;
1985 }
1986 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001987 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1988 goto out;
1989 if (kwm == KWM_STD) {
1990 curproxy->options &= ~PR_O_HTTP_MODE;
1991 curproxy->options |= PR_O_HTTP_CLO;
1992 goto out;
1993 }
1994 else if (kwm == KWM_NO) {
1995 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1996 curproxy->options &= ~PR_O_HTTP_MODE;
1997 goto out;
1998 }
1999 }
2000 else if (strcmp(args[1], "http-server-close") == 0) {
2001 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2002 goto out;
2003 if (kwm == KWM_STD) {
2004 curproxy->options &= ~PR_O_HTTP_MODE;
2005 curproxy->options |= PR_O_HTTP_SCL;
2006 goto out;
2007 }
2008 else if (kwm == KWM_NO) {
2009 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2010 curproxy->options &= ~PR_O_HTTP_MODE;
2011 goto out;
2012 }
2013 }
2014 else if (strcmp(args[1], "http-keep-alive") == 0) {
2015 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2016 goto out;
2017 if (kwm == KWM_STD) {
2018 curproxy->options &= ~PR_O_HTTP_MODE;
2019 curproxy->options |= PR_O_HTTP_KAL;
2020 goto out;
2021 }
2022 else if (kwm == KWM_NO) {
2023 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2024 curproxy->options &= ~PR_O_HTTP_MODE;
2025 goto out;
2026 }
2027 }
2028 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002029 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 +02002030 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002031 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002032 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002033 }
2034
2035 /* Redispatch can take an integer argument that control when the
2036 * resispatch occurs. All values are relative to the retries option.
2037 * This can be cancelled using "no option xxx".
2038 */
2039 if (strcmp(args[1], "redispatch") == 0) {
2040 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2041 err_code |= ERR_WARN;
2042 goto out;
2043 }
2044
2045 curproxy->no_options &= ~PR_O_REDISP;
2046 curproxy->options &= ~PR_O_REDISP;
2047
2048 switch (kwm) {
2049 case KWM_STD:
2050 curproxy->options |= PR_O_REDISP;
2051 curproxy->redispatch_after = -1;
2052 if(*args[2]) {
2053 curproxy->redispatch_after = atol(args[2]);
2054 }
2055 break;
2056 case KWM_NO:
2057 curproxy->no_options |= PR_O_REDISP;
2058 curproxy->redispatch_after = 0;
2059 break;
2060 case KWM_DEF: /* already cleared */
2061 break;
2062 }
2063 goto out;
2064 }
2065
Willy Tarreau25241232021-07-18 19:18:56 +02002066 if (strcmp(args[1], "http_proxy") == 0) {
2067 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",
2068 file, linenum, args[1]);
2069 err_code |= ERR_ALERT | ERR_FATAL;
2070 goto out;
2071 }
2072
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002073 if (kwm != KWM_STD) {
2074 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2075 file, linenum, args[1]);
2076 err_code |= ERR_ALERT | ERR_FATAL;
2077 goto out;
2078 }
2079
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002080 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002081 char *logformat;
2082 /* generate a complete HTTP log */
2083 logformat = default_http_log_format;
2084 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002085 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002086 curproxy->options2 |= PR_O2_CLFLOG;
2087 logformat = clf_http_log_format;
2088 } else {
2089 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2090 err_code |= ERR_ALERT | ERR_FATAL;
2091 goto out;
2092 }
2093 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2094 goto out;
2095 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002096 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002097 char *oldlogformat = "log-format";
2098 char *clflogformat = "";
2099
2100 if (curproxy->conf.logformat_string == default_http_log_format)
2101 oldlogformat = "option httplog";
2102 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2103 oldlogformat = "option tcplog";
2104 else if (curproxy->conf.logformat_string == clf_http_log_format)
2105 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002106 else if (curproxy->conf.logformat_string == default_https_log_format)
2107 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002108 if (logformat == clf_http_log_format)
2109 clflogformat = " clf";
2110 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2111 file, linenum, clflogformat, oldlogformat);
2112 }
2113 if (curproxy->conf.logformat_string != default_http_log_format &&
2114 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002115 curproxy->conf.logformat_string != clf_http_log_format &&
2116 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002117 free(curproxy->conf.logformat_string);
2118 curproxy->conf.logformat_string = logformat;
2119
2120 free(curproxy->conf.lfs_file);
2121 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2122 curproxy->conf.lfs_line = curproxy->conf.args.line;
2123
Willy Tarreau5d095c22021-02-12 10:15:59 +01002124 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002125 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2126 file, linenum, curproxy->id);
2127 err_code |= ERR_WARN;
2128 }
2129 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002130 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002131 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002132 char *oldlogformat = "log-format";
2133
2134 if (curproxy->conf.logformat_string == default_http_log_format)
2135 oldlogformat = "option httplog";
2136 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2137 oldlogformat = "option tcplog";
2138 else if (curproxy->conf.logformat_string == clf_http_log_format)
2139 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002140 else if (curproxy->conf.logformat_string == default_https_log_format)
2141 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002142 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2143 file, linenum, oldlogformat);
2144 }
2145 /* generate a detailed TCP log */
2146 if (curproxy->conf.logformat_string != default_http_log_format &&
2147 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002148 curproxy->conf.logformat_string != clf_http_log_format &&
2149 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002150 free(curproxy->conf.logformat_string);
2151 curproxy->conf.logformat_string = default_tcp_log_format;
2152
2153 free(curproxy->conf.lfs_file);
2154 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2155 curproxy->conf.lfs_line = curproxy->conf.args.line;
2156
2157 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2158 goto out;
2159
Willy Tarreau5d095c22021-02-12 10:15:59 +01002160 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002161 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2162 file, linenum, curproxy->id);
2163 err_code |= ERR_WARN;
2164 }
2165 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002166 else if (strcmp(args[1], "httpslog") == 0) {
2167 char *logformat;
2168 /* generate a complete HTTP log */
2169 logformat = default_https_log_format;
2170 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2171 char *oldlogformat = "log-format";
2172
2173 if (curproxy->conf.logformat_string == default_http_log_format)
2174 oldlogformat = "option httplog";
2175 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2176 oldlogformat = "option tcplog";
2177 else if (curproxy->conf.logformat_string == clf_http_log_format)
2178 oldlogformat = "option httplog clf";
2179 else if (curproxy->conf.logformat_string == default_https_log_format)
2180 oldlogformat = "option httpslog";
2181 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2182 file, linenum, oldlogformat);
2183 }
2184 if (curproxy->conf.logformat_string != default_http_log_format &&
2185 curproxy->conf.logformat_string != default_tcp_log_format &&
2186 curproxy->conf.logformat_string != clf_http_log_format &&
2187 curproxy->conf.logformat_string != default_https_log_format)
2188 free(curproxy->conf.logformat_string);
2189 curproxy->conf.logformat_string = logformat;
2190
2191 free(curproxy->conf.lfs_file);
2192 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2193 curproxy->conf.lfs_line = curproxy->conf.args.line;
2194
2195 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2196 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2197 file, linenum, curproxy->id);
2198 err_code |= ERR_WARN;
2199 }
2200 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002201 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002202 /* enable TCP keep-alives on client and server streams */
2203 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2204 err_code |= ERR_WARN;
2205
2206 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2207 goto out;
2208
2209 if (curproxy->cap & PR_CAP_FE)
2210 curproxy->options |= PR_O_TCP_CLI_KA;
2211 if (curproxy->cap & PR_CAP_BE)
2212 curproxy->options |= PR_O_TCP_SRV_KA;
2213 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002214 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002215 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002216 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002217 goto out;
2218 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002219 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002220 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002221 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002222 goto out;
2223 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002224 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002225 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002226 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002227 goto out;
2228 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002229 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002230 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002231 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002232 goto out;
2233 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002234 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002235 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002236 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002237 goto out;
2238 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002239 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002240 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002241 if (err_code & ERR_FATAL)
2242 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002243 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002244 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002245 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002246 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002247 goto out;
2248 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002249 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002250 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002251 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002252 goto out;
2253 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002254 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002255 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002256 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002257 goto out;
2258 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002259 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002260 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002261 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002262 goto out;
2263 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002264 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002265 int cur_arg;
2266
2267 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002268 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 */
2270
2271 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2272
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002273 istfree(&curproxy->fwdfor_hdr_name);
2274 curproxy->fwdfor_hdr_name = istdup(ist(DEF_XFORWARDFOR_HDR));
2275 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002276 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002277 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002278
2279 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2280 cur_arg = 2;
2281 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002282 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002283 unsigned char mask;
2284 int i;
2285
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002286 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002287 if (*(args[cur_arg+1]) &&
2288 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2289 curproxy->except_xff_net.family = AF_INET;
2290 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2291 }
2292 else if (*(args[cur_arg+1]) &&
2293 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2294 curproxy->except_xff_net.family = AF_INET6;
2295 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2296 for (i = 0; i < 16; i++)
2297 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2298 }
2299 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002300 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2301 file, linenum, args[0], args[1], args[cur_arg]);
2302 err_code |= ERR_ALERT | ERR_FATAL;
2303 goto out;
2304 }
2305 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002306 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002307 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002308 /* suboption header - needs additional argument for it */
2309 if (*(args[cur_arg+1]) == 0) {
2310 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2311 file, linenum, args[0], args[1], args[cur_arg]);
2312 err_code |= ERR_ALERT | ERR_FATAL;
2313 goto out;
2314 }
Tim Duesterhusb50ab842022-03-05 00:52:41 +01002315 istfree(&curproxy->fwdfor_hdr_name);
2316 curproxy->fwdfor_hdr_name = istdup(ist(args[cur_arg+1]));
2317 if (!isttest(curproxy->fwdfor_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002318 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002319 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002320 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002321 curproxy->options &= ~PR_O_FF_ALWAYS;
2322 cur_arg += 1;
2323 } else {
2324 /* unknown suboption - catchall */
2325 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2326 file, linenum, args[0], args[1]);
2327 err_code |= ERR_ALERT | ERR_FATAL;
2328 goto out;
2329 }
2330 } /* end while loop */
2331 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002332 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002333 int cur_arg;
2334
2335 /* insert x-original-to field, but not for the IP address listed as an except.
2336 * set default options (ie: bitfield, header name, etc)
2337 */
2338
2339 curproxy->options |= PR_O_ORGTO;
2340
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002341 istfree(&curproxy->orgto_hdr_name);
2342 curproxy->orgto_hdr_name = istdup(ist(DEF_XORIGINALTO_HDR));
2343 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002344 goto alloc_error;
Christopher Faulet5d1def62021-02-26 09:19:15 +01002345 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002346
2347 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2348 cur_arg = 2;
2349 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002350 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002351 unsigned char mask;
2352 int i;
2353
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002354 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002355 if (*(args[cur_arg+1]) &&
2356 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2357 curproxy->except_xot_net.family = AF_INET;
2358 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2359 }
2360 else if (*(args[cur_arg+1]) &&
2361 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2362 curproxy->except_xot_net.family = AF_INET6;
2363 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2364 for (i = 0; i < 16; i++)
2365 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2366 }
2367 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002368 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2369 file, linenum, args[0], args[1], args[cur_arg]);
2370 err_code |= ERR_ALERT | ERR_FATAL;
2371 goto out;
2372 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002373 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002374 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002375 /* suboption header - needs additional argument for it */
2376 if (*(args[cur_arg+1]) == 0) {
2377 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2378 file, linenum, args[0], args[1], args[cur_arg]);
2379 err_code |= ERR_ALERT | ERR_FATAL;
2380 goto out;
2381 }
Tim Duesterhuse502c3e2022-03-05 00:52:42 +01002382 istfree(&curproxy->orgto_hdr_name);
2383 curproxy->orgto_hdr_name = istdup(ist(args[cur_arg+1]));
2384 if (!isttest(curproxy->orgto_hdr_name))
Christopher Fauletb15625a2021-04-12 21:31:45 +02002385 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002386 cur_arg += 2;
2387 } else {
2388 /* unknown suboption - catchall */
2389 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2390 file, linenum, args[0], args[1]);
2391 err_code |= ERR_ALERT | ERR_FATAL;
2392 goto out;
2393 }
2394 } /* end while loop */
2395 }
Christopher Faulet18c13d32022-05-16 11:43:10 +02002396 else if (strcmp(args[1], "http-restrict-req-hdr-names") == 0) {
Christopher Faulet18c13d32022-05-16 11:43:10 +02002397 if (alertif_too_many_args(2, file, linenum, args, &err_code))
2398 goto out;
2399
2400 if (*(args[2]) == 0) {
2401 ha_alert("parsing [%s:%d] : missing parameter. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2402 file, linenum, args[1]);
2403 err_code |= ERR_ALERT | ERR_FATAL;
2404 goto out;
2405 }
2406
2407 curproxy->options2 &= ~PR_O2_RSTRICT_REQ_HDR_NAMES_MASK;
2408 if (strcmp(args[2], "preserve") == 0)
2409 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_NOOP;
2410 else if (strcmp(args[2], "reject") == 0)
2411 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_BLK;
2412 else if (strcmp(args[2], "delete") == 0)
2413 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_DEL;
2414 else {
2415 ha_alert("parsing [%s:%d] : invalid parameter '%s'. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2416 file, linenum, args[2], args[1]);
2417 err_code |= ERR_ALERT | ERR_FATAL;
2418 goto out;
2419 }
2420 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002421 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002422 const char *best = proxy_find_best_option(args[1], common_options);
2423
2424 if (best)
2425 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2426 else
2427 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2428
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002429 err_code |= ERR_ALERT | ERR_FATAL;
2430 goto out;
2431 }
2432 goto out;
2433 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002434 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002435 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2436 err_code |= ERR_WARN;
2437
2438 if (*(args[1]) == 0) {
2439 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2440 err_code |= ERR_ALERT | ERR_FATAL;
2441 goto out;
2442 }
2443 free(curproxy->defbe.name);
2444 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002445 if (!curproxy->defbe.name)
2446 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002447
2448 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2449 goto out;
2450 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002451 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002452 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 +01002453
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002454 err_code |= ERR_ALERT | ERR_FATAL;
2455 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002456 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002457 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002458 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2459 err_code |= ERR_WARN;
2460
2461 if (strcmp(args[1], "never") == 0) {
2462 /* enable a graceful server shutdown on an HTTP 404 response */
2463 curproxy->options &= ~PR_O_REUSE_MASK;
2464 curproxy->options |= PR_O_REUSE_NEVR;
2465 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2466 goto out;
2467 }
2468 else if (strcmp(args[1], "safe") == 0) {
2469 /* enable a graceful server shutdown on an HTTP 404 response */
2470 curproxy->options &= ~PR_O_REUSE_MASK;
2471 curproxy->options |= PR_O_REUSE_SAFE;
2472 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2473 goto out;
2474 }
2475 else if (strcmp(args[1], "aggressive") == 0) {
2476 curproxy->options &= ~PR_O_REUSE_MASK;
2477 curproxy->options |= PR_O_REUSE_AGGR;
2478 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2479 goto out;
2480 }
2481 else if (strcmp(args[1], "always") == 0) {
2482 /* enable a graceful server shutdown on an HTTP 404 response */
2483 curproxy->options &= ~PR_O_REUSE_MASK;
2484 curproxy->options |= PR_O_REUSE_ALWS;
2485 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2486 goto out;
2487 }
2488 else {
2489 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2490 err_code |= ERR_ALERT | ERR_FATAL;
2491 goto out;
2492 }
2493 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002494 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002495 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002496 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2497 err_code |= ERR_ALERT | ERR_FATAL;
2498 goto out;
2499 }
2500
2501 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2502 err_code |= ERR_WARN;
2503
2504 if (strcmp(args[1], "fail") == 0) {
2505 /* add a condition to fail monitor requests */
2506 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2507 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2508 file, linenum, args[0], args[1]);
2509 err_code |= ERR_ALERT | ERR_FATAL;
2510 goto out;
2511 }
2512
2513 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2514 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2515 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2516 file, linenum, args[0], args[1], errmsg);
2517 err_code |= ERR_ALERT | ERR_FATAL;
2518 goto out;
2519 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002520 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002521 }
2522 else {
2523 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2524 err_code |= ERR_ALERT | ERR_FATAL;
2525 goto out;
2526 }
2527 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002528#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002529 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002530 /* enable transparent proxy connections */
2531 curproxy->options |= PR_O_TRANSP;
2532 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2533 goto out;
2534 }
2535#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002536 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002537 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2538 err_code |= ERR_WARN;
2539
2540 if (*(args[1]) == 0) {
2541 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2542 err_code |= ERR_ALERT | ERR_FATAL;
2543 goto out;
2544 }
2545 curproxy->maxconn = atol(args[1]);
2546 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2547 goto out;
2548 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002549 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002550 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2551 err_code |= ERR_WARN;
2552
2553 if (*(args[1]) == 0) {
2554 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2555 err_code |= ERR_ALERT | ERR_FATAL;
2556 goto out;
2557 }
2558 curproxy->backlog = atol(args[1]);
2559 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2560 goto out;
2561 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002562 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002563 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2564 err_code |= ERR_WARN;
2565
2566 if (*(args[1]) == 0) {
2567 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2568 err_code |= ERR_ALERT | ERR_FATAL;
2569 goto out;
2570 }
2571 curproxy->fullconn = atol(args[1]);
2572 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2573 goto out;
2574 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002575 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002576 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 +02002577 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002578 err_code |= ERR_ALERT | ERR_FATAL;
2579 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002580 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002581 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002582 struct sockaddr_storage *sk;
2583 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002584
Willy Tarreau5d095c22021-02-12 10:15:59 +01002585 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002586 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2587 err_code |= ERR_ALERT | ERR_FATAL;
2588 goto out;
2589 }
2590 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2591 err_code |= ERR_WARN;
2592
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002593 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2594 &errmsg, NULL, NULL,
2595 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 +01002596 if (!sk) {
2597 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2598 err_code |= ERR_ALERT | ERR_FATAL;
2599 goto out;
2600 }
2601
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002602 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2603 goto out;
2604
2605 curproxy->dispatch_addr = *sk;
2606 curproxy->options |= PR_O_DISPATCH;
2607 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002608 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002609 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2610 err_code |= ERR_WARN;
2611
2612 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2613 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2614 err_code |= ERR_ALERT | ERR_FATAL;
2615 goto out;
2616 }
2617 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002618 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002619 /**
2620 * The syntax for hash-type config element is
2621 * hash-type {map-based|consistent} [[<algo>] avalanche]
2622 *
2623 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2624 */
2625 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2626
2627 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2628 err_code |= ERR_WARN;
2629
2630 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2631 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2632 }
2633 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2634 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2635 }
2636 else if (strcmp(args[1], "avalanche") == 0) {
2637 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]);
2638 err_code |= ERR_ALERT | ERR_FATAL;
2639 goto out;
2640 }
2641 else {
2642 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2643 err_code |= ERR_ALERT | ERR_FATAL;
2644 goto out;
2645 }
2646
2647 /* set the hash function to use */
2648 if (!*args[2]) {
2649 /* the default algo is sdbm */
2650 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2651
2652 /* if consistent with no argument, then avalanche modifier is also applied */
2653 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2654 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2655 } else {
2656 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002657 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002658 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2659 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002660 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002661 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2662 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002663 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002664 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002666 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002667 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2668 }
2669 else {
2670 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2671 err_code |= ERR_ALERT | ERR_FATAL;
2672 goto out;
2673 }
2674
2675 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002676 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002677 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2678 }
2679 else if (*args[3]) {
2680 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2681 err_code |= ERR_ALERT | ERR_FATAL;
2682 goto out;
2683 }
2684 }
2685 }
2686 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2687 if (*(args[1]) == 0) {
2688 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2689 err_code |= ERR_ALERT | ERR_FATAL;
2690 goto out;
2691 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002692 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2693 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002694 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2695 err_code |= ERR_ALERT | ERR_FATAL;
2696 goto out;
2697 }
2698 }
2699 else if (strcmp(args[0], "unique-id-format") == 0) {
2700 if (!*(args[1])) {
2701 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2702 err_code |= ERR_ALERT | ERR_FATAL;
2703 goto out;
2704 }
2705 if (*(args[2])) {
2706 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2707 err_code |= ERR_ALERT | ERR_FATAL;
2708 goto out;
2709 }
2710 free(curproxy->conf.uniqueid_format_string);
2711 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002712 if (!curproxy->conf.uniqueid_format_string)
2713 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002714
2715 free(curproxy->conf.uif_file);
2716 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2717 curproxy->conf.uif_line = curproxy->conf.args.line;
2718 }
2719
2720 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002721 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002722 if (!*(args[1])) {
2723 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2724 err_code |= ERR_ALERT | ERR_FATAL;
2725 goto out;
2726 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002727 copy = strdup(args[1]);
2728 if (copy == NULL) {
2729 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2730 err_code |= ERR_ALERT | ERR_FATAL;
2731 goto out;
2732 }
2733
2734 istfree(&curproxy->header_unique_id);
2735 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002736 }
2737
2738 else if (strcmp(args[0], "log-format") == 0) {
2739 if (!*(args[1])) {
2740 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2741 err_code |= ERR_ALERT | ERR_FATAL;
2742 goto out;
2743 }
2744 if (*(args[2])) {
2745 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2746 err_code |= ERR_ALERT | ERR_FATAL;
2747 goto out;
2748 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002749 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002750 char *oldlogformat = "log-format";
2751
2752 if (curproxy->conf.logformat_string == default_http_log_format)
2753 oldlogformat = "option httplog";
2754 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2755 oldlogformat = "option tcplog";
2756 else if (curproxy->conf.logformat_string == clf_http_log_format)
2757 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002758 else if (curproxy->conf.logformat_string == default_https_log_format)
2759 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002760 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2761 file, linenum, oldlogformat);
2762 }
2763 if (curproxy->conf.logformat_string != default_http_log_format &&
2764 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002765 curproxy->conf.logformat_string != clf_http_log_format &&
2766 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002767 free(curproxy->conf.logformat_string);
2768 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002769 if (!curproxy->conf.logformat_string)
2770 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002771
2772 free(curproxy->conf.lfs_file);
2773 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2774 curproxy->conf.lfs_line = curproxy->conf.args.line;
2775
2776 /* get a chance to improve log-format error reporting by
2777 * reporting the correct line-number when possible.
2778 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002779 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002780 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2781 file, linenum, curproxy->id);
2782 err_code |= ERR_WARN;
2783 }
2784 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002785 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002786 if (!*(args[1])) {
2787 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2788 err_code |= ERR_ALERT | ERR_FATAL;
2789 goto out;
2790 }
2791 if (*(args[2])) {
2792 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2793 err_code |= ERR_ALERT | ERR_FATAL;
2794 goto out;
2795 }
2796
2797 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2798 free(curproxy->conf.logformat_sd_string);
2799 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002800 if (!curproxy->conf.logformat_sd_string)
2801 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002802
2803 free(curproxy->conf.lfsd_file);
2804 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2805 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2806
2807 /* get a chance to improve log-format-sd error reporting by
2808 * reporting the correct line-number when possible.
2809 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002810 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002811 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2812 file, linenum, curproxy->id);
2813 err_code |= ERR_WARN;
2814 }
2815 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002816 else if (strcmp(args[0], "error-log-format") == 0) {
2817 if (!*(args[1])) {
2818 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2819 err_code |= ERR_ALERT | ERR_FATAL;
2820 goto out;
2821 }
2822 if (*(args[2])) {
2823 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2824 err_code |= ERR_ALERT | ERR_FATAL;
2825 goto out;
2826 }
2827 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2828 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2829 file, linenum);
2830 }
2831 free(curproxy->conf.error_logformat_string);
2832 curproxy->conf.error_logformat_string = strdup(args[1]);
2833 if (!curproxy->conf.error_logformat_string)
2834 goto alloc_error;
2835
2836 free(curproxy->conf.elfs_file);
2837 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2838 curproxy->conf.elfs_line = curproxy->conf.args.line;
2839
2840 /* get a chance to improve log-format error reporting by
2841 * reporting the correct line-number when possible.
2842 */
2843 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2844 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2845 file, linenum, curproxy->id);
2846 err_code |= ERR_WARN;
2847 }
2848 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002849 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002850 if (*(args[1]) == 0) {
2851 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2852 err_code |= ERR_ALERT | ERR_FATAL;
2853 goto out;
2854 }
2855 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002856 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2857 if (b_orig(&curproxy->log_tag) == NULL) {
2858 chunk_destroy(&curproxy->log_tag);
2859 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2860 err_code |= ERR_ALERT | ERR_FATAL;
2861 goto out;
2862 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002863 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002864 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002865 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002866 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2867 err_code |= ERR_ALERT | ERR_FATAL;
2868 goto out;
2869 }
2870 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002871 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002872 int cur_arg;
2873 int port1, port2;
2874 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002875
2876 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2877 err_code |= ERR_WARN;
2878
2879 if (!*args[1]) {
2880 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2881 file, linenum, "source", "usesrc", "interface");
2882 err_code |= ERR_ALERT | ERR_FATAL;
2883 goto out;
2884 }
2885
Christopher Faulet31930372019-07-15 10:16:58 +02002886 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002887 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002888 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002889 curproxy->conn_src.iface_len = 0;
2890
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002891 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2892 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002893 if (!sk) {
2894 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2895 file, linenum, args[0], args[1], errmsg);
2896 err_code |= ERR_ALERT | ERR_FATAL;
2897 goto out;
2898 }
2899
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002900 curproxy->conn_src.source_addr = *sk;
2901 curproxy->conn_src.opts |= CO_SRC_BIND;
2902
2903 cur_arg = 2;
2904 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002905 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002906#if defined(CONFIG_HAP_TRANSPARENT)
2907 if (!*args[cur_arg + 1]) {
2908 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2909 file, linenum, "usesrc");
2910 err_code |= ERR_ALERT | ERR_FATAL;
2911 goto out;
2912 }
2913
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002914 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002915 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2916 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002917 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002918 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2919 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2920 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2921 char *name, *end;
2922
2923 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002924 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002925 name++;
2926
2927 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002928 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002929 end++;
2930
2931 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2932 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002933 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002934 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002935 if (!curproxy->conn_src.bind_hdr_name)
2936 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002937 curproxy->conn_src.bind_hdr_len = end - name;
2938 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2939 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2940 curproxy->conn_src.bind_hdr_occ = -1;
2941
2942 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002943 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002944 end++;
2945 if (*end == ',') {
2946 end++;
2947 name = end;
2948 if (*end == '-')
2949 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002950 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002951 end++;
2952 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2953 }
2954
2955 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2956 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2957 " occurrences values smaller than %d.\n",
2958 file, linenum, MAX_HDR_HISTORY);
2959 err_code |= ERR_ALERT | ERR_FATAL;
2960 goto out;
2961 }
2962 } else {
2963 struct sockaddr_storage *sk;
2964
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002965 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2966 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002967 if (!sk) {
2968 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2969 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2970 err_code |= ERR_ALERT | ERR_FATAL;
2971 goto out;
2972 }
2973
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002974 curproxy->conn_src.tproxy_addr = *sk;
2975 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2976 }
2977 global.last_checks |= LSTCHK_NETADM;
2978#else /* no TPROXY support */
2979 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2980 file, linenum, "usesrc");
2981 err_code |= ERR_ALERT | ERR_FATAL;
2982 goto out;
2983#endif
2984 cur_arg += 2;
2985 continue;
2986 }
2987
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002988 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002989#ifdef SO_BINDTODEVICE
2990 if (!*args[cur_arg + 1]) {
2991 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2992 file, linenum, args[0]);
2993 err_code |= ERR_ALERT | ERR_FATAL;
2994 goto out;
2995 }
2996 free(curproxy->conn_src.iface_name);
2997 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002998 if (!curproxy->conn_src.iface_name)
2999 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003000 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3001 global.last_checks |= LSTCHK_NETADM;
3002#else
3003 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3004 file, linenum, args[0], args[cur_arg]);
3005 err_code |= ERR_ALERT | ERR_FATAL;
3006 goto out;
3007#endif
3008 cur_arg += 2;
3009 continue;
3010 }
3011 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3012 file, linenum, args[0], "interface", "usesrc");
3013 err_code |= ERR_ALERT | ERR_FATAL;
3014 goto out;
3015 }
3016 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003017 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003018 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3019 file, linenum, "usesrc", "source");
3020 err_code |= ERR_ALERT | ERR_FATAL;
3021 goto out;
3022 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003023 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 +02003024 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003025 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003026 file, linenum, args[0]);
3027 err_code |= ERR_ALERT | ERR_FATAL;
3028 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003029 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003030 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003031 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3032 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3033 err_code |= ERR_ALERT | ERR_FATAL;
3034 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003035 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003036 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003037 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3038 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3039 err_code |= ERR_ALERT | ERR_FATAL;
3040 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003041 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003042 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003043 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3044 err_code |= ERR_ALERT | ERR_FATAL;
3045 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003046 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003047 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003048 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3049 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3050 err_code |= ERR_ALERT | ERR_FATAL;
3051 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003052 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003053 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003054 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3055 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3056 err_code |= ERR_ALERT | ERR_FATAL;
3057 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003058 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003059 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003060 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3061 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3062 err_code |= ERR_ALERT | ERR_FATAL;
3063 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003064 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003065 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003066 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3067 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3068 err_code |= ERR_ALERT | ERR_FATAL;
3069 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003071 else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003072 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3073 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3074 err_code |= ERR_ALERT | ERR_FATAL;
3075 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003076 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003077 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003078 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3079 err_code |= ERR_ALERT | ERR_FATAL;
3080 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003081 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003082 else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003083 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3084 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3085 err_code |= ERR_ALERT | ERR_FATAL;
3086 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003087 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003088 else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003089 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3090 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3091 err_code |= ERR_ALERT | ERR_FATAL;
3092 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003093 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003094 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003095 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3096 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3097 err_code |= ERR_ALERT | ERR_FATAL;
3098 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003099 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003100 else if (strcmp(args[0], "srvexp") == 0 || strcmp(args[0], "rsprep") == 0) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003101 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3102 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003105 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003106 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003107 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3108 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3109 err_code |= ERR_ALERT | ERR_FATAL;
3110 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003111 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003112 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003113 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3114 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3115 err_code |= ERR_ALERT | ERR_FATAL;
3116 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003117 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003118 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303119 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003120 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3121 err_code |= ERR_ALERT | ERR_FATAL;
3122 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003123 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003124 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003125 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3126 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3127 err_code |= ERR_ALERT | ERR_FATAL;
3128 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003129 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003130 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003131 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3132 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3133 err_code |= ERR_ALERT | ERR_FATAL;
3134 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003135 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003136 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003137 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3138 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3139 err_code |= ERR_ALERT | ERR_FATAL;
3140 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003141 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003142 else {
3143 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003144 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003145 int index;
3146
3147 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3148 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3149 if (kwl->kw[index].section != CFG_LISTEN)
3150 continue;
3151 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003152 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003153 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003154 err_code |= ERR_ALERT | ERR_FATAL;
3155 goto out;
3156 }
3157
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003158 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003159 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003160 if (rc < 0) {
3161 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3162 err_code |= ERR_ALERT | ERR_FATAL;
3163 goto out;
3164 }
3165 else if (rc > 0) {
3166 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3167 err_code |= ERR_WARN;
3168 goto out;
3169 }
3170 goto out;
3171 }
3172 }
3173 }
3174
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003175 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3176 if (best)
3177 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3178 else
3179 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003180 err_code |= ERR_ALERT | ERR_FATAL;
3181 goto out;
3182 }
3183 out:
3184 free(errmsg);
3185 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003186
3187 alloc_error:
3188 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3189 err_code |= ERR_ALERT | ERR_ABORT;
3190 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003191}