blob: b7f8303b12e2a3fed58e30ecc09d805ea7650b22 [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>
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +010023#include <haproxy/http_ext.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020024#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020025#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020026#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020027#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020028#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020029#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020030#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020031#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020032#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020033#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020034#include <haproxy/tcpcheck.h>
Willy Tarreaue9dcb3c2021-05-08 13:00:23 +020035#include <haproxy/tools.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020036#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010037
Willy Tarreauc0ff6792021-03-12 09:14:19 +010038/* some keywords that are still being parsed using strcmp() and are not
39 * registered anywhere. They are used as suggestions for mistyped words.
40 */
41static const char *common_kw_list[] = {
42 "listen", "frontend", "backend", "defaults", "server",
43 "default-server", "server-template", "bind", "monitor-net",
44 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
Willy Tarreau94f763b2022-07-15 17:14:40 +020045 "acl", "dynamic-cookie-key", "cookie", "email-alert",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010046 "persist", "appsession", "load-server-state-from-file",
47 "server-state-file-name", "max-session-srv-conns", "capture",
48 "retries", "http-request", "http-response", "http-after-response",
49 "http-send-name-header", "block", "redirect", "use_backend",
50 "use-server", "force-persist", "ignore-persist", "force-persist",
51 "stick-table", "stick", "stats", "option", "default_backend",
52 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
Willy Tarreaueb778242021-06-11 16:27:10 +020053 "fullconn", "dispatch", "balance", "hash-type",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010054 "hash-balance-factor", "unique-id-format", "unique-id-header",
55 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +020056 "error-log-format",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010057 NULL /* must be last */
58};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010059
Willy Tarreau31a3cea2021-03-15 11:11:55 +010060static const char *common_options[] = {
Willy Tarreau6ba69842021-06-11 16:01:50 +020061 "httpclose", "http-server-close", "http-keep-alive",
Willy Tarreaud2f25372021-06-11 16:06:29 +020062 "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010063 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
64 "mysql-check", "ldap-check", "spop-check", "tcp-check",
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +010065 "external-check", "forwardfor", "original-to", "forwarded",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010066 NULL /* must be last */
67};
68
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010069/* Report a warning if a rule is placed after a 'tcp-request session' rule.
70 * Return 1 if the warning has been emitted, otherwise 0.
71 */
72int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
73{
74 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
75 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
76 file, line, arg);
77 return 1;
78 }
79 return 0;
80}
81
82/* Report a warning if a rule is placed after a 'tcp-request content' rule.
83 * Return 1 if the warning has been emitted, otherwise 0.
84 */
85int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
86{
87 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
88 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
89 file, line, arg);
90 return 1;
91 }
92 return 0;
93}
94
95/* Report a warning if a rule is placed after a 'monitor fail' rule.
96 * Return 1 if the warning has been emitted, otherwise 0.
97 */
98int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
99{
100 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
101 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
102 file, line, arg);
103 return 1;
104 }
105 return 0;
106}
107
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100108/* Report a warning if a rule is placed after an 'http_request' rule.
109 * Return 1 if the warning has been emitted, otherwise 0.
110 */
111int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
112{
113 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
114 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
115 file, line, arg);
116 return 1;
117 }
118 return 0;
119}
120
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100121/* Report a warning if a rule is placed after a redirect rule.
122 * Return 1 if the warning has been emitted, otherwise 0.
123 */
124int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
125{
126 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
127 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
128 file, line, arg);
129 return 1;
130 }
131 return 0;
132}
133
134/* Report a warning if a rule is placed after a 'use_backend' rule.
135 * Return 1 if the warning has been emitted, otherwise 0.
136 */
137int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
138{
139 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
140 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
141 file, line, arg);
142 return 1;
143 }
144 return 0;
145}
146
147/* Report a warning if a rule is placed after a 'use-server' rule.
148 * Return 1 if the warning has been emitted, otherwise 0.
149 */
150int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
151{
152 if (!LIST_ISEMPTY(&proxy->server_rules)) {
153 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
154 file, line, arg);
155 return 1;
156 }
157 return 0;
158}
159
160/* report a warning if a redirect rule is dangerously placed */
161int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
162{
163 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
164 warnif_rule_after_use_server(proxy, file, line, arg);
165}
166
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100167/* report a warning if an http-request rule is dangerously placed */
168int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
169{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200170 return warnif_rule_after_redirect(proxy, file, line, arg) ||
171 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100172}
173
174/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200175int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100176{
177 return warnif_rule_after_http_req(proxy, file, line, arg) ||
178 warnif_misplaced_http_req(proxy, file, line, arg);
179}
180
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100181/* report a warning if a "tcp request content" rule is dangerously placed */
182int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
183{
184 return warnif_rule_after_monitor(proxy, file, line, arg) ||
185 warnif_misplaced_monitor(proxy, file, line, arg);
186}
187
188/* report a warning if a "tcp request session" rule is dangerously placed */
189int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
190{
191 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
192 warnif_misplaced_tcp_cont(proxy, file, line, arg);
193}
194
195/* report a warning if a "tcp request connection" rule is dangerously placed */
196int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
197{
198 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
199 warnif_misplaced_tcp_sess(proxy, file, line, arg);
200}
201
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100202int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
203{
204 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100205 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100206 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100208 int rc;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100209 int err_code = 0;
210 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100211 char *errmsg = NULL;
212 struct bind_conf *bind_conf;
213
Willy Tarreaue90904d2021-02-12 14:08:31 +0100214 if (!last_defproxy) {
215 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100216 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100217
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)) {
Aurelien DARRAGON7030ce22023-11-29 15:03:25 +0100325 ha_warning("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);
Christopher Fauletb4054202021-10-12 18:57:43 +0200328 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:
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001410 free_acl_cond(cond);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001411 if (rule)
1412 ha_free(&(rule->be.name));
1413 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001414 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001415 }
1416 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001417 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001418 }
1419 else if (strcmp(args[0], "use-server") == 0) {
1420 struct server_rule *rule;
1421
Willy Tarreau5d095c22021-02-12 10:15:59 +01001422 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001423 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1424 err_code |= ERR_ALERT | ERR_FATAL;
1425 goto out;
1426 }
1427
1428 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1429 err_code |= ERR_WARN;
1430
1431 if (*(args[1]) == 0) {
1432 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1433 err_code |= ERR_ALERT | ERR_FATAL;
1434 goto out;
1435 }
1436
1437 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1438 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1439 file, linenum, args[0]);
1440 err_code |= ERR_ALERT | ERR_FATAL;
1441 goto out;
1442 }
1443
1444 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1445 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1446 file, linenum, errmsg);
1447 err_code |= ERR_ALERT | ERR_FATAL;
1448 goto out;
1449 }
1450
1451 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1452
1453 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001454 if (!rule)
1455 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001456 rule->cond = cond;
1457 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001458 if (!rule->srv.name)
1459 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001460 rule->line = linenum;
1461 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001462 if (!rule->file) {
1463 use_server_alloc_error:
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001464 free_acl_cond(cond);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001465 if (rule)
1466 ha_free(&(rule->srv.name));
1467 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001468 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001469 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001470 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001471 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001472 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1473 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001474 else if ((strcmp(args[0], "force-persist") == 0) ||
1475 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001476 struct persist_rule *rule;
1477
Willy Tarreau5d095c22021-02-12 10:15:59 +01001478 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001479 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1480 err_code |= ERR_ALERT | ERR_FATAL;
1481 goto out;
1482 }
1483
1484 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1485 err_code |= ERR_WARN;
1486
1487 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1488 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1489 file, linenum, args[0]);
1490 err_code |= ERR_ALERT | ERR_FATAL;
1491 goto out;
1492 }
1493
1494 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1495 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1496 file, linenum, args[0], errmsg);
1497 err_code |= ERR_ALERT | ERR_FATAL;
1498 goto out;
1499 }
1500
1501 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1502 * where force-persist is applied.
1503 */
1504 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1505
1506 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001507 if (!rule) {
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001508 free_acl_cond(cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001509 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001510 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001511 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001512 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001513 rule->type = PERSIST_TYPE_FORCE;
1514 } else {
1515 rule->type = PERSIST_TYPE_IGNORE;
1516 }
1517 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001518 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001519 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001520 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001521 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001522
Willy Tarreau5d095c22021-02-12 10:15:59 +01001523 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001524 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1525 file, linenum);
1526 err_code |= ERR_ALERT | ERR_FATAL;
1527 goto out;
1528 }
1529
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001530 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001531 if (other) {
1532 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 +01001533 file, linenum, curproxy->id,
1534 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1535 other->proxy ? other->id : other->peers.p->id,
1536 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001537 err_code |= ERR_ALERT | ERR_FATAL;
1538 goto out;
1539 }
1540
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001541 curproxy->table = calloc(1, sizeof *curproxy->table);
1542 if (!curproxy->table) {
1543 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1544 file, linenum, args[0], args[1]);
1545 err_code |= ERR_ALERT | ERR_FATAL;
1546 goto out;
1547 }
1548
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001549 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1550 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001551 if (err_code & ERR_FATAL) {
1552 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001553 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001554 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001555
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001556 /* Store the proxy in the stick-table. */
1557 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001558
1559 stktable_store_name(curproxy->table);
1560 curproxy->table->next = stktables_list;
1561 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001562
1563 /* Add this proxy to the list of proxies which refer to its stick-table. */
1564 if (curproxy->table->proxies_list != curproxy) {
1565 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1566 curproxy->table->proxies_list = curproxy;
1567 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001568 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001569 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001570 struct sticking_rule *rule;
1571 struct sample_expr *expr;
1572 int myidx = 0;
1573 const char *name = NULL;
1574 int flags;
1575
Willy Tarreau5d095c22021-02-12 10:15:59 +01001576 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001577 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1578 err_code |= ERR_ALERT | ERR_FATAL;
1579 goto out;
1580 }
1581
1582 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1583 err_code |= ERR_WARN;
1584 goto out;
1585 }
1586
1587 myidx++;
1588 if ((strcmp(args[myidx], "store") == 0) ||
1589 (strcmp(args[myidx], "store-request") == 0)) {
1590 myidx++;
1591 flags = STK_IS_STORE;
1592 }
1593 else if (strcmp(args[myidx], "store-response") == 0) {
1594 myidx++;
1595 flags = STK_IS_STORE | STK_ON_RSP;
1596 }
1597 else if (strcmp(args[myidx], "match") == 0) {
1598 myidx++;
1599 flags = STK_IS_MATCH;
1600 }
1601 else if (strcmp(args[myidx], "on") == 0) {
1602 myidx++;
1603 flags = STK_IS_MATCH | STK_IS_STORE;
1604 }
1605 else {
1606 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1607 err_code |= ERR_ALERT | ERR_FATAL;
1608 goto out;
1609 }
1610
1611 if (*(args[myidx]) == 0) {
1612 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1613 err_code |= ERR_ALERT | ERR_FATAL;
1614 goto out;
1615 }
1616
1617 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001618 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001619 if (!expr) {
1620 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1621 err_code |= ERR_ALERT | ERR_FATAL;
1622 goto out;
1623 }
1624
1625 if (flags & STK_ON_RSP) {
1626 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1627 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1628 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1629 err_code |= ERR_ALERT | ERR_FATAL;
1630 free(expr);
1631 goto out;
1632 }
1633 } else {
1634 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1635 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1636 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1637 err_code |= ERR_ALERT | ERR_FATAL;
1638 free(expr);
1639 goto out;
1640 }
1641 }
1642
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001643 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001644 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1645
1646 if (strcmp(args[myidx], "table") == 0) {
1647 myidx++;
1648 name = args[myidx++];
1649 }
1650
1651 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1652 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1653 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1654 file, linenum, args[0], errmsg);
1655 err_code |= ERR_ALERT | ERR_FATAL;
1656 free(expr);
1657 goto out;
1658 }
1659 }
1660 else if (*(args[myidx])) {
1661 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1662 file, linenum, args[0], args[myidx]);
1663 err_code |= ERR_ALERT | ERR_FATAL;
1664 free(expr);
1665 goto out;
1666 }
1667 if (flags & STK_ON_RSP)
1668 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1669 else
1670 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1671
1672 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001673 if (!rule) {
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001674 free_acl_cond(cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001675 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001676 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001677 rule->cond = cond;
1678 rule->expr = expr;
1679 rule->flags = flags;
1680 rule->table.name = name ? strdup(name) : NULL;
1681 LIST_INIT(&rule->list);
1682 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001683 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001684 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001685 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001686 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001687 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001688 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001689 curproxy->uri_auth = NULL; /* we must detach from the default config */
1690
1691 if (!*args[1]) {
1692 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001693 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001694 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001695 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001696
Willy Tarreau5d095c22021-02-12 10:15:59 +01001697 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001698 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1699 err_code |= ERR_ALERT | ERR_FATAL;
1700 goto out;
1701 }
1702
Christopher Fauletb15625a2021-04-12 21:31:45 +02001703 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1704 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001705
1706 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1707 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1708 file, linenum, args[0], args[1]);
1709 err_code |= ERR_ALERT | ERR_FATAL;
1710 goto out;
1711 }
1712 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1713 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1714 file, linenum, args[0], args[1], errmsg);
1715 err_code |= ERR_ALERT | ERR_FATAL;
1716 goto out;
1717 }
1718
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001719 if (curproxy->cap & PR_CAP_FE)
1720 where |= SMP_VAL_FE_HRQ_HDR;
1721 if (curproxy->cap & PR_CAP_BE)
1722 where |= SMP_VAL_BE_HRQ_HDR;
1723 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001724
1725 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001726 if (!rule) {
Aurelien DARRAGONc6100952023-05-11 12:29:51 +02001727 free_acl_cond(cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001728 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001729 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001730 rule->cond = cond;
1731 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001732 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001733 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001734 if (*(args[2]) == 0) {
1735 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1736 err_code |= ERR_ALERT | ERR_FATAL;
1737 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001738 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1739 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001740 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001741 if (*(args[2]) == 0) {
1742 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1743 err_code |= ERR_ALERT | ERR_FATAL;
1744 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001745 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1746 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001747 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001748 unsigned interval;
1749
1750 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001751 if (err == PARSE_TIME_OVER) {
1752 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1753 file, linenum, args[2]);
1754 err_code |= ERR_ALERT | ERR_FATAL;
1755 goto out;
1756 }
1757 else if (err == PARSE_TIME_UNDER) {
1758 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1759 file, linenum, args[2]);
1760 err_code |= ERR_ALERT | ERR_FATAL;
1761 goto out;
1762 }
1763 else if (err) {
1764 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001765 file, linenum, *err);
1766 err_code |= ERR_ALERT | ERR_FATAL;
1767 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001768 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1769 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001770 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001771 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001772 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001773
Willy Tarreau5d095c22021-02-12 10:15:59 +01001774 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001775 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1776 err_code |= ERR_ALERT | ERR_FATAL;
1777 goto out;
1778 }
1779
Christopher Fauletb15625a2021-04-12 21:31:45 +02001780 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1781 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001782
1783 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1784 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1785 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1786 file, linenum, args[0]);
1787 err_code |= ERR_WARN;
1788 }
1789
1790 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1791
1792 if (!rule) {
1793 err_code |= ERR_ALERT | ERR_ABORT;
1794 goto out;
1795 }
1796
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001797 if (curproxy->cap & PR_CAP_FE)
1798 where |= SMP_VAL_FE_HRQ_HDR;
1799 if (curproxy->cap & PR_CAP_BE)
1800 where |= SMP_VAL_BE_HRQ_HDR;
1801 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001802 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001803
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001804 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001805 if (*(args[2]) == 0) {
1806 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1807 err_code |= ERR_ALERT | ERR_FATAL;
1808 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001809 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1810 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001811 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001812 if (*(args[2]) == 0) {
1813 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1814 err_code |= ERR_ALERT | ERR_FATAL;
1815 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001816 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1817 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001818 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001819 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1820 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001821 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001822 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1823 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001824 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001825 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1826 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001827 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001828 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1829 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001830 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001831
1832 if (*args[2]) {
1833 int i;
1834 char c;
1835
1836 for (i=0; args[2][i]; i++) {
1837 c = args[2][i];
1838 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1839 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1840 break;
1841 }
1842
1843 if (!i || args[2][i]) {
1844 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1845 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1846 file, linenum, args[0], args[1]);
1847 err_code |= ERR_ALERT | ERR_FATAL;
1848 goto out;
1849 }
1850 }
1851
Christopher Fauletb15625a2021-04-12 21:31:45 +02001852 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1853 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001854 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001855 char *desc = NULL;
1856
1857 if (*args[2]) {
1858 int i, len=0;
1859 char *d;
1860
1861 for (i = 2; *args[i]; i++)
1862 len += strlen(args[i]) + 1;
1863
1864 desc = d = calloc(1, len);
1865
1866 d += snprintf(d, desc + len - d, "%s", args[2]);
1867 for (i = 3; *args[i]; i++)
1868 d += snprintf(d, desc + len - d, " %s", args[i]);
1869 }
1870
1871 if (!*args[2] && !global.desc)
1872 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1873 file, linenum, args[1]);
1874 else {
1875 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1876 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001877 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001878 }
1879 free(desc);
1880 }
1881 } else {
1882stats_error_parsing:
1883 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1884 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1885 err_code |= ERR_ALERT | ERR_FATAL;
1886 goto out;
1887 }
1888 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001889 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001890 int optnum;
1891
1892 if (*(args[1]) == '\0') {
1893 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1894 file, linenum, args[0]);
1895 err_code |= ERR_ALERT | ERR_FATAL;
1896 goto out;
1897 }
1898
1899 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001900 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001901 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1902 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1903 file, linenum, cfg_opts[optnum].name);
1904 err_code |= ERR_ALERT | ERR_FATAL;
1905 goto out;
1906 }
1907 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1908 goto out;
1909
1910 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1911 err_code |= ERR_WARN;
1912 goto out;
1913 }
1914
1915 curproxy->no_options &= ~cfg_opts[optnum].val;
1916 curproxy->options &= ~cfg_opts[optnum].val;
1917
1918 switch (kwm) {
1919 case KWM_STD:
1920 curproxy->options |= cfg_opts[optnum].val;
1921 break;
1922 case KWM_NO:
1923 curproxy->no_options |= cfg_opts[optnum].val;
1924 break;
1925 case KWM_DEF: /* already cleared */
1926 break;
1927 }
1928
1929 goto out;
1930 }
1931 }
1932
1933 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001934 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001935 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1936 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1937 file, linenum, cfg_opts2[optnum].name);
1938 err_code |= ERR_ALERT | ERR_FATAL;
1939 goto out;
1940 }
1941 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1942 goto out;
1943 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1944 err_code |= ERR_WARN;
1945 goto out;
1946 }
1947
1948 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1949 curproxy->options2 &= ~cfg_opts2[optnum].val;
1950
1951 switch (kwm) {
1952 case KWM_STD:
1953 curproxy->options2 |= cfg_opts2[optnum].val;
1954 break;
1955 case KWM_NO:
1956 curproxy->no_options2 |= cfg_opts2[optnum].val;
1957 break;
1958 case KWM_DEF: /* already cleared */
1959 break;
1960 }
1961 goto out;
1962 }
1963 }
1964
1965 /* HTTP options override each other. They can be cancelled using
1966 * "no option xxx" which only switches to default mode if the mode
1967 * was this one (useful for cancelling options set in defaults
1968 * sections).
1969 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001970 if (strcmp(args[1], "forceclose") == 0) {
1971 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",
1972 file, linenum, args[1]);
1973 err_code |= ERR_ALERT | ERR_FATAL;
1974 goto out;
1975 }
1976 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001977 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1978 goto out;
1979 if (kwm == KWM_STD) {
1980 curproxy->options &= ~PR_O_HTTP_MODE;
1981 curproxy->options |= PR_O_HTTP_CLO;
1982 goto out;
1983 }
1984 else if (kwm == KWM_NO) {
1985 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1986 curproxy->options &= ~PR_O_HTTP_MODE;
1987 goto out;
1988 }
1989 }
1990 else if (strcmp(args[1], "http-server-close") == 0) {
1991 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1992 goto out;
1993 if (kwm == KWM_STD) {
1994 curproxy->options &= ~PR_O_HTTP_MODE;
1995 curproxy->options |= PR_O_HTTP_SCL;
1996 goto out;
1997 }
1998 else if (kwm == KWM_NO) {
1999 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2000 curproxy->options &= ~PR_O_HTTP_MODE;
2001 goto out;
2002 }
2003 }
2004 else if (strcmp(args[1], "http-keep-alive") == 0) {
2005 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2006 goto out;
2007 if (kwm == KWM_STD) {
2008 curproxy->options &= ~PR_O_HTTP_MODE;
2009 curproxy->options |= PR_O_HTTP_KAL;
2010 goto out;
2011 }
2012 else if (kwm == KWM_NO) {
2013 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2014 curproxy->options &= ~PR_O_HTTP_MODE;
2015 goto out;
2016 }
2017 }
2018 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002019 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 +02002020 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002021 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002022 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002023 }
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +01002024 else if (strcmp(args[1], "forwarded") == 0) {
2025 if (kwm == KWM_STD) {
2026 err_code |= proxy_http_parse_7239(args, 0, curproxy, curr_defproxy, file, linenum);
2027 goto out;
2028 }
2029 else if (kwm == KWM_NO) {
Aurelien DARRAGONb2e2ec52023-01-09 11:09:03 +01002030 if (curproxy->http_ext)
2031 http_ext_7239_clean(curproxy);
Aurelien DARRAGONb2bb9252022-12-28 15:37:57 +01002032 goto out;
2033 }
2034 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002035
2036 /* Redispatch can take an integer argument that control when the
2037 * resispatch occurs. All values are relative to the retries option.
2038 * This can be cancelled using "no option xxx".
2039 */
2040 if (strcmp(args[1], "redispatch") == 0) {
2041 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2042 err_code |= ERR_WARN;
2043 goto out;
2044 }
2045
2046 curproxy->no_options &= ~PR_O_REDISP;
2047 curproxy->options &= ~PR_O_REDISP;
2048
2049 switch (kwm) {
2050 case KWM_STD:
2051 curproxy->options |= PR_O_REDISP;
2052 curproxy->redispatch_after = -1;
2053 if(*args[2]) {
2054 curproxy->redispatch_after = atol(args[2]);
2055 }
2056 break;
2057 case KWM_NO:
2058 curproxy->no_options |= PR_O_REDISP;
2059 curproxy->redispatch_after = 0;
2060 break;
2061 case KWM_DEF: /* already cleared */
2062 break;
2063 }
2064 goto out;
2065 }
2066
Willy Tarreau25241232021-07-18 19:18:56 +02002067 if (strcmp(args[1], "http_proxy") == 0) {
2068 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",
2069 file, linenum, args[1]);
2070 err_code |= ERR_ALERT | ERR_FATAL;
2071 goto out;
2072 }
2073
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002074 if (kwm != KWM_STD) {
2075 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2076 file, linenum, args[1]);
2077 err_code |= ERR_ALERT | ERR_FATAL;
2078 goto out;
2079 }
2080
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002081 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002082 char *logformat;
2083 /* generate a complete HTTP log */
2084 logformat = default_http_log_format;
2085 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002086 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002087 curproxy->options2 |= PR_O2_CLFLOG;
2088 logformat = clf_http_log_format;
2089 } else {
2090 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2091 err_code |= ERR_ALERT | ERR_FATAL;
2092 goto out;
2093 }
2094 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2095 goto out;
2096 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002097 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002098 char *oldlogformat = "log-format";
2099 char *clflogformat = "";
2100
2101 if (curproxy->conf.logformat_string == default_http_log_format)
2102 oldlogformat = "option httplog";
2103 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2104 oldlogformat = "option tcplog";
2105 else if (curproxy->conf.logformat_string == clf_http_log_format)
2106 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002107 else if (curproxy->conf.logformat_string == default_https_log_format)
2108 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002109 if (logformat == clf_http_log_format)
2110 clflogformat = " clf";
2111 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2112 file, linenum, clflogformat, oldlogformat);
2113 }
2114 if (curproxy->conf.logformat_string != default_http_log_format &&
2115 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002116 curproxy->conf.logformat_string != clf_http_log_format &&
2117 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002118 free(curproxy->conf.logformat_string);
2119 curproxy->conf.logformat_string = logformat;
2120
2121 free(curproxy->conf.lfs_file);
2122 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2123 curproxy->conf.lfs_line = curproxy->conf.args.line;
2124
Willy Tarreau5d095c22021-02-12 10:15:59 +01002125 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002126 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2127 file, linenum, curproxy->id);
2128 err_code |= ERR_WARN;
2129 }
2130 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002131 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002132 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002133 char *oldlogformat = "log-format";
2134
2135 if (curproxy->conf.logformat_string == default_http_log_format)
2136 oldlogformat = "option httplog";
2137 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2138 oldlogformat = "option tcplog";
2139 else if (curproxy->conf.logformat_string == clf_http_log_format)
2140 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002141 else if (curproxy->conf.logformat_string == default_https_log_format)
2142 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002143 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2144 file, linenum, oldlogformat);
2145 }
2146 /* generate a detailed TCP log */
2147 if (curproxy->conf.logformat_string != default_http_log_format &&
2148 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002149 curproxy->conf.logformat_string != clf_http_log_format &&
2150 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002151 free(curproxy->conf.logformat_string);
2152 curproxy->conf.logformat_string = default_tcp_log_format;
2153
2154 free(curproxy->conf.lfs_file);
2155 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2156 curproxy->conf.lfs_line = curproxy->conf.args.line;
2157
2158 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2159 goto out;
2160
Willy Tarreau5d095c22021-02-12 10:15:59 +01002161 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002162 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2163 file, linenum, curproxy->id);
2164 err_code |= ERR_WARN;
2165 }
2166 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002167 else if (strcmp(args[1], "httpslog") == 0) {
2168 char *logformat;
2169 /* generate a complete HTTP log */
2170 logformat = default_https_log_format;
2171 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2172 char *oldlogformat = "log-format";
2173
2174 if (curproxy->conf.logformat_string == default_http_log_format)
2175 oldlogformat = "option httplog";
2176 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2177 oldlogformat = "option tcplog";
2178 else if (curproxy->conf.logformat_string == clf_http_log_format)
2179 oldlogformat = "option httplog clf";
2180 else if (curproxy->conf.logformat_string == default_https_log_format)
2181 oldlogformat = "option httpslog";
2182 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2183 file, linenum, oldlogformat);
2184 }
2185 if (curproxy->conf.logformat_string != default_http_log_format &&
2186 curproxy->conf.logformat_string != default_tcp_log_format &&
2187 curproxy->conf.logformat_string != clf_http_log_format &&
2188 curproxy->conf.logformat_string != default_https_log_format)
2189 free(curproxy->conf.logformat_string);
2190 curproxy->conf.logformat_string = logformat;
2191
2192 free(curproxy->conf.lfs_file);
2193 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2194 curproxy->conf.lfs_line = curproxy->conf.args.line;
2195
2196 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2197 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2198 file, linenum, curproxy->id);
2199 err_code |= ERR_WARN;
2200 }
2201 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002202 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002203 /* enable TCP keep-alives on client and server streams */
2204 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2205 err_code |= ERR_WARN;
2206
2207 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2208 goto out;
2209
2210 if (curproxy->cap & PR_CAP_FE)
2211 curproxy->options |= PR_O_TCP_CLI_KA;
2212 if (curproxy->cap & PR_CAP_BE)
2213 curproxy->options |= PR_O_TCP_SRV_KA;
2214 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002215 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002216 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002217 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002218 goto out;
2219 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002220 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002221 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002222 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002223 goto out;
2224 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002225 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002226 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002227 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002228 goto out;
2229 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002230 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002231 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002232 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002233 goto out;
2234 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002235 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002236 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002237 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002238 goto out;
2239 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002240 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002241 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002242 if (err_code & ERR_FATAL)
2243 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002244 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002245 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002246 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002247 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002248 goto out;
2249 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002250 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002251 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002252 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002253 goto out;
2254 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002255 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002256 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002257 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002258 goto out;
2259 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002260 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002261 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002262 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002263 goto out;
2264 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002265 else if (strcmp(args[1], "forwardfor") == 0) {
Aurelien DARRAGON730b9832022-12-28 18:53:05 +01002266 err_code |= proxy_http_parse_xff(args, 0, curproxy, curr_defproxy, file, linenum);
2267 if (err_code & ERR_FATAL)
2268 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002270 else if (strcmp(args[1], "originalto") == 0) {
Aurelien DARRAGONf9583412022-12-29 15:45:41 +01002271 err_code |= proxy_http_parse_xot(args, 0, curproxy, curr_defproxy, file, linenum);
2272 if (err_code & ERR_FATAL)
2273 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002274 }
Christopher Faulet18c13d32022-05-16 11:43:10 +02002275 else if (strcmp(args[1], "http-restrict-req-hdr-names") == 0) {
Christopher Faulet18c13d32022-05-16 11:43:10 +02002276 if (alertif_too_many_args(2, file, linenum, args, &err_code))
2277 goto out;
2278
2279 if (*(args[2]) == 0) {
2280 ha_alert("parsing [%s:%d] : missing parameter. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2281 file, linenum, args[1]);
2282 err_code |= ERR_ALERT | ERR_FATAL;
2283 goto out;
2284 }
2285
2286 curproxy->options2 &= ~PR_O2_RSTRICT_REQ_HDR_NAMES_MASK;
2287 if (strcmp(args[2], "preserve") == 0)
2288 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_NOOP;
2289 else if (strcmp(args[2], "reject") == 0)
2290 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_BLK;
2291 else if (strcmp(args[2], "delete") == 0)
2292 curproxy->options2 |= PR_O2_RSTRICT_REQ_HDR_NAMES_DEL;
2293 else {
2294 ha_alert("parsing [%s:%d] : invalid parameter '%s'. option '%s' expects 'preserve', 'reject' or 'delete' option.\n",
2295 file, linenum, args[2], args[1]);
2296 err_code |= ERR_ALERT | ERR_FATAL;
2297 goto out;
2298 }
2299 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002300 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002301 const char *best = proxy_find_best_option(args[1], common_options);
2302
2303 if (best)
2304 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2305 else
2306 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2307
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002308 err_code |= ERR_ALERT | ERR_FATAL;
2309 goto out;
2310 }
2311 goto out;
2312 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002313 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002314 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2315 err_code |= ERR_WARN;
2316
2317 if (*(args[1]) == 0) {
2318 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2319 err_code |= ERR_ALERT | ERR_FATAL;
2320 goto out;
2321 }
2322 free(curproxy->defbe.name);
2323 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002324 if (!curproxy->defbe.name)
2325 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002326
2327 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2328 goto out;
2329 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002330 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002331 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 +01002332
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002333 err_code |= ERR_ALERT | ERR_FATAL;
2334 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002335 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002336 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002337 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2338 err_code |= ERR_WARN;
2339
2340 if (strcmp(args[1], "never") == 0) {
2341 /* enable a graceful server shutdown on an HTTP 404 response */
2342 curproxy->options &= ~PR_O_REUSE_MASK;
2343 curproxy->options |= PR_O_REUSE_NEVR;
2344 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2345 goto out;
2346 }
2347 else if (strcmp(args[1], "safe") == 0) {
2348 /* enable a graceful server shutdown on an HTTP 404 response */
2349 curproxy->options &= ~PR_O_REUSE_MASK;
2350 curproxy->options |= PR_O_REUSE_SAFE;
2351 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2352 goto out;
2353 }
2354 else if (strcmp(args[1], "aggressive") == 0) {
2355 curproxy->options &= ~PR_O_REUSE_MASK;
2356 curproxy->options |= PR_O_REUSE_AGGR;
2357 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2358 goto out;
2359 }
2360 else if (strcmp(args[1], "always") == 0) {
2361 /* enable a graceful server shutdown on an HTTP 404 response */
2362 curproxy->options &= ~PR_O_REUSE_MASK;
2363 curproxy->options |= PR_O_REUSE_ALWS;
2364 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2365 goto out;
2366 }
2367 else {
2368 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2369 err_code |= ERR_ALERT | ERR_FATAL;
2370 goto out;
2371 }
2372 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002373 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002374 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002375 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2376 err_code |= ERR_ALERT | ERR_FATAL;
2377 goto out;
2378 }
2379
2380 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2381 err_code |= ERR_WARN;
2382
2383 if (strcmp(args[1], "fail") == 0) {
2384 /* add a condition to fail monitor requests */
2385 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2386 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2387 file, linenum, args[0], args[1]);
2388 err_code |= ERR_ALERT | ERR_FATAL;
2389 goto out;
2390 }
2391
2392 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2393 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2394 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2395 file, linenum, args[0], args[1], errmsg);
2396 err_code |= ERR_ALERT | ERR_FATAL;
2397 goto out;
2398 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002399 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002400 }
2401 else {
2402 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2403 err_code |= ERR_ALERT | ERR_FATAL;
2404 goto out;
2405 }
2406 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002407#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002408 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002409 /* enable transparent proxy connections */
2410 curproxy->options |= PR_O_TRANSP;
2411 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2412 goto out;
2413 }
2414#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002415 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002416 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2417 err_code |= ERR_WARN;
2418
2419 if (*(args[1]) == 0) {
2420 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2421 err_code |= ERR_ALERT | ERR_FATAL;
2422 goto out;
2423 }
2424 curproxy->maxconn = atol(args[1]);
2425 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2426 goto out;
2427 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002428 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002429 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2430 err_code |= ERR_WARN;
2431
2432 if (*(args[1]) == 0) {
2433 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2434 err_code |= ERR_ALERT | ERR_FATAL;
2435 goto out;
2436 }
2437 curproxy->backlog = atol(args[1]);
2438 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2439 goto out;
2440 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002441 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002442 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2443 err_code |= ERR_WARN;
2444
2445 if (*(args[1]) == 0) {
2446 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2447 err_code |= ERR_ALERT | ERR_FATAL;
2448 goto out;
2449 }
2450 curproxy->fullconn = atol(args[1]);
2451 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2452 goto out;
2453 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002454 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002455 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 +02002456 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002457 err_code |= ERR_ALERT | ERR_FATAL;
2458 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002459 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002460 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002461 struct sockaddr_storage *sk;
2462 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002463
Willy Tarreau5d095c22021-02-12 10:15:59 +01002464 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002465 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2466 err_code |= ERR_ALERT | ERR_FATAL;
2467 goto out;
2468 }
2469 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2470 err_code |= ERR_WARN;
2471
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002472 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2473 &errmsg, NULL, NULL,
2474 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 +01002475 if (!sk) {
2476 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2477 err_code |= ERR_ALERT | ERR_FATAL;
2478 goto out;
2479 }
2480
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002481 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2482 goto out;
2483
2484 curproxy->dispatch_addr = *sk;
2485 curproxy->options |= PR_O_DISPATCH;
2486 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002487 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002488 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2489 err_code |= ERR_WARN;
2490
2491 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2492 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2493 err_code |= ERR_ALERT | ERR_FATAL;
2494 goto out;
2495 }
2496 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002497 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002498 /**
2499 * The syntax for hash-type config element is
2500 * hash-type {map-based|consistent} [[<algo>] avalanche]
2501 *
2502 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2503 */
2504 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2505
2506 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2507 err_code |= ERR_WARN;
2508
2509 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2510 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2511 }
2512 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2513 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2514 }
2515 else if (strcmp(args[1], "avalanche") == 0) {
2516 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]);
2517 err_code |= ERR_ALERT | ERR_FATAL;
2518 goto out;
2519 }
2520 else {
2521 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2522 err_code |= ERR_ALERT | ERR_FATAL;
2523 goto out;
2524 }
2525
2526 /* set the hash function to use */
2527 if (!*args[2]) {
2528 /* the default algo is sdbm */
2529 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2530
2531 /* if consistent with no argument, then avalanche modifier is also applied */
2532 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2533 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2534 } else {
2535 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002536 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002537 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2538 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002539 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002540 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2541 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002542 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002543 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2544 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002545 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002546 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2547 }
2548 else {
2549 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2550 err_code |= ERR_ALERT | ERR_FATAL;
2551 goto out;
2552 }
2553
2554 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002555 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002556 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2557 }
2558 else if (*args[3]) {
2559 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2560 err_code |= ERR_ALERT | ERR_FATAL;
2561 goto out;
2562 }
2563 }
2564 }
2565 else if (strcmp(args[0], "hash-balance-factor") == 0) {
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 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002571 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2572 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002573 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2574 err_code |= ERR_ALERT | ERR_FATAL;
2575 goto out;
2576 }
2577 }
2578 else if (strcmp(args[0], "unique-id-format") == 0) {
2579 if (!*(args[1])) {
2580 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2581 err_code |= ERR_ALERT | ERR_FATAL;
2582 goto out;
2583 }
2584 if (*(args[2])) {
2585 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2586 err_code |= ERR_ALERT | ERR_FATAL;
2587 goto out;
2588 }
2589 free(curproxy->conf.uniqueid_format_string);
2590 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002591 if (!curproxy->conf.uniqueid_format_string)
2592 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002593
2594 free(curproxy->conf.uif_file);
2595 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2596 curproxy->conf.uif_line = curproxy->conf.args.line;
2597 }
2598
2599 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002600 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002601 if (!*(args[1])) {
2602 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2603 err_code |= ERR_ALERT | ERR_FATAL;
2604 goto out;
2605 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002606 copy = strdup(args[1]);
2607 if (copy == NULL) {
2608 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2609 err_code |= ERR_ALERT | ERR_FATAL;
2610 goto out;
2611 }
2612
2613 istfree(&curproxy->header_unique_id);
2614 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002615 }
2616
2617 else if (strcmp(args[0], "log-format") == 0) {
2618 if (!*(args[1])) {
2619 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2620 err_code |= ERR_ALERT | ERR_FATAL;
2621 goto out;
2622 }
2623 if (*(args[2])) {
2624 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2625 err_code |= ERR_ALERT | ERR_FATAL;
2626 goto out;
2627 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002628 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002629 char *oldlogformat = "log-format";
2630
2631 if (curproxy->conf.logformat_string == default_http_log_format)
2632 oldlogformat = "option httplog";
2633 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2634 oldlogformat = "option tcplog";
2635 else if (curproxy->conf.logformat_string == clf_http_log_format)
2636 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002637 else if (curproxy->conf.logformat_string == default_https_log_format)
2638 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002639 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2640 file, linenum, oldlogformat);
2641 }
2642 if (curproxy->conf.logformat_string != default_http_log_format &&
2643 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002644 curproxy->conf.logformat_string != clf_http_log_format &&
2645 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002646 free(curproxy->conf.logformat_string);
2647 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002648 if (!curproxy->conf.logformat_string)
2649 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002650
2651 free(curproxy->conf.lfs_file);
2652 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2653 curproxy->conf.lfs_line = curproxy->conf.args.line;
2654
2655 /* get a chance to improve log-format error reporting by
2656 * reporting the correct line-number when possible.
2657 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002658 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002659 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2660 file, linenum, curproxy->id);
2661 err_code |= ERR_WARN;
2662 }
2663 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002664 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002665 if (!*(args[1])) {
2666 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2667 err_code |= ERR_ALERT | ERR_FATAL;
2668 goto out;
2669 }
2670 if (*(args[2])) {
2671 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2672 err_code |= ERR_ALERT | ERR_FATAL;
2673 goto out;
2674 }
2675
2676 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2677 free(curproxy->conf.logformat_sd_string);
2678 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002679 if (!curproxy->conf.logformat_sd_string)
2680 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002681
2682 free(curproxy->conf.lfsd_file);
2683 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2684 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2685
2686 /* get a chance to improve log-format-sd error reporting by
2687 * reporting the correct line-number when possible.
2688 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002689 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002690 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2691 file, linenum, curproxy->id);
2692 err_code |= ERR_WARN;
2693 }
2694 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002695 else if (strcmp(args[0], "error-log-format") == 0) {
2696 if (!*(args[1])) {
2697 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2698 err_code |= ERR_ALERT | ERR_FATAL;
2699 goto out;
2700 }
2701 if (*(args[2])) {
2702 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2703 err_code |= ERR_ALERT | ERR_FATAL;
2704 goto out;
2705 }
2706 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2707 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2708 file, linenum);
2709 }
2710 free(curproxy->conf.error_logformat_string);
2711 curproxy->conf.error_logformat_string = strdup(args[1]);
2712 if (!curproxy->conf.error_logformat_string)
2713 goto alloc_error;
2714
2715 free(curproxy->conf.elfs_file);
2716 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2717 curproxy->conf.elfs_line = curproxy->conf.args.line;
2718
2719 /* get a chance to improve log-format error reporting by
2720 * reporting the correct line-number when possible.
2721 */
2722 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2723 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2724 file, linenum, curproxy->id);
2725 err_code |= ERR_WARN;
2726 }
2727 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002728 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002729 if (*(args[1]) == 0) {
2730 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2731 err_code |= ERR_ALERT | ERR_FATAL;
2732 goto out;
2733 }
2734 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002735 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2736 if (b_orig(&curproxy->log_tag) == NULL) {
2737 chunk_destroy(&curproxy->log_tag);
2738 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2739 err_code |= ERR_ALERT | ERR_FATAL;
2740 goto out;
2741 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002742 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002743 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002744 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002745 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2746 err_code |= ERR_ALERT | ERR_FATAL;
2747 goto out;
2748 }
2749 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002750 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002751 int cur_arg;
2752 int port1, port2;
2753 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002754
2755 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2756 err_code |= ERR_WARN;
2757
2758 if (!*args[1]) {
2759 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2760 file, linenum, "source", "usesrc", "interface");
2761 err_code |= ERR_ALERT | ERR_FATAL;
2762 goto out;
2763 }
2764
Christopher Faulet31930372019-07-15 10:16:58 +02002765 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002766 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002767 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002768 curproxy->conn_src.iface_len = 0;
2769
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002770 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2771 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002772 if (!sk) {
2773 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2774 file, linenum, args[0], args[1], errmsg);
2775 err_code |= ERR_ALERT | ERR_FATAL;
2776 goto out;
2777 }
2778
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002779 curproxy->conn_src.source_addr = *sk;
2780 curproxy->conn_src.opts |= CO_SRC_BIND;
2781
2782 cur_arg = 2;
2783 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002784 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002785#if defined(CONFIG_HAP_TRANSPARENT)
2786 if (!*args[cur_arg + 1]) {
2787 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2788 file, linenum, "usesrc");
2789 err_code |= ERR_ALERT | ERR_FATAL;
2790 goto out;
2791 }
2792
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002793 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002794 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2795 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002796 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002797 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2798 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2799 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2800 char *name, *end;
2801
2802 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002803 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002804 name++;
2805
2806 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002807 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002808 end++;
2809
2810 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2811 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002812 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002813 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002814 if (!curproxy->conn_src.bind_hdr_name)
2815 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002816 curproxy->conn_src.bind_hdr_len = end - name;
2817 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2818 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2819 curproxy->conn_src.bind_hdr_occ = -1;
2820
2821 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002822 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002823 end++;
2824 if (*end == ',') {
2825 end++;
2826 name = end;
2827 if (*end == '-')
2828 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002829 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002830 end++;
2831 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2832 }
2833
2834 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2835 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2836 " occurrences values smaller than %d.\n",
2837 file, linenum, MAX_HDR_HISTORY);
2838 err_code |= ERR_ALERT | ERR_FATAL;
2839 goto out;
2840 }
2841 } else {
2842 struct sockaddr_storage *sk;
2843
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002844 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2845 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002846 if (!sk) {
2847 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2848 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2849 err_code |= ERR_ALERT | ERR_FATAL;
2850 goto out;
2851 }
2852
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002853 curproxy->conn_src.tproxy_addr = *sk;
2854 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2855 }
2856 global.last_checks |= LSTCHK_NETADM;
2857#else /* no TPROXY support */
2858 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2859 file, linenum, "usesrc");
2860 err_code |= ERR_ALERT | ERR_FATAL;
2861 goto out;
2862#endif
2863 cur_arg += 2;
2864 continue;
2865 }
2866
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002867 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002868#ifdef SO_BINDTODEVICE
2869 if (!*args[cur_arg + 1]) {
2870 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2871 file, linenum, args[0]);
2872 err_code |= ERR_ALERT | ERR_FATAL;
2873 goto out;
2874 }
2875 free(curproxy->conn_src.iface_name);
2876 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002877 if (!curproxy->conn_src.iface_name)
2878 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002879 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2880 global.last_checks |= LSTCHK_NETADM;
2881#else
2882 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2883 file, linenum, args[0], args[cur_arg]);
2884 err_code |= ERR_ALERT | ERR_FATAL;
2885 goto out;
2886#endif
2887 cur_arg += 2;
2888 continue;
2889 }
2890 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2891 file, linenum, args[0], "interface", "usesrc");
2892 err_code |= ERR_ALERT | ERR_FATAL;
2893 goto out;
2894 }
2895 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002896 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002897 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2898 file, linenum, "usesrc", "source");
2899 err_code |= ERR_ALERT | ERR_FATAL;
2900 goto out;
2901 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002902 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 +02002903 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002904 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002905 file, linenum, args[0]);
2906 err_code |= ERR_ALERT | ERR_FATAL;
2907 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002908 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002909 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002910 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2911 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2912 err_code |= ERR_ALERT | ERR_FATAL;
2913 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002914 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002915 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002916 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2917 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2918 err_code |= ERR_ALERT | ERR_FATAL;
2919 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002920 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002921 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002922 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2923 err_code |= ERR_ALERT | ERR_FATAL;
2924 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002926 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002927 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2928 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2929 err_code |= ERR_ALERT | ERR_FATAL;
2930 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002931 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002932 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002933 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2934 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2935 err_code |= ERR_ALERT | ERR_FATAL;
2936 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002937 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002938 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002939 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2940 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2941 err_code |= ERR_ALERT | ERR_FATAL;
2942 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002943 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002944 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002945 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2946 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2947 err_code |= ERR_ALERT | ERR_FATAL;
2948 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002949 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002950 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 +02002951 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2952 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2953 err_code |= ERR_ALERT | ERR_FATAL;
2954 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002955 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002956 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002957 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2958 err_code |= ERR_ALERT | ERR_FATAL;
2959 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002960 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002961 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 +02002962 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2963 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2964 err_code |= ERR_ALERT | ERR_FATAL;
2965 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002966 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002967 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 +02002968 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2969 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2970 err_code |= ERR_ALERT | ERR_FATAL;
2971 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002972 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002973 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002974 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2975 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2976 err_code |= ERR_ALERT | ERR_FATAL;
2977 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002978 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002979 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 +02002980 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2981 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2982 err_code |= ERR_ALERT | ERR_FATAL;
2983 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002984 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002985 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002986 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2987 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2988 err_code |= ERR_ALERT | ERR_FATAL;
2989 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002990 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002991 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002992 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2993 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2994 err_code |= ERR_ALERT | ERR_FATAL;
2995 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002996 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002997 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302998 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002999 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3000 err_code |= ERR_ALERT | ERR_FATAL;
3001 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003002 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003003 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003004 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3005 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3006 err_code |= ERR_ALERT | ERR_FATAL;
3007 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003008 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003009 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003010 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3011 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3012 err_code |= ERR_ALERT | ERR_FATAL;
3013 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003014 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003015 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003016 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3017 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3018 err_code |= ERR_ALERT | ERR_FATAL;
3019 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003020 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003021 else {
3022 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003023 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003024 int index;
3025
3026 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3027 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3028 if (kwl->kw[index].section != CFG_LISTEN)
3029 continue;
3030 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003031 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003032 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003033 err_code |= ERR_ALERT | ERR_FATAL;
3034 goto out;
3035 }
3036
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003037 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003038 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003039 if (rc < 0) {
3040 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3041 err_code |= ERR_ALERT | ERR_FATAL;
3042 goto out;
3043 }
3044 else if (rc > 0) {
3045 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3046 err_code |= ERR_WARN;
3047 goto out;
3048 }
3049 goto out;
3050 }
3051 }
3052 }
3053
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003054 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3055 if (best)
3056 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3057 else
3058 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003059 err_code |= ERR_ALERT | ERR_FATAL;
3060 goto out;
3061 }
3062 out:
3063 free(errmsg);
3064 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003065
3066 alloc_error:
3067 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3068 err_code |= ERR_ALERT | ERR_ABORT;
3069 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003070}