blob: 5deec5e6bd66003621649b70059e5968679f57a1 [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>
11#include <fcntl.h>
12#include <unistd.h>
13
Willy Tarreaudcc048a2020-06-04 19:11:43 +020014#include <haproxy/acl.h>
Eric Salama7cea6062020-10-02 11:58:19 +020015#include <haproxy/buf.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020016#include <haproxy/capture-t.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020017#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020018#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020019#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020020#include <haproxy/connection.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020021#include <haproxy/extcheck.h>
Willy Tarreaub7fc4c42021-10-06 18:56:42 +020022#include <haproxy/http_ana.h>
Willy Tarreau87735332020-06-04 09:08:41 +020023#include <haproxy/http_htx.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",
45 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
46 "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",
65 "external-check", "forwardfor", "original-to",
66 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);
217 proxy_preset_defaults(last_defproxy);
218
Willy Tarreaue90904d2021-02-12 14:08:31 +0100219 curr_defproxy = last_defproxy;
220 if (!last_defproxy) {
221 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
222 err_code |= ERR_ALERT | ERR_ABORT;
223 goto out;
224 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100225 }
226
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 if (strcmp(args[0], "listen") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200228 rc = PR_CAP_LISTEN | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100229 else if (strcmp(args[0], "frontend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200230 rc = PR_CAP_FE | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100231 else if (strcmp(args[0], "backend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200232 rc = PR_CAP_BE | PR_CAP_LB;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100233 else if (strcmp(args[0], "defaults") == 0) {
234 /* "defaults" must first delete the last no-name defaults if any */
Willy Tarreaue90904d2021-02-12 14:08:31 +0100235 curr_defproxy = NULL;
236 rc = PR_CAP_DEF | PR_CAP_LISTEN;
237 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100238 else
239 rc = PR_CAP_NONE;
240
Willy Tarreaue90904d2021-02-12 14:08:31 +0100241 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100242 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100243 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100244 file, linenum, args[0]);
245 err_code |= ERR_ALERT | ERR_ABORT;
246 goto out;
247 }
248
249 err = invalid_char(args[1]);
250 if (err) {
251 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
252 file, linenum, *err, args[0], args[1]);
253 err_code |= ERR_ALERT | ERR_FATAL;
254 }
255
256 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
257 if (curproxy) {
258 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
259 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
260 curproxy->id, curproxy->conf.file, curproxy->conf.line);
261 err_code |= ERR_ALERT | ERR_FATAL;
262 }
263
Emeric Brunb0c331f2020-10-07 17:05:59 +0200264 curproxy = log_forward_by_name(args[1]);
265 if (curproxy) {
266 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
267 file, linenum, proxy_cap_str(rc), args[1],
268 curproxy->id, curproxy->conf.file, curproxy->conf.line);
269 err_code |= ERR_ALERT | ERR_FATAL;
270 }
271
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100272 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
273 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100274 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100275 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
276 goto out;
277 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100278 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100279
Willy Tarreaue90904d2021-02-12 14:08:31 +0100280 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100281 const char *name = args[1];
282 int arg = 2;
283
284 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
285 // also support "defaults from blah" (no name then)
286 arg = 1;
287 name = "";
288 }
289
290 /* only regular proxies inherit from the previous defaults section */
291 if (!(rc & PR_CAP_DEF))
292 curr_defproxy = last_defproxy;
293
294 if (strcmp(args[arg], "from") == 0) {
295 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
296
297 if (!curr_defproxy) {
298 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
299 err_code |= ERR_ALERT | ERR_ABORT;
300 goto out;
301 }
302
303 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
304 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
305
306 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
307 file, linenum, args[arg+1], proxy_cap_str(rc), name,
308 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
309 err_code |= ERR_ALERT | ERR_FATAL;
310 }
311
312 err = invalid_char(args[arg+1]);
313 if (err) {
314 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",
315 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
316 err_code |= ERR_ALERT | ERR_FATAL;
317 }
Christopher Fauletb4054202021-10-12 18:57:43 +0200318 curr_defproxy->flags |= PR_FL_EXPLICIT_REF;
319 }
320 else if (curr_defproxy)
321 curr_defproxy->flags |= PR_FL_IMPLICIT_REF;
322
323 if (curr_defproxy && (curr_defproxy->flags & (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) == (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) {
324 ha_alert("parsing [%s:%d] : defaults section '%s' (declared at %s:%d) is explicitly referenced by another proxy and implicitly used here."
325 " To avoid any ambiguity don't mix both usage. Add a last defaults section not explicitly used or always use explicit references.\n",
326 file, linenum, curr_defproxy->id, curr_defproxy->conf.file, curr_defproxy->conf.line);
327 err_code |= ERR_WARN;
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100328 }
329
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100330 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100331 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100332 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100333 goto out;
334 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100335
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200336 if (curr_defproxy && (!LIST_ISEMPTY(&curr_defproxy->http_req_rules) ||
337 !LIST_ISEMPTY(&curr_defproxy->http_res_rules) ||
338 !LIST_ISEMPTY(&curr_defproxy->http_after_res_rules) ||
339 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
340 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules) ||
341 !LIST_ISEMPTY(&curr_defproxy->tcp_req.inspect_rules) ||
342 !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules))) {
343 /* If the current default proxy defines TCP/HTTP rules, the
344 * current proxy will keep a reference on it. But some sanity
345 * checks are performed first:
346 *
347 * - It cannot be used to init a defaults section
348 * - It cannot be used to init a listen section
349 * - It cannot be used to init backend and frontend sections at
350 * same time. It can be used to init several sections of the
351 * same type only.
352 * - It cannot define L4/L5 TCP rules if it is used to init
353 * backend sections.
354 * - It cannot define 'tcp-response content' rules if it
355 * is used to init frontend sections.
356 *
357 * If no error is found, refcount of the default proxy is incremented.
358 */
359
360 /* Note: Add tcpcheck_rules too if unresolve args become allowed in defaults section */
361 if (rc & PR_CAP_DEF) {
362 ha_alert("parsing [%s:%d]: a defaults section cannot inherit from a defaults section defining TCP/HTTP rules (defaults section at %s:%d).\n",
363 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
364 err_code |= ERR_ALERT | ERR_ABORT;
365 }
366 else if ((rc & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
367 ha_alert("parsing [%s:%d]: a listen section cannot inherit from a defaults section defining TCP/HTTP rules.\n",
368 file, linenum);
369 err_code |= ERR_ALERT | ERR_ABORT;
370 }
371 else {
372 char defcap = (curr_defproxy->cap & PR_CAP_LISTEN);
373
374 if ((defcap == PR_CAP_BE || defcap == PR_CAP_FE) && (rc & PR_CAP_LISTEN) != defcap) {
375 ha_alert("parsing [%s:%d]: frontends and backends cannot inherit from the same defaults section"
376 " if it defines TCP/HTTP rules (defaults section at %s:%d).\n",
377 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
378 err_code |= ERR_ALERT | ERR_ABORT;
379 }
380 else if (!(rc & PR_CAP_FE) && (!LIST_ISEMPTY(&curr_defproxy->tcp_req.l4_rules) ||
381 !LIST_ISEMPTY(&curr_defproxy->tcp_req.l5_rules))) {
382 ha_alert("parsing [%s:%d]: a backend section cannot inherit from a defaults section defining"
383 " 'tcp-request connection' or 'tcp-request session' rules (defaults section at %s:%d).\n",
384 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
385 err_code |= ERR_ALERT | ERR_ABORT;
386 }
387 else if (!(rc & PR_CAP_BE) && !LIST_ISEMPTY(&curr_defproxy->tcp_rep.inspect_rules)) {
388 ha_alert("parsing [%s:%d]: a frontend section cannot inherit from a defaults section defining"
389 " 'tcp-response content' rules (defaults section at %s:%d).\n",
390 file, linenum, curr_defproxy->conf.file, curr_defproxy->conf.line);
391 err_code |= ERR_ALERT | ERR_ABORT;
392 }
393 else {
394 curr_defproxy->cap = (curr_defproxy->cap & ~PR_CAP_LISTEN) | (rc & PR_CAP_LISTEN);
395 proxy_ref_defaults(curproxy, curr_defproxy);
396 }
397 }
398 }
399
Christopher Faulet6ff7de52021-10-13 15:18:36 +0200400 if (curr_defproxy && (curr_defproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) &&
401 (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_BE) {
402 /* If the current default proxy defines tcpcheck rules, the
403 * current proxy will keep a reference on it. but only if the
404 * current proxy has the backend capability.
405 */
406 proxy_ref_defaults(curproxy, curr_defproxy);
407 }
408
Willy Tarreaue90904d2021-02-12 14:08:31 +0100409 if (rc & PR_CAP_DEF) {
410 /* last and current proxies must be updated to this one */
411 curr_defproxy = last_defproxy = curproxy;
412 } else {
413 /* regular proxies are in a list */
414 curproxy->next = proxies_list;
415 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100416 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100417 goto out;
418 }
419 else if (curproxy == NULL) {
420 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
421 err_code |= ERR_ALERT | ERR_FATAL;
422 goto out;
423 }
424
425 /* update the current file and line being parsed */
426 curproxy->conf.args.file = curproxy->conf.file;
427 curproxy->conf.args.line = linenum;
428
429 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100430 if ((strcmp(args[0], "server") == 0)) {
431 err_code |= parse_server(file, linenum, args,
432 curproxy, curr_defproxy,
433 SRV_PARSE_PARSE_ADDR);
434
435 if (err_code & ERR_FATAL)
436 goto out;
437 }
438 else if (strcmp(args[0], "default-server") == 0) {
439 err_code |= parse_server(file, linenum, args,
440 curproxy, curr_defproxy,
441 SRV_PARSE_DEFAULT_SERVER);
442
443 if (err_code & ERR_FATAL)
444 goto out;
445 }
446 else if (strcmp(args[0], "server-template") == 0) {
447 err_code |= parse_server(file, linenum, args,
448 curproxy, curr_defproxy,
449 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
450
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100451 if (err_code & ERR_FATAL)
452 goto out;
453 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100454 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100455 struct listener *l;
456 int cur_arg;
457
Willy Tarreau5d095c22021-02-12 10:15:59 +0100458 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100459 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
460 err_code |= ERR_ALERT | ERR_FATAL;
461 goto out;
462 }
463 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
464 err_code |= ERR_WARN;
465
466 if (!*(args[1])) {
467 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
468 file, linenum, args[0]);
469 err_code |= ERR_ALERT | ERR_FATAL;
470 goto out;
471 }
472
473 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200474 if (!bind_conf)
475 goto alloc_error;
476
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100477 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200478 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
479 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
480 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100481
482 /* NOTE: the following line might create several listeners if there
483 * are comma-separated IPs or port ranges. So all further processing
484 * will have to be applied to all listeners created after last_listen.
485 */
486 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
487 if (errmsg && *errmsg) {
488 indent_msg(&errmsg, 2);
489 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
490 }
491 else
492 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
493 file, linenum, args[0], args[1]);
494 err_code |= ERR_ALERT | ERR_FATAL;
495 goto out;
496 }
497
498 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
499 /* Set default global rights and owner for unix bind */
500 global.maxsock++;
501 }
502
503 cur_arg = 2;
504 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100505 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100506 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100507
508 kw = bind_find_kw(args[cur_arg]);
509 if (kw) {
510 char *err = NULL;
511 int code;
512
513 if (!kw->parse) {
514 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
515 file, linenum, args[0], args[1], args[cur_arg]);
516 cur_arg += 1 + kw->skip ;
517 err_code |= ERR_ALERT | ERR_FATAL;
518 goto out;
519 }
520
521 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
522 err_code |= code;
523
524 if (code) {
525 if (err && *err) {
526 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200527 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
528 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
529 else
530 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100531 }
532 else
533 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
534 file, linenum, args[0], args[1], args[cur_arg]);
535 if (code & ERR_FATAL) {
536 free(err);
537 cur_arg += 1 + kw->skip;
538 goto out;
539 }
540 }
541 free(err);
542 cur_arg += 1 + kw->skip;
543 continue;
544 }
545
Willy Tarreau433b05f2021-03-12 10:14:07 +0100546 best = bind_find_best_kw(args[cur_arg]);
547 if (best)
548 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
549 file, linenum, args[0], args[1], args[cur_arg], best);
550 else
551 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
552 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100553
554 err_code |= ERR_ALERT | ERR_FATAL;
555 goto out;
556 }
557 goto out;
558 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100559 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200560 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]);
561 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100562 goto out;
563 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100564 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100565 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
566 err_code |= ERR_WARN;
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 URI.\n",
573 file, linenum, args[0]);
574 err_code |= ERR_ALERT | ERR_FATAL;
575 goto out;
576 }
577
578 free(curproxy->monitor_uri);
579 curproxy->monitor_uri_len = strlen(args[1]);
580 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200581 if (!curproxy->monitor_uri)
582 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100583 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
584 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
585
586 goto out;
587 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100588 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100589 if (alertif_too_many_args(1, file, linenum, args, &err_code))
590 goto out;
591
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100592 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
593 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
594 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200595 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
596 err_code |= ERR_ALERT | ERR_FATAL;
597 goto out;
598 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100599 else {
600 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
601 err_code |= ERR_ALERT | ERR_FATAL;
602 goto out;
603 }
604 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100605 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100606 struct eb32_node *node;
607
Willy Tarreau5d095c22021-02-12 10:15:59 +0100608 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100609 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
610 file, linenum, args[0]);
611 err_code |= ERR_ALERT | ERR_FATAL;
612 goto out;
613 }
614
615 if (alertif_too_many_args(1, file, linenum, args, &err_code))
616 goto out;
617
618 if (!*args[1]) {
619 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
620 file, linenum, args[0]);
621 err_code |= ERR_ALERT | ERR_FATAL;
622 goto out;
623 }
624
625 curproxy->uuid = atol(args[1]);
626 curproxy->conf.id.key = curproxy->uuid;
627 curproxy->options |= PR_O_FORCED_ID;
628
629 if (curproxy->uuid <= 0) {
630 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
631 file, linenum);
632 err_code |= ERR_ALERT | ERR_FATAL;
633 goto out;
634 }
635
636 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
637 if (node) {
638 struct proxy *target = container_of(node, struct proxy, conf.id);
639 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
640 file, linenum, proxy_type_str(curproxy), curproxy->id,
641 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
642 err_code |= ERR_ALERT | ERR_FATAL;
643 goto out;
644 }
645 eb32_insert(&used_proxy_id, &curproxy->conf.id);
646 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100647 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100648 int i, len=0;
649 char *d;
650
Willy Tarreau5d095c22021-02-12 10:15:59 +0100651 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100652 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
653 file, linenum, args[0]);
654 err_code |= ERR_ALERT | ERR_FATAL;
655 goto out;
656 }
657
658 if (!*args[1]) {
659 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
660 file, linenum, args[0]);
661 return -1;
662 }
663
664 for (i = 1; *args[i]; i++)
665 len += strlen(args[i]) + 1;
666
667 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200668 if (!d)
669 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100670 curproxy->desc = d;
671
672 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
673 for (i = 2; *args[i]; i++)
674 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
675
676 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100677 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100678 if (alertif_too_many_args(0, file, linenum, args, &err_code))
679 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200680 curproxy->flags |= PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100681 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100682 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100683 if (alertif_too_many_args(0, file, linenum, args, &err_code))
684 goto out;
Christopher Fauletdfd10ab2021-10-06 14:24:19 +0200685 curproxy->flags &= ~PR_FL_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100686 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100687 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100688 int cur_arg = 1;
689 unsigned long set = 0;
690
691 while (*args[cur_arg]) {
692 if (strcmp(args[cur_arg], "all") == 0) {
693 set = 0;
694 break;
695 }
Willy Tarreau72faef32021-06-15 08:36:30 +0200696 if (parse_process_number(args[cur_arg], &set, 1, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100697 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
698 err_code |= ERR_ALERT | ERR_FATAL;
699 goto out;
700 }
701 cur_arg++;
702 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200703 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
704 file, linenum, args[0]);
705 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Christopher Fauletee08d6c2021-10-13 15:40:15 +0200708 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
709 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100710 err_code |= ERR_ALERT | ERR_FATAL;
711 goto out;
712 }
713
714 err = invalid_char(args[1]);
715 if (err) {
716 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
717 file, linenum, *err, args[1]);
718 err_code |= ERR_ALERT | ERR_FATAL;
719 goto out;
720 }
721
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100722 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100723 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100724 "logical disjunction within a condition.\n",
725 file, linenum, args[1]);
726 err_code |= ERR_ALERT | ERR_FATAL;
727 goto out;
728 }
729
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100730 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
731 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
732 file, linenum, args[1], errmsg);
733 err_code |= ERR_ALERT | ERR_FATAL;
734 goto out;
735 }
736 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100737 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100738
739 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
740 err_code |= ERR_WARN;
741
742 if (*(args[1]) == 0) {
743 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
744 file, linenum, args[0]);
745 err_code |= ERR_ALERT | ERR_FATAL;
746 goto out;
747 }
748 free(curproxy->dyncookie_key);
749 curproxy->dyncookie_key = strdup(args[1]);
750 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100751 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100752 int cur_arg;
753
754 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
755 err_code |= ERR_WARN;
756
757 if (*(args[1]) == 0) {
758 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
759 file, linenum, args[0]);
760 err_code |= ERR_ALERT | ERR_FATAL;
761 goto out;
762 }
763
764 curproxy->ck_opts = 0;
765 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100766 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100767 free(curproxy->cookie_name);
768 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200769 if (!curproxy->cookie_name)
770 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100771 curproxy->cookie_len = strlen(curproxy->cookie_name);
772
773 cur_arg = 2;
774 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100775 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100776 curproxy->ck_opts |= PR_CK_RW;
777 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100778 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100779 curproxy->ck_opts |= PR_CK_IND;
780 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100781 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100782 curproxy->ck_opts |= PR_CK_INS;
783 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100784 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100785 curproxy->ck_opts |= PR_CK_NOC;
786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100788 curproxy->ck_opts |= PR_CK_POST;
789 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100790 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100791 curproxy->ck_opts |= PR_CK_PSV;
792 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100793 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100794 curproxy->ck_opts |= PR_CK_PFX;
795 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100796 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100797 curproxy->ck_opts |= PR_CK_HTTPONLY;
798 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100799 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100800 curproxy->ck_opts |= PR_CK_SECURE;
801 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100802 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100803 if (!*args[cur_arg + 1]) {
804 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
805 file, linenum, args[cur_arg]);
806 err_code |= ERR_ALERT | ERR_FATAL;
807 goto out;
808 }
809
Joao Moraise1583752019-10-30 21:04:00 -0300810 if (!strchr(args[cur_arg + 1], '.')) {
811 /* rfc6265, 5.2.3 The Domain Attribute */
812 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
813 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100814 file, linenum, args[cur_arg + 1]);
815 err_code |= ERR_WARN;
816 }
817
818 err = invalid_domainchar(args[cur_arg + 1]);
819 if (err) {
820 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
821 file, linenum, *err, args[cur_arg + 1]);
822 err_code |= ERR_ALERT | ERR_FATAL;
823 goto out;
824 }
825
826 if (!curproxy->cookie_domain) {
827 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
828 } else {
829 /* one domain was already specified, add another one by
830 * building the string which will be returned along with
831 * the cookie.
832 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200833 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
834 }
835
Christopher Fauletb15625a2021-04-12 21:31:45 +0200836 if (!curproxy->cookie_domain)
837 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100838 cur_arg++;
839 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100840 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100841 unsigned int maxidle;
842 const char *res;
843
844 if (!*args[cur_arg + 1]) {
845 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
846 file, linenum, args[cur_arg]);
847 err_code |= ERR_ALERT | ERR_FATAL;
848 goto out;
849 }
850
851 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200852 if (res == PARSE_TIME_OVER) {
853 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
854 file, linenum, args[cur_arg+1], args[cur_arg]);
855 err_code |= ERR_ALERT | ERR_FATAL;
856 goto out;
857 }
858 else if (res == PARSE_TIME_UNDER) {
859 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
860 file, linenum, args[cur_arg+1], args[cur_arg]);
861 err_code |= ERR_ALERT | ERR_FATAL;
862 goto out;
863 }
864 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100865 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
866 file, linenum, *res, args[cur_arg]);
867 err_code |= ERR_ALERT | ERR_FATAL;
868 goto out;
869 }
870 curproxy->cookie_maxidle = maxidle;
871 cur_arg++;
872 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100873 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100874 unsigned int maxlife;
875 const char *res;
876
877 if (!*args[cur_arg + 1]) {
878 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
879 file, linenum, args[cur_arg]);
880 err_code |= ERR_ALERT | ERR_FATAL;
881 goto out;
882 }
883
Willy Tarreau9faebe32019-06-07 19:00:37 +0200884
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100885 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200886 if (res == PARSE_TIME_OVER) {
887 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
888 file, linenum, args[cur_arg+1], args[cur_arg]);
889 err_code |= ERR_ALERT | ERR_FATAL;
890 goto out;
891 }
892 else if (res == PARSE_TIME_UNDER) {
893 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
894 file, linenum, args[cur_arg+1], args[cur_arg]);
895 err_code |= ERR_ALERT | ERR_FATAL;
896 goto out;
897 }
898 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100899 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
900 file, linenum, *res, args[cur_arg]);
901 err_code |= ERR_ALERT | ERR_FATAL;
902 goto out;
903 }
904 curproxy->cookie_maxlife = maxlife;
905 cur_arg++;
906 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100907 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100908
909 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
910 err_code |= ERR_WARN;
911 curproxy->ck_opts |= PR_CK_DYNAMIC;
912 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100913 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100914 char *val;
915 if (!*args[cur_arg + 1]) {
916 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
917 file, linenum, args[cur_arg]);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921 val = args[cur_arg + 1];
922 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100923 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100924 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
925 file, linenum, *val);
926 err_code |= ERR_ALERT | ERR_FATAL;
927 goto out;
928 }
929 val++;
930 }
931 /* don't add ';' for the first attribute */
932 if (!curproxy->cookie_attrs)
933 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
934 else
935 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200936
Christopher Fauletb15625a2021-04-12 21:31:45 +0200937 if (!curproxy->cookie_attrs)
938 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100939 cur_arg++;
940 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100941
942 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100943 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 +0100944 file, linenum, args[0]);
945 err_code |= ERR_ALERT | ERR_FATAL;
946 goto out;
947 }
948 cur_arg++;
949 }
950 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
951 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
952 file, linenum);
953 err_code |= ERR_ALERT | ERR_FATAL;
954 }
955
956 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
957 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
958 file, linenum);
959 err_code |= ERR_ALERT | ERR_FATAL;
960 }
961
962 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
963 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
964 file, linenum);
965 err_code |= ERR_ALERT | ERR_FATAL;
966 }
967 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100968 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100969 if (*(args[1]) == 0) {
970 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
971 file, linenum, args[0]);
972 err_code |= ERR_ALERT | ERR_FATAL;
973 goto out;
974 }
975
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100976 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100977 if (*(args[1]) == 0) {
978 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
979 file, linenum, args[1]);
980 err_code |= ERR_ALERT | ERR_FATAL;
981 goto out;
982 }
983 free(curproxy->email_alert.from);
984 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200985 if (!curproxy->email_alert.from)
986 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100987 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100988 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100989 if (*(args[1]) == 0) {
990 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
991 file, linenum, args[1]);
992 err_code |= ERR_ALERT | ERR_FATAL;
993 goto out;
994 }
995 free(curproxy->email_alert.mailers.name);
996 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200997 if (!curproxy->email_alert.mailers.name)
998 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100999 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001000 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001001 if (*(args[1]) == 0) {
1002 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1003 file, linenum, args[1]);
1004 err_code |= ERR_ALERT | ERR_FATAL;
1005 goto out;
1006 }
1007 free(curproxy->email_alert.myhostname);
1008 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001009 if (!curproxy->email_alert.myhostname)
1010 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001011 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001012 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001013 curproxy->email_alert.level = get_log_level(args[2]);
1014 if (curproxy->email_alert.level < 0) {
1015 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1016 file, linenum, args[1], args[2]);
1017 err_code |= ERR_ALERT | ERR_FATAL;
1018 goto out;
1019 }
1020 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001021 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001022 if (*(args[1]) == 0) {
1023 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1024 file, linenum, args[1]);
1025 err_code |= ERR_ALERT | ERR_FATAL;
1026 goto out;
1027 }
1028 free(curproxy->email_alert.to);
1029 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001030 if (!curproxy->email_alert.to)
1031 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001032 }
1033 else {
1034 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1035 file, linenum, args[1]);
1036 err_code |= ERR_ALERT | ERR_FATAL;
1037 goto out;
1038 }
1039 /* Indicate that the email_alert is at least partially configured */
1040 curproxy->email_alert.set = 1;
1041 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001042 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001043 if (*(args[1]) == 0) {
1044 ha_alert("parsing [%s:%d] : missing persist method.\n",
1045 file, linenum);
1046 err_code |= ERR_ALERT | ERR_FATAL;
1047 goto out;
1048 }
1049
1050 if (!strncmp(args[1], "rdp-cookie", 10)) {
1051 curproxy->options2 |= PR_O2_RDPC_PRST;
1052
1053 if (*(args[1] + 10) == '(') { /* cookie name */
1054 const char *beg, *end;
1055
1056 beg = args[1] + 11;
1057 end = strchr(beg, ')');
1058
1059 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1060 goto out;
1061
1062 if (!end || end == beg) {
1063 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1064 file, linenum);
1065 err_code |= ERR_ALERT | ERR_FATAL;
1066 goto out;
1067 }
1068
1069 free(curproxy->rdp_cookie_name);
1070 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001071 if (!curproxy->rdp_cookie_name)
1072 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001073 curproxy->rdp_cookie_len = end-beg;
1074 }
1075 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1076 free(curproxy->rdp_cookie_name);
1077 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +02001078 if (!curproxy->rdp_cookie_name)
1079 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001080 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1081 }
1082 else { /* syntax */
1083 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1084 file, linenum);
1085 err_code |= ERR_ALERT | ERR_FATAL;
1086 goto out;
1087 }
1088 }
1089 else {
1090 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1091 file, linenum);
1092 err_code |= ERR_ALERT | ERR_FATAL;
1093 goto out;
1094 }
1095 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001096 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001097 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 +01001098 err_code |= ERR_ALERT | ERR_FATAL;
1099 goto out;
1100 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001101 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001102 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1103 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001104 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001105 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1106 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001107 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 +01001108 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1109 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001110 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001111 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1112 }
1113 else {
1114 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1115 file, linenum, args[0], args[1]);
1116 err_code |= ERR_ALERT | ERR_FATAL;
1117 goto out;
1118 }
1119 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001120 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001121 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1122 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001123 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001124 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001125
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001126 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001127
1128 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001129 curproxy->server_state_file_name = strdup(curproxy->id);
1130 else
1131 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001132
Christopher Fauletb15625a2021-04-12 21:31:45 +02001133 if (!curproxy->server_state_file_name)
1134 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001135 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001136 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001137 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1138 err_code |= ERR_WARN;
1139 if (*(args[1]) == 0) {
1140 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1141 file, linenum, args[0]);
1142 err_code |= ERR_ALERT | ERR_FATAL;
1143 goto out;
1144 }
1145 curproxy->max_out_conns = atoi(args[1]);
1146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001147 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001148 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1149 err_code |= ERR_WARN;
1150
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001151 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001152 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001153 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1154 err_code |= ERR_ALERT | ERR_FATAL;
1155 goto out;
1156 }
1157
1158 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1159 goto out;
1160
1161 if (*(args[4]) == 0) {
1162 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1163 file, linenum, args[0]);
1164 err_code |= ERR_ALERT | ERR_FATAL;
1165 goto out;
1166 }
1167 free(curproxy->capture_name);
1168 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001169 if (!curproxy->capture_name)
1170 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001171 curproxy->capture_namelen = strlen(curproxy->capture_name);
1172 curproxy->capture_len = atol(args[4]);
1173 curproxy->to_log |= LW_COOKIE;
1174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001175 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001176 struct cap_hdr *hdr;
1177
Willy Tarreau5d095c22021-02-12 10:15:59 +01001178 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001179 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1180 err_code |= ERR_ALERT | ERR_FATAL;
1181 goto out;
1182 }
1183
1184 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1185 goto out;
1186
1187 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1188 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1189 file, linenum, args[0], args[1]);
1190 err_code |= ERR_ALERT | ERR_FATAL;
1191 goto out;
1192 }
1193
1194 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001195 if (!hdr)
1196 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001197 hdr->next = curproxy->req_cap;
1198 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001199 if (!hdr->name)
1200 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001201 hdr->namelen = strlen(args[3]);
1202 hdr->len = atol(args[5]);
1203 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001204 if (!hdr->pool) {
1205 req_caphdr_alloc_error:
1206 if (hdr)
1207 ha_free(&hdr->name);
1208 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001209 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001210 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001211 hdr->index = curproxy->nb_req_cap++;
1212 curproxy->req_cap = hdr;
1213 curproxy->to_log |= LW_REQHDR;
1214 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001215 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001216 struct cap_hdr *hdr;
1217
Willy Tarreau5d095c22021-02-12 10:15:59 +01001218 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001219 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1220 err_code |= ERR_ALERT | ERR_FATAL;
1221 goto out;
1222 }
1223
1224 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1225 goto out;
1226
1227 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1228 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1229 file, linenum, args[0], args[1]);
1230 err_code |= ERR_ALERT | ERR_FATAL;
1231 goto out;
1232 }
1233 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001234 if (!hdr)
1235 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001236 hdr->next = curproxy->rsp_cap;
1237 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001238 if (!hdr->name)
1239 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001240 hdr->namelen = strlen(args[3]);
1241 hdr->len = atol(args[5]);
1242 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001243 if (!hdr->pool) {
1244 res_caphdr_alloc_error:
1245 if (hdr)
1246 ha_free(&hdr->name);
1247 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001248 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001249 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001250 hdr->index = curproxy->nb_rsp_cap++;
1251 curproxy->rsp_cap = hdr;
1252 curproxy->to_log |= LW_RSPHDR;
1253 }
1254 else {
1255 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1256 file, linenum, args[0]);
1257 err_code |= ERR_ALERT | ERR_FATAL;
1258 goto out;
1259 }
1260 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001261 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001262 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1263 err_code |= ERR_WARN;
1264
1265 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1266 goto out;
1267
1268 if (*(args[1]) == 0) {
1269 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1270 file, linenum, args[0]);
1271 err_code |= ERR_ALERT | ERR_FATAL;
1272 goto out;
1273 }
1274 curproxy->conn_retries = atol(args[1]);
1275 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001276 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001277 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001278 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001279
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001280 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1281 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001282 err_code |= ERR_ALERT | ERR_FATAL;
1283 goto out;
1284 }
1285
1286 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1287 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001288 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001289 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1290 file, linenum, args[0]);
1291 err_code |= ERR_WARN;
1292 }
1293
1294 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1295
1296 if (!rule) {
1297 err_code |= ERR_ALERT | ERR_ABORT;
1298 goto out;
1299 }
1300
1301 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001302
1303 if (curproxy->cap & PR_CAP_FE)
1304 where |= SMP_VAL_FE_HRQ_HDR;
1305 if (curproxy->cap & PR_CAP_BE)
1306 where |= SMP_VAL_BE_HRQ_HDR;
1307 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001308
Willy Tarreau2b718102021-04-21 07:32:39 +02001309 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001310 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001311 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001312 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001313 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001314
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001315 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1316 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001317 err_code |= ERR_ALERT | ERR_FATAL;
1318 goto out;
1319 }
1320
1321 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1322 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001323 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001324 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1325 file, linenum, args[0]);
1326 err_code |= ERR_WARN;
1327 }
1328
1329 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1330
1331 if (!rule) {
1332 err_code |= ERR_ALERT | ERR_ABORT;
1333 goto out;
1334 }
1335
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001336 if (curproxy->cap & PR_CAP_FE)
1337 where |= SMP_VAL_FE_HRS_HDR;
1338 if (curproxy->cap & PR_CAP_BE)
1339 where |= SMP_VAL_BE_HRS_HDR;
1340 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001341
Willy Tarreau2b718102021-04-21 07:32:39 +02001342 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001343 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001344 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001345 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001346 int where = 0;
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001347 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1348 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001349 err_code |= ERR_ALERT | ERR_FATAL;
1350 goto out;
1351 }
1352
1353 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1354 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1355 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1356 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1357 file, linenum, args[0]);
1358 err_code |= ERR_WARN;
1359 }
1360
1361 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1362
1363 if (!rule) {
1364 err_code |= ERR_ALERT | ERR_ABORT;
1365 goto out;
1366 }
1367
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001368 if (curproxy->cap & PR_CAP_FE)
1369 where |= SMP_VAL_FE_HRS_HDR;
1370 if (curproxy->cap & PR_CAP_BE)
1371 where |= SMP_VAL_BE_HRS_HDR;
1372 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001373
Willy Tarreau2b718102021-04-21 07:32:39 +02001374 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001375 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001376 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001377 /* set the header name and length into the proxy structure */
1378 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1379 err_code |= ERR_WARN;
1380
1381 if (!*args[1]) {
1382 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1383 file, linenum, args[0]);
1384 err_code |= ERR_ALERT | ERR_FATAL;
1385 goto out;
1386 }
1387
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001388 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001389 free(curproxy->server_id_hdr_name);
1390 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001391 if (!curproxy->server_id_hdr_name)
1392 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001393 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001394 ist2bin_lc(curproxy->server_id_hdr_name, ist2(curproxy->server_id_hdr_name, curproxy->server_id_hdr_len));
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001395 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001396 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001397 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 +01001398
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001399 err_code |= ERR_ALERT | ERR_FATAL;
1400 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001401 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001402 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001403 struct redirect_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001404 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001405
Willy Tarreau5d095c22021-02-12 10:15:59 +01001406 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001407 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1408 err_code |= ERR_ALERT | ERR_FATAL;
1409 goto out;
1410 }
1411
1412 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1413 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1414 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1415 err_code |= ERR_ALERT | ERR_FATAL;
1416 goto out;
1417 }
1418
Willy Tarreau2b718102021-04-21 07:32:39 +02001419 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001420 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001421
1422 if (curproxy->cap & PR_CAP_FE)
1423 where |= SMP_VAL_FE_HRQ_HDR;
1424 if (curproxy->cap & PR_CAP_BE)
1425 where |= SMP_VAL_BE_HRQ_HDR;
1426 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001427 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001428 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001429 struct switching_rule *rule;
1430
Willy Tarreau5d095c22021-02-12 10:15:59 +01001431 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001432 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1433 err_code |= ERR_ALERT | ERR_FATAL;
1434 goto out;
1435 }
1436
1437 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1438 err_code |= ERR_WARN;
1439
1440 if (*(args[1]) == 0) {
1441 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1442 err_code |= ERR_ALERT | ERR_FATAL;
1443 goto out;
1444 }
1445
1446 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1447 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1448 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1449 file, linenum, errmsg);
1450 err_code |= ERR_ALERT | ERR_FATAL;
1451 goto out;
1452 }
1453
1454 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1455 }
1456 else if (*args[2]) {
1457 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1458 file, linenum, args[2]);
1459 err_code |= ERR_ALERT | ERR_FATAL;
1460 goto out;
1461 }
1462
1463 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001464 if (!rule)
1465 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001466 rule->cond = cond;
1467 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001468 if (!rule->be.name)
1469 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001470 rule->line = linenum;
1471 rule->file = strdup(file);
1472 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001473 use_backend_alloc_error:
1474 if (cond)
1475 prune_acl_cond(cond);
1476 ha_free(&cond);
1477 if (rule)
1478 ha_free(&(rule->be.name));
1479 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001480 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001481 }
1482 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001483 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001484 }
1485 else if (strcmp(args[0], "use-server") == 0) {
1486 struct server_rule *rule;
1487
Willy Tarreau5d095c22021-02-12 10:15:59 +01001488 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001489 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1490 err_code |= ERR_ALERT | ERR_FATAL;
1491 goto out;
1492 }
1493
1494 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1495 err_code |= ERR_WARN;
1496
1497 if (*(args[1]) == 0) {
1498 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1499 err_code |= ERR_ALERT | ERR_FATAL;
1500 goto out;
1501 }
1502
1503 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1504 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1505 file, linenum, args[0]);
1506 err_code |= ERR_ALERT | ERR_FATAL;
1507 goto out;
1508 }
1509
1510 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1511 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1512 file, linenum, errmsg);
1513 err_code |= ERR_ALERT | ERR_FATAL;
1514 goto out;
1515 }
1516
1517 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1518
1519 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001520 if (!rule)
1521 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001522 rule->cond = cond;
1523 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001524 if (!rule->srv.name)
1525 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001526 rule->line = linenum;
1527 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001528 if (!rule->file) {
1529 use_server_alloc_error:
1530 if (cond)
1531 prune_acl_cond(cond);
1532 ha_free(&cond);
1533 if (rule)
1534 ha_free(&(rule->srv.name));
1535 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001536 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001537 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001538 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001539 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001540 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1541 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001542 else if ((strcmp(args[0], "force-persist") == 0) ||
1543 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001544 struct persist_rule *rule;
1545
Willy Tarreau5d095c22021-02-12 10:15:59 +01001546 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001547 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1548 err_code |= ERR_ALERT | ERR_FATAL;
1549 goto out;
1550 }
1551
1552 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1553 err_code |= ERR_WARN;
1554
1555 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1556 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1557 file, linenum, args[0]);
1558 err_code |= ERR_ALERT | ERR_FATAL;
1559 goto out;
1560 }
1561
1562 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1563 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1564 file, linenum, args[0], errmsg);
1565 err_code |= ERR_ALERT | ERR_FATAL;
1566 goto out;
1567 }
1568
1569 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1570 * where force-persist is applied.
1571 */
1572 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1573
1574 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001575 if (!rule) {
1576 if (cond)
1577 prune_acl_cond(cond);
1578 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001579 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001580 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001581 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001582 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001583 rule->type = PERSIST_TYPE_FORCE;
1584 } else {
1585 rule->type = PERSIST_TYPE_IGNORE;
1586 }
1587 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001588 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001589 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001590 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001591 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001592
Willy Tarreau5d095c22021-02-12 10:15:59 +01001593 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001594 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1595 file, linenum);
1596 err_code |= ERR_ALERT | ERR_FATAL;
1597 goto out;
1598 }
1599
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001600 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001601 if (other) {
1602 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 +01001603 file, linenum, curproxy->id,
1604 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1605 other->proxy ? other->id : other->peers.p->id,
1606 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001607 err_code |= ERR_ALERT | ERR_FATAL;
1608 goto out;
1609 }
1610
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001611 curproxy->table = calloc(1, sizeof *curproxy->table);
1612 if (!curproxy->table) {
1613 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1614 file, linenum, args[0], args[1]);
1615 err_code |= ERR_ALERT | ERR_FATAL;
1616 goto out;
1617 }
1618
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001619 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1620 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001621 if (err_code & ERR_FATAL) {
1622 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001623 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001624 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001625
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001626 /* Store the proxy in the stick-table. */
1627 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001628
1629 stktable_store_name(curproxy->table);
1630 curproxy->table->next = stktables_list;
1631 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001632
1633 /* Add this proxy to the list of proxies which refer to its stick-table. */
1634 if (curproxy->table->proxies_list != curproxy) {
1635 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1636 curproxy->table->proxies_list = curproxy;
1637 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001638 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001639 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001640 struct sticking_rule *rule;
1641 struct sample_expr *expr;
1642 int myidx = 0;
1643 const char *name = NULL;
1644 int flags;
1645
Willy Tarreau5d095c22021-02-12 10:15:59 +01001646 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001647 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1648 err_code |= ERR_ALERT | ERR_FATAL;
1649 goto out;
1650 }
1651
1652 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1653 err_code |= ERR_WARN;
1654 goto out;
1655 }
1656
1657 myidx++;
1658 if ((strcmp(args[myidx], "store") == 0) ||
1659 (strcmp(args[myidx], "store-request") == 0)) {
1660 myidx++;
1661 flags = STK_IS_STORE;
1662 }
1663 else if (strcmp(args[myidx], "store-response") == 0) {
1664 myidx++;
1665 flags = STK_IS_STORE | STK_ON_RSP;
1666 }
1667 else if (strcmp(args[myidx], "match") == 0) {
1668 myidx++;
1669 flags = STK_IS_MATCH;
1670 }
1671 else if (strcmp(args[myidx], "on") == 0) {
1672 myidx++;
1673 flags = STK_IS_MATCH | STK_IS_STORE;
1674 }
1675 else {
1676 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1677 err_code |= ERR_ALERT | ERR_FATAL;
1678 goto out;
1679 }
1680
1681 if (*(args[myidx]) == 0) {
1682 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1683 err_code |= ERR_ALERT | ERR_FATAL;
1684 goto out;
1685 }
1686
1687 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001688 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001689 if (!expr) {
1690 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1691 err_code |= ERR_ALERT | ERR_FATAL;
1692 goto out;
1693 }
1694
1695 if (flags & STK_ON_RSP) {
1696 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1697 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1698 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1699 err_code |= ERR_ALERT | ERR_FATAL;
1700 free(expr);
1701 goto out;
1702 }
1703 } else {
1704 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1705 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1706 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1707 err_code |= ERR_ALERT | ERR_FATAL;
1708 free(expr);
1709 goto out;
1710 }
1711 }
1712
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001713 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001714 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1715
1716 if (strcmp(args[myidx], "table") == 0) {
1717 myidx++;
1718 name = args[myidx++];
1719 }
1720
1721 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1722 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1723 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1724 file, linenum, args[0], errmsg);
1725 err_code |= ERR_ALERT | ERR_FATAL;
1726 free(expr);
1727 goto out;
1728 }
1729 }
1730 else if (*(args[myidx])) {
1731 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1732 file, linenum, args[0], args[myidx]);
1733 err_code |= ERR_ALERT | ERR_FATAL;
1734 free(expr);
1735 goto out;
1736 }
1737 if (flags & STK_ON_RSP)
1738 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1739 else
1740 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1741
1742 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001743 if (!rule) {
1744 if (cond)
1745 prune_acl_cond(cond);
1746 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001747 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001748 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001749 rule->cond = cond;
1750 rule->expr = expr;
1751 rule->flags = flags;
1752 rule->table.name = name ? strdup(name) : NULL;
1753 LIST_INIT(&rule->list);
1754 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001755 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001756 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001757 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001758 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001759 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001760 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001761 curproxy->uri_auth = NULL; /* we must detach from the default config */
1762
1763 if (!*args[1]) {
1764 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001765 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001766 struct stats_admin_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001767 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001768
Willy Tarreau5d095c22021-02-12 10:15:59 +01001769 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001770 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1771 err_code |= ERR_ALERT | ERR_FATAL;
1772 goto out;
1773 }
1774
Christopher Fauletb15625a2021-04-12 21:31:45 +02001775 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1776 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001777
1778 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1779 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1780 file, linenum, args[0], args[1]);
1781 err_code |= ERR_ALERT | ERR_FATAL;
1782 goto out;
1783 }
1784 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1785 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1786 file, linenum, args[0], args[1], errmsg);
1787 err_code |= ERR_ALERT | ERR_FATAL;
1788 goto out;
1789 }
1790
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001791 if (curproxy->cap & PR_CAP_FE)
1792 where |= SMP_VAL_FE_HRQ_HDR;
1793 if (curproxy->cap & PR_CAP_BE)
1794 where |= SMP_VAL_BE_HRQ_HDR;
1795 err_code |= warnif_cond_conflicts(cond, where, file, linenum);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001796
1797 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001798 if (!rule) {
1799 if (cond)
1800 prune_acl_cond(cond);
1801 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001802 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001803 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001804 rule->cond = cond;
1805 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001806 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001807 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001808 if (*(args[2]) == 0) {
1809 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1810 err_code |= ERR_ALERT | ERR_FATAL;
1811 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001812 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1813 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001814 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001815 if (*(args[2]) == 0) {
1816 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1817 err_code |= ERR_ALERT | ERR_FATAL;
1818 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001819 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1820 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001821 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001822 unsigned interval;
1823
1824 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001825 if (err == PARSE_TIME_OVER) {
1826 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1827 file, linenum, args[2]);
1828 err_code |= ERR_ALERT | ERR_FATAL;
1829 goto out;
1830 }
1831 else if (err == PARSE_TIME_UNDER) {
1832 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1833 file, linenum, args[2]);
1834 err_code |= ERR_ALERT | ERR_FATAL;
1835 goto out;
1836 }
1837 else if (err) {
1838 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001839 file, linenum, *err);
1840 err_code |= ERR_ALERT | ERR_FATAL;
1841 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001842 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1843 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001844 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001845 struct act_rule *rule;
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001846 int where = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001847
Willy Tarreau5d095c22021-02-12 10:15:59 +01001848 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001849 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1850 err_code |= ERR_ALERT | ERR_FATAL;
1851 goto out;
1852 }
1853
Christopher Fauletb15625a2021-04-12 21:31:45 +02001854 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1855 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001856
1857 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1858 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1859 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1860 file, linenum, args[0]);
1861 err_code |= ERR_WARN;
1862 }
1863
1864 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1865
1866 if (!rule) {
1867 err_code |= ERR_ALERT | ERR_ABORT;
1868 goto out;
1869 }
1870
Christopher Faulet7a06ffb2021-10-13 17:22:17 +02001871 if (curproxy->cap & PR_CAP_FE)
1872 where |= SMP_VAL_FE_HRQ_HDR;
1873 if (curproxy->cap & PR_CAP_BE)
1874 where |= SMP_VAL_BE_HRQ_HDR;
1875 err_code |= warnif_cond_conflicts(rule->cond, where, file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001876 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001877
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001878 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001879 if (*(args[2]) == 0) {
1880 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1881 err_code |= ERR_ALERT | ERR_FATAL;
1882 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001883 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1884 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001885 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001886 if (*(args[2]) == 0) {
1887 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1888 err_code |= ERR_ALERT | ERR_FATAL;
1889 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001890 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1891 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001892 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001893 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1894 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001895 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001896 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1897 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001898 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001899 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1900 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001901 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001902 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1903 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001904 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001905
1906 if (*args[2]) {
1907 int i;
1908 char c;
1909
1910 for (i=0; args[2][i]; i++) {
1911 c = args[2][i];
1912 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1913 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1914 break;
1915 }
1916
1917 if (!i || args[2][i]) {
1918 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1919 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1920 file, linenum, args[0], args[1]);
1921 err_code |= ERR_ALERT | ERR_FATAL;
1922 goto out;
1923 }
1924 }
1925
Christopher Fauletb15625a2021-04-12 21:31:45 +02001926 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1927 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001928 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001929 char *desc = NULL;
1930
1931 if (*args[2]) {
1932 int i, len=0;
1933 char *d;
1934
1935 for (i = 2; *args[i]; i++)
1936 len += strlen(args[i]) + 1;
1937
1938 desc = d = calloc(1, len);
1939
1940 d += snprintf(d, desc + len - d, "%s", args[2]);
1941 for (i = 3; *args[i]; i++)
1942 d += snprintf(d, desc + len - d, " %s", args[i]);
1943 }
1944
1945 if (!*args[2] && !global.desc)
1946 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1947 file, linenum, args[1]);
1948 else {
1949 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1950 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001951 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001952 }
1953 free(desc);
1954 }
1955 } else {
1956stats_error_parsing:
1957 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1958 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1959 err_code |= ERR_ALERT | ERR_FATAL;
1960 goto out;
1961 }
1962 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001963 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001964 int optnum;
1965
1966 if (*(args[1]) == '\0') {
1967 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1968 file, linenum, args[0]);
1969 err_code |= ERR_ALERT | ERR_FATAL;
1970 goto out;
1971 }
1972
1973 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001974 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001975 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1976 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1977 file, linenum, cfg_opts[optnum].name);
1978 err_code |= ERR_ALERT | ERR_FATAL;
1979 goto out;
1980 }
1981 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1982 goto out;
1983
1984 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1985 err_code |= ERR_WARN;
1986 goto out;
1987 }
1988
1989 curproxy->no_options &= ~cfg_opts[optnum].val;
1990 curproxy->options &= ~cfg_opts[optnum].val;
1991
1992 switch (kwm) {
1993 case KWM_STD:
1994 curproxy->options |= cfg_opts[optnum].val;
1995 break;
1996 case KWM_NO:
1997 curproxy->no_options |= cfg_opts[optnum].val;
1998 break;
1999 case KWM_DEF: /* already cleared */
2000 break;
2001 }
2002
2003 goto out;
2004 }
2005 }
2006
2007 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002008 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002009 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2010 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2011 file, linenum, cfg_opts2[optnum].name);
2012 err_code |= ERR_ALERT | ERR_FATAL;
2013 goto out;
2014 }
2015 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2016 goto out;
2017 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2018 err_code |= ERR_WARN;
2019 goto out;
2020 }
2021
2022 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2023 curproxy->options2 &= ~cfg_opts2[optnum].val;
2024
2025 switch (kwm) {
2026 case KWM_STD:
2027 curproxy->options2 |= cfg_opts2[optnum].val;
2028 break;
2029 case KWM_NO:
2030 curproxy->no_options2 |= cfg_opts2[optnum].val;
2031 break;
2032 case KWM_DEF: /* already cleared */
2033 break;
2034 }
2035 goto out;
2036 }
2037 }
2038
2039 /* HTTP options override each other. They can be cancelled using
2040 * "no option xxx" which only switches to default mode if the mode
2041 * was this one (useful for cancelling options set in defaults
2042 * sections).
2043 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02002044 if (strcmp(args[1], "forceclose") == 0) {
2045 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",
2046 file, linenum, args[1]);
2047 err_code |= ERR_ALERT | ERR_FATAL;
2048 goto out;
2049 }
2050 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002051 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2052 goto out;
2053 if (kwm == KWM_STD) {
2054 curproxy->options &= ~PR_O_HTTP_MODE;
2055 curproxy->options |= PR_O_HTTP_CLO;
2056 goto out;
2057 }
2058 else if (kwm == KWM_NO) {
2059 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2060 curproxy->options &= ~PR_O_HTTP_MODE;
2061 goto out;
2062 }
2063 }
2064 else if (strcmp(args[1], "http-server-close") == 0) {
2065 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2066 goto out;
2067 if (kwm == KWM_STD) {
2068 curproxy->options &= ~PR_O_HTTP_MODE;
2069 curproxy->options |= PR_O_HTTP_SCL;
2070 goto out;
2071 }
2072 else if (kwm == KWM_NO) {
2073 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2074 curproxy->options &= ~PR_O_HTTP_MODE;
2075 goto out;
2076 }
2077 }
2078 else if (strcmp(args[1], "http-keep-alive") == 0) {
2079 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2080 goto out;
2081 if (kwm == KWM_STD) {
2082 curproxy->options &= ~PR_O_HTTP_MODE;
2083 curproxy->options |= PR_O_HTTP_KAL;
2084 goto out;
2085 }
2086 else if (kwm == KWM_NO) {
2087 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2088 curproxy->options &= ~PR_O_HTTP_MODE;
2089 goto out;
2090 }
2091 }
2092 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002093 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 +02002094 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002095 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002096 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002097 }
2098
2099 /* Redispatch can take an integer argument that control when the
2100 * resispatch occurs. All values are relative to the retries option.
2101 * This can be cancelled using "no option xxx".
2102 */
2103 if (strcmp(args[1], "redispatch") == 0) {
2104 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2105 err_code |= ERR_WARN;
2106 goto out;
2107 }
2108
2109 curproxy->no_options &= ~PR_O_REDISP;
2110 curproxy->options &= ~PR_O_REDISP;
2111
2112 switch (kwm) {
2113 case KWM_STD:
2114 curproxy->options |= PR_O_REDISP;
2115 curproxy->redispatch_after = -1;
2116 if(*args[2]) {
2117 curproxy->redispatch_after = atol(args[2]);
2118 }
2119 break;
2120 case KWM_NO:
2121 curproxy->no_options |= PR_O_REDISP;
2122 curproxy->redispatch_after = 0;
2123 break;
2124 case KWM_DEF: /* already cleared */
2125 break;
2126 }
2127 goto out;
2128 }
2129
Willy Tarreau25241232021-07-18 19:18:56 +02002130 if (strcmp(args[1], "http_proxy") == 0) {
2131 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",
2132 file, linenum, args[1]);
2133 err_code |= ERR_ALERT | ERR_FATAL;
2134 goto out;
2135 }
2136
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002137 if (kwm != KWM_STD) {
2138 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2139 file, linenum, args[1]);
2140 err_code |= ERR_ALERT | ERR_FATAL;
2141 goto out;
2142 }
2143
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002144 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002145 char *logformat;
2146 /* generate a complete HTTP log */
2147 logformat = default_http_log_format;
2148 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002149 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002150 curproxy->options2 |= PR_O2_CLFLOG;
2151 logformat = clf_http_log_format;
2152 } else {
2153 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2154 err_code |= ERR_ALERT | ERR_FATAL;
2155 goto out;
2156 }
2157 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2158 goto out;
2159 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002160 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002161 char *oldlogformat = "log-format";
2162 char *clflogformat = "";
2163
2164 if (curproxy->conf.logformat_string == default_http_log_format)
2165 oldlogformat = "option httplog";
2166 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2167 oldlogformat = "option tcplog";
2168 else if (curproxy->conf.logformat_string == clf_http_log_format)
2169 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002170 else if (curproxy->conf.logformat_string == default_https_log_format)
2171 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002172 if (logformat == clf_http_log_format)
2173 clflogformat = " clf";
2174 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2175 file, linenum, clflogformat, oldlogformat);
2176 }
2177 if (curproxy->conf.logformat_string != default_http_log_format &&
2178 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002179 curproxy->conf.logformat_string != clf_http_log_format &&
2180 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002181 free(curproxy->conf.logformat_string);
2182 curproxy->conf.logformat_string = logformat;
2183
2184 free(curproxy->conf.lfs_file);
2185 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2186 curproxy->conf.lfs_line = curproxy->conf.args.line;
2187
Willy Tarreau5d095c22021-02-12 10:15:59 +01002188 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002189 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2190 file, linenum, curproxy->id);
2191 err_code |= ERR_WARN;
2192 }
2193 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002194 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002195 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002196 char *oldlogformat = "log-format";
2197
2198 if (curproxy->conf.logformat_string == default_http_log_format)
2199 oldlogformat = "option httplog";
2200 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2201 oldlogformat = "option tcplog";
2202 else if (curproxy->conf.logformat_string == clf_http_log_format)
2203 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002204 else if (curproxy->conf.logformat_string == default_https_log_format)
2205 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002206 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2207 file, linenum, oldlogformat);
2208 }
2209 /* generate a detailed TCP log */
2210 if (curproxy->conf.logformat_string != default_http_log_format &&
2211 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002212 curproxy->conf.logformat_string != clf_http_log_format &&
2213 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002214 free(curproxy->conf.logformat_string);
2215 curproxy->conf.logformat_string = default_tcp_log_format;
2216
2217 free(curproxy->conf.lfs_file);
2218 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2219 curproxy->conf.lfs_line = curproxy->conf.args.line;
2220
2221 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2222 goto out;
2223
Willy Tarreau5d095c22021-02-12 10:15:59 +01002224 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002225 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2226 file, linenum, curproxy->id);
2227 err_code |= ERR_WARN;
2228 }
2229 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002230 else if (strcmp(args[1], "httpslog") == 0) {
2231 char *logformat;
2232 /* generate a complete HTTP log */
2233 logformat = default_https_log_format;
2234 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2235 char *oldlogformat = "log-format";
2236
2237 if (curproxy->conf.logformat_string == default_http_log_format)
2238 oldlogformat = "option httplog";
2239 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2240 oldlogformat = "option tcplog";
2241 else if (curproxy->conf.logformat_string == clf_http_log_format)
2242 oldlogformat = "option httplog clf";
2243 else if (curproxy->conf.logformat_string == default_https_log_format)
2244 oldlogformat = "option httpslog";
2245 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2246 file, linenum, oldlogformat);
2247 }
2248 if (curproxy->conf.logformat_string != default_http_log_format &&
2249 curproxy->conf.logformat_string != default_tcp_log_format &&
2250 curproxy->conf.logformat_string != clf_http_log_format &&
2251 curproxy->conf.logformat_string != default_https_log_format)
2252 free(curproxy->conf.logformat_string);
2253 curproxy->conf.logformat_string = logformat;
2254
2255 free(curproxy->conf.lfs_file);
2256 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2257 curproxy->conf.lfs_line = curproxy->conf.args.line;
2258
2259 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2260 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2261 file, linenum, curproxy->id);
2262 err_code |= ERR_WARN;
2263 }
2264 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002265 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002266 /* enable TCP keep-alives on client and server streams */
2267 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2268 err_code |= ERR_WARN;
2269
2270 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2271 goto out;
2272
2273 if (curproxy->cap & PR_CAP_FE)
2274 curproxy->options |= PR_O_TCP_CLI_KA;
2275 if (curproxy->cap & PR_CAP_BE)
2276 curproxy->options |= PR_O_TCP_SRV_KA;
2277 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002278 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002279 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002280 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002281 goto out;
2282 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002283 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002284 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002285 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002286 goto out;
2287 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002288 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002289 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002290 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002291 goto out;
2292 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002293 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002294 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002295 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002296 goto out;
2297 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002298 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002299 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002300 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002301 goto out;
2302 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002303 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002304 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002305 if (err_code & ERR_FATAL)
2306 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002307 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002308 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002309 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002310 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002311 goto out;
2312 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002313 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002314 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002315 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002316 goto out;
2317 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002318 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002319 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002320 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002321 goto out;
2322 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002323 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002324 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002325 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002326 goto out;
2327 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002328 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002329 int cur_arg;
2330
2331 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002332 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002333 */
2334
2335 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2336
2337 free(curproxy->fwdfor_hdr_name);
2338 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002339 if (!curproxy->fwdfor_hdr_name)
2340 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002341 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002342 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002343
2344 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2345 cur_arg = 2;
2346 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002347 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002348 unsigned char mask;
2349 int i;
2350
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002351 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002352 if (*(args[cur_arg+1]) &&
2353 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2354 curproxy->except_xff_net.family = AF_INET;
2355 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2356 }
2357 else if (*(args[cur_arg+1]) &&
2358 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2359 curproxy->except_xff_net.family = AF_INET6;
2360 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2361 for (i = 0; i < 16; i++)
2362 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2363 }
2364 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002365 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2366 file, linenum, args[0], args[1], args[cur_arg]);
2367 err_code |= ERR_ALERT | ERR_FATAL;
2368 goto out;
2369 }
2370 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002371 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002372 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002373 /* suboption header - needs additional argument for it */
2374 if (*(args[cur_arg+1]) == 0) {
2375 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2376 file, linenum, args[0], args[1], args[cur_arg]);
2377 err_code |= ERR_ALERT | ERR_FATAL;
2378 goto out;
2379 }
2380 free(curproxy->fwdfor_hdr_name);
2381 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002382 if (!curproxy->fwdfor_hdr_name)
2383 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002384 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2385 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002386 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002387 curproxy->options &= ~PR_O_FF_ALWAYS;
2388 cur_arg += 1;
2389 } else {
2390 /* unknown suboption - catchall */
2391 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2392 file, linenum, args[0], args[1]);
2393 err_code |= ERR_ALERT | ERR_FATAL;
2394 goto out;
2395 }
2396 } /* end while loop */
2397 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002398 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002399 int cur_arg;
2400
2401 /* insert x-original-to field, but not for the IP address listed as an except.
2402 * set default options (ie: bitfield, header name, etc)
2403 */
2404
2405 curproxy->options |= PR_O_ORGTO;
2406
2407 free(curproxy->orgto_hdr_name);
2408 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002409 if (!curproxy->orgto_hdr_name)
2410 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002411 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002412 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002413
2414 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2415 cur_arg = 2;
2416 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002417 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002418 unsigned char mask;
2419 int i;
2420
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002421 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002422 if (*(args[cur_arg+1]) &&
2423 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2424 curproxy->except_xot_net.family = AF_INET;
2425 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2426 }
2427 else if (*(args[cur_arg+1]) &&
2428 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2429 curproxy->except_xot_net.family = AF_INET6;
2430 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2431 for (i = 0; i < 16; i++)
2432 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2433 }
2434 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002435 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2436 file, linenum, args[0], args[1], args[cur_arg]);
2437 err_code |= ERR_ALERT | ERR_FATAL;
2438 goto out;
2439 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002440 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002441 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002442 /* suboption header - needs additional argument for it */
2443 if (*(args[cur_arg+1]) == 0) {
2444 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2445 file, linenum, args[0], args[1], args[cur_arg]);
2446 err_code |= ERR_ALERT | ERR_FATAL;
2447 goto out;
2448 }
2449 free(curproxy->orgto_hdr_name);
2450 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002451 if (!curproxy->orgto_hdr_name)
2452 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002453 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2454 cur_arg += 2;
2455 } else {
2456 /* unknown suboption - catchall */
2457 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2458 file, linenum, args[0], args[1]);
2459 err_code |= ERR_ALERT | ERR_FATAL;
2460 goto out;
2461 }
2462 } /* end while loop */
2463 }
2464 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002465 const char *best = proxy_find_best_option(args[1], common_options);
2466
2467 if (best)
2468 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2469 else
2470 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2471
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002472 err_code |= ERR_ALERT | ERR_FATAL;
2473 goto out;
2474 }
2475 goto out;
2476 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002477 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002478 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2479 err_code |= ERR_WARN;
2480
2481 if (*(args[1]) == 0) {
2482 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2483 err_code |= ERR_ALERT | ERR_FATAL;
2484 goto out;
2485 }
2486 free(curproxy->defbe.name);
2487 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002488 if (!curproxy->defbe.name)
2489 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002490
2491 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2492 goto out;
2493 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002494 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002495 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 +01002496
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002497 err_code |= ERR_ALERT | ERR_FATAL;
2498 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002499 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002500 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002501 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2502 err_code |= ERR_WARN;
2503
2504 if (strcmp(args[1], "never") == 0) {
2505 /* enable a graceful server shutdown on an HTTP 404 response */
2506 curproxy->options &= ~PR_O_REUSE_MASK;
2507 curproxy->options |= PR_O_REUSE_NEVR;
2508 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2509 goto out;
2510 }
2511 else if (strcmp(args[1], "safe") == 0) {
2512 /* enable a graceful server shutdown on an HTTP 404 response */
2513 curproxy->options &= ~PR_O_REUSE_MASK;
2514 curproxy->options |= PR_O_REUSE_SAFE;
2515 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2516 goto out;
2517 }
2518 else if (strcmp(args[1], "aggressive") == 0) {
2519 curproxy->options &= ~PR_O_REUSE_MASK;
2520 curproxy->options |= PR_O_REUSE_AGGR;
2521 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2522 goto out;
2523 }
2524 else if (strcmp(args[1], "always") == 0) {
2525 /* enable a graceful server shutdown on an HTTP 404 response */
2526 curproxy->options &= ~PR_O_REUSE_MASK;
2527 curproxy->options |= PR_O_REUSE_ALWS;
2528 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2529 goto out;
2530 }
2531 else {
2532 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2533 err_code |= ERR_ALERT | ERR_FATAL;
2534 goto out;
2535 }
2536 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002537 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002538 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002539 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2540 err_code |= ERR_ALERT | ERR_FATAL;
2541 goto out;
2542 }
2543
2544 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2545 err_code |= ERR_WARN;
2546
2547 if (strcmp(args[1], "fail") == 0) {
2548 /* add a condition to fail monitor requests */
2549 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2550 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2551 file, linenum, args[0], args[1]);
2552 err_code |= ERR_ALERT | ERR_FATAL;
2553 goto out;
2554 }
2555
2556 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2557 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2558 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2559 file, linenum, args[0], args[1], errmsg);
2560 err_code |= ERR_ALERT | ERR_FATAL;
2561 goto out;
2562 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002563 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002564 }
2565 else {
2566 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2567 err_code |= ERR_ALERT | ERR_FATAL;
2568 goto out;
2569 }
2570 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002571#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002572 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002573 /* enable transparent proxy connections */
2574 curproxy->options |= PR_O_TRANSP;
2575 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2576 goto out;
2577 }
2578#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002579 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002580 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2581 err_code |= ERR_WARN;
2582
2583 if (*(args[1]) == 0) {
2584 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2585 err_code |= ERR_ALERT | ERR_FATAL;
2586 goto out;
2587 }
2588 curproxy->maxconn = atol(args[1]);
2589 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2590 goto out;
2591 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002592 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002593 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2594 err_code |= ERR_WARN;
2595
2596 if (*(args[1]) == 0) {
2597 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2598 err_code |= ERR_ALERT | ERR_FATAL;
2599 goto out;
2600 }
2601 curproxy->backlog = atol(args[1]);
2602 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2603 goto out;
2604 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002605 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002606 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2607 err_code |= ERR_WARN;
2608
2609 if (*(args[1]) == 0) {
2610 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2611 err_code |= ERR_ALERT | ERR_FATAL;
2612 goto out;
2613 }
2614 curproxy->fullconn = atol(args[1]);
2615 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2616 goto out;
2617 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002618 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002619 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 +02002620 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002621 err_code |= ERR_ALERT | ERR_FATAL;
2622 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002623 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002624 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002625 struct sockaddr_storage *sk;
2626 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002627
Willy Tarreau5d095c22021-02-12 10:15:59 +01002628 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002629 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2630 err_code |= ERR_ALERT | ERR_FATAL;
2631 goto out;
2632 }
2633 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2634 err_code |= ERR_WARN;
2635
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002636 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2637 &errmsg, NULL, NULL,
2638 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 +01002639 if (!sk) {
2640 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2641 err_code |= ERR_ALERT | ERR_FATAL;
2642 goto out;
2643 }
2644
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002645 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2646 goto out;
2647
2648 curproxy->dispatch_addr = *sk;
2649 curproxy->options |= PR_O_DISPATCH;
2650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002651 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002652 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2653 err_code |= ERR_WARN;
2654
2655 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2656 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2657 err_code |= ERR_ALERT | ERR_FATAL;
2658 goto out;
2659 }
2660 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002661 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002662 /**
2663 * The syntax for hash-type config element is
2664 * hash-type {map-based|consistent} [[<algo>] avalanche]
2665 *
2666 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2667 */
2668 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2669
2670 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2671 err_code |= ERR_WARN;
2672
2673 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2674 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2675 }
2676 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2677 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2678 }
2679 else if (strcmp(args[1], "avalanche") == 0) {
2680 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]);
2681 err_code |= ERR_ALERT | ERR_FATAL;
2682 goto out;
2683 }
2684 else {
2685 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2686 err_code |= ERR_ALERT | ERR_FATAL;
2687 goto out;
2688 }
2689
2690 /* set the hash function to use */
2691 if (!*args[2]) {
2692 /* the default algo is sdbm */
2693 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2694
2695 /* if consistent with no argument, then avalanche modifier is also applied */
2696 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2697 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2698 } else {
2699 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002700 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002701 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2702 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002703 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002704 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2705 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002706 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002707 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2708 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002709 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002710 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2711 }
2712 else {
2713 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2714 err_code |= ERR_ALERT | ERR_FATAL;
2715 goto out;
2716 }
2717
2718 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002719 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002720 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2721 }
2722 else if (*args[3]) {
2723 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2724 err_code |= ERR_ALERT | ERR_FATAL;
2725 goto out;
2726 }
2727 }
2728 }
2729 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2730 if (*(args[1]) == 0) {
2731 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2732 err_code |= ERR_ALERT | ERR_FATAL;
2733 goto out;
2734 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002735 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2736 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002737 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2738 err_code |= ERR_ALERT | ERR_FATAL;
2739 goto out;
2740 }
2741 }
2742 else if (strcmp(args[0], "unique-id-format") == 0) {
2743 if (!*(args[1])) {
2744 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2745 err_code |= ERR_ALERT | ERR_FATAL;
2746 goto out;
2747 }
2748 if (*(args[2])) {
2749 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2750 err_code |= ERR_ALERT | ERR_FATAL;
2751 goto out;
2752 }
2753 free(curproxy->conf.uniqueid_format_string);
2754 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002755 if (!curproxy->conf.uniqueid_format_string)
2756 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002757
2758 free(curproxy->conf.uif_file);
2759 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2760 curproxy->conf.uif_line = curproxy->conf.args.line;
2761 }
2762
2763 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002764 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002765 if (!*(args[1])) {
2766 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2767 err_code |= ERR_ALERT | ERR_FATAL;
2768 goto out;
2769 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002770 copy = strdup(args[1]);
2771 if (copy == NULL) {
2772 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2773 err_code |= ERR_ALERT | ERR_FATAL;
2774 goto out;
2775 }
2776
2777 istfree(&curproxy->header_unique_id);
2778 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002779 }
2780
2781 else if (strcmp(args[0], "log-format") == 0) {
2782 if (!*(args[1])) {
2783 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2784 err_code |= ERR_ALERT | ERR_FATAL;
2785 goto out;
2786 }
2787 if (*(args[2])) {
2788 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2789 err_code |= ERR_ALERT | ERR_FATAL;
2790 goto out;
2791 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002792 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002793 char *oldlogformat = "log-format";
2794
2795 if (curproxy->conf.logformat_string == default_http_log_format)
2796 oldlogformat = "option httplog";
2797 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2798 oldlogformat = "option tcplog";
2799 else if (curproxy->conf.logformat_string == clf_http_log_format)
2800 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002801 else if (curproxy->conf.logformat_string == default_https_log_format)
2802 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002803 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2804 file, linenum, oldlogformat);
2805 }
2806 if (curproxy->conf.logformat_string != default_http_log_format &&
2807 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002808 curproxy->conf.logformat_string != clf_http_log_format &&
2809 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002810 free(curproxy->conf.logformat_string);
2811 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002812 if (!curproxy->conf.logformat_string)
2813 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002814
2815 free(curproxy->conf.lfs_file);
2816 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2817 curproxy->conf.lfs_line = curproxy->conf.args.line;
2818
2819 /* get a chance to improve log-format error reporting by
2820 * reporting the correct line-number when possible.
2821 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002822 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002823 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2824 file, linenum, curproxy->id);
2825 err_code |= ERR_WARN;
2826 }
2827 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002828 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002829 if (!*(args[1])) {
2830 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2831 err_code |= ERR_ALERT | ERR_FATAL;
2832 goto out;
2833 }
2834 if (*(args[2])) {
2835 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2836 err_code |= ERR_ALERT | ERR_FATAL;
2837 goto out;
2838 }
2839
2840 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2841 free(curproxy->conf.logformat_sd_string);
2842 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002843 if (!curproxy->conf.logformat_sd_string)
2844 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002845
2846 free(curproxy->conf.lfsd_file);
2847 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2848 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2849
2850 /* get a chance to improve log-format-sd error reporting by
2851 * reporting the correct line-number when possible.
2852 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002853 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002854 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2855 file, linenum, curproxy->id);
2856 err_code |= ERR_WARN;
2857 }
2858 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002859 else if (strcmp(args[0], "error-log-format") == 0) {
2860 if (!*(args[1])) {
2861 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2862 err_code |= ERR_ALERT | ERR_FATAL;
2863 goto out;
2864 }
2865 if (*(args[2])) {
2866 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2867 err_code |= ERR_ALERT | ERR_FATAL;
2868 goto out;
2869 }
2870 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2871 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2872 file, linenum);
2873 }
2874 free(curproxy->conf.error_logformat_string);
2875 curproxy->conf.error_logformat_string = strdup(args[1]);
2876 if (!curproxy->conf.error_logformat_string)
2877 goto alloc_error;
2878
2879 free(curproxy->conf.elfs_file);
2880 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2881 curproxy->conf.elfs_line = curproxy->conf.args.line;
2882
2883 /* get a chance to improve log-format error reporting by
2884 * reporting the correct line-number when possible.
2885 */
2886 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2887 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2888 file, linenum, curproxy->id);
2889 err_code |= ERR_WARN;
2890 }
2891 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002892 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002893 if (*(args[1]) == 0) {
2894 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2895 err_code |= ERR_ALERT | ERR_FATAL;
2896 goto out;
2897 }
2898 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002899 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2900 if (b_orig(&curproxy->log_tag) == NULL) {
2901 chunk_destroy(&curproxy->log_tag);
2902 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2903 err_code |= ERR_ALERT | ERR_FATAL;
2904 goto out;
2905 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002906 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002907 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002908 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002909 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2910 err_code |= ERR_ALERT | ERR_FATAL;
2911 goto out;
2912 }
2913 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002914 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002915 int cur_arg;
2916 int port1, port2;
2917 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002918
2919 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2920 err_code |= ERR_WARN;
2921
2922 if (!*args[1]) {
2923 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2924 file, linenum, "source", "usesrc", "interface");
2925 err_code |= ERR_ALERT | ERR_FATAL;
2926 goto out;
2927 }
2928
Christopher Faulet31930372019-07-15 10:16:58 +02002929 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002930 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002931 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002932 curproxy->conn_src.iface_len = 0;
2933
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002934 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2935 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002936 if (!sk) {
2937 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2938 file, linenum, args[0], args[1], errmsg);
2939 err_code |= ERR_ALERT | ERR_FATAL;
2940 goto out;
2941 }
2942
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002943 curproxy->conn_src.source_addr = *sk;
2944 curproxy->conn_src.opts |= CO_SRC_BIND;
2945
2946 cur_arg = 2;
2947 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002948 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002949#if defined(CONFIG_HAP_TRANSPARENT)
2950 if (!*args[cur_arg + 1]) {
2951 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2952 file, linenum, "usesrc");
2953 err_code |= ERR_ALERT | ERR_FATAL;
2954 goto out;
2955 }
2956
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002957 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002958 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2959 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002960 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002961 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2962 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2963 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2964 char *name, *end;
2965
2966 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002967 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002968 name++;
2969
2970 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002971 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002972 end++;
2973
2974 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2975 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002976 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002977 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002978 if (!curproxy->conn_src.bind_hdr_name)
2979 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002980 curproxy->conn_src.bind_hdr_len = end - name;
2981 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2982 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2983 curproxy->conn_src.bind_hdr_occ = -1;
2984
2985 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002986 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002987 end++;
2988 if (*end == ',') {
2989 end++;
2990 name = end;
2991 if (*end == '-')
2992 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002993 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002994 end++;
2995 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2996 }
2997
2998 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2999 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
3000 " occurrences values smaller than %d.\n",
3001 file, linenum, MAX_HDR_HISTORY);
3002 err_code |= ERR_ALERT | ERR_FATAL;
3003 goto out;
3004 }
3005 } else {
3006 struct sockaddr_storage *sk;
3007
Willy Tarreau65ec4e32020-09-16 19:17:08 +02003008 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
3009 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003010 if (!sk) {
3011 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
3012 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
3013 err_code |= ERR_ALERT | ERR_FATAL;
3014 goto out;
3015 }
3016
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003017 curproxy->conn_src.tproxy_addr = *sk;
3018 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3019 }
3020 global.last_checks |= LSTCHK_NETADM;
3021#else /* no TPROXY support */
3022 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3023 file, linenum, "usesrc");
3024 err_code |= ERR_ALERT | ERR_FATAL;
3025 goto out;
3026#endif
3027 cur_arg += 2;
3028 continue;
3029 }
3030
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003031 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003032#ifdef SO_BINDTODEVICE
3033 if (!*args[cur_arg + 1]) {
3034 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3035 file, linenum, args[0]);
3036 err_code |= ERR_ALERT | ERR_FATAL;
3037 goto out;
3038 }
3039 free(curproxy->conn_src.iface_name);
3040 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02003041 if (!curproxy->conn_src.iface_name)
3042 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003043 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3044 global.last_checks |= LSTCHK_NETADM;
3045#else
3046 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3047 file, linenum, args[0], args[cur_arg]);
3048 err_code |= ERR_ALERT | ERR_FATAL;
3049 goto out;
3050#endif
3051 cur_arg += 2;
3052 continue;
3053 }
3054 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3055 file, linenum, args[0], "interface", "usesrc");
3056 err_code |= ERR_ALERT | ERR_FATAL;
3057 goto out;
3058 }
3059 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003060 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003061 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3062 file, linenum, "usesrc", "source");
3063 err_code |= ERR_ALERT | ERR_FATAL;
3064 goto out;
3065 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003066 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 +02003067 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003068 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003069 file, linenum, args[0]);
3070 err_code |= ERR_ALERT | ERR_FATAL;
3071 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003072 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003073 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003074 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3075 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3076 err_code |= ERR_ALERT | ERR_FATAL;
3077 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003078 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003079 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003080 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3081 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3082 err_code |= ERR_ALERT | ERR_FATAL;
3083 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003084 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003085 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003086 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3087 err_code |= ERR_ALERT | ERR_FATAL;
3088 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003089 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003090 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003091 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3092 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3093 err_code |= ERR_ALERT | ERR_FATAL;
3094 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003095 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003096 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003097 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3098 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3099 err_code |= ERR_ALERT | ERR_FATAL;
3100 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003101 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003102 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003103 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3104 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3105 err_code |= ERR_ALERT | ERR_FATAL;
3106 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003107 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003108 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003109 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3110 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3111 err_code |= ERR_ALERT | ERR_FATAL;
3112 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003113 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003114 else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003115 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3116 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3117 err_code |= ERR_ALERT | ERR_FATAL;
3118 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003119 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003120 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003121 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3122 err_code |= ERR_ALERT | ERR_FATAL;
3123 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003124 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003125 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 +02003126 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3127 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3128 err_code |= ERR_ALERT | ERR_FATAL;
3129 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003130 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003131 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 +02003132 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3133 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3134 err_code |= ERR_ALERT | ERR_FATAL;
3135 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003136 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003137 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003138 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3139 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3140 err_code |= ERR_ALERT | ERR_FATAL;
3141 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003142 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003143 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 +02003144 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3145 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3146 err_code |= ERR_ALERT | ERR_FATAL;
3147 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003148 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003149 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003150 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3151 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3152 err_code |= ERR_ALERT | ERR_FATAL;
3153 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003154 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003155 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003156 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3157 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3158 err_code |= ERR_ALERT | ERR_FATAL;
3159 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003160 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003161 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303162 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003163 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3164 err_code |= ERR_ALERT | ERR_FATAL;
3165 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003166 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003167 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003168 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3169 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3170 err_code |= ERR_ALERT | ERR_FATAL;
3171 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003172 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003173 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003174 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3175 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3176 err_code |= ERR_ALERT | ERR_FATAL;
3177 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003178 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003179 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003180 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3181 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3182 err_code |= ERR_ALERT | ERR_FATAL;
3183 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003184 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003185 else {
3186 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003187 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003188 int index;
3189
3190 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3191 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3192 if (kwl->kw[index].section != CFG_LISTEN)
3193 continue;
3194 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003195 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003196 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003197 err_code |= ERR_ALERT | ERR_FATAL;
3198 goto out;
3199 }
3200
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003201 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003202 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003203 if (rc < 0) {
3204 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3205 err_code |= ERR_ALERT | ERR_FATAL;
3206 goto out;
3207 }
3208 else if (rc > 0) {
3209 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3210 err_code |= ERR_WARN;
3211 goto out;
3212 }
3213 goto out;
3214 }
3215 }
3216 }
3217
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003218 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3219 if (best)
3220 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3221 else
3222 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003223 err_code |= ERR_ALERT | ERR_FATAL;
3224 goto out;
3225 }
3226 out:
3227 free(errmsg);
3228 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003229
3230 alloc_error:
3231 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3232 err_code |= ERR_ALERT | ERR_ABORT;
3233 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003234}