blob: 9dbf7ed980f179cfb4aff6b1269a15ee592d0ad4 [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;
1278
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001279 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1280 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001281 err_code |= ERR_ALERT | ERR_FATAL;
1282 goto out;
1283 }
1284
1285 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1286 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001287 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001288 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1289 file, linenum, args[0]);
1290 err_code |= ERR_WARN;
1291 }
1292
1293 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1294
1295 if (!rule) {
1296 err_code |= ERR_ALERT | ERR_ABORT;
1297 goto out;
1298 }
1299
1300 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1301 err_code |= warnif_cond_conflicts(rule->cond,
1302 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1303 file, linenum);
1304
Willy Tarreau2b718102021-04-21 07:32:39 +02001305 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001306 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001307 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001308 struct act_rule *rule;
1309
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001310 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1311 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001312 err_code |= ERR_ALERT | ERR_FATAL;
1313 goto out;
1314 }
1315
1316 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1317 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001318 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001319 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1320 file, linenum, args[0]);
1321 err_code |= ERR_WARN;
1322 }
1323
1324 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1325
1326 if (!rule) {
1327 err_code |= ERR_ALERT | ERR_ABORT;
1328 goto out;
1329 }
1330
1331 err_code |= warnif_cond_conflicts(rule->cond,
1332 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1333 file, linenum);
1334
Willy Tarreau2b718102021-04-21 07:32:39 +02001335 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001336 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001337 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001338 struct act_rule *rule;
1339
Christopher Fauletee08d6c2021-10-13 15:40:15 +02001340 if ((curproxy->cap & PR_CAP_DEF) && strlen(curproxy->id) == 0) {
1341 ha_alert("parsing [%s:%d] : '%s' not allowed in anonymous 'defaults' section.\n", file, linenum, args[0]);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001342 err_code |= ERR_ALERT | ERR_FATAL;
1343 goto out;
1344 }
1345
1346 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1347 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1348 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1349 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1350 file, linenum, args[0]);
1351 err_code |= ERR_WARN;
1352 }
1353
1354 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1355
1356 if (!rule) {
1357 err_code |= ERR_ALERT | ERR_ABORT;
1358 goto out;
1359 }
1360
1361 err_code |= warnif_cond_conflicts(rule->cond,
1362 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1363 file, linenum);
1364
Willy Tarreau2b718102021-04-21 07:32:39 +02001365 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001366 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001367 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001368 /* set the header name and length into the proxy structure */
1369 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1370 err_code |= ERR_WARN;
1371
1372 if (!*args[1]) {
1373 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1374 file, linenum, args[0]);
1375 err_code |= ERR_ALERT | ERR_FATAL;
1376 goto out;
1377 }
1378
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001379 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001380 free(curproxy->server_id_hdr_name);
1381 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001382 if (!curproxy->server_id_hdr_name)
1383 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001384 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001385 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 +01001386 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001387 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001388 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 +01001389
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001390 err_code |= ERR_ALERT | ERR_FATAL;
1391 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001392 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001393 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001394 struct redirect_rule *rule;
1395
Willy Tarreau5d095c22021-02-12 10:15:59 +01001396 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001397 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1398 err_code |= ERR_ALERT | ERR_FATAL;
1399 goto out;
1400 }
1401
1402 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1403 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1404 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1405 err_code |= ERR_ALERT | ERR_FATAL;
1406 goto out;
1407 }
1408
Willy Tarreau2b718102021-04-21 07:32:39 +02001409 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001410 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1411 err_code |= warnif_cond_conflicts(rule->cond,
1412 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1413 file, linenum);
1414 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001415 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001416 struct switching_rule *rule;
1417
Willy Tarreau5d095c22021-02-12 10:15:59 +01001418 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001419 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1420 err_code |= ERR_ALERT | ERR_FATAL;
1421 goto out;
1422 }
1423
1424 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1425 err_code |= ERR_WARN;
1426
1427 if (*(args[1]) == 0) {
1428 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1429 err_code |= ERR_ALERT | ERR_FATAL;
1430 goto out;
1431 }
1432
1433 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1434 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1435 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1436 file, linenum, errmsg);
1437 err_code |= ERR_ALERT | ERR_FATAL;
1438 goto out;
1439 }
1440
1441 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1442 }
1443 else if (*args[2]) {
1444 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1445 file, linenum, args[2]);
1446 err_code |= ERR_ALERT | ERR_FATAL;
1447 goto out;
1448 }
1449
1450 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001451 if (!rule)
1452 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001453 rule->cond = cond;
1454 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001455 if (!rule->be.name)
1456 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001457 rule->line = linenum;
1458 rule->file = strdup(file);
1459 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001460 use_backend_alloc_error:
1461 if (cond)
1462 prune_acl_cond(cond);
1463 ha_free(&cond);
1464 if (rule)
1465 ha_free(&(rule->be.name));
1466 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001467 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001468 }
1469 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001470 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001471 }
1472 else if (strcmp(args[0], "use-server") == 0) {
1473 struct server_rule *rule;
1474
Willy Tarreau5d095c22021-02-12 10:15:59 +01001475 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001476 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1477 err_code |= ERR_ALERT | ERR_FATAL;
1478 goto out;
1479 }
1480
1481 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1482 err_code |= ERR_WARN;
1483
1484 if (*(args[1]) == 0) {
1485 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1486 err_code |= ERR_ALERT | ERR_FATAL;
1487 goto out;
1488 }
1489
1490 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1491 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1492 file, linenum, args[0]);
1493 err_code |= ERR_ALERT | ERR_FATAL;
1494 goto out;
1495 }
1496
1497 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1498 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1499 file, linenum, errmsg);
1500 err_code |= ERR_ALERT | ERR_FATAL;
1501 goto out;
1502 }
1503
1504 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1505
1506 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001507 if (!rule)
1508 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001509 rule->cond = cond;
1510 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001511 if (!rule->srv.name)
1512 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001513 rule->line = linenum;
1514 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001515 if (!rule->file) {
1516 use_server_alloc_error:
1517 if (cond)
1518 prune_acl_cond(cond);
1519 ha_free(&cond);
1520 if (rule)
1521 ha_free(&(rule->srv.name));
1522 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001523 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001524 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001525 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001526 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001527 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1528 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001529 else if ((strcmp(args[0], "force-persist") == 0) ||
1530 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001531 struct persist_rule *rule;
1532
Willy Tarreau5d095c22021-02-12 10:15:59 +01001533 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001534 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1535 err_code |= ERR_ALERT | ERR_FATAL;
1536 goto out;
1537 }
1538
1539 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1540 err_code |= ERR_WARN;
1541
1542 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1543 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1544 file, linenum, args[0]);
1545 err_code |= ERR_ALERT | ERR_FATAL;
1546 goto out;
1547 }
1548
1549 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1550 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1551 file, linenum, args[0], errmsg);
1552 err_code |= ERR_ALERT | ERR_FATAL;
1553 goto out;
1554 }
1555
1556 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1557 * where force-persist is applied.
1558 */
1559 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1560
1561 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001562 if (!rule) {
1563 if (cond)
1564 prune_acl_cond(cond);
1565 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001566 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001567 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001568 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001569 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001570 rule->type = PERSIST_TYPE_FORCE;
1571 } else {
1572 rule->type = PERSIST_TYPE_IGNORE;
1573 }
1574 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001575 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001576 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001577 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001578 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001579
Willy Tarreau5d095c22021-02-12 10:15:59 +01001580 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001581 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1582 file, linenum);
1583 err_code |= ERR_ALERT | ERR_FATAL;
1584 goto out;
1585 }
1586
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001587 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001588 if (other) {
1589 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 +01001590 file, linenum, curproxy->id,
1591 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1592 other->proxy ? other->id : other->peers.p->id,
1593 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001594 err_code |= ERR_ALERT | ERR_FATAL;
1595 goto out;
1596 }
1597
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001598 curproxy->table = calloc(1, sizeof *curproxy->table);
1599 if (!curproxy->table) {
1600 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1601 file, linenum, args[0], args[1]);
1602 err_code |= ERR_ALERT | ERR_FATAL;
1603 goto out;
1604 }
1605
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001606 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1607 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001608 if (err_code & ERR_FATAL) {
1609 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001610 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001611 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001612
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001613 /* Store the proxy in the stick-table. */
1614 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001615
1616 stktable_store_name(curproxy->table);
1617 curproxy->table->next = stktables_list;
1618 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001619
1620 /* Add this proxy to the list of proxies which refer to its stick-table. */
1621 if (curproxy->table->proxies_list != curproxy) {
1622 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1623 curproxy->table->proxies_list = curproxy;
1624 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001625 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001626 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001627 struct sticking_rule *rule;
1628 struct sample_expr *expr;
1629 int myidx = 0;
1630 const char *name = NULL;
1631 int flags;
1632
Willy Tarreau5d095c22021-02-12 10:15:59 +01001633 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001634 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1635 err_code |= ERR_ALERT | ERR_FATAL;
1636 goto out;
1637 }
1638
1639 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1640 err_code |= ERR_WARN;
1641 goto out;
1642 }
1643
1644 myidx++;
1645 if ((strcmp(args[myidx], "store") == 0) ||
1646 (strcmp(args[myidx], "store-request") == 0)) {
1647 myidx++;
1648 flags = STK_IS_STORE;
1649 }
1650 else if (strcmp(args[myidx], "store-response") == 0) {
1651 myidx++;
1652 flags = STK_IS_STORE | STK_ON_RSP;
1653 }
1654 else if (strcmp(args[myidx], "match") == 0) {
1655 myidx++;
1656 flags = STK_IS_MATCH;
1657 }
1658 else if (strcmp(args[myidx], "on") == 0) {
1659 myidx++;
1660 flags = STK_IS_MATCH | STK_IS_STORE;
1661 }
1662 else {
1663 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1664 err_code |= ERR_ALERT | ERR_FATAL;
1665 goto out;
1666 }
1667
1668 if (*(args[myidx]) == 0) {
1669 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1670 err_code |= ERR_ALERT | ERR_FATAL;
1671 goto out;
1672 }
1673
1674 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001675 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001676 if (!expr) {
1677 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1678 err_code |= ERR_ALERT | ERR_FATAL;
1679 goto out;
1680 }
1681
1682 if (flags & STK_ON_RSP) {
1683 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1684 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1685 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1686 err_code |= ERR_ALERT | ERR_FATAL;
1687 free(expr);
1688 goto out;
1689 }
1690 } else {
1691 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1692 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1693 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1694 err_code |= ERR_ALERT | ERR_FATAL;
1695 free(expr);
1696 goto out;
1697 }
1698 }
1699
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001700 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001701 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1702
1703 if (strcmp(args[myidx], "table") == 0) {
1704 myidx++;
1705 name = args[myidx++];
1706 }
1707
1708 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1709 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1710 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1711 file, linenum, args[0], errmsg);
1712 err_code |= ERR_ALERT | ERR_FATAL;
1713 free(expr);
1714 goto out;
1715 }
1716 }
1717 else if (*(args[myidx])) {
1718 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1719 file, linenum, args[0], args[myidx]);
1720 err_code |= ERR_ALERT | ERR_FATAL;
1721 free(expr);
1722 goto out;
1723 }
1724 if (flags & STK_ON_RSP)
1725 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1726 else
1727 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1728
1729 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001730 if (!rule) {
1731 if (cond)
1732 prune_acl_cond(cond);
1733 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001734 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001735 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001736 rule->cond = cond;
1737 rule->expr = expr;
1738 rule->flags = flags;
1739 rule->table.name = name ? strdup(name) : NULL;
1740 LIST_INIT(&rule->list);
1741 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001742 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001743 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001744 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001745 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001746 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001747 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001748 curproxy->uri_auth = NULL; /* we must detach from the default config */
1749
1750 if (!*args[1]) {
1751 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001752 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001753 struct stats_admin_rule *rule;
1754
Willy Tarreau5d095c22021-02-12 10:15:59 +01001755 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001756 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1757 err_code |= ERR_ALERT | ERR_FATAL;
1758 goto out;
1759 }
1760
Christopher Fauletb15625a2021-04-12 21:31:45 +02001761 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1762 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001763
1764 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1765 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1766 file, linenum, args[0], args[1]);
1767 err_code |= ERR_ALERT | ERR_FATAL;
1768 goto out;
1769 }
1770 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1771 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1772 file, linenum, args[0], args[1], errmsg);
1773 err_code |= ERR_ALERT | ERR_FATAL;
1774 goto out;
1775 }
1776
1777 err_code |= warnif_cond_conflicts(cond,
1778 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1779 file, linenum);
1780
1781 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001782 if (!rule) {
1783 if (cond)
1784 prune_acl_cond(cond);
1785 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001786 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001787 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001788 rule->cond = cond;
1789 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001790 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001791 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001792 if (*(args[2]) == 0) {
1793 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1794 err_code |= ERR_ALERT | ERR_FATAL;
1795 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001796 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1797 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001798 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001799 if (*(args[2]) == 0) {
1800 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1801 err_code |= ERR_ALERT | ERR_FATAL;
1802 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001803 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1804 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001805 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001806 unsigned interval;
1807
1808 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001809 if (err == PARSE_TIME_OVER) {
1810 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1811 file, linenum, args[2]);
1812 err_code |= ERR_ALERT | ERR_FATAL;
1813 goto out;
1814 }
1815 else if (err == PARSE_TIME_UNDER) {
1816 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1817 file, linenum, args[2]);
1818 err_code |= ERR_ALERT | ERR_FATAL;
1819 goto out;
1820 }
1821 else if (err) {
1822 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001823 file, linenum, *err);
1824 err_code |= ERR_ALERT | ERR_FATAL;
1825 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001826 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1827 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001828 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001829 struct act_rule *rule;
1830
Willy Tarreau5d095c22021-02-12 10:15:59 +01001831 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001832 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1833 err_code |= ERR_ALERT | ERR_FATAL;
1834 goto out;
1835 }
1836
Christopher Fauletb15625a2021-04-12 21:31:45 +02001837 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1838 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001839
1840 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1841 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1842 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1843 file, linenum, args[0]);
1844 err_code |= ERR_WARN;
1845 }
1846
1847 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1848
1849 if (!rule) {
1850 err_code |= ERR_ALERT | ERR_ABORT;
1851 goto out;
1852 }
1853
1854 err_code |= warnif_cond_conflicts(rule->cond,
1855 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1856 file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001857 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001858
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001859 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001860 if (*(args[2]) == 0) {
1861 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1862 err_code |= ERR_ALERT | ERR_FATAL;
1863 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001864 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1865 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001866 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001867 if (*(args[2]) == 0) {
1868 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1869 err_code |= ERR_ALERT | ERR_FATAL;
1870 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001871 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1872 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001873 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001874 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1875 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001876 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001877 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1878 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001879 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001880 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1881 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001882 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001883 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1884 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001885 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001886
1887 if (*args[2]) {
1888 int i;
1889 char c;
1890
1891 for (i=0; args[2][i]; i++) {
1892 c = args[2][i];
1893 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1894 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1895 break;
1896 }
1897
1898 if (!i || args[2][i]) {
1899 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1900 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1901 file, linenum, args[0], args[1]);
1902 err_code |= ERR_ALERT | ERR_FATAL;
1903 goto out;
1904 }
1905 }
1906
Christopher Fauletb15625a2021-04-12 21:31:45 +02001907 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1908 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001909 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001910 char *desc = NULL;
1911
1912 if (*args[2]) {
1913 int i, len=0;
1914 char *d;
1915
1916 for (i = 2; *args[i]; i++)
1917 len += strlen(args[i]) + 1;
1918
1919 desc = d = calloc(1, len);
1920
1921 d += snprintf(d, desc + len - d, "%s", args[2]);
1922 for (i = 3; *args[i]; i++)
1923 d += snprintf(d, desc + len - d, " %s", args[i]);
1924 }
1925
1926 if (!*args[2] && !global.desc)
1927 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1928 file, linenum, args[1]);
1929 else {
1930 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1931 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001932 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001933 }
1934 free(desc);
1935 }
1936 } else {
1937stats_error_parsing:
1938 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1939 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1940 err_code |= ERR_ALERT | ERR_FATAL;
1941 goto out;
1942 }
1943 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001944 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001945 int optnum;
1946
1947 if (*(args[1]) == '\0') {
1948 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1949 file, linenum, args[0]);
1950 err_code |= ERR_ALERT | ERR_FATAL;
1951 goto out;
1952 }
1953
1954 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001955 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001956 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1957 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1958 file, linenum, cfg_opts[optnum].name);
1959 err_code |= ERR_ALERT | ERR_FATAL;
1960 goto out;
1961 }
1962 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1963 goto out;
1964
1965 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1966 err_code |= ERR_WARN;
1967 goto out;
1968 }
1969
1970 curproxy->no_options &= ~cfg_opts[optnum].val;
1971 curproxy->options &= ~cfg_opts[optnum].val;
1972
1973 switch (kwm) {
1974 case KWM_STD:
1975 curproxy->options |= cfg_opts[optnum].val;
1976 break;
1977 case KWM_NO:
1978 curproxy->no_options |= cfg_opts[optnum].val;
1979 break;
1980 case KWM_DEF: /* already cleared */
1981 break;
1982 }
1983
1984 goto out;
1985 }
1986 }
1987
1988 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001989 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001990 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1991 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1992 file, linenum, cfg_opts2[optnum].name);
1993 err_code |= ERR_ALERT | ERR_FATAL;
1994 goto out;
1995 }
1996 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1997 goto out;
1998 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1999 err_code |= ERR_WARN;
2000 goto out;
2001 }
2002
2003 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2004 curproxy->options2 &= ~cfg_opts2[optnum].val;
2005
2006 switch (kwm) {
2007 case KWM_STD:
2008 curproxy->options2 |= cfg_opts2[optnum].val;
2009 break;
2010 case KWM_NO:
2011 curproxy->no_options2 |= cfg_opts2[optnum].val;
2012 break;
2013 case KWM_DEF: /* already cleared */
2014 break;
2015 }
2016 goto out;
2017 }
2018 }
2019
2020 /* HTTP options override each other. They can be cancelled using
2021 * "no option xxx" which only switches to default mode if the mode
2022 * was this one (useful for cancelling options set in defaults
2023 * sections).
2024 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02002025 if (strcmp(args[1], "forceclose") == 0) {
2026 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",
2027 file, linenum, args[1]);
2028 err_code |= ERR_ALERT | ERR_FATAL;
2029 goto out;
2030 }
2031 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002032 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2033 goto out;
2034 if (kwm == KWM_STD) {
2035 curproxy->options &= ~PR_O_HTTP_MODE;
2036 curproxy->options |= PR_O_HTTP_CLO;
2037 goto out;
2038 }
2039 else if (kwm == KWM_NO) {
2040 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2041 curproxy->options &= ~PR_O_HTTP_MODE;
2042 goto out;
2043 }
2044 }
2045 else if (strcmp(args[1], "http-server-close") == 0) {
2046 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2047 goto out;
2048 if (kwm == KWM_STD) {
2049 curproxy->options &= ~PR_O_HTTP_MODE;
2050 curproxy->options |= PR_O_HTTP_SCL;
2051 goto out;
2052 }
2053 else if (kwm == KWM_NO) {
2054 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2055 curproxy->options &= ~PR_O_HTTP_MODE;
2056 goto out;
2057 }
2058 }
2059 else if (strcmp(args[1], "http-keep-alive") == 0) {
2060 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2061 goto out;
2062 if (kwm == KWM_STD) {
2063 curproxy->options &= ~PR_O_HTTP_MODE;
2064 curproxy->options |= PR_O_HTTP_KAL;
2065 goto out;
2066 }
2067 else if (kwm == KWM_NO) {
2068 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2069 curproxy->options &= ~PR_O_HTTP_MODE;
2070 goto out;
2071 }
2072 }
2073 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02002074 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 +02002075 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02002076 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002077 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002078 }
2079
2080 /* Redispatch can take an integer argument that control when the
2081 * resispatch occurs. All values are relative to the retries option.
2082 * This can be cancelled using "no option xxx".
2083 */
2084 if (strcmp(args[1], "redispatch") == 0) {
2085 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2086 err_code |= ERR_WARN;
2087 goto out;
2088 }
2089
2090 curproxy->no_options &= ~PR_O_REDISP;
2091 curproxy->options &= ~PR_O_REDISP;
2092
2093 switch (kwm) {
2094 case KWM_STD:
2095 curproxy->options |= PR_O_REDISP;
2096 curproxy->redispatch_after = -1;
2097 if(*args[2]) {
2098 curproxy->redispatch_after = atol(args[2]);
2099 }
2100 break;
2101 case KWM_NO:
2102 curproxy->no_options |= PR_O_REDISP;
2103 curproxy->redispatch_after = 0;
2104 break;
2105 case KWM_DEF: /* already cleared */
2106 break;
2107 }
2108 goto out;
2109 }
2110
Willy Tarreau25241232021-07-18 19:18:56 +02002111 if (strcmp(args[1], "http_proxy") == 0) {
2112 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",
2113 file, linenum, args[1]);
2114 err_code |= ERR_ALERT | ERR_FATAL;
2115 goto out;
2116 }
2117
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002118 if (kwm != KWM_STD) {
2119 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2120 file, linenum, args[1]);
2121 err_code |= ERR_ALERT | ERR_FATAL;
2122 goto out;
2123 }
2124
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002125 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002126 char *logformat;
2127 /* generate a complete HTTP log */
2128 logformat = default_http_log_format;
2129 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002130 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002131 curproxy->options2 |= PR_O2_CLFLOG;
2132 logformat = clf_http_log_format;
2133 } else {
2134 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2135 err_code |= ERR_ALERT | ERR_FATAL;
2136 goto out;
2137 }
2138 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2139 goto out;
2140 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002141 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002142 char *oldlogformat = "log-format";
2143 char *clflogformat = "";
2144
2145 if (curproxy->conf.logformat_string == default_http_log_format)
2146 oldlogformat = "option httplog";
2147 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2148 oldlogformat = "option tcplog";
2149 else if (curproxy->conf.logformat_string == clf_http_log_format)
2150 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002151 else if (curproxy->conf.logformat_string == default_https_log_format)
2152 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002153 if (logformat == clf_http_log_format)
2154 clflogformat = " clf";
2155 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2156 file, linenum, clflogformat, oldlogformat);
2157 }
2158 if (curproxy->conf.logformat_string != default_http_log_format &&
2159 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002160 curproxy->conf.logformat_string != clf_http_log_format &&
2161 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002162 free(curproxy->conf.logformat_string);
2163 curproxy->conf.logformat_string = logformat;
2164
2165 free(curproxy->conf.lfs_file);
2166 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2167 curproxy->conf.lfs_line = curproxy->conf.args.line;
2168
Willy Tarreau5d095c22021-02-12 10:15:59 +01002169 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002170 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2171 file, linenum, curproxy->id);
2172 err_code |= ERR_WARN;
2173 }
2174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002175 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002176 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002177 char *oldlogformat = "log-format";
2178
2179 if (curproxy->conf.logformat_string == default_http_log_format)
2180 oldlogformat = "option httplog";
2181 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2182 oldlogformat = "option tcplog";
2183 else if (curproxy->conf.logformat_string == clf_http_log_format)
2184 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002185 else if (curproxy->conf.logformat_string == default_https_log_format)
2186 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002187 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2188 file, linenum, oldlogformat);
2189 }
2190 /* generate a detailed TCP log */
2191 if (curproxy->conf.logformat_string != default_http_log_format &&
2192 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002193 curproxy->conf.logformat_string != clf_http_log_format &&
2194 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002195 free(curproxy->conf.logformat_string);
2196 curproxy->conf.logformat_string = default_tcp_log_format;
2197
2198 free(curproxy->conf.lfs_file);
2199 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2200 curproxy->conf.lfs_line = curproxy->conf.args.line;
2201
2202 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2203 goto out;
2204
Willy Tarreau5d095c22021-02-12 10:15:59 +01002205 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002206 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2207 file, linenum, curproxy->id);
2208 err_code |= ERR_WARN;
2209 }
2210 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002211 else if (strcmp(args[1], "httpslog") == 0) {
2212 char *logformat;
2213 /* generate a complete HTTP log */
2214 logformat = default_https_log_format;
2215 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2216 char *oldlogformat = "log-format";
2217
2218 if (curproxy->conf.logformat_string == default_http_log_format)
2219 oldlogformat = "option httplog";
2220 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2221 oldlogformat = "option tcplog";
2222 else if (curproxy->conf.logformat_string == clf_http_log_format)
2223 oldlogformat = "option httplog clf";
2224 else if (curproxy->conf.logformat_string == default_https_log_format)
2225 oldlogformat = "option httpslog";
2226 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2227 file, linenum, oldlogformat);
2228 }
2229 if (curproxy->conf.logformat_string != default_http_log_format &&
2230 curproxy->conf.logformat_string != default_tcp_log_format &&
2231 curproxy->conf.logformat_string != clf_http_log_format &&
2232 curproxy->conf.logformat_string != default_https_log_format)
2233 free(curproxy->conf.logformat_string);
2234 curproxy->conf.logformat_string = logformat;
2235
2236 free(curproxy->conf.lfs_file);
2237 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2238 curproxy->conf.lfs_line = curproxy->conf.args.line;
2239
2240 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2241 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2242 file, linenum, curproxy->id);
2243 err_code |= ERR_WARN;
2244 }
2245 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002246 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002247 /* enable TCP keep-alives on client and server streams */
2248 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2249 err_code |= ERR_WARN;
2250
2251 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2252 goto out;
2253
2254 if (curproxy->cap & PR_CAP_FE)
2255 curproxy->options |= PR_O_TCP_CLI_KA;
2256 if (curproxy->cap & PR_CAP_BE)
2257 curproxy->options |= PR_O_TCP_SRV_KA;
2258 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002259 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002260 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002261 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002262 goto out;
2263 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002264 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002265 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002266 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002267 goto out;
2268 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002269 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002270 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002271 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002272 goto out;
2273 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002274 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002275 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002276 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002277 goto out;
2278 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002279 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002280 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002281 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002282 goto out;
2283 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002284 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002285 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002286 if (err_code & ERR_FATAL)
2287 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002288 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002289 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002290 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002291 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002292 goto out;
2293 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002294 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002295 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002296 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002297 goto out;
2298 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002299 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002300 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002301 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002302 goto out;
2303 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002304 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002305 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002306 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002307 goto out;
2308 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002309 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002310 int cur_arg;
2311
2312 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002313 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002314 */
2315
2316 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2317
2318 free(curproxy->fwdfor_hdr_name);
2319 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002320 if (!curproxy->fwdfor_hdr_name)
2321 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002322 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002323 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002324
2325 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2326 cur_arg = 2;
2327 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002328 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002329 unsigned char mask;
2330 int i;
2331
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002332 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002333 if (*(args[cur_arg+1]) &&
2334 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2335 curproxy->except_xff_net.family = AF_INET;
2336 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2337 }
2338 else if (*(args[cur_arg+1]) &&
2339 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2340 curproxy->except_xff_net.family = AF_INET6;
2341 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2342 for (i = 0; i < 16; i++)
2343 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2344 }
2345 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002346 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2347 file, linenum, args[0], args[1], args[cur_arg]);
2348 err_code |= ERR_ALERT | ERR_FATAL;
2349 goto out;
2350 }
2351 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002352 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002353 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002354 /* suboption header - needs additional argument for it */
2355 if (*(args[cur_arg+1]) == 0) {
2356 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2357 file, linenum, args[0], args[1], args[cur_arg]);
2358 err_code |= ERR_ALERT | ERR_FATAL;
2359 goto out;
2360 }
2361 free(curproxy->fwdfor_hdr_name);
2362 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002363 if (!curproxy->fwdfor_hdr_name)
2364 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002365 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2366 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002367 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002368 curproxy->options &= ~PR_O_FF_ALWAYS;
2369 cur_arg += 1;
2370 } else {
2371 /* unknown suboption - catchall */
2372 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2373 file, linenum, args[0], args[1]);
2374 err_code |= ERR_ALERT | ERR_FATAL;
2375 goto out;
2376 }
2377 } /* end while loop */
2378 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002379 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002380 int cur_arg;
2381
2382 /* insert x-original-to field, but not for the IP address listed as an except.
2383 * set default options (ie: bitfield, header name, etc)
2384 */
2385
2386 curproxy->options |= PR_O_ORGTO;
2387
2388 free(curproxy->orgto_hdr_name);
2389 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002390 if (!curproxy->orgto_hdr_name)
2391 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002392 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002393 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002394
2395 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2396 cur_arg = 2;
2397 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002398 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002399 unsigned char mask;
2400 int i;
2401
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002402 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002403 if (*(args[cur_arg+1]) &&
2404 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2405 curproxy->except_xot_net.family = AF_INET;
2406 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2407 }
2408 else if (*(args[cur_arg+1]) &&
2409 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2410 curproxy->except_xot_net.family = AF_INET6;
2411 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2412 for (i = 0; i < 16; i++)
2413 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2414 }
2415 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002416 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2417 file, linenum, args[0], args[1], args[cur_arg]);
2418 err_code |= ERR_ALERT | ERR_FATAL;
2419 goto out;
2420 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002421 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002422 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002423 /* suboption header - needs additional argument for it */
2424 if (*(args[cur_arg+1]) == 0) {
2425 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2426 file, linenum, args[0], args[1], args[cur_arg]);
2427 err_code |= ERR_ALERT | ERR_FATAL;
2428 goto out;
2429 }
2430 free(curproxy->orgto_hdr_name);
2431 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002432 if (!curproxy->orgto_hdr_name)
2433 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002434 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2435 cur_arg += 2;
2436 } else {
2437 /* unknown suboption - catchall */
2438 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2439 file, linenum, args[0], args[1]);
2440 err_code |= ERR_ALERT | ERR_FATAL;
2441 goto out;
2442 }
2443 } /* end while loop */
2444 }
2445 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002446 const char *best = proxy_find_best_option(args[1], common_options);
2447
2448 if (best)
2449 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2450 else
2451 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2452
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002453 err_code |= ERR_ALERT | ERR_FATAL;
2454 goto out;
2455 }
2456 goto out;
2457 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002458 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002459 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2460 err_code |= ERR_WARN;
2461
2462 if (*(args[1]) == 0) {
2463 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2464 err_code |= ERR_ALERT | ERR_FATAL;
2465 goto out;
2466 }
2467 free(curproxy->defbe.name);
2468 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002469 if (!curproxy->defbe.name)
2470 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002471
2472 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2473 goto out;
2474 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002475 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002476 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 +01002477
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002478 err_code |= ERR_ALERT | ERR_FATAL;
2479 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002480 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002481 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002482 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2483 err_code |= ERR_WARN;
2484
2485 if (strcmp(args[1], "never") == 0) {
2486 /* enable a graceful server shutdown on an HTTP 404 response */
2487 curproxy->options &= ~PR_O_REUSE_MASK;
2488 curproxy->options |= PR_O_REUSE_NEVR;
2489 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2490 goto out;
2491 }
2492 else if (strcmp(args[1], "safe") == 0) {
2493 /* enable a graceful server shutdown on an HTTP 404 response */
2494 curproxy->options &= ~PR_O_REUSE_MASK;
2495 curproxy->options |= PR_O_REUSE_SAFE;
2496 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2497 goto out;
2498 }
2499 else if (strcmp(args[1], "aggressive") == 0) {
2500 curproxy->options &= ~PR_O_REUSE_MASK;
2501 curproxy->options |= PR_O_REUSE_AGGR;
2502 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2503 goto out;
2504 }
2505 else if (strcmp(args[1], "always") == 0) {
2506 /* enable a graceful server shutdown on an HTTP 404 response */
2507 curproxy->options &= ~PR_O_REUSE_MASK;
2508 curproxy->options |= PR_O_REUSE_ALWS;
2509 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2510 goto out;
2511 }
2512 else {
2513 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2514 err_code |= ERR_ALERT | ERR_FATAL;
2515 goto out;
2516 }
2517 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002518 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002519 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002520 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2521 err_code |= ERR_ALERT | ERR_FATAL;
2522 goto out;
2523 }
2524
2525 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2526 err_code |= ERR_WARN;
2527
2528 if (strcmp(args[1], "fail") == 0) {
2529 /* add a condition to fail monitor requests */
2530 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2531 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2532 file, linenum, args[0], args[1]);
2533 err_code |= ERR_ALERT | ERR_FATAL;
2534 goto out;
2535 }
2536
2537 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2538 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2539 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2540 file, linenum, args[0], args[1], errmsg);
2541 err_code |= ERR_ALERT | ERR_FATAL;
2542 goto out;
2543 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002544 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002545 }
2546 else {
2547 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2548 err_code |= ERR_ALERT | ERR_FATAL;
2549 goto out;
2550 }
2551 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002552#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002553 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002554 /* enable transparent proxy connections */
2555 curproxy->options |= PR_O_TRANSP;
2556 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2557 goto out;
2558 }
2559#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002560 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002561 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2562 err_code |= ERR_WARN;
2563
2564 if (*(args[1]) == 0) {
2565 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2566 err_code |= ERR_ALERT | ERR_FATAL;
2567 goto out;
2568 }
2569 curproxy->maxconn = atol(args[1]);
2570 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2571 goto out;
2572 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002573 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002574 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2575 err_code |= ERR_WARN;
2576
2577 if (*(args[1]) == 0) {
2578 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2579 err_code |= ERR_ALERT | ERR_FATAL;
2580 goto out;
2581 }
2582 curproxy->backlog = atol(args[1]);
2583 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2584 goto out;
2585 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002586 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002587 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2588 err_code |= ERR_WARN;
2589
2590 if (*(args[1]) == 0) {
2591 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2592 err_code |= ERR_ALERT | ERR_FATAL;
2593 goto out;
2594 }
2595 curproxy->fullconn = atol(args[1]);
2596 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2597 goto out;
2598 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002599 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002600 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 +02002601 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002602 err_code |= ERR_ALERT | ERR_FATAL;
2603 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002605 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002606 struct sockaddr_storage *sk;
2607 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002608
Willy Tarreau5d095c22021-02-12 10:15:59 +01002609 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002610 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2611 err_code |= ERR_ALERT | ERR_FATAL;
2612 goto out;
2613 }
2614 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2615 err_code |= ERR_WARN;
2616
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002617 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2618 &errmsg, NULL, NULL,
2619 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 +01002620 if (!sk) {
2621 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2622 err_code |= ERR_ALERT | ERR_FATAL;
2623 goto out;
2624 }
2625
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002626 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2627 goto out;
2628
2629 curproxy->dispatch_addr = *sk;
2630 curproxy->options |= PR_O_DISPATCH;
2631 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002632 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002633 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2634 err_code |= ERR_WARN;
2635
2636 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2637 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2638 err_code |= ERR_ALERT | ERR_FATAL;
2639 goto out;
2640 }
2641 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002642 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002643 /**
2644 * The syntax for hash-type config element is
2645 * hash-type {map-based|consistent} [[<algo>] avalanche]
2646 *
2647 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2648 */
2649 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2650
2651 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2652 err_code |= ERR_WARN;
2653
2654 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2655 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2656 }
2657 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2658 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2659 }
2660 else if (strcmp(args[1], "avalanche") == 0) {
2661 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]);
2662 err_code |= ERR_ALERT | ERR_FATAL;
2663 goto out;
2664 }
2665 else {
2666 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2667 err_code |= ERR_ALERT | ERR_FATAL;
2668 goto out;
2669 }
2670
2671 /* set the hash function to use */
2672 if (!*args[2]) {
2673 /* the default algo is sdbm */
2674 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2675
2676 /* if consistent with no argument, then avalanche modifier is also applied */
2677 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2678 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2679 } else {
2680 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002681 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002682 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2683 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002684 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002685 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2686 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002687 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002688 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2689 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002690 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002691 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2692 }
2693 else {
2694 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2695 err_code |= ERR_ALERT | ERR_FATAL;
2696 goto out;
2697 }
2698
2699 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002700 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002701 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2702 }
2703 else if (*args[3]) {
2704 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2705 err_code |= ERR_ALERT | ERR_FATAL;
2706 goto out;
2707 }
2708 }
2709 }
2710 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2711 if (*(args[1]) == 0) {
2712 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2713 err_code |= ERR_ALERT | ERR_FATAL;
2714 goto out;
2715 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002716 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2717 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002718 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2719 err_code |= ERR_ALERT | ERR_FATAL;
2720 goto out;
2721 }
2722 }
2723 else if (strcmp(args[0], "unique-id-format") == 0) {
2724 if (!*(args[1])) {
2725 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2726 err_code |= ERR_ALERT | ERR_FATAL;
2727 goto out;
2728 }
2729 if (*(args[2])) {
2730 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2731 err_code |= ERR_ALERT | ERR_FATAL;
2732 goto out;
2733 }
2734 free(curproxy->conf.uniqueid_format_string);
2735 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002736 if (!curproxy->conf.uniqueid_format_string)
2737 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002738
2739 free(curproxy->conf.uif_file);
2740 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2741 curproxy->conf.uif_line = curproxy->conf.args.line;
2742 }
2743
2744 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002745 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002746 if (!*(args[1])) {
2747 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2748 err_code |= ERR_ALERT | ERR_FATAL;
2749 goto out;
2750 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002751 copy = strdup(args[1]);
2752 if (copy == NULL) {
2753 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2754 err_code |= ERR_ALERT | ERR_FATAL;
2755 goto out;
2756 }
2757
2758 istfree(&curproxy->header_unique_id);
2759 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002760 }
2761
2762 else if (strcmp(args[0], "log-format") == 0) {
2763 if (!*(args[1])) {
2764 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2765 err_code |= ERR_ALERT | ERR_FATAL;
2766 goto out;
2767 }
2768 if (*(args[2])) {
2769 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2770 err_code |= ERR_ALERT | ERR_FATAL;
2771 goto out;
2772 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002773 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002774 char *oldlogformat = "log-format";
2775
2776 if (curproxy->conf.logformat_string == default_http_log_format)
2777 oldlogformat = "option httplog";
2778 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2779 oldlogformat = "option tcplog";
2780 else if (curproxy->conf.logformat_string == clf_http_log_format)
2781 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002782 else if (curproxy->conf.logformat_string == default_https_log_format)
2783 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002784 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2785 file, linenum, oldlogformat);
2786 }
2787 if (curproxy->conf.logformat_string != default_http_log_format &&
2788 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002789 curproxy->conf.logformat_string != clf_http_log_format &&
2790 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002791 free(curproxy->conf.logformat_string);
2792 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002793 if (!curproxy->conf.logformat_string)
2794 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002795
2796 free(curproxy->conf.lfs_file);
2797 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2798 curproxy->conf.lfs_line = curproxy->conf.args.line;
2799
2800 /* get a chance to improve log-format error reporting by
2801 * reporting the correct line-number when possible.
2802 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002803 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002804 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2805 file, linenum, curproxy->id);
2806 err_code |= ERR_WARN;
2807 }
2808 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002809 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002810 if (!*(args[1])) {
2811 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2812 err_code |= ERR_ALERT | ERR_FATAL;
2813 goto out;
2814 }
2815 if (*(args[2])) {
2816 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2817 err_code |= ERR_ALERT | ERR_FATAL;
2818 goto out;
2819 }
2820
2821 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2822 free(curproxy->conf.logformat_sd_string);
2823 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002824 if (!curproxy->conf.logformat_sd_string)
2825 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002826
2827 free(curproxy->conf.lfsd_file);
2828 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2829 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2830
2831 /* get a chance to improve log-format-sd error reporting by
2832 * reporting the correct line-number when possible.
2833 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002834 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002835 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2836 file, linenum, curproxy->id);
2837 err_code |= ERR_WARN;
2838 }
2839 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002840 else if (strcmp(args[0], "error-log-format") == 0) {
2841 if (!*(args[1])) {
2842 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2843 err_code |= ERR_ALERT | ERR_FATAL;
2844 goto out;
2845 }
2846 if (*(args[2])) {
2847 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2848 err_code |= ERR_ALERT | ERR_FATAL;
2849 goto out;
2850 }
2851 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2852 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2853 file, linenum);
2854 }
2855 free(curproxy->conf.error_logformat_string);
2856 curproxy->conf.error_logformat_string = strdup(args[1]);
2857 if (!curproxy->conf.error_logformat_string)
2858 goto alloc_error;
2859
2860 free(curproxy->conf.elfs_file);
2861 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2862 curproxy->conf.elfs_line = curproxy->conf.args.line;
2863
2864 /* get a chance to improve log-format error reporting by
2865 * reporting the correct line-number when possible.
2866 */
2867 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2868 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2869 file, linenum, curproxy->id);
2870 err_code |= ERR_WARN;
2871 }
2872 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002873 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002874 if (*(args[1]) == 0) {
2875 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2876 err_code |= ERR_ALERT | ERR_FATAL;
2877 goto out;
2878 }
2879 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002880 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2881 if (b_orig(&curproxy->log_tag) == NULL) {
2882 chunk_destroy(&curproxy->log_tag);
2883 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2884 err_code |= ERR_ALERT | ERR_FATAL;
2885 goto out;
2886 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002887 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002888 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002889 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002890 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2891 err_code |= ERR_ALERT | ERR_FATAL;
2892 goto out;
2893 }
2894 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002895 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002896 int cur_arg;
2897 int port1, port2;
2898 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002899
2900 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2901 err_code |= ERR_WARN;
2902
2903 if (!*args[1]) {
2904 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2905 file, linenum, "source", "usesrc", "interface");
2906 err_code |= ERR_ALERT | ERR_FATAL;
2907 goto out;
2908 }
2909
Christopher Faulet31930372019-07-15 10:16:58 +02002910 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002911 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002912 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002913 curproxy->conn_src.iface_len = 0;
2914
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002915 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2916 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002917 if (!sk) {
2918 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2919 file, linenum, args[0], args[1], errmsg);
2920 err_code |= ERR_ALERT | ERR_FATAL;
2921 goto out;
2922 }
2923
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002924 curproxy->conn_src.source_addr = *sk;
2925 curproxy->conn_src.opts |= CO_SRC_BIND;
2926
2927 cur_arg = 2;
2928 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002929 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002930#if defined(CONFIG_HAP_TRANSPARENT)
2931 if (!*args[cur_arg + 1]) {
2932 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2933 file, linenum, "usesrc");
2934 err_code |= ERR_ALERT | ERR_FATAL;
2935 goto out;
2936 }
2937
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002938 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002939 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2940 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002941 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002942 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2943 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2944 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2945 char *name, *end;
2946
2947 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002948 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002949 name++;
2950
2951 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002952 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002953 end++;
2954
2955 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2956 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002957 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002958 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002959 if (!curproxy->conn_src.bind_hdr_name)
2960 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002961 curproxy->conn_src.bind_hdr_len = end - name;
2962 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2963 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2964 curproxy->conn_src.bind_hdr_occ = -1;
2965
2966 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002967 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002968 end++;
2969 if (*end == ',') {
2970 end++;
2971 name = end;
2972 if (*end == '-')
2973 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002974 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002975 end++;
2976 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2977 }
2978
2979 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2980 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2981 " occurrences values smaller than %d.\n",
2982 file, linenum, MAX_HDR_HISTORY);
2983 err_code |= ERR_ALERT | ERR_FATAL;
2984 goto out;
2985 }
2986 } else {
2987 struct sockaddr_storage *sk;
2988
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002989 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2990 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002991 if (!sk) {
2992 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2993 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2994 err_code |= ERR_ALERT | ERR_FATAL;
2995 goto out;
2996 }
2997
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002998 curproxy->conn_src.tproxy_addr = *sk;
2999 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3000 }
3001 global.last_checks |= LSTCHK_NETADM;
3002#else /* no TPROXY support */
3003 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3004 file, linenum, "usesrc");
3005 err_code |= ERR_ALERT | ERR_FATAL;
3006 goto out;
3007#endif
3008 cur_arg += 2;
3009 continue;
3010 }
3011
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003012 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003013#ifdef SO_BINDTODEVICE
3014 if (!*args[cur_arg + 1]) {
3015 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3016 file, linenum, args[0]);
3017 err_code |= ERR_ALERT | ERR_FATAL;
3018 goto out;
3019 }
3020 free(curproxy->conn_src.iface_name);
3021 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02003022 if (!curproxy->conn_src.iface_name)
3023 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003024 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3025 global.last_checks |= LSTCHK_NETADM;
3026#else
3027 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3028 file, linenum, args[0], args[cur_arg]);
3029 err_code |= ERR_ALERT | ERR_FATAL;
3030 goto out;
3031#endif
3032 cur_arg += 2;
3033 continue;
3034 }
3035 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3036 file, linenum, args[0], "interface", "usesrc");
3037 err_code |= ERR_ALERT | ERR_FATAL;
3038 goto out;
3039 }
3040 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003041 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003042 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3043 file, linenum, "usesrc", "source");
3044 err_code |= ERR_ALERT | ERR_FATAL;
3045 goto out;
3046 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003047 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 +02003048 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003049 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003050 file, linenum, args[0]);
3051 err_code |= ERR_ALERT | ERR_FATAL;
3052 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003053 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003054 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003055 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3056 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3057 err_code |= ERR_ALERT | ERR_FATAL;
3058 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003059 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003060 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003061 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3062 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3063 err_code |= ERR_ALERT | ERR_FATAL;
3064 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003065 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003066 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003067 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3068 err_code |= ERR_ALERT | ERR_FATAL;
3069 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003071 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003072 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3073 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3074 err_code |= ERR_ALERT | ERR_FATAL;
3075 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003076 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003077 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003078 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3079 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3080 err_code |= ERR_ALERT | ERR_FATAL;
3081 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003082 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003083 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003084 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3085 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3086 err_code |= ERR_ALERT | ERR_FATAL;
3087 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003088 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003089 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003090 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3091 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3092 err_code |= ERR_ALERT | ERR_FATAL;
3093 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003094 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003095 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 +02003096 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3097 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3098 err_code |= ERR_ALERT | ERR_FATAL;
3099 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003100 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003101 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003102 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003105 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003106 else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003107 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3108 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3109 err_code |= ERR_ALERT | ERR_FATAL;
3110 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003111 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003112 else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003113 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3114 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3115 err_code |= ERR_ALERT | ERR_FATAL;
3116 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003117 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003118 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003119 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3120 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3121 err_code |= ERR_ALERT | ERR_FATAL;
3122 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003123 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003124 else if (strcmp(args[0], "srvexp") == 0 || strcmp(args[0], "rsprep") == 0) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003125 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3126 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3127 err_code |= ERR_ALERT | ERR_FATAL;
3128 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003129 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003130 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003131 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3132 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3133 err_code |= ERR_ALERT | ERR_FATAL;
3134 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003135 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003136 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003137 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3138 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3139 err_code |= ERR_ALERT | ERR_FATAL;
3140 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003141 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003142 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303143 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003144 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3145 err_code |= ERR_ALERT | ERR_FATAL;
3146 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003147 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003148 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003149 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3150 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3151 err_code |= ERR_ALERT | ERR_FATAL;
3152 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003153 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003154 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003155 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3156 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3157 err_code |= ERR_ALERT | ERR_FATAL;
3158 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003159 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003160 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003161 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3162 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3163 err_code |= ERR_ALERT | ERR_FATAL;
3164 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003165 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003166 else {
3167 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003168 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003169 int index;
3170
3171 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3172 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3173 if (kwl->kw[index].section != CFG_LISTEN)
3174 continue;
3175 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003176 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003177 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003178 err_code |= ERR_ALERT | ERR_FATAL;
3179 goto out;
3180 }
3181
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003182 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003183 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003184 if (rc < 0) {
3185 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3186 err_code |= ERR_ALERT | ERR_FATAL;
3187 goto out;
3188 }
3189 else if (rc > 0) {
3190 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3191 err_code |= ERR_WARN;
3192 goto out;
3193 }
3194 goto out;
3195 }
3196 }
3197 }
3198
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003199 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3200 if (best)
3201 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3202 else
3203 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003204 err_code |= ERR_ALERT | ERR_FATAL;
3205 goto out;
3206 }
3207 out:
3208 free(errmsg);
3209 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003210
3211 alloc_error:
3212 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3213 err_code |= ERR_ALERT | ERR_ABORT;
3214 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003215}