blob: d4a73e7c75102a30a7cd50ad6382845963353f68 [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 Tarreau87735332020-06-04 09:08:41 +020022#include <haproxy/http_htx.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020023#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020024#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020025#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020026#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020027#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020028#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020029#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020030#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020031#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020032#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/tcpcheck.h>
Willy Tarreaue9dcb3c2021-05-08 13:00:23 +020034#include <haproxy/tools.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020035#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010036
Willy Tarreauc0ff6792021-03-12 09:14:19 +010037/* some keywords that are still being parsed using strcmp() and are not
38 * registered anywhere. They are used as suggestions for mistyped words.
39 */
40static const char *common_kw_list[] = {
41 "listen", "frontend", "backend", "defaults", "server",
42 "default-server", "server-template", "bind", "monitor-net",
43 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
44 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
45 "persist", "appsession", "load-server-state-from-file",
46 "server-state-file-name", "max-session-srv-conns", "capture",
47 "retries", "http-request", "http-response", "http-after-response",
48 "http-send-name-header", "block", "redirect", "use_backend",
49 "use-server", "force-persist", "ignore-persist", "force-persist",
50 "stick-table", "stick", "stats", "option", "default_backend",
51 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
Willy Tarreaueb778242021-06-11 16:27:10 +020052 "fullconn", "dispatch", "balance", "hash-type",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010053 "hash-balance-factor", "unique-id-format", "unique-id-header",
54 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +020055 "error-log-format",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010056 NULL /* must be last */
57};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010058
Willy Tarreau31a3cea2021-03-15 11:11:55 +010059static const char *common_options[] = {
Willy Tarreau6ba69842021-06-11 16:01:50 +020060 "httpclose", "http-server-close", "http-keep-alive",
Willy Tarreaud2f25372021-06-11 16:06:29 +020061 "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010062 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
63 "mysql-check", "ldap-check", "spop-check", "tcp-check",
64 "external-check", "forwardfor", "original-to",
65 NULL /* must be last */
66};
67
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010068/* Report a warning if a rule is placed after a 'tcp-request session' rule.
69 * Return 1 if the warning has been emitted, otherwise 0.
70 */
71int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
72{
73 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
74 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
75 file, line, arg);
76 return 1;
77 }
78 return 0;
79}
80
81/* Report a warning if a rule is placed after a 'tcp-request content' rule.
82 * Return 1 if the warning has been emitted, otherwise 0.
83 */
84int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
85{
86 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
87 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
88 file, line, arg);
89 return 1;
90 }
91 return 0;
92}
93
94/* Report a warning if a rule is placed after a 'monitor fail' rule.
95 * Return 1 if the warning has been emitted, otherwise 0.
96 */
97int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
98{
99 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
100 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
101 file, line, arg);
102 return 1;
103 }
104 return 0;
105}
106
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100107/* Report a warning if a rule is placed after an 'http_request' rule.
108 * Return 1 if the warning has been emitted, otherwise 0.
109 */
110int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
111{
112 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
113 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
114 file, line, arg);
115 return 1;
116 }
117 return 0;
118}
119
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100120/* Report a warning if a rule is placed after a redirect rule.
121 * Return 1 if the warning has been emitted, otherwise 0.
122 */
123int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
124{
125 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
126 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
127 file, line, arg);
128 return 1;
129 }
130 return 0;
131}
132
133/* Report a warning if a rule is placed after a 'use_backend' rule.
134 * Return 1 if the warning has been emitted, otherwise 0.
135 */
136int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
137{
138 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
139 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
140 file, line, arg);
141 return 1;
142 }
143 return 0;
144}
145
146/* Report a warning if a rule is placed after a 'use-server' rule.
147 * Return 1 if the warning has been emitted, otherwise 0.
148 */
149int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
150{
151 if (!LIST_ISEMPTY(&proxy->server_rules)) {
152 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
153 file, line, arg);
154 return 1;
155 }
156 return 0;
157}
158
159/* report a warning if a redirect rule is dangerously placed */
160int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
161{
162 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
163 warnif_rule_after_use_server(proxy, file, line, arg);
164}
165
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100166/* report a warning if an http-request rule is dangerously placed */
167int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
168{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200169 return warnif_rule_after_redirect(proxy, file, line, arg) ||
170 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100171}
172
173/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200174int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100175{
176 return warnif_rule_after_http_req(proxy, file, line, arg) ||
177 warnif_misplaced_http_req(proxy, file, line, arg);
178}
179
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100180/* report a warning if a "tcp request content" rule is dangerously placed */
181int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
182{
183 return warnif_rule_after_monitor(proxy, file, line, arg) ||
184 warnif_misplaced_monitor(proxy, file, line, arg);
185}
186
187/* report a warning if a "tcp request session" rule is dangerously placed */
188int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
189{
190 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
191 warnif_misplaced_tcp_cont(proxy, file, line, arg);
192}
193
194/* report a warning if a "tcp request connection" rule is dangerously placed */
195int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
196{
197 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
198 warnif_misplaced_tcp_sess(proxy, file, line, arg);
199}
200
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100201int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
202{
203 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100204 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100205 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100206 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 int rc;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100208 int err_code = 0;
209 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100210 char *errmsg = NULL;
211 struct bind_conf *bind_conf;
212
Willy Tarreaue90904d2021-02-12 14:08:31 +0100213 if (!last_defproxy) {
214 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100215 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
216 proxy_preset_defaults(last_defproxy);
217
Willy Tarreaue90904d2021-02-12 14:08:31 +0100218 curr_defproxy = last_defproxy;
219 if (!last_defproxy) {
220 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
221 err_code |= ERR_ALERT | ERR_ABORT;
222 goto out;
223 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100224 }
225
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100226 if (strcmp(args[0], "listen") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200227 rc = PR_CAP_LISTEN | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100228 else if (strcmp(args[0], "frontend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200229 rc = PR_CAP_FE | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100230 else if (strcmp(args[0], "backend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200231 rc = PR_CAP_BE | PR_CAP_LB;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100232 else if (strcmp(args[0], "defaults") == 0) {
233 /* "defaults" must first delete the last no-name defaults if any */
234 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
235 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 }
318 }
319
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100320 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100321 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100322 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100323 goto out;
324 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100325
Willy Tarreaue90904d2021-02-12 14:08:31 +0100326 if (rc & PR_CAP_DEF) {
327 /* last and current proxies must be updated to this one */
328 curr_defproxy = last_defproxy = curproxy;
329 } else {
330 /* regular proxies are in a list */
331 curproxy->next = proxies_list;
332 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100333 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100334 goto out;
335 }
336 else if (curproxy == NULL) {
337 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
338 err_code |= ERR_ALERT | ERR_FATAL;
339 goto out;
340 }
341
342 /* update the current file and line being parsed */
343 curproxy->conf.args.file = curproxy->conf.file;
344 curproxy->conf.args.line = linenum;
345
346 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100347 if ((strcmp(args[0], "server") == 0)) {
348 err_code |= parse_server(file, linenum, args,
349 curproxy, curr_defproxy,
350 SRV_PARSE_PARSE_ADDR);
351
352 if (err_code & ERR_FATAL)
353 goto out;
354 }
355 else if (strcmp(args[0], "default-server") == 0) {
356 err_code |= parse_server(file, linenum, args,
357 curproxy, curr_defproxy,
358 SRV_PARSE_DEFAULT_SERVER);
359
360 if (err_code & ERR_FATAL)
361 goto out;
362 }
363 else if (strcmp(args[0], "server-template") == 0) {
364 err_code |= parse_server(file, linenum, args,
365 curproxy, curr_defproxy,
366 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
367
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100368 if (err_code & ERR_FATAL)
369 goto out;
370 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100371 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100372 struct listener *l;
373 int cur_arg;
374
Willy Tarreau5d095c22021-02-12 10:15:59 +0100375 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100376 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
377 err_code |= ERR_ALERT | ERR_FATAL;
378 goto out;
379 }
380 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
381 err_code |= ERR_WARN;
382
383 if (!*(args[1])) {
384 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
385 file, linenum, args[0]);
386 err_code |= ERR_ALERT | ERR_FATAL;
387 goto out;
388 }
389
390 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200391 if (!bind_conf)
392 goto alloc_error;
393
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100394 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200395 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
396 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
397 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100398
399 /* NOTE: the following line might create several listeners if there
400 * are comma-separated IPs or port ranges. So all further processing
401 * will have to be applied to all listeners created after last_listen.
402 */
403 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
404 if (errmsg && *errmsg) {
405 indent_msg(&errmsg, 2);
406 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
407 }
408 else
409 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
410 file, linenum, args[0], args[1]);
411 err_code |= ERR_ALERT | ERR_FATAL;
412 goto out;
413 }
414
415 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
416 /* Set default global rights and owner for unix bind */
417 global.maxsock++;
418 }
419
420 cur_arg = 2;
421 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100422 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100423 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100424
425 kw = bind_find_kw(args[cur_arg]);
426 if (kw) {
427 char *err = NULL;
428 int code;
429
430 if (!kw->parse) {
431 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
432 file, linenum, args[0], args[1], args[cur_arg]);
433 cur_arg += 1 + kw->skip ;
434 err_code |= ERR_ALERT | ERR_FATAL;
435 goto out;
436 }
437
438 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
439 err_code |= code;
440
441 if (code) {
442 if (err && *err) {
443 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200444 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
445 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
446 else
447 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100448 }
449 else
450 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
451 file, linenum, args[0], args[1], args[cur_arg]);
452 if (code & ERR_FATAL) {
453 free(err);
454 cur_arg += 1 + kw->skip;
455 goto out;
456 }
457 }
458 free(err);
459 cur_arg += 1 + kw->skip;
460 continue;
461 }
462
Willy Tarreau433b05f2021-03-12 10:14:07 +0100463 best = bind_find_best_kw(args[cur_arg]);
464 if (best)
465 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
466 file, linenum, args[0], args[1], args[cur_arg], best);
467 else
468 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
469 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100470
471 err_code |= ERR_ALERT | ERR_FATAL;
472 goto out;
473 }
474 goto out;
475 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100476 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200477 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]);
478 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100479 goto out;
480 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100481 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100482 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
483 err_code |= ERR_WARN;
484
485 if (alertif_too_many_args(1, file, linenum, args, &err_code))
486 goto out;
487
488 if (!*args[1]) {
489 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
490 file, linenum, args[0]);
491 err_code |= ERR_ALERT | ERR_FATAL;
492 goto out;
493 }
494
495 free(curproxy->monitor_uri);
496 curproxy->monitor_uri_len = strlen(args[1]);
497 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200498 if (!curproxy->monitor_uri)
499 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100500 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
501 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
502
503 goto out;
504 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100505 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100506 if (alertif_too_many_args(1, file, linenum, args, &err_code))
507 goto out;
508
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100509 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
510 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
511 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200512 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
513 err_code |= ERR_ALERT | ERR_FATAL;
514 goto out;
515 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100516 else {
517 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
518 err_code |= ERR_ALERT | ERR_FATAL;
519 goto out;
520 }
521 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100522 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100523 struct eb32_node *node;
524
Willy Tarreau5d095c22021-02-12 10:15:59 +0100525 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100526 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
527 file, linenum, args[0]);
528 err_code |= ERR_ALERT | ERR_FATAL;
529 goto out;
530 }
531
532 if (alertif_too_many_args(1, file, linenum, args, &err_code))
533 goto out;
534
535 if (!*args[1]) {
536 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
537 file, linenum, args[0]);
538 err_code |= ERR_ALERT | ERR_FATAL;
539 goto out;
540 }
541
542 curproxy->uuid = atol(args[1]);
543 curproxy->conf.id.key = curproxy->uuid;
544 curproxy->options |= PR_O_FORCED_ID;
545
546 if (curproxy->uuid <= 0) {
547 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
548 file, linenum);
549 err_code |= ERR_ALERT | ERR_FATAL;
550 goto out;
551 }
552
553 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
554 if (node) {
555 struct proxy *target = container_of(node, struct proxy, conf.id);
556 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
557 file, linenum, proxy_type_str(curproxy), curproxy->id,
558 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
559 err_code |= ERR_ALERT | ERR_FATAL;
560 goto out;
561 }
562 eb32_insert(&used_proxy_id, &curproxy->conf.id);
563 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100564 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100565 int i, len=0;
566 char *d;
567
Willy Tarreau5d095c22021-02-12 10:15:59 +0100568 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100569 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
570 file, linenum, args[0]);
571 err_code |= ERR_ALERT | ERR_FATAL;
572 goto out;
573 }
574
575 if (!*args[1]) {
576 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
577 file, linenum, args[0]);
578 return -1;
579 }
580
581 for (i = 1; *args[i]; i++)
582 len += strlen(args[i]) + 1;
583
584 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200585 if (!d)
586 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100587 curproxy->desc = d;
588
589 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
590 for (i = 2; *args[i]; i++)
591 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
592
593 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100594 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100595 if (alertif_too_many_args(0, file, linenum, args, &err_code))
596 goto out;
William Lallemand8e765b82021-08-03 11:58:03 +0200597 curproxy->disabled = PR_DISABLED;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100598 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100599 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100600 if (alertif_too_many_args(0, file, linenum, args, &err_code))
601 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200602 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100603 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100604 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100605 int cur_arg = 1;
606 unsigned long set = 0;
607
608 while (*args[cur_arg]) {
609 if (strcmp(args[cur_arg], "all") == 0) {
610 set = 0;
611 break;
612 }
Willy Tarreau72faef32021-06-15 08:36:30 +0200613 if (parse_process_number(args[cur_arg], &set, 1, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100614 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
615 err_code |= ERR_ALERT | ERR_FATAL;
616 goto out;
617 }
618 cur_arg++;
619 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200620 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
621 file, linenum, args[0]);
622 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100623 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100624 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100625 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100626 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
627 err_code |= ERR_ALERT | ERR_FATAL;
628 goto out;
629 }
630
631 err = invalid_char(args[1]);
632 if (err) {
633 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
634 file, linenum, *err, args[1]);
635 err_code |= ERR_ALERT | ERR_FATAL;
636 goto out;
637 }
638
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100639 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100640 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100641 "logical disjunction within a condition.\n",
642 file, linenum, args[1]);
643 err_code |= ERR_ALERT | ERR_FATAL;
644 goto out;
645 }
646
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100647 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
648 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
649 file, linenum, args[1], errmsg);
650 err_code |= ERR_ALERT | ERR_FATAL;
651 goto out;
652 }
653 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100654 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100655
656 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
657 err_code |= ERR_WARN;
658
659 if (*(args[1]) == 0) {
660 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
661 file, linenum, args[0]);
662 err_code |= ERR_ALERT | ERR_FATAL;
663 goto out;
664 }
665 free(curproxy->dyncookie_key);
666 curproxy->dyncookie_key = strdup(args[1]);
667 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100668 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100669 int cur_arg;
670
671 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
672 err_code |= ERR_WARN;
673
674 if (*(args[1]) == 0) {
675 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
676 file, linenum, args[0]);
677 err_code |= ERR_ALERT | ERR_FATAL;
678 goto out;
679 }
680
681 curproxy->ck_opts = 0;
682 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100683 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100684 free(curproxy->cookie_name);
685 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200686 if (!curproxy->cookie_name)
687 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100688 curproxy->cookie_len = strlen(curproxy->cookie_name);
689
690 cur_arg = 2;
691 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100692 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100693 curproxy->ck_opts |= PR_CK_RW;
694 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100695 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100696 curproxy->ck_opts |= PR_CK_IND;
697 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100698 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100699 curproxy->ck_opts |= PR_CK_INS;
700 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100701 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100702 curproxy->ck_opts |= PR_CK_NOC;
703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100704 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100705 curproxy->ck_opts |= PR_CK_POST;
706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100708 curproxy->ck_opts |= PR_CK_PSV;
709 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100710 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100711 curproxy->ck_opts |= PR_CK_PFX;
712 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100713 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100714 curproxy->ck_opts |= PR_CK_HTTPONLY;
715 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100716 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100717 curproxy->ck_opts |= PR_CK_SECURE;
718 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100719 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100720 if (!*args[cur_arg + 1]) {
721 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
722 file, linenum, args[cur_arg]);
723 err_code |= ERR_ALERT | ERR_FATAL;
724 goto out;
725 }
726
Joao Moraise1583752019-10-30 21:04:00 -0300727 if (!strchr(args[cur_arg + 1], '.')) {
728 /* rfc6265, 5.2.3 The Domain Attribute */
729 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
730 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100731 file, linenum, args[cur_arg + 1]);
732 err_code |= ERR_WARN;
733 }
734
735 err = invalid_domainchar(args[cur_arg + 1]);
736 if (err) {
737 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
738 file, linenum, *err, args[cur_arg + 1]);
739 err_code |= ERR_ALERT | ERR_FATAL;
740 goto out;
741 }
742
743 if (!curproxy->cookie_domain) {
744 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
745 } else {
746 /* one domain was already specified, add another one by
747 * building the string which will be returned along with
748 * the cookie.
749 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200750 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
751 }
752
Christopher Fauletb15625a2021-04-12 21:31:45 +0200753 if (!curproxy->cookie_domain)
754 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100755 cur_arg++;
756 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100757 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100758 unsigned int maxidle;
759 const char *res;
760
761 if (!*args[cur_arg + 1]) {
762 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
763 file, linenum, args[cur_arg]);
764 err_code |= ERR_ALERT | ERR_FATAL;
765 goto out;
766 }
767
768 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200769 if (res == PARSE_TIME_OVER) {
770 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
771 file, linenum, args[cur_arg+1], args[cur_arg]);
772 err_code |= ERR_ALERT | ERR_FATAL;
773 goto out;
774 }
775 else if (res == PARSE_TIME_UNDER) {
776 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
777 file, linenum, args[cur_arg+1], args[cur_arg]);
778 err_code |= ERR_ALERT | ERR_FATAL;
779 goto out;
780 }
781 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100782 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
783 file, linenum, *res, args[cur_arg]);
784 err_code |= ERR_ALERT | ERR_FATAL;
785 goto out;
786 }
787 curproxy->cookie_maxidle = maxidle;
788 cur_arg++;
789 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100790 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100791 unsigned int maxlife;
792 const char *res;
793
794 if (!*args[cur_arg + 1]) {
795 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
796 file, linenum, args[cur_arg]);
797 err_code |= ERR_ALERT | ERR_FATAL;
798 goto out;
799 }
800
Willy Tarreau9faebe32019-06-07 19:00:37 +0200801
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100802 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200803 if (res == PARSE_TIME_OVER) {
804 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
805 file, linenum, args[cur_arg+1], args[cur_arg]);
806 err_code |= ERR_ALERT | ERR_FATAL;
807 goto out;
808 }
809 else if (res == PARSE_TIME_UNDER) {
810 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
811 file, linenum, args[cur_arg+1], args[cur_arg]);
812 err_code |= ERR_ALERT | ERR_FATAL;
813 goto out;
814 }
815 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100816 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
817 file, linenum, *res, args[cur_arg]);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821 curproxy->cookie_maxlife = maxlife;
822 cur_arg++;
823 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100824 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100825
826 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
827 err_code |= ERR_WARN;
828 curproxy->ck_opts |= PR_CK_DYNAMIC;
829 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100830 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100831 char *val;
832 if (!*args[cur_arg + 1]) {
833 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
834 file, linenum, args[cur_arg]);
835 err_code |= ERR_ALERT | ERR_FATAL;
836 goto out;
837 }
838 val = args[cur_arg + 1];
839 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100840 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100841 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
842 file, linenum, *val);
843 err_code |= ERR_ALERT | ERR_FATAL;
844 goto out;
845 }
846 val++;
847 }
848 /* don't add ';' for the first attribute */
849 if (!curproxy->cookie_attrs)
850 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
851 else
852 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200853
Christopher Fauletb15625a2021-04-12 21:31:45 +0200854 if (!curproxy->cookie_attrs)
855 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100856 cur_arg++;
857 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100858
859 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100860 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 +0100861 file, linenum, args[0]);
862 err_code |= ERR_ALERT | ERR_FATAL;
863 goto out;
864 }
865 cur_arg++;
866 }
867 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
868 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
869 file, linenum);
870 err_code |= ERR_ALERT | ERR_FATAL;
871 }
872
873 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
874 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
875 file, linenum);
876 err_code |= ERR_ALERT | ERR_FATAL;
877 }
878
879 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
880 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
881 file, linenum);
882 err_code |= ERR_ALERT | ERR_FATAL;
883 }
884 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100885 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100886 if (*(args[1]) == 0) {
887 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
888 file, linenum, args[0]);
889 err_code |= ERR_ALERT | ERR_FATAL;
890 goto out;
891 }
892
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100893 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100894 if (*(args[1]) == 0) {
895 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
896 file, linenum, args[1]);
897 err_code |= ERR_ALERT | ERR_FATAL;
898 goto out;
899 }
900 free(curproxy->email_alert.from);
901 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200902 if (!curproxy->email_alert.from)
903 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100904 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100905 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100906 if (*(args[1]) == 0) {
907 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
908 file, linenum, args[1]);
909 err_code |= ERR_ALERT | ERR_FATAL;
910 goto out;
911 }
912 free(curproxy->email_alert.mailers.name);
913 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200914 if (!curproxy->email_alert.mailers.name)
915 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100916 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100917 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100918 if (*(args[1]) == 0) {
919 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
920 file, linenum, args[1]);
921 err_code |= ERR_ALERT | ERR_FATAL;
922 goto out;
923 }
924 free(curproxy->email_alert.myhostname);
925 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200926 if (!curproxy->email_alert.myhostname)
927 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100928 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100929 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100930 curproxy->email_alert.level = get_log_level(args[2]);
931 if (curproxy->email_alert.level < 0) {
932 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
933 file, linenum, args[1], args[2]);
934 err_code |= ERR_ALERT | ERR_FATAL;
935 goto out;
936 }
937 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100938 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100939 if (*(args[1]) == 0) {
940 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
941 file, linenum, args[1]);
942 err_code |= ERR_ALERT | ERR_FATAL;
943 goto out;
944 }
945 free(curproxy->email_alert.to);
946 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200947 if (!curproxy->email_alert.to)
948 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100949 }
950 else {
951 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
952 file, linenum, args[1]);
953 err_code |= ERR_ALERT | ERR_FATAL;
954 goto out;
955 }
956 /* Indicate that the email_alert is at least partially configured */
957 curproxy->email_alert.set = 1;
958 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100959 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100960 if (*(args[1]) == 0) {
961 ha_alert("parsing [%s:%d] : missing persist method.\n",
962 file, linenum);
963 err_code |= ERR_ALERT | ERR_FATAL;
964 goto out;
965 }
966
967 if (!strncmp(args[1], "rdp-cookie", 10)) {
968 curproxy->options2 |= PR_O2_RDPC_PRST;
969
970 if (*(args[1] + 10) == '(') { /* cookie name */
971 const char *beg, *end;
972
973 beg = args[1] + 11;
974 end = strchr(beg, ')');
975
976 if (alertif_too_many_args(1, file, linenum, args, &err_code))
977 goto out;
978
979 if (!end || end == beg) {
980 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
981 file, linenum);
982 err_code |= ERR_ALERT | ERR_FATAL;
983 goto out;
984 }
985
986 free(curproxy->rdp_cookie_name);
987 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200988 if (!curproxy->rdp_cookie_name)
989 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100990 curproxy->rdp_cookie_len = end-beg;
991 }
992 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
993 free(curproxy->rdp_cookie_name);
994 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +0200995 if (!curproxy->rdp_cookie_name)
996 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100997 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
998 }
999 else { /* syntax */
1000 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1001 file, linenum);
1002 err_code |= ERR_ALERT | ERR_FATAL;
1003 goto out;
1004 }
1005 }
1006 else {
1007 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1008 file, linenum);
1009 err_code |= ERR_ALERT | ERR_FATAL;
1010 goto out;
1011 }
1012 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001013 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001014 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 +01001015 err_code |= ERR_ALERT | ERR_FATAL;
1016 goto out;
1017 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001018 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001019 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1020 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001021 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001022 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1023 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001024 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 +01001025 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1026 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001027 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001028 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1029 }
1030 else {
1031 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1032 file, linenum, args[0], args[1]);
1033 err_code |= ERR_ALERT | ERR_FATAL;
1034 goto out;
1035 }
1036 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001037 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001038 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1039 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001040 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001041 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001042
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001043 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001044
1045 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001046 curproxy->server_state_file_name = strdup(curproxy->id);
1047 else
1048 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001049
Christopher Fauletb15625a2021-04-12 21:31:45 +02001050 if (!curproxy->server_state_file_name)
1051 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001052 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001053 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001054 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1055 err_code |= ERR_WARN;
1056 if (*(args[1]) == 0) {
1057 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1058 file, linenum, args[0]);
1059 err_code |= ERR_ALERT | ERR_FATAL;
1060 goto out;
1061 }
1062 curproxy->max_out_conns = atoi(args[1]);
1063 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001064 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001065 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1066 err_code |= ERR_WARN;
1067
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001068 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001069 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001070 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1071 err_code |= ERR_ALERT | ERR_FATAL;
1072 goto out;
1073 }
1074
1075 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1076 goto out;
1077
1078 if (*(args[4]) == 0) {
1079 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1080 file, linenum, args[0]);
1081 err_code |= ERR_ALERT | ERR_FATAL;
1082 goto out;
1083 }
1084 free(curproxy->capture_name);
1085 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001086 if (!curproxy->capture_name)
1087 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001088 curproxy->capture_namelen = strlen(curproxy->capture_name);
1089 curproxy->capture_len = atol(args[4]);
1090 curproxy->to_log |= LW_COOKIE;
1091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001092 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001093 struct cap_hdr *hdr;
1094
Willy Tarreau5d095c22021-02-12 10:15:59 +01001095 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001096 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1097 err_code |= ERR_ALERT | ERR_FATAL;
1098 goto out;
1099 }
1100
1101 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1102 goto out;
1103
1104 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1105 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1106 file, linenum, args[0], args[1]);
1107 err_code |= ERR_ALERT | ERR_FATAL;
1108 goto out;
1109 }
1110
1111 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001112 if (!hdr)
1113 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001114 hdr->next = curproxy->req_cap;
1115 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001116 if (!hdr->name)
1117 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001118 hdr->namelen = strlen(args[3]);
1119 hdr->len = atol(args[5]);
1120 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001121 if (!hdr->pool) {
1122 req_caphdr_alloc_error:
1123 if (hdr)
1124 ha_free(&hdr->name);
1125 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001126 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001127 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001128 hdr->index = curproxy->nb_req_cap++;
1129 curproxy->req_cap = hdr;
1130 curproxy->to_log |= LW_REQHDR;
1131 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001132 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001133 struct cap_hdr *hdr;
1134
Willy Tarreau5d095c22021-02-12 10:15:59 +01001135 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001136 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1137 err_code |= ERR_ALERT | ERR_FATAL;
1138 goto out;
1139 }
1140
1141 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1142 goto out;
1143
1144 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1145 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1146 file, linenum, args[0], args[1]);
1147 err_code |= ERR_ALERT | ERR_FATAL;
1148 goto out;
1149 }
1150 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001151 if (!hdr)
1152 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001153 hdr->next = curproxy->rsp_cap;
1154 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001155 if (!hdr->name)
1156 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001157 hdr->namelen = strlen(args[3]);
1158 hdr->len = atol(args[5]);
1159 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001160 if (!hdr->pool) {
1161 res_caphdr_alloc_error:
1162 if (hdr)
1163 ha_free(&hdr->name);
1164 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001165 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001166 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001167 hdr->index = curproxy->nb_rsp_cap++;
1168 curproxy->rsp_cap = hdr;
1169 curproxy->to_log |= LW_RSPHDR;
1170 }
1171 else {
1172 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1173 file, linenum, args[0]);
1174 err_code |= ERR_ALERT | ERR_FATAL;
1175 goto out;
1176 }
1177 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001178 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001179 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1180 err_code |= ERR_WARN;
1181
1182 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1183 goto out;
1184
1185 if (*(args[1]) == 0) {
1186 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1187 file, linenum, args[0]);
1188 err_code |= ERR_ALERT | ERR_FATAL;
1189 goto out;
1190 }
1191 curproxy->conn_retries = atol(args[1]);
1192 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001193 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001194 struct act_rule *rule;
1195
Willy Tarreau5d095c22021-02-12 10:15:59 +01001196 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001197 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1198 err_code |= ERR_ALERT | ERR_FATAL;
1199 goto out;
1200 }
1201
1202 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1203 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001204 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001205 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1206 file, linenum, args[0]);
1207 err_code |= ERR_WARN;
1208 }
1209
1210 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1211
1212 if (!rule) {
1213 err_code |= ERR_ALERT | ERR_ABORT;
1214 goto out;
1215 }
1216
1217 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1218 err_code |= warnif_cond_conflicts(rule->cond,
1219 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1220 file, linenum);
1221
Willy Tarreau2b718102021-04-21 07:32:39 +02001222 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001223 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001224 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001225 struct act_rule *rule;
1226
Willy Tarreau5d095c22021-02-12 10:15:59 +01001227 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001228 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1229 err_code |= ERR_ALERT | ERR_FATAL;
1230 goto out;
1231 }
1232
1233 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1234 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001235 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001236 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1237 file, linenum, args[0]);
1238 err_code |= ERR_WARN;
1239 }
1240
1241 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1242
1243 if (!rule) {
1244 err_code |= ERR_ALERT | ERR_ABORT;
1245 goto out;
1246 }
1247
1248 err_code |= warnif_cond_conflicts(rule->cond,
1249 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1250 file, linenum);
1251
Willy Tarreau2b718102021-04-21 07:32:39 +02001252 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001253 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001254 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001255 struct act_rule *rule;
1256
Willy Tarreau5d095c22021-02-12 10:15:59 +01001257 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001258 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1259 err_code |= ERR_ALERT | ERR_FATAL;
1260 goto out;
1261 }
1262
1263 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1264 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1265 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1266 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1267 file, linenum, args[0]);
1268 err_code |= ERR_WARN;
1269 }
1270
1271 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1272
1273 if (!rule) {
1274 err_code |= ERR_ALERT | ERR_ABORT;
1275 goto out;
1276 }
1277
1278 err_code |= warnif_cond_conflicts(rule->cond,
1279 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1280 file, linenum);
1281
Willy Tarreau2b718102021-04-21 07:32:39 +02001282 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001283 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001284 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001285 /* set the header name and length into the proxy structure */
1286 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1287 err_code |= ERR_WARN;
1288
1289 if (!*args[1]) {
1290 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1291 file, linenum, args[0]);
1292 err_code |= ERR_ALERT | ERR_FATAL;
1293 goto out;
1294 }
1295
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001296 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001297 free(curproxy->server_id_hdr_name);
1298 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001299 if (!curproxy->server_id_hdr_name)
1300 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001301 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001302 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 +01001303 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001304 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001305 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 +01001306
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001307 err_code |= ERR_ALERT | ERR_FATAL;
1308 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001309 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001310 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001311 struct redirect_rule *rule;
1312
Willy Tarreau5d095c22021-02-12 10:15:59 +01001313 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001314 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1315 err_code |= ERR_ALERT | ERR_FATAL;
1316 goto out;
1317 }
1318
1319 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1320 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1321 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325
Willy Tarreau2b718102021-04-21 07:32:39 +02001326 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001327 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1328 err_code |= warnif_cond_conflicts(rule->cond,
1329 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1330 file, linenum);
1331 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001332 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001333 struct switching_rule *rule;
1334
Willy Tarreau5d095c22021-02-12 10:15:59 +01001335 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001336 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1337 err_code |= ERR_ALERT | ERR_FATAL;
1338 goto out;
1339 }
1340
1341 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1342 err_code |= ERR_WARN;
1343
1344 if (*(args[1]) == 0) {
1345 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1346 err_code |= ERR_ALERT | ERR_FATAL;
1347 goto out;
1348 }
1349
1350 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1351 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1352 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1353 file, linenum, errmsg);
1354 err_code |= ERR_ALERT | ERR_FATAL;
1355 goto out;
1356 }
1357
1358 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1359 }
1360 else if (*args[2]) {
1361 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1362 file, linenum, args[2]);
1363 err_code |= ERR_ALERT | ERR_FATAL;
1364 goto out;
1365 }
1366
1367 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001368 if (!rule)
1369 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001370 rule->cond = cond;
1371 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001372 if (!rule->be.name)
1373 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001374 rule->line = linenum;
1375 rule->file = strdup(file);
1376 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001377 use_backend_alloc_error:
1378 if (cond)
1379 prune_acl_cond(cond);
1380 ha_free(&cond);
1381 if (rule)
1382 ha_free(&(rule->be.name));
1383 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001384 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001385 }
1386 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001387 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001388 }
1389 else if (strcmp(args[0], "use-server") == 0) {
1390 struct server_rule *rule;
1391
Willy Tarreau5d095c22021-02-12 10:15:59 +01001392 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001393 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1394 err_code |= ERR_ALERT | ERR_FATAL;
1395 goto out;
1396 }
1397
1398 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1399 err_code |= ERR_WARN;
1400
1401 if (*(args[1]) == 0) {
1402 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1403 err_code |= ERR_ALERT | ERR_FATAL;
1404 goto out;
1405 }
1406
1407 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1408 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1409 file, linenum, args[0]);
1410 err_code |= ERR_ALERT | ERR_FATAL;
1411 goto out;
1412 }
1413
1414 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1415 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1416 file, linenum, errmsg);
1417 err_code |= ERR_ALERT | ERR_FATAL;
1418 goto out;
1419 }
1420
1421 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1422
1423 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001424 if (!rule)
1425 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001426 rule->cond = cond;
1427 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001428 if (!rule->srv.name)
1429 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001430 rule->line = linenum;
1431 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001432 if (!rule->file) {
1433 use_server_alloc_error:
1434 if (cond)
1435 prune_acl_cond(cond);
1436 ha_free(&cond);
1437 if (rule)
1438 ha_free(&(rule->srv.name));
1439 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001440 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001441 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001442 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001443 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001444 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1445 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001446 else if ((strcmp(args[0], "force-persist") == 0) ||
1447 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 struct persist_rule *rule;
1449
Willy Tarreau5d095c22021-02-12 10:15:59 +01001450 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001451 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1452 err_code |= ERR_ALERT | ERR_FATAL;
1453 goto out;
1454 }
1455
1456 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1457 err_code |= ERR_WARN;
1458
1459 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1460 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1461 file, linenum, args[0]);
1462 err_code |= ERR_ALERT | ERR_FATAL;
1463 goto out;
1464 }
1465
1466 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1467 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1468 file, linenum, args[0], errmsg);
1469 err_code |= ERR_ALERT | ERR_FATAL;
1470 goto out;
1471 }
1472
1473 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1474 * where force-persist is applied.
1475 */
1476 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1477
1478 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001479 if (!rule) {
1480 if (cond)
1481 prune_acl_cond(cond);
1482 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001483 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001484 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001485 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001486 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001487 rule->type = PERSIST_TYPE_FORCE;
1488 } else {
1489 rule->type = PERSIST_TYPE_IGNORE;
1490 }
1491 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001492 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001493 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001494 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001495 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001496
Willy Tarreau5d095c22021-02-12 10:15:59 +01001497 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001498 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1499 file, linenum);
1500 err_code |= ERR_ALERT | ERR_FATAL;
1501 goto out;
1502 }
1503
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001504 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001505 if (other) {
1506 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 +01001507 file, linenum, curproxy->id,
1508 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1509 other->proxy ? other->id : other->peers.p->id,
1510 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001511 err_code |= ERR_ALERT | ERR_FATAL;
1512 goto out;
1513 }
1514
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001515 curproxy->table = calloc(1, sizeof *curproxy->table);
1516 if (!curproxy->table) {
1517 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1518 file, linenum, args[0], args[1]);
1519 err_code |= ERR_ALERT | ERR_FATAL;
1520 goto out;
1521 }
1522
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001523 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1524 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001525 if (err_code & ERR_FATAL) {
1526 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001527 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001528 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001529
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001530 /* Store the proxy in the stick-table. */
1531 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001532
1533 stktable_store_name(curproxy->table);
1534 curproxy->table->next = stktables_list;
1535 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001536
1537 /* Add this proxy to the list of proxies which refer to its stick-table. */
1538 if (curproxy->table->proxies_list != curproxy) {
1539 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1540 curproxy->table->proxies_list = curproxy;
1541 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001542 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001543 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001544 struct sticking_rule *rule;
1545 struct sample_expr *expr;
1546 int myidx = 0;
1547 const char *name = NULL;
1548 int flags;
1549
Willy Tarreau5d095c22021-02-12 10:15:59 +01001550 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001551 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1552 err_code |= ERR_ALERT | ERR_FATAL;
1553 goto out;
1554 }
1555
1556 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1557 err_code |= ERR_WARN;
1558 goto out;
1559 }
1560
1561 myidx++;
1562 if ((strcmp(args[myidx], "store") == 0) ||
1563 (strcmp(args[myidx], "store-request") == 0)) {
1564 myidx++;
1565 flags = STK_IS_STORE;
1566 }
1567 else if (strcmp(args[myidx], "store-response") == 0) {
1568 myidx++;
1569 flags = STK_IS_STORE | STK_ON_RSP;
1570 }
1571 else if (strcmp(args[myidx], "match") == 0) {
1572 myidx++;
1573 flags = STK_IS_MATCH;
1574 }
1575 else if (strcmp(args[myidx], "on") == 0) {
1576 myidx++;
1577 flags = STK_IS_MATCH | STK_IS_STORE;
1578 }
1579 else {
1580 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1581 err_code |= ERR_ALERT | ERR_FATAL;
1582 goto out;
1583 }
1584
1585 if (*(args[myidx]) == 0) {
1586 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1587 err_code |= ERR_ALERT | ERR_FATAL;
1588 goto out;
1589 }
1590
1591 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001592 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001593 if (!expr) {
1594 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1595 err_code |= ERR_ALERT | ERR_FATAL;
1596 goto out;
1597 }
1598
1599 if (flags & STK_ON_RSP) {
1600 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1601 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1602 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1603 err_code |= ERR_ALERT | ERR_FATAL;
1604 free(expr);
1605 goto out;
1606 }
1607 } else {
1608 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1609 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1610 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1611 err_code |= ERR_ALERT | ERR_FATAL;
1612 free(expr);
1613 goto out;
1614 }
1615 }
1616
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001617 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001618 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1619
1620 if (strcmp(args[myidx], "table") == 0) {
1621 myidx++;
1622 name = args[myidx++];
1623 }
1624
1625 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1626 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1627 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1628 file, linenum, args[0], errmsg);
1629 err_code |= ERR_ALERT | ERR_FATAL;
1630 free(expr);
1631 goto out;
1632 }
1633 }
1634 else if (*(args[myidx])) {
1635 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1636 file, linenum, args[0], args[myidx]);
1637 err_code |= ERR_ALERT | ERR_FATAL;
1638 free(expr);
1639 goto out;
1640 }
1641 if (flags & STK_ON_RSP)
1642 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1643 else
1644 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1645
1646 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001647 if (!rule) {
1648 if (cond)
1649 prune_acl_cond(cond);
1650 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001651 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001652 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001653 rule->cond = cond;
1654 rule->expr = expr;
1655 rule->flags = flags;
1656 rule->table.name = name ? strdup(name) : NULL;
1657 LIST_INIT(&rule->list);
1658 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001659 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001660 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001661 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001662 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001663 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001664 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001665 curproxy->uri_auth = NULL; /* we must detach from the default config */
1666
1667 if (!*args[1]) {
1668 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001669 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001670 struct stats_admin_rule *rule;
1671
Willy Tarreau5d095c22021-02-12 10:15:59 +01001672 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001673 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1674 err_code |= ERR_ALERT | ERR_FATAL;
1675 goto out;
1676 }
1677
Christopher Fauletb15625a2021-04-12 21:31:45 +02001678 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1679 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001680
1681 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1682 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1683 file, linenum, args[0], args[1]);
1684 err_code |= ERR_ALERT | ERR_FATAL;
1685 goto out;
1686 }
1687 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1688 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1689 file, linenum, args[0], args[1], errmsg);
1690 err_code |= ERR_ALERT | ERR_FATAL;
1691 goto out;
1692 }
1693
1694 err_code |= warnif_cond_conflicts(cond,
1695 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1696 file, linenum);
1697
1698 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001699 if (!rule) {
1700 if (cond)
1701 prune_acl_cond(cond);
1702 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001703 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001704 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001705 rule->cond = cond;
1706 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001707 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001708 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001709 if (*(args[2]) == 0) {
1710 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1711 err_code |= ERR_ALERT | ERR_FATAL;
1712 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001713 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1714 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001715 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001716 if (*(args[2]) == 0) {
1717 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1718 err_code |= ERR_ALERT | ERR_FATAL;
1719 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001720 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1721 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001722 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001723 unsigned interval;
1724
1725 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001726 if (err == PARSE_TIME_OVER) {
1727 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1728 file, linenum, args[2]);
1729 err_code |= ERR_ALERT | ERR_FATAL;
1730 goto out;
1731 }
1732 else if (err == PARSE_TIME_UNDER) {
1733 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1734 file, linenum, args[2]);
1735 err_code |= ERR_ALERT | ERR_FATAL;
1736 goto out;
1737 }
1738 else if (err) {
1739 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001740 file, linenum, *err);
1741 err_code |= ERR_ALERT | ERR_FATAL;
1742 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001743 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1744 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001745 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001746 struct act_rule *rule;
1747
Willy Tarreau5d095c22021-02-12 10:15:59 +01001748 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001749 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1750 err_code |= ERR_ALERT | ERR_FATAL;
1751 goto out;
1752 }
1753
Christopher Fauletb15625a2021-04-12 21:31:45 +02001754 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1755 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001756
1757 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1758 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1759 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1760 file, linenum, args[0]);
1761 err_code |= ERR_WARN;
1762 }
1763
1764 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1765
1766 if (!rule) {
1767 err_code |= ERR_ALERT | ERR_ABORT;
1768 goto out;
1769 }
1770
1771 err_code |= warnif_cond_conflicts(rule->cond,
1772 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1773 file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001774 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001775
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001776 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001777 if (*(args[2]) == 0) {
1778 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1779 err_code |= ERR_ALERT | ERR_FATAL;
1780 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001781 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1782 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001783 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001784 if (*(args[2]) == 0) {
1785 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1786 err_code |= ERR_ALERT | ERR_FATAL;
1787 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001788 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1789 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001790 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001791 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1792 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001793 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001794 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1795 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001796 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001797 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1798 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001799 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001800 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1801 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001802 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001803
1804 if (*args[2]) {
1805 int i;
1806 char c;
1807
1808 for (i=0; args[2][i]; i++) {
1809 c = args[2][i];
1810 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1811 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1812 break;
1813 }
1814
1815 if (!i || args[2][i]) {
1816 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1817 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1818 file, linenum, args[0], args[1]);
1819 err_code |= ERR_ALERT | ERR_FATAL;
1820 goto out;
1821 }
1822 }
1823
Christopher Fauletb15625a2021-04-12 21:31:45 +02001824 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1825 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001826 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001827 char *desc = NULL;
1828
1829 if (*args[2]) {
1830 int i, len=0;
1831 char *d;
1832
1833 for (i = 2; *args[i]; i++)
1834 len += strlen(args[i]) + 1;
1835
1836 desc = d = calloc(1, len);
1837
1838 d += snprintf(d, desc + len - d, "%s", args[2]);
1839 for (i = 3; *args[i]; i++)
1840 d += snprintf(d, desc + len - d, " %s", args[i]);
1841 }
1842
1843 if (!*args[2] && !global.desc)
1844 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1845 file, linenum, args[1]);
1846 else {
1847 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1848 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001849 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001850 }
1851 free(desc);
1852 }
1853 } else {
1854stats_error_parsing:
1855 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1856 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1857 err_code |= ERR_ALERT | ERR_FATAL;
1858 goto out;
1859 }
1860 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001861 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001862 int optnum;
1863
1864 if (*(args[1]) == '\0') {
1865 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1866 file, linenum, args[0]);
1867 err_code |= ERR_ALERT | ERR_FATAL;
1868 goto out;
1869 }
1870
1871 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001872 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001873 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1874 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1875 file, linenum, cfg_opts[optnum].name);
1876 err_code |= ERR_ALERT | ERR_FATAL;
1877 goto out;
1878 }
1879 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1880 goto out;
1881
1882 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1883 err_code |= ERR_WARN;
1884 goto out;
1885 }
1886
1887 curproxy->no_options &= ~cfg_opts[optnum].val;
1888 curproxy->options &= ~cfg_opts[optnum].val;
1889
1890 switch (kwm) {
1891 case KWM_STD:
1892 curproxy->options |= cfg_opts[optnum].val;
1893 break;
1894 case KWM_NO:
1895 curproxy->no_options |= cfg_opts[optnum].val;
1896 break;
1897 case KWM_DEF: /* already cleared */
1898 break;
1899 }
1900
1901 goto out;
1902 }
1903 }
1904
1905 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001906 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001907 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1908 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1909 file, linenum, cfg_opts2[optnum].name);
1910 err_code |= ERR_ALERT | ERR_FATAL;
1911 goto out;
1912 }
1913 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1914 goto out;
1915 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1916 err_code |= ERR_WARN;
1917 goto out;
1918 }
1919
1920 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1921 curproxy->options2 &= ~cfg_opts2[optnum].val;
1922
1923 switch (kwm) {
1924 case KWM_STD:
1925 curproxy->options2 |= cfg_opts2[optnum].val;
1926 break;
1927 case KWM_NO:
1928 curproxy->no_options2 |= cfg_opts2[optnum].val;
1929 break;
1930 case KWM_DEF: /* already cleared */
1931 break;
1932 }
1933 goto out;
1934 }
1935 }
1936
1937 /* HTTP options override each other. They can be cancelled using
1938 * "no option xxx" which only switches to default mode if the mode
1939 * was this one (useful for cancelling options set in defaults
1940 * sections).
1941 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001942 if (strcmp(args[1], "forceclose") == 0) {
1943 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",
1944 file, linenum, args[1]);
1945 err_code |= ERR_ALERT | ERR_FATAL;
1946 goto out;
1947 }
1948 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001949 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1950 goto out;
1951 if (kwm == KWM_STD) {
1952 curproxy->options &= ~PR_O_HTTP_MODE;
1953 curproxy->options |= PR_O_HTTP_CLO;
1954 goto out;
1955 }
1956 else if (kwm == KWM_NO) {
1957 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1958 curproxy->options &= ~PR_O_HTTP_MODE;
1959 goto out;
1960 }
1961 }
1962 else if (strcmp(args[1], "http-server-close") == 0) {
1963 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1964 goto out;
1965 if (kwm == KWM_STD) {
1966 curproxy->options &= ~PR_O_HTTP_MODE;
1967 curproxy->options |= PR_O_HTTP_SCL;
1968 goto out;
1969 }
1970 else if (kwm == KWM_NO) {
1971 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1972 curproxy->options &= ~PR_O_HTTP_MODE;
1973 goto out;
1974 }
1975 }
1976 else if (strcmp(args[1], "http-keep-alive") == 0) {
1977 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1978 goto out;
1979 if (kwm == KWM_STD) {
1980 curproxy->options &= ~PR_O_HTTP_MODE;
1981 curproxy->options |= PR_O_HTTP_KAL;
1982 goto out;
1983 }
1984 else if (kwm == KWM_NO) {
1985 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1986 curproxy->options &= ~PR_O_HTTP_MODE;
1987 goto out;
1988 }
1989 }
1990 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02001991 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 +02001992 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02001993 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001994 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001995 }
1996
1997 /* Redispatch can take an integer argument that control when the
1998 * resispatch occurs. All values are relative to the retries option.
1999 * This can be cancelled using "no option xxx".
2000 */
2001 if (strcmp(args[1], "redispatch") == 0) {
2002 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2003 err_code |= ERR_WARN;
2004 goto out;
2005 }
2006
2007 curproxy->no_options &= ~PR_O_REDISP;
2008 curproxy->options &= ~PR_O_REDISP;
2009
2010 switch (kwm) {
2011 case KWM_STD:
2012 curproxy->options |= PR_O_REDISP;
2013 curproxy->redispatch_after = -1;
2014 if(*args[2]) {
2015 curproxy->redispatch_after = atol(args[2]);
2016 }
2017 break;
2018 case KWM_NO:
2019 curproxy->no_options |= PR_O_REDISP;
2020 curproxy->redispatch_after = 0;
2021 break;
2022 case KWM_DEF: /* already cleared */
2023 break;
2024 }
2025 goto out;
2026 }
2027
Willy Tarreau25241232021-07-18 19:18:56 +02002028 if (strcmp(args[1], "http_proxy") == 0) {
2029 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",
2030 file, linenum, args[1]);
2031 err_code |= ERR_ALERT | ERR_FATAL;
2032 goto out;
2033 }
2034
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002035 if (kwm != KWM_STD) {
2036 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2037 file, linenum, args[1]);
2038 err_code |= ERR_ALERT | ERR_FATAL;
2039 goto out;
2040 }
2041
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002042 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002043 char *logformat;
2044 /* generate a complete HTTP log */
2045 logformat = default_http_log_format;
2046 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002047 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002048 curproxy->options2 |= PR_O2_CLFLOG;
2049 logformat = clf_http_log_format;
2050 } else {
2051 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2052 err_code |= ERR_ALERT | ERR_FATAL;
2053 goto out;
2054 }
2055 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2056 goto out;
2057 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002058 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002059 char *oldlogformat = "log-format";
2060 char *clflogformat = "";
2061
2062 if (curproxy->conf.logformat_string == default_http_log_format)
2063 oldlogformat = "option httplog";
2064 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2065 oldlogformat = "option tcplog";
2066 else if (curproxy->conf.logformat_string == clf_http_log_format)
2067 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002068 else if (curproxy->conf.logformat_string == default_https_log_format)
2069 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002070 if (logformat == clf_http_log_format)
2071 clflogformat = " clf";
2072 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2073 file, linenum, clflogformat, oldlogformat);
2074 }
2075 if (curproxy->conf.logformat_string != default_http_log_format &&
2076 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002077 curproxy->conf.logformat_string != clf_http_log_format &&
2078 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002079 free(curproxy->conf.logformat_string);
2080 curproxy->conf.logformat_string = logformat;
2081
2082 free(curproxy->conf.lfs_file);
2083 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2084 curproxy->conf.lfs_line = curproxy->conf.args.line;
2085
Willy Tarreau5d095c22021-02-12 10:15:59 +01002086 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002087 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2088 file, linenum, curproxy->id);
2089 err_code |= ERR_WARN;
2090 }
2091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002092 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002093 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002094 char *oldlogformat = "log-format";
2095
2096 if (curproxy->conf.logformat_string == default_http_log_format)
2097 oldlogformat = "option httplog";
2098 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2099 oldlogformat = "option tcplog";
2100 else if (curproxy->conf.logformat_string == clf_http_log_format)
2101 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002102 else if (curproxy->conf.logformat_string == default_https_log_format)
2103 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002104 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2105 file, linenum, oldlogformat);
2106 }
2107 /* generate a detailed TCP log */
2108 if (curproxy->conf.logformat_string != default_http_log_format &&
2109 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002110 curproxy->conf.logformat_string != clf_http_log_format &&
2111 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002112 free(curproxy->conf.logformat_string);
2113 curproxy->conf.logformat_string = default_tcp_log_format;
2114
2115 free(curproxy->conf.lfs_file);
2116 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2117 curproxy->conf.lfs_line = curproxy->conf.args.line;
2118
2119 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2120 goto out;
2121
Willy Tarreau5d095c22021-02-12 10:15:59 +01002122 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002123 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2124 file, linenum, curproxy->id);
2125 err_code |= ERR_WARN;
2126 }
2127 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002128 else if (strcmp(args[1], "httpslog") == 0) {
2129 char *logformat;
2130 /* generate a complete HTTP log */
2131 logformat = default_https_log_format;
2132 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2133 char *oldlogformat = "log-format";
2134
2135 if (curproxy->conf.logformat_string == default_http_log_format)
2136 oldlogformat = "option httplog";
2137 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2138 oldlogformat = "option tcplog";
2139 else if (curproxy->conf.logformat_string == clf_http_log_format)
2140 oldlogformat = "option httplog clf";
2141 else if (curproxy->conf.logformat_string == default_https_log_format)
2142 oldlogformat = "option httpslog";
2143 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2144 file, linenum, oldlogformat);
2145 }
2146 if (curproxy->conf.logformat_string != default_http_log_format &&
2147 curproxy->conf.logformat_string != default_tcp_log_format &&
2148 curproxy->conf.logformat_string != clf_http_log_format &&
2149 curproxy->conf.logformat_string != default_https_log_format)
2150 free(curproxy->conf.logformat_string);
2151 curproxy->conf.logformat_string = logformat;
2152
2153 free(curproxy->conf.lfs_file);
2154 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2155 curproxy->conf.lfs_line = curproxy->conf.args.line;
2156
2157 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2158 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2159 file, linenum, curproxy->id);
2160 err_code |= ERR_WARN;
2161 }
2162 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002163 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002164 /* enable TCP keep-alives on client and server streams */
2165 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2166 err_code |= ERR_WARN;
2167
2168 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2169 goto out;
2170
2171 if (curproxy->cap & PR_CAP_FE)
2172 curproxy->options |= PR_O_TCP_CLI_KA;
2173 if (curproxy->cap & PR_CAP_BE)
2174 curproxy->options |= PR_O_TCP_SRV_KA;
2175 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002176 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002177 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002178 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002179 goto out;
2180 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002181 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002182 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002183 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002184 goto out;
2185 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002186 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002187 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002188 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002189 goto out;
2190 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002191 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002192 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002193 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002194 goto out;
2195 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002196 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002197 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002198 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002199 goto out;
2200 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002201 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002202 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002203 if (err_code & ERR_FATAL)
2204 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002205 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002206 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002207 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002208 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002209 goto out;
2210 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002211 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002212 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002213 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002214 goto out;
2215 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002216 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002217 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002218 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002219 goto out;
2220 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002221 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002222 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002223 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002224 goto out;
2225 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002226 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002227 int cur_arg;
2228
2229 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002230 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002231 */
2232
2233 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2234
2235 free(curproxy->fwdfor_hdr_name);
2236 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002237 if (!curproxy->fwdfor_hdr_name)
2238 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002239 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002240 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002241
2242 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2243 cur_arg = 2;
2244 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002245 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002246 unsigned char mask;
2247 int i;
2248
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002249 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002250 if (*(args[cur_arg+1]) &&
2251 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2252 curproxy->except_xff_net.family = AF_INET;
2253 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2254 }
2255 else if (*(args[cur_arg+1]) &&
2256 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2257 curproxy->except_xff_net.family = AF_INET6;
2258 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2259 for (i = 0; i < 16; i++)
2260 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2261 }
2262 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002263 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2264 file, linenum, args[0], args[1], args[cur_arg]);
2265 err_code |= ERR_ALERT | ERR_FATAL;
2266 goto out;
2267 }
2268 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002270 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002271 /* suboption header - needs additional argument for it */
2272 if (*(args[cur_arg+1]) == 0) {
2273 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2274 file, linenum, args[0], args[1], args[cur_arg]);
2275 err_code |= ERR_ALERT | ERR_FATAL;
2276 goto out;
2277 }
2278 free(curproxy->fwdfor_hdr_name);
2279 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002280 if (!curproxy->fwdfor_hdr_name)
2281 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002282 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2283 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002284 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002285 curproxy->options &= ~PR_O_FF_ALWAYS;
2286 cur_arg += 1;
2287 } else {
2288 /* unknown suboption - catchall */
2289 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2290 file, linenum, args[0], args[1]);
2291 err_code |= ERR_ALERT | ERR_FATAL;
2292 goto out;
2293 }
2294 } /* end while loop */
2295 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002296 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002297 int cur_arg;
2298
2299 /* insert x-original-to field, but not for the IP address listed as an except.
2300 * set default options (ie: bitfield, header name, etc)
2301 */
2302
2303 curproxy->options |= PR_O_ORGTO;
2304
2305 free(curproxy->orgto_hdr_name);
2306 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002307 if (!curproxy->orgto_hdr_name)
2308 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002309 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002310 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002311
2312 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2313 cur_arg = 2;
2314 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002315 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002316 unsigned char mask;
2317 int i;
2318
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002319 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002320 if (*(args[cur_arg+1]) &&
2321 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2322 curproxy->except_xot_net.family = AF_INET;
2323 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2324 }
2325 else if (*(args[cur_arg+1]) &&
2326 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2327 curproxy->except_xot_net.family = AF_INET6;
2328 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2329 for (i = 0; i < 16; i++)
2330 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2331 }
2332 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002333 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2334 file, linenum, args[0], args[1], args[cur_arg]);
2335 err_code |= ERR_ALERT | ERR_FATAL;
2336 goto out;
2337 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002338 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002339 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002340 /* suboption header - needs additional argument for it */
2341 if (*(args[cur_arg+1]) == 0) {
2342 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2343 file, linenum, args[0], args[1], args[cur_arg]);
2344 err_code |= ERR_ALERT | ERR_FATAL;
2345 goto out;
2346 }
2347 free(curproxy->orgto_hdr_name);
2348 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002349 if (!curproxy->orgto_hdr_name)
2350 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002351 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2352 cur_arg += 2;
2353 } else {
2354 /* unknown suboption - catchall */
2355 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2356 file, linenum, args[0], args[1]);
2357 err_code |= ERR_ALERT | ERR_FATAL;
2358 goto out;
2359 }
2360 } /* end while loop */
2361 }
2362 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002363 const char *best = proxy_find_best_option(args[1], common_options);
2364
2365 if (best)
2366 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2367 else
2368 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2369
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002370 err_code |= ERR_ALERT | ERR_FATAL;
2371 goto out;
2372 }
2373 goto out;
2374 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002375 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002376 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2377 err_code |= ERR_WARN;
2378
2379 if (*(args[1]) == 0) {
2380 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2381 err_code |= ERR_ALERT | ERR_FATAL;
2382 goto out;
2383 }
2384 free(curproxy->defbe.name);
2385 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002386 if (!curproxy->defbe.name)
2387 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002388
2389 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2390 goto out;
2391 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002392 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002393 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 +01002394
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002395 err_code |= ERR_ALERT | ERR_FATAL;
2396 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002397 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002398 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002399 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2400 err_code |= ERR_WARN;
2401
2402 if (strcmp(args[1], "never") == 0) {
2403 /* enable a graceful server shutdown on an HTTP 404 response */
2404 curproxy->options &= ~PR_O_REUSE_MASK;
2405 curproxy->options |= PR_O_REUSE_NEVR;
2406 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2407 goto out;
2408 }
2409 else if (strcmp(args[1], "safe") == 0) {
2410 /* enable a graceful server shutdown on an HTTP 404 response */
2411 curproxy->options &= ~PR_O_REUSE_MASK;
2412 curproxy->options |= PR_O_REUSE_SAFE;
2413 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2414 goto out;
2415 }
2416 else if (strcmp(args[1], "aggressive") == 0) {
2417 curproxy->options &= ~PR_O_REUSE_MASK;
2418 curproxy->options |= PR_O_REUSE_AGGR;
2419 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2420 goto out;
2421 }
2422 else if (strcmp(args[1], "always") == 0) {
2423 /* enable a graceful server shutdown on an HTTP 404 response */
2424 curproxy->options &= ~PR_O_REUSE_MASK;
2425 curproxy->options |= PR_O_REUSE_ALWS;
2426 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2427 goto out;
2428 }
2429 else {
2430 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2431 err_code |= ERR_ALERT | ERR_FATAL;
2432 goto out;
2433 }
2434 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002435 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002436 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002437 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2438 err_code |= ERR_ALERT | ERR_FATAL;
2439 goto out;
2440 }
2441
2442 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2443 err_code |= ERR_WARN;
2444
2445 if (strcmp(args[1], "fail") == 0) {
2446 /* add a condition to fail monitor requests */
2447 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2448 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2449 file, linenum, args[0], args[1]);
2450 err_code |= ERR_ALERT | ERR_FATAL;
2451 goto out;
2452 }
2453
2454 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2455 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2456 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2457 file, linenum, args[0], args[1], errmsg);
2458 err_code |= ERR_ALERT | ERR_FATAL;
2459 goto out;
2460 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002461 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002462 }
2463 else {
2464 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2465 err_code |= ERR_ALERT | ERR_FATAL;
2466 goto out;
2467 }
2468 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002469#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002470 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002471 /* enable transparent proxy connections */
2472 curproxy->options |= PR_O_TRANSP;
2473 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2474 goto out;
2475 }
2476#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002477 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002478 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2479 err_code |= ERR_WARN;
2480
2481 if (*(args[1]) == 0) {
2482 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2483 err_code |= ERR_ALERT | ERR_FATAL;
2484 goto out;
2485 }
2486 curproxy->maxconn = atol(args[1]);
2487 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2488 goto out;
2489 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002490 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002491 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2492 err_code |= ERR_WARN;
2493
2494 if (*(args[1]) == 0) {
2495 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2496 err_code |= ERR_ALERT | ERR_FATAL;
2497 goto out;
2498 }
2499 curproxy->backlog = atol(args[1]);
2500 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2501 goto out;
2502 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002503 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002504 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2505 err_code |= ERR_WARN;
2506
2507 if (*(args[1]) == 0) {
2508 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2509 err_code |= ERR_ALERT | ERR_FATAL;
2510 goto out;
2511 }
2512 curproxy->fullconn = atol(args[1]);
2513 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2514 goto out;
2515 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002516 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002517 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 +02002518 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002519 err_code |= ERR_ALERT | ERR_FATAL;
2520 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002521 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002522 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002523 struct sockaddr_storage *sk;
2524 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002525
Willy Tarreau5d095c22021-02-12 10:15:59 +01002526 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002527 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2528 err_code |= ERR_ALERT | ERR_FATAL;
2529 goto out;
2530 }
2531 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2532 err_code |= ERR_WARN;
2533
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002534 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2535 &errmsg, NULL, NULL,
2536 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 +01002537 if (!sk) {
2538 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2539 err_code |= ERR_ALERT | ERR_FATAL;
2540 goto out;
2541 }
2542
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002543 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2544 goto out;
2545
2546 curproxy->dispatch_addr = *sk;
2547 curproxy->options |= PR_O_DISPATCH;
2548 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002549 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002550 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2551 err_code |= ERR_WARN;
2552
2553 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2554 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2555 err_code |= ERR_ALERT | ERR_FATAL;
2556 goto out;
2557 }
2558 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002559 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002560 /**
2561 * The syntax for hash-type config element is
2562 * hash-type {map-based|consistent} [[<algo>] avalanche]
2563 *
2564 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2565 */
2566 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2567
2568 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2569 err_code |= ERR_WARN;
2570
2571 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2572 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2573 }
2574 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2575 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2576 }
2577 else if (strcmp(args[1], "avalanche") == 0) {
2578 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]);
2579 err_code |= ERR_ALERT | ERR_FATAL;
2580 goto out;
2581 }
2582 else {
2583 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2584 err_code |= ERR_ALERT | ERR_FATAL;
2585 goto out;
2586 }
2587
2588 /* set the hash function to use */
2589 if (!*args[2]) {
2590 /* the default algo is sdbm */
2591 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2592
2593 /* if consistent with no argument, then avalanche modifier is also applied */
2594 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2595 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2596 } else {
2597 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002598 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002599 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2600 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002601 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002602 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2603 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002604 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002605 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2606 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002607 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002608 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2609 }
2610 else {
2611 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2612 err_code |= ERR_ALERT | ERR_FATAL;
2613 goto out;
2614 }
2615
2616 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002617 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002618 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2619 }
2620 else if (*args[3]) {
2621 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2622 err_code |= ERR_ALERT | ERR_FATAL;
2623 goto out;
2624 }
2625 }
2626 }
2627 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2628 if (*(args[1]) == 0) {
2629 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2630 err_code |= ERR_ALERT | ERR_FATAL;
2631 goto out;
2632 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002633 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2634 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002635 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2636 err_code |= ERR_ALERT | ERR_FATAL;
2637 goto out;
2638 }
2639 }
2640 else if (strcmp(args[0], "unique-id-format") == 0) {
2641 if (!*(args[1])) {
2642 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2643 err_code |= ERR_ALERT | ERR_FATAL;
2644 goto out;
2645 }
2646 if (*(args[2])) {
2647 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2648 err_code |= ERR_ALERT | ERR_FATAL;
2649 goto out;
2650 }
2651 free(curproxy->conf.uniqueid_format_string);
2652 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002653 if (!curproxy->conf.uniqueid_format_string)
2654 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002655
2656 free(curproxy->conf.uif_file);
2657 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2658 curproxy->conf.uif_line = curproxy->conf.args.line;
2659 }
2660
2661 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002662 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002663 if (!*(args[1])) {
2664 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2665 err_code |= ERR_ALERT | ERR_FATAL;
2666 goto out;
2667 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002668 copy = strdup(args[1]);
2669 if (copy == NULL) {
2670 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2671 err_code |= ERR_ALERT | ERR_FATAL;
2672 goto out;
2673 }
2674
2675 istfree(&curproxy->header_unique_id);
2676 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002677 }
2678
2679 else if (strcmp(args[0], "log-format") == 0) {
2680 if (!*(args[1])) {
2681 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2682 err_code |= ERR_ALERT | ERR_FATAL;
2683 goto out;
2684 }
2685 if (*(args[2])) {
2686 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2687 err_code |= ERR_ALERT | ERR_FATAL;
2688 goto out;
2689 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002690 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002691 char *oldlogformat = "log-format";
2692
2693 if (curproxy->conf.logformat_string == default_http_log_format)
2694 oldlogformat = "option httplog";
2695 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2696 oldlogformat = "option tcplog";
2697 else if (curproxy->conf.logformat_string == clf_http_log_format)
2698 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002699 else if (curproxy->conf.logformat_string == default_https_log_format)
2700 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002701 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2702 file, linenum, oldlogformat);
2703 }
2704 if (curproxy->conf.logformat_string != default_http_log_format &&
2705 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002706 curproxy->conf.logformat_string != clf_http_log_format &&
2707 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002708 free(curproxy->conf.logformat_string);
2709 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002710 if (!curproxy->conf.logformat_string)
2711 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002712
2713 free(curproxy->conf.lfs_file);
2714 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2715 curproxy->conf.lfs_line = curproxy->conf.args.line;
2716
2717 /* get a chance to improve log-format error reporting by
2718 * reporting the correct line-number when possible.
2719 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002720 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002721 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2722 file, linenum, curproxy->id);
2723 err_code |= ERR_WARN;
2724 }
2725 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002726 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002727 if (!*(args[1])) {
2728 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2729 err_code |= ERR_ALERT | ERR_FATAL;
2730 goto out;
2731 }
2732 if (*(args[2])) {
2733 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2734 err_code |= ERR_ALERT | ERR_FATAL;
2735 goto out;
2736 }
2737
2738 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2739 free(curproxy->conf.logformat_sd_string);
2740 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002741 if (!curproxy->conf.logformat_sd_string)
2742 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002743
2744 free(curproxy->conf.lfsd_file);
2745 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2746 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2747
2748 /* get a chance to improve log-format-sd error reporting by
2749 * reporting the correct line-number when possible.
2750 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002751 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002752 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2753 file, linenum, curproxy->id);
2754 err_code |= ERR_WARN;
2755 }
2756 }
Remi Tricot-Le Bretonfe21fe72021-08-31 12:08:52 +02002757 else if (strcmp(args[0], "error-log-format") == 0) {
2758 if (!*(args[1])) {
2759 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2760 err_code |= ERR_ALERT | ERR_FATAL;
2761 goto out;
2762 }
2763 if (*(args[2])) {
2764 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2765 err_code |= ERR_ALERT | ERR_FATAL;
2766 goto out;
2767 }
2768 if (curproxy->conf.error_logformat_string && curproxy->cap & PR_CAP_DEF) {
2769 ha_warning("parsing [%s:%d]: 'error-log-format' overrides previous 'error-log-format' in 'defaults' section.\n",
2770 file, linenum);
2771 }
2772 free(curproxy->conf.error_logformat_string);
2773 curproxy->conf.error_logformat_string = strdup(args[1]);
2774 if (!curproxy->conf.error_logformat_string)
2775 goto alloc_error;
2776
2777 free(curproxy->conf.elfs_file);
2778 curproxy->conf.elfs_file = strdup(curproxy->conf.args.file);
2779 curproxy->conf.elfs_line = curproxy->conf.args.line;
2780
2781 /* get a chance to improve log-format error reporting by
2782 * reporting the correct line-number when possible.
2783 */
2784 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2785 ha_warning("parsing [%s:%d] : backend '%s' : 'error-log-format' directive is ignored in backends.\n",
2786 file, linenum, curproxy->id);
2787 err_code |= ERR_WARN;
2788 }
2789 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002790 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002791 if (*(args[1]) == 0) {
2792 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2793 err_code |= ERR_ALERT | ERR_FATAL;
2794 goto out;
2795 }
2796 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002797 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2798 if (b_orig(&curproxy->log_tag) == NULL) {
2799 chunk_destroy(&curproxy->log_tag);
2800 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2801 err_code |= ERR_ALERT | ERR_FATAL;
2802 goto out;
2803 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002804 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002805 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002806 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002807 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2808 err_code |= ERR_ALERT | ERR_FATAL;
2809 goto out;
2810 }
2811 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002812 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002813 int cur_arg;
2814 int port1, port2;
2815 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002816
2817 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2818 err_code |= ERR_WARN;
2819
2820 if (!*args[1]) {
2821 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2822 file, linenum, "source", "usesrc", "interface");
2823 err_code |= ERR_ALERT | ERR_FATAL;
2824 goto out;
2825 }
2826
Christopher Faulet31930372019-07-15 10:16:58 +02002827 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002828 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002829 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002830 curproxy->conn_src.iface_len = 0;
2831
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002832 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2833 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002834 if (!sk) {
2835 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2836 file, linenum, args[0], args[1], errmsg);
2837 err_code |= ERR_ALERT | ERR_FATAL;
2838 goto out;
2839 }
2840
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002841 curproxy->conn_src.source_addr = *sk;
2842 curproxy->conn_src.opts |= CO_SRC_BIND;
2843
2844 cur_arg = 2;
2845 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002846 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002847#if defined(CONFIG_HAP_TRANSPARENT)
2848 if (!*args[cur_arg + 1]) {
2849 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2850 file, linenum, "usesrc");
2851 err_code |= ERR_ALERT | ERR_FATAL;
2852 goto out;
2853 }
2854
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002855 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002856 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2857 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002858 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002859 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2860 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2861 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2862 char *name, *end;
2863
2864 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002865 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002866 name++;
2867
2868 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002869 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002870 end++;
2871
2872 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2873 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002874 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002875 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002876 if (!curproxy->conn_src.bind_hdr_name)
2877 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002878 curproxy->conn_src.bind_hdr_len = end - name;
2879 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2880 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2881 curproxy->conn_src.bind_hdr_occ = -1;
2882
2883 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002884 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002885 end++;
2886 if (*end == ',') {
2887 end++;
2888 name = end;
2889 if (*end == '-')
2890 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002891 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002892 end++;
2893 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2894 }
2895
2896 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2897 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2898 " occurrences values smaller than %d.\n",
2899 file, linenum, MAX_HDR_HISTORY);
2900 err_code |= ERR_ALERT | ERR_FATAL;
2901 goto out;
2902 }
2903 } else {
2904 struct sockaddr_storage *sk;
2905
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002906 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2907 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002908 if (!sk) {
2909 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2910 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2911 err_code |= ERR_ALERT | ERR_FATAL;
2912 goto out;
2913 }
2914
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002915 curproxy->conn_src.tproxy_addr = *sk;
2916 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2917 }
2918 global.last_checks |= LSTCHK_NETADM;
2919#else /* no TPROXY support */
2920 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2921 file, linenum, "usesrc");
2922 err_code |= ERR_ALERT | ERR_FATAL;
2923 goto out;
2924#endif
2925 cur_arg += 2;
2926 continue;
2927 }
2928
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002929 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002930#ifdef SO_BINDTODEVICE
2931 if (!*args[cur_arg + 1]) {
2932 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2933 file, linenum, args[0]);
2934 err_code |= ERR_ALERT | ERR_FATAL;
2935 goto out;
2936 }
2937 free(curproxy->conn_src.iface_name);
2938 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002939 if (!curproxy->conn_src.iface_name)
2940 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002941 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2942 global.last_checks |= LSTCHK_NETADM;
2943#else
2944 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2945 file, linenum, args[0], args[cur_arg]);
2946 err_code |= ERR_ALERT | ERR_FATAL;
2947 goto out;
2948#endif
2949 cur_arg += 2;
2950 continue;
2951 }
2952 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2953 file, linenum, args[0], "interface", "usesrc");
2954 err_code |= ERR_ALERT | ERR_FATAL;
2955 goto out;
2956 }
2957 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002958 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002959 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2960 file, linenum, "usesrc", "source");
2961 err_code |= ERR_ALERT | ERR_FATAL;
2962 goto out;
2963 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002964 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 +02002965 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002966 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002967 file, linenum, args[0]);
2968 err_code |= ERR_ALERT | ERR_FATAL;
2969 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002970 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002971 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002972 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2973 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2974 err_code |= ERR_ALERT | ERR_FATAL;
2975 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002976 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002977 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002978 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2979 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2980 err_code |= ERR_ALERT | ERR_FATAL;
2981 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002982 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002983 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002984 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2985 err_code |= ERR_ALERT | ERR_FATAL;
2986 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002987 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002988 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002989 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2990 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2991 err_code |= ERR_ALERT | ERR_FATAL;
2992 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002993 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002994 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002995 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2996 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2997 err_code |= ERR_ALERT | ERR_FATAL;
2998 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002999 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003000 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003001 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3002 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3003 err_code |= ERR_ALERT | ERR_FATAL;
3004 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003005 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003006 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003007 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3008 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3009 err_code |= ERR_ALERT | ERR_FATAL;
3010 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003011 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003012 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 +02003013 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3014 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3015 err_code |= ERR_ALERT | ERR_FATAL;
3016 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003017 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003018 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003019 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3020 err_code |= ERR_ALERT | ERR_FATAL;
3021 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003022 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003023 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 +02003024 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3025 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3026 err_code |= ERR_ALERT | ERR_FATAL;
3027 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003028 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003029 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 +02003030 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3031 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3032 err_code |= ERR_ALERT | ERR_FATAL;
3033 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003034 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003035 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003036 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3037 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3038 err_code |= ERR_ALERT | ERR_FATAL;
3039 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003040 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003041 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 +02003042 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3043 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3044 err_code |= ERR_ALERT | ERR_FATAL;
3045 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003046 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003047 else if (strcmp(args[0], "rspdel") == 0) { /* delete response 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. "
3049 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3050 err_code |= ERR_ALERT | ERR_FATAL;
3051 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003052 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003053 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003054 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3055 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3056 err_code |= ERR_ALERT | ERR_FATAL;
3057 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003058 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003059 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303060 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003061 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3062 err_code |= ERR_ALERT | ERR_FATAL;
3063 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003064 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003065 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003066 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3067 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3068 err_code |= ERR_ALERT | ERR_FATAL;
3069 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003071 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003072 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3073 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3074 err_code |= ERR_ALERT | ERR_FATAL;
3075 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003076 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003077 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
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-response add-header' instead.\n", file, linenum, args[0]);
3080 err_code |= ERR_ALERT | ERR_FATAL;
3081 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003082 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003083 else {
3084 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003085 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003086 int index;
3087
3088 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3089 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3090 if (kwl->kw[index].section != CFG_LISTEN)
3091 continue;
3092 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003093 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003094 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003095 err_code |= ERR_ALERT | ERR_FATAL;
3096 goto out;
3097 }
3098
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003099 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003100 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003101 if (rc < 0) {
3102 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
3105 }
3106 else if (rc > 0) {
3107 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3108 err_code |= ERR_WARN;
3109 goto out;
3110 }
3111 goto out;
3112 }
3113 }
3114 }
3115
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003116 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3117 if (best)
3118 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3119 else
3120 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003121 err_code |= ERR_ALERT | ERR_FATAL;
3122 goto out;
3123 }
3124 out:
3125 free(errmsg);
3126 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003127
3128 alloc_error:
3129 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3130 err_code |= ERR_ALERT | ERR_ABORT;
3131 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003132}