blob: 5b494337dfc26553621ba8d89e3a6975943f0499 [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",
52 "fullconn", "grace", "dispatch", "balance", "hash-type",
53 "hash-balance-factor", "unique-id-format", "unique-id-header",
54 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
55 NULL /* must be last */
56};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010057
Willy Tarreau31a3cea2021-03-15 11:11:55 +010058static const char *common_options[] = {
59 "httpclose", "forceclose", "http-server-close", "http-keep-alive",
60 "http-tunnel", "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
61 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
62 "mysql-check", "ldap-check", "spop-check", "tcp-check",
63 "external-check", "forwardfor", "original-to",
64 NULL /* must be last */
65};
66
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010067/* Report a warning if a rule is placed after a 'tcp-request session' rule.
68 * Return 1 if the warning has been emitted, otherwise 0.
69 */
70int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
71{
72 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
73 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
74 file, line, arg);
75 return 1;
76 }
77 return 0;
78}
79
80/* Report a warning if a rule is placed after a 'tcp-request content' rule.
81 * Return 1 if the warning has been emitted, otherwise 0.
82 */
83int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
84{
85 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
86 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
87 file, line, arg);
88 return 1;
89 }
90 return 0;
91}
92
93/* Report a warning if a rule is placed after a 'monitor fail' rule.
94 * Return 1 if the warning has been emitted, otherwise 0.
95 */
96int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
97{
98 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
99 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
100 file, line, arg);
101 return 1;
102 }
103 return 0;
104}
105
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100106/* Report a warning if a rule is placed after an 'http_request' rule.
107 * Return 1 if the warning has been emitted, otherwise 0.
108 */
109int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
110{
111 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
112 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
113 file, line, arg);
114 return 1;
115 }
116 return 0;
117}
118
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100119/* Report a warning if a rule is placed after a redirect rule.
120 * Return 1 if the warning has been emitted, otherwise 0.
121 */
122int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
123{
124 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
125 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
126 file, line, arg);
127 return 1;
128 }
129 return 0;
130}
131
132/* Report a warning if a rule is placed after a 'use_backend' rule.
133 * Return 1 if the warning has been emitted, otherwise 0.
134 */
135int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
136{
137 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
138 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
139 file, line, arg);
140 return 1;
141 }
142 return 0;
143}
144
145/* Report a warning if a rule is placed after a 'use-server' rule.
146 * Return 1 if the warning has been emitted, otherwise 0.
147 */
148int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
149{
150 if (!LIST_ISEMPTY(&proxy->server_rules)) {
151 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
152 file, line, arg);
153 return 1;
154 }
155 return 0;
156}
157
158/* report a warning if a redirect rule is dangerously placed */
159int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
160{
161 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
162 warnif_rule_after_use_server(proxy, file, line, arg);
163}
164
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100165/* report a warning if an http-request rule is dangerously placed */
166int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
167{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200168 return warnif_rule_after_redirect(proxy, file, line, arg) ||
169 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100170}
171
172/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200173int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100174{
175 return warnif_rule_after_http_req(proxy, file, line, arg) ||
176 warnif_misplaced_http_req(proxy, file, line, arg);
177}
178
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100179/* report a warning if a "tcp request content" rule is dangerously placed */
180int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
181{
182 return warnif_rule_after_monitor(proxy, file, line, arg) ||
183 warnif_misplaced_monitor(proxy, file, line, arg);
184}
185
186/* report a warning if a "tcp request session" rule is dangerously placed */
187int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
188{
189 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
190 warnif_misplaced_tcp_cont(proxy, file, line, arg);
191}
192
193/* report a warning if a "tcp request connection" rule is dangerously placed */
194int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
195{
196 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
197 warnif_misplaced_tcp_sess(proxy, file, line, arg);
198}
199
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100200int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
201{
202 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100203 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100204 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100205 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100206 int rc;
207 unsigned val;
208 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;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200597 curproxy->disabled = 1;
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 Tarreauff9c9142019-02-07 10:39:36 +0100613 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, 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 }
620 curproxy->bind_proc = set;
621 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100622 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100623 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100624 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
625 err_code |= ERR_ALERT | ERR_FATAL;
626 goto out;
627 }
628
629 err = invalid_char(args[1]);
630 if (err) {
631 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
632 file, linenum, *err, args[1]);
633 err_code |= ERR_ALERT | ERR_FATAL;
634 goto out;
635 }
636
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100637 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100638 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100639 "logical disjunction within a condition.\n",
640 file, linenum, args[1]);
641 err_code |= ERR_ALERT | ERR_FATAL;
642 goto out;
643 }
644
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100645 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
646 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
647 file, linenum, args[1], errmsg);
648 err_code |= ERR_ALERT | ERR_FATAL;
649 goto out;
650 }
651 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100652 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100653
654 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
655 err_code |= ERR_WARN;
656
657 if (*(args[1]) == 0) {
658 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
659 file, linenum, args[0]);
660 err_code |= ERR_ALERT | ERR_FATAL;
661 goto out;
662 }
663 free(curproxy->dyncookie_key);
664 curproxy->dyncookie_key = strdup(args[1]);
665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100666 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100667 int cur_arg;
668
669 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
670 err_code |= ERR_WARN;
671
672 if (*(args[1]) == 0) {
673 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
674 file, linenum, args[0]);
675 err_code |= ERR_ALERT | ERR_FATAL;
676 goto out;
677 }
678
679 curproxy->ck_opts = 0;
680 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100681 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100682 free(curproxy->cookie_name);
683 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200684 if (!curproxy->cookie_name)
685 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100686 curproxy->cookie_len = strlen(curproxy->cookie_name);
687
688 cur_arg = 2;
689 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100690 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100691 curproxy->ck_opts |= PR_CK_RW;
692 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100693 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100694 curproxy->ck_opts |= PR_CK_IND;
695 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100696 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100697 curproxy->ck_opts |= PR_CK_INS;
698 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100699 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100700 curproxy->ck_opts |= PR_CK_NOC;
701 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100702 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100703 curproxy->ck_opts |= PR_CK_POST;
704 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100705 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100706 curproxy->ck_opts |= PR_CK_PSV;
707 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100708 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100709 curproxy->ck_opts |= PR_CK_PFX;
710 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100711 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100712 curproxy->ck_opts |= PR_CK_HTTPONLY;
713 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100714 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100715 curproxy->ck_opts |= PR_CK_SECURE;
716 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100717 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100718 if (!*args[cur_arg + 1]) {
719 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
720 file, linenum, args[cur_arg]);
721 err_code |= ERR_ALERT | ERR_FATAL;
722 goto out;
723 }
724
Joao Moraise1583752019-10-30 21:04:00 -0300725 if (!strchr(args[cur_arg + 1], '.')) {
726 /* rfc6265, 5.2.3 The Domain Attribute */
727 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
728 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100729 file, linenum, args[cur_arg + 1]);
730 err_code |= ERR_WARN;
731 }
732
733 err = invalid_domainchar(args[cur_arg + 1]);
734 if (err) {
735 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
736 file, linenum, *err, args[cur_arg + 1]);
737 err_code |= ERR_ALERT | ERR_FATAL;
738 goto out;
739 }
740
741 if (!curproxy->cookie_domain) {
742 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
743 } else {
744 /* one domain was already specified, add another one by
745 * building the string which will be returned along with
746 * the cookie.
747 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200748 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
749 }
750
Christopher Fauletb15625a2021-04-12 21:31:45 +0200751 if (!curproxy->cookie_domain)
752 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100753 cur_arg++;
754 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100755 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100756 unsigned int maxidle;
757 const char *res;
758
759 if (!*args[cur_arg + 1]) {
760 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
761 file, linenum, args[cur_arg]);
762 err_code |= ERR_ALERT | ERR_FATAL;
763 goto out;
764 }
765
766 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200767 if (res == PARSE_TIME_OVER) {
768 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
769 file, linenum, args[cur_arg+1], args[cur_arg]);
770 err_code |= ERR_ALERT | ERR_FATAL;
771 goto out;
772 }
773 else if (res == PARSE_TIME_UNDER) {
774 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
775 file, linenum, args[cur_arg+1], args[cur_arg]);
776 err_code |= ERR_ALERT | ERR_FATAL;
777 goto out;
778 }
779 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100780 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
781 file, linenum, *res, args[cur_arg]);
782 err_code |= ERR_ALERT | ERR_FATAL;
783 goto out;
784 }
785 curproxy->cookie_maxidle = maxidle;
786 cur_arg++;
787 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100788 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100789 unsigned int maxlife;
790 const char *res;
791
792 if (!*args[cur_arg + 1]) {
793 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
794 file, linenum, args[cur_arg]);
795 err_code |= ERR_ALERT | ERR_FATAL;
796 goto out;
797 }
798
Willy Tarreau9faebe32019-06-07 19:00:37 +0200799
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100800 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200801 if (res == PARSE_TIME_OVER) {
802 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
803 file, linenum, args[cur_arg+1], args[cur_arg]);
804 err_code |= ERR_ALERT | ERR_FATAL;
805 goto out;
806 }
807 else if (res == PARSE_TIME_UNDER) {
808 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
809 file, linenum, args[cur_arg+1], args[cur_arg]);
810 err_code |= ERR_ALERT | ERR_FATAL;
811 goto out;
812 }
813 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100814 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
815 file, linenum, *res, args[cur_arg]);
816 err_code |= ERR_ALERT | ERR_FATAL;
817 goto out;
818 }
819 curproxy->cookie_maxlife = maxlife;
820 cur_arg++;
821 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100822 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100823
824 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
825 err_code |= ERR_WARN;
826 curproxy->ck_opts |= PR_CK_DYNAMIC;
827 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100828 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100829 char *val;
830 if (!*args[cur_arg + 1]) {
831 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
832 file, linenum, args[cur_arg]);
833 err_code |= ERR_ALERT | ERR_FATAL;
834 goto out;
835 }
836 val = args[cur_arg + 1];
837 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100838 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100839 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
840 file, linenum, *val);
841 err_code |= ERR_ALERT | ERR_FATAL;
842 goto out;
843 }
844 val++;
845 }
846 /* don't add ';' for the first attribute */
847 if (!curproxy->cookie_attrs)
848 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
849 else
850 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200851
Christopher Fauletb15625a2021-04-12 21:31:45 +0200852 if (!curproxy->cookie_attrs)
853 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100854 cur_arg++;
855 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100856
857 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100858 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 +0100859 file, linenum, args[0]);
860 err_code |= ERR_ALERT | ERR_FATAL;
861 goto out;
862 }
863 cur_arg++;
864 }
865 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
866 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
867 file, linenum);
868 err_code |= ERR_ALERT | ERR_FATAL;
869 }
870
871 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
872 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
873 file, linenum);
874 err_code |= ERR_ALERT | ERR_FATAL;
875 }
876
877 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
878 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
879 file, linenum);
880 err_code |= ERR_ALERT | ERR_FATAL;
881 }
882 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100883 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100884 if (*(args[1]) == 0) {
885 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
886 file, linenum, args[0]);
887 err_code |= ERR_ALERT | ERR_FATAL;
888 goto out;
889 }
890
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100891 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100892 if (*(args[1]) == 0) {
893 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
894 file, linenum, args[1]);
895 err_code |= ERR_ALERT | ERR_FATAL;
896 goto out;
897 }
898 free(curproxy->email_alert.from);
899 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200900 if (!curproxy->email_alert.from)
901 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100902 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100903 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100904 if (*(args[1]) == 0) {
905 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
906 file, linenum, args[1]);
907 err_code |= ERR_ALERT | ERR_FATAL;
908 goto out;
909 }
910 free(curproxy->email_alert.mailers.name);
911 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200912 if (!curproxy->email_alert.mailers.name)
913 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100914 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100915 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100916 if (*(args[1]) == 0) {
917 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
918 file, linenum, args[1]);
919 err_code |= ERR_ALERT | ERR_FATAL;
920 goto out;
921 }
922 free(curproxy->email_alert.myhostname);
923 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200924 if (!curproxy->email_alert.myhostname)
925 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100926 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100927 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100928 curproxy->email_alert.level = get_log_level(args[2]);
929 if (curproxy->email_alert.level < 0) {
930 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
931 file, linenum, args[1], args[2]);
932 err_code |= ERR_ALERT | ERR_FATAL;
933 goto out;
934 }
935 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100936 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100937 if (*(args[1]) == 0) {
938 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
939 file, linenum, args[1]);
940 err_code |= ERR_ALERT | ERR_FATAL;
941 goto out;
942 }
943 free(curproxy->email_alert.to);
944 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200945 if (!curproxy->email_alert.to)
946 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100947 }
948 else {
949 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
950 file, linenum, args[1]);
951 err_code |= ERR_ALERT | ERR_FATAL;
952 goto out;
953 }
954 /* Indicate that the email_alert is at least partially configured */
955 curproxy->email_alert.set = 1;
956 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100957 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100958 if (*(args[1]) == 0) {
959 ha_alert("parsing [%s:%d] : missing persist method.\n",
960 file, linenum);
961 err_code |= ERR_ALERT | ERR_FATAL;
962 goto out;
963 }
964
965 if (!strncmp(args[1], "rdp-cookie", 10)) {
966 curproxy->options2 |= PR_O2_RDPC_PRST;
967
968 if (*(args[1] + 10) == '(') { /* cookie name */
969 const char *beg, *end;
970
971 beg = args[1] + 11;
972 end = strchr(beg, ')');
973
974 if (alertif_too_many_args(1, file, linenum, args, &err_code))
975 goto out;
976
977 if (!end || end == beg) {
978 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
979 file, linenum);
980 err_code |= ERR_ALERT | ERR_FATAL;
981 goto out;
982 }
983
984 free(curproxy->rdp_cookie_name);
985 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200986 if (!curproxy->rdp_cookie_name)
987 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100988 curproxy->rdp_cookie_len = end-beg;
989 }
990 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
991 free(curproxy->rdp_cookie_name);
992 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +0200993 if (!curproxy->rdp_cookie_name)
994 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100995 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
996 }
997 else { /* syntax */
998 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
999 file, linenum);
1000 err_code |= ERR_ALERT | ERR_FATAL;
1001 goto out;
1002 }
1003 }
1004 else {
1005 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1006 file, linenum);
1007 err_code |= ERR_ALERT | ERR_FATAL;
1008 goto out;
1009 }
1010 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001011 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001012 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 +01001013 err_code |= ERR_ALERT | ERR_FATAL;
1014 goto out;
1015 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001016 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001017 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1018 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001019 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001020 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1021 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001022 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 +01001023 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1024 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001025 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001026 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1027 }
1028 else {
1029 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1030 file, linenum, args[0], args[1]);
1031 err_code |= ERR_ALERT | ERR_FATAL;
1032 goto out;
1033 }
1034 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001035 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001036 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1037 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001038 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001039 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001040
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001041 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001042
1043 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001044 curproxy->server_state_file_name = strdup(curproxy->id);
1045 else
1046 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001047
Christopher Fauletb15625a2021-04-12 21:31:45 +02001048 if (!curproxy->server_state_file_name)
1049 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001050 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001051 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001052 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1053 err_code |= ERR_WARN;
1054 if (*(args[1]) == 0) {
1055 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1056 file, linenum, args[0]);
1057 err_code |= ERR_ALERT | ERR_FATAL;
1058 goto out;
1059 }
1060 curproxy->max_out_conns = atoi(args[1]);
1061 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001062 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001063 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1064 err_code |= ERR_WARN;
1065
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001066 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001067 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001068 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1069 err_code |= ERR_ALERT | ERR_FATAL;
1070 goto out;
1071 }
1072
1073 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1074 goto out;
1075
1076 if (*(args[4]) == 0) {
1077 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1078 file, linenum, args[0]);
1079 err_code |= ERR_ALERT | ERR_FATAL;
1080 goto out;
1081 }
1082 free(curproxy->capture_name);
1083 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001084 if (!curproxy->capture_name)
1085 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001086 curproxy->capture_namelen = strlen(curproxy->capture_name);
1087 curproxy->capture_len = atol(args[4]);
1088 curproxy->to_log |= LW_COOKIE;
1089 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001090 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001091 struct cap_hdr *hdr;
1092
Willy Tarreau5d095c22021-02-12 10:15:59 +01001093 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001094 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1095 err_code |= ERR_ALERT | ERR_FATAL;
1096 goto out;
1097 }
1098
1099 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1100 goto out;
1101
1102 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1103 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1104 file, linenum, args[0], args[1]);
1105 err_code |= ERR_ALERT | ERR_FATAL;
1106 goto out;
1107 }
1108
1109 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001110 if (!hdr)
1111 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001112 hdr->next = curproxy->req_cap;
1113 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001114 if (!hdr->name)
1115 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001116 hdr->namelen = strlen(args[3]);
1117 hdr->len = atol(args[5]);
1118 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001119 if (!hdr->pool) {
1120 req_caphdr_alloc_error:
1121 if (hdr)
1122 ha_free(&hdr->name);
1123 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001124 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001125 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001126 hdr->index = curproxy->nb_req_cap++;
1127 curproxy->req_cap = hdr;
1128 curproxy->to_log |= LW_REQHDR;
1129 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001130 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001131 struct cap_hdr *hdr;
1132
Willy Tarreau5d095c22021-02-12 10:15:59 +01001133 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001134 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1135 err_code |= ERR_ALERT | ERR_FATAL;
1136 goto out;
1137 }
1138
1139 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1140 goto out;
1141
1142 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1143 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1144 file, linenum, args[0], args[1]);
1145 err_code |= ERR_ALERT | ERR_FATAL;
1146 goto out;
1147 }
1148 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001149 if (!hdr)
1150 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001151 hdr->next = curproxy->rsp_cap;
1152 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001153 if (!hdr->name)
1154 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001155 hdr->namelen = strlen(args[3]);
1156 hdr->len = atol(args[5]);
1157 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001158 if (!hdr->pool) {
1159 res_caphdr_alloc_error:
1160 if (hdr)
1161 ha_free(&hdr->name);
1162 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001163 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001164 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001165 hdr->index = curproxy->nb_rsp_cap++;
1166 curproxy->rsp_cap = hdr;
1167 curproxy->to_log |= LW_RSPHDR;
1168 }
1169 else {
1170 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1171 file, linenum, args[0]);
1172 err_code |= ERR_ALERT | ERR_FATAL;
1173 goto out;
1174 }
1175 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001176 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001177 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1178 err_code |= ERR_WARN;
1179
1180 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1181 goto out;
1182
1183 if (*(args[1]) == 0) {
1184 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1185 file, linenum, args[0]);
1186 err_code |= ERR_ALERT | ERR_FATAL;
1187 goto out;
1188 }
1189 curproxy->conn_retries = atol(args[1]);
1190 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001191 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001192 struct act_rule *rule;
1193
Willy Tarreau5d095c22021-02-12 10:15:59 +01001194 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001195 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1196 err_code |= ERR_ALERT | ERR_FATAL;
1197 goto out;
1198 }
1199
1200 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1201 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001202 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001203 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1204 file, linenum, args[0]);
1205 err_code |= ERR_WARN;
1206 }
1207
1208 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1209
1210 if (!rule) {
1211 err_code |= ERR_ALERT | ERR_ABORT;
1212 goto out;
1213 }
1214
1215 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1216 err_code |= warnif_cond_conflicts(rule->cond,
1217 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1218 file, linenum);
1219
Willy Tarreau2b718102021-04-21 07:32:39 +02001220 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001221 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001222 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001223 struct act_rule *rule;
1224
Willy Tarreau5d095c22021-02-12 10:15:59 +01001225 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001226 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1227 err_code |= ERR_ALERT | ERR_FATAL;
1228 goto out;
1229 }
1230
1231 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1232 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001233 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001234 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1235 file, linenum, args[0]);
1236 err_code |= ERR_WARN;
1237 }
1238
1239 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1240
1241 if (!rule) {
1242 err_code |= ERR_ALERT | ERR_ABORT;
1243 goto out;
1244 }
1245
1246 err_code |= warnif_cond_conflicts(rule->cond,
1247 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1248 file, linenum);
1249
Willy Tarreau2b718102021-04-21 07:32:39 +02001250 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001251 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001252 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001253 struct act_rule *rule;
1254
Willy Tarreau5d095c22021-02-12 10:15:59 +01001255 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001256 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1257 err_code |= ERR_ALERT | ERR_FATAL;
1258 goto out;
1259 }
1260
1261 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1262 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1263 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1264 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1265 file, linenum, args[0]);
1266 err_code |= ERR_WARN;
1267 }
1268
1269 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1270
1271 if (!rule) {
1272 err_code |= ERR_ALERT | ERR_ABORT;
1273 goto out;
1274 }
1275
1276 err_code |= warnif_cond_conflicts(rule->cond,
1277 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1278 file, linenum);
1279
Willy Tarreau2b718102021-04-21 07:32:39 +02001280 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001281 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001282 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001283 /* set the header name and length into the proxy structure */
1284 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1285 err_code |= ERR_WARN;
1286
1287 if (!*args[1]) {
1288 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1289 file, linenum, args[0]);
1290 err_code |= ERR_ALERT | ERR_FATAL;
1291 goto out;
1292 }
1293
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001294 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001295 free(curproxy->server_id_hdr_name);
1296 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001297 if (!curproxy->server_id_hdr_name)
1298 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001299 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001300 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 +01001301 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001302 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001303 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 +01001304
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001305 err_code |= ERR_ALERT | ERR_FATAL;
1306 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001307 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001308 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001309 struct redirect_rule *rule;
1310
Willy Tarreau5d095c22021-02-12 10:15:59 +01001311 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001312 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1313 err_code |= ERR_ALERT | ERR_FATAL;
1314 goto out;
1315 }
1316
1317 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1318 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1319 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1320 err_code |= ERR_ALERT | ERR_FATAL;
1321 goto out;
1322 }
1323
Willy Tarreau2b718102021-04-21 07:32:39 +02001324 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001325 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1326 err_code |= warnif_cond_conflicts(rule->cond,
1327 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1328 file, linenum);
1329 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001330 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001331 struct switching_rule *rule;
1332
Willy Tarreau5d095c22021-02-12 10:15:59 +01001333 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001334 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1335 err_code |= ERR_ALERT | ERR_FATAL;
1336 goto out;
1337 }
1338
1339 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1340 err_code |= ERR_WARN;
1341
1342 if (*(args[1]) == 0) {
1343 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1344 err_code |= ERR_ALERT | ERR_FATAL;
1345 goto out;
1346 }
1347
1348 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1349 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1350 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1351 file, linenum, errmsg);
1352 err_code |= ERR_ALERT | ERR_FATAL;
1353 goto out;
1354 }
1355
1356 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1357 }
1358 else if (*args[2]) {
1359 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1360 file, linenum, args[2]);
1361 err_code |= ERR_ALERT | ERR_FATAL;
1362 goto out;
1363 }
1364
1365 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001366 if (!rule)
1367 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001368 rule->cond = cond;
1369 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001370 if (!rule->be.name)
1371 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001372 rule->line = linenum;
1373 rule->file = strdup(file);
1374 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001375 use_backend_alloc_error:
1376 if (cond)
1377 prune_acl_cond(cond);
1378 ha_free(&cond);
1379 if (rule)
1380 ha_free(&(rule->be.name));
1381 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001382 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001383 }
1384 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001385 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001386 }
1387 else if (strcmp(args[0], "use-server") == 0) {
1388 struct server_rule *rule;
1389
Willy Tarreau5d095c22021-02-12 10:15:59 +01001390 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001391 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1392 err_code |= ERR_ALERT | ERR_FATAL;
1393 goto out;
1394 }
1395
1396 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1397 err_code |= ERR_WARN;
1398
1399 if (*(args[1]) == 0) {
1400 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1401 err_code |= ERR_ALERT | ERR_FATAL;
1402 goto out;
1403 }
1404
1405 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1406 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1407 file, linenum, args[0]);
1408 err_code |= ERR_ALERT | ERR_FATAL;
1409 goto out;
1410 }
1411
1412 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1413 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1414 file, linenum, errmsg);
1415 err_code |= ERR_ALERT | ERR_FATAL;
1416 goto out;
1417 }
1418
1419 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1420
1421 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001422 if (!rule)
1423 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001424 rule->cond = cond;
1425 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001426 if (!rule->srv.name)
1427 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001428 rule->line = linenum;
1429 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001430 if (!rule->file) {
1431 use_server_alloc_error:
1432 if (cond)
1433 prune_acl_cond(cond);
1434 ha_free(&cond);
1435 if (rule)
1436 ha_free(&(rule->srv.name));
1437 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001438 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001439 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001440 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001441 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001442 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1443 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001444 else if ((strcmp(args[0], "force-persist") == 0) ||
1445 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001446 struct persist_rule *rule;
1447
Willy Tarreau5d095c22021-02-12 10:15:59 +01001448 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001449 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1450 err_code |= ERR_ALERT | ERR_FATAL;
1451 goto out;
1452 }
1453
1454 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1455 err_code |= ERR_WARN;
1456
1457 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1458 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1459 file, linenum, args[0]);
1460 err_code |= ERR_ALERT | ERR_FATAL;
1461 goto out;
1462 }
1463
1464 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1465 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1466 file, linenum, args[0], errmsg);
1467 err_code |= ERR_ALERT | ERR_FATAL;
1468 goto out;
1469 }
1470
1471 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1472 * where force-persist is applied.
1473 */
1474 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1475
1476 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001477 if (!rule) {
1478 if (cond)
1479 prune_acl_cond(cond);
1480 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001481 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001482 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001483 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001484 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001485 rule->type = PERSIST_TYPE_FORCE;
1486 } else {
1487 rule->type = PERSIST_TYPE_IGNORE;
1488 }
1489 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001490 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001491 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001492 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001493 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001494
Willy Tarreau5d095c22021-02-12 10:15:59 +01001495 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001496 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1497 file, linenum);
1498 err_code |= ERR_ALERT | ERR_FATAL;
1499 goto out;
1500 }
1501
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001502 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001503 if (other) {
1504 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 +01001505 file, linenum, curproxy->id,
1506 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1507 other->proxy ? other->id : other->peers.p->id,
1508 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001509 err_code |= ERR_ALERT | ERR_FATAL;
1510 goto out;
1511 }
1512
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001513 curproxy->table = calloc(1, sizeof *curproxy->table);
1514 if (!curproxy->table) {
1515 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1516 file, linenum, args[0], args[1]);
1517 err_code |= ERR_ALERT | ERR_FATAL;
1518 goto out;
1519 }
1520
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001521 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1522 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001523 if (err_code & ERR_FATAL) {
1524 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001525 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001526 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001527
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001528 /* Store the proxy in the stick-table. */
1529 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001530
1531 stktable_store_name(curproxy->table);
1532 curproxy->table->next = stktables_list;
1533 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001534
1535 /* Add this proxy to the list of proxies which refer to its stick-table. */
1536 if (curproxy->table->proxies_list != curproxy) {
1537 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1538 curproxy->table->proxies_list = curproxy;
1539 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001540 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001541 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001542 struct sticking_rule *rule;
1543 struct sample_expr *expr;
1544 int myidx = 0;
1545 const char *name = NULL;
1546 int flags;
1547
Willy Tarreau5d095c22021-02-12 10:15:59 +01001548 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001549 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1550 err_code |= ERR_ALERT | ERR_FATAL;
1551 goto out;
1552 }
1553
1554 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1555 err_code |= ERR_WARN;
1556 goto out;
1557 }
1558
1559 myidx++;
1560 if ((strcmp(args[myidx], "store") == 0) ||
1561 (strcmp(args[myidx], "store-request") == 0)) {
1562 myidx++;
1563 flags = STK_IS_STORE;
1564 }
1565 else if (strcmp(args[myidx], "store-response") == 0) {
1566 myidx++;
1567 flags = STK_IS_STORE | STK_ON_RSP;
1568 }
1569 else if (strcmp(args[myidx], "match") == 0) {
1570 myidx++;
1571 flags = STK_IS_MATCH;
1572 }
1573 else if (strcmp(args[myidx], "on") == 0) {
1574 myidx++;
1575 flags = STK_IS_MATCH | STK_IS_STORE;
1576 }
1577 else {
1578 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1579 err_code |= ERR_ALERT | ERR_FATAL;
1580 goto out;
1581 }
1582
1583 if (*(args[myidx]) == 0) {
1584 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1585 err_code |= ERR_ALERT | ERR_FATAL;
1586 goto out;
1587 }
1588
1589 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001590 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001591 if (!expr) {
1592 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1593 err_code |= ERR_ALERT | ERR_FATAL;
1594 goto out;
1595 }
1596
1597 if (flags & STK_ON_RSP) {
1598 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1599 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1600 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1601 err_code |= ERR_ALERT | ERR_FATAL;
1602 free(expr);
1603 goto out;
1604 }
1605 } else {
1606 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1607 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1608 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1609 err_code |= ERR_ALERT | ERR_FATAL;
1610 free(expr);
1611 goto out;
1612 }
1613 }
1614
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001615 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001616 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1617
1618 if (strcmp(args[myidx], "table") == 0) {
1619 myidx++;
1620 name = args[myidx++];
1621 }
1622
1623 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1624 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1625 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1626 file, linenum, args[0], errmsg);
1627 err_code |= ERR_ALERT | ERR_FATAL;
1628 free(expr);
1629 goto out;
1630 }
1631 }
1632 else if (*(args[myidx])) {
1633 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1634 file, linenum, args[0], args[myidx]);
1635 err_code |= ERR_ALERT | ERR_FATAL;
1636 free(expr);
1637 goto out;
1638 }
1639 if (flags & STK_ON_RSP)
1640 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1641 else
1642 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1643
1644 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001645 if (!rule) {
1646 if (cond)
1647 prune_acl_cond(cond);
1648 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001649 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001650 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001651 rule->cond = cond;
1652 rule->expr = expr;
1653 rule->flags = flags;
1654 rule->table.name = name ? strdup(name) : NULL;
1655 LIST_INIT(&rule->list);
1656 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001657 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001658 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001659 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001660 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001661 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001662 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001663 curproxy->uri_auth = NULL; /* we must detach from the default config */
1664
1665 if (!*args[1]) {
1666 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001667 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001668 struct stats_admin_rule *rule;
1669
Willy Tarreau5d095c22021-02-12 10:15:59 +01001670 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001671 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1672 err_code |= ERR_ALERT | ERR_FATAL;
1673 goto out;
1674 }
1675
Christopher Fauletb15625a2021-04-12 21:31:45 +02001676 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1677 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001678
1679 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1680 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1681 file, linenum, args[0], args[1]);
1682 err_code |= ERR_ALERT | ERR_FATAL;
1683 goto out;
1684 }
1685 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1686 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1687 file, linenum, args[0], args[1], errmsg);
1688 err_code |= ERR_ALERT | ERR_FATAL;
1689 goto out;
1690 }
1691
1692 err_code |= warnif_cond_conflicts(cond,
1693 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1694 file, linenum);
1695
1696 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001697 if (!rule) {
1698 if (cond)
1699 prune_acl_cond(cond);
1700 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001701 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001702 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001703 rule->cond = cond;
1704 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001705 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001706 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001707 if (*(args[2]) == 0) {
1708 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1709 err_code |= ERR_ALERT | ERR_FATAL;
1710 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001711 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1712 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001713 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001714 if (*(args[2]) == 0) {
1715 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1716 err_code |= ERR_ALERT | ERR_FATAL;
1717 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001718 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1719 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001720 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001721 unsigned interval;
1722
1723 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001724 if (err == PARSE_TIME_OVER) {
1725 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1726 file, linenum, args[2]);
1727 err_code |= ERR_ALERT | ERR_FATAL;
1728 goto out;
1729 }
1730 else if (err == PARSE_TIME_UNDER) {
1731 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1732 file, linenum, args[2]);
1733 err_code |= ERR_ALERT | ERR_FATAL;
1734 goto out;
1735 }
1736 else if (err) {
1737 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001738 file, linenum, *err);
1739 err_code |= ERR_ALERT | ERR_FATAL;
1740 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001741 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1742 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001743 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001744 struct act_rule *rule;
1745
Willy Tarreau5d095c22021-02-12 10:15:59 +01001746 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001747 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1748 err_code |= ERR_ALERT | ERR_FATAL;
1749 goto out;
1750 }
1751
Christopher Fauletb15625a2021-04-12 21:31:45 +02001752 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1753 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001754
1755 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1756 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1757 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1758 file, linenum, args[0]);
1759 err_code |= ERR_WARN;
1760 }
1761
1762 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1763
1764 if (!rule) {
1765 err_code |= ERR_ALERT | ERR_ABORT;
1766 goto out;
1767 }
1768
1769 err_code |= warnif_cond_conflicts(rule->cond,
1770 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1771 file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001772 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001773
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001774 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001775 if (*(args[2]) == 0) {
1776 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1777 err_code |= ERR_ALERT | ERR_FATAL;
1778 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001779 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1780 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001781 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001782 if (*(args[2]) == 0) {
1783 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1784 err_code |= ERR_ALERT | ERR_FATAL;
1785 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001786 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1787 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001788 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001789 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1790 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001791 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001792 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1793 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001794 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001795 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1796 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001797 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001798 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1799 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001800 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001801
1802 if (*args[2]) {
1803 int i;
1804 char c;
1805
1806 for (i=0; args[2][i]; i++) {
1807 c = args[2][i];
1808 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1809 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1810 break;
1811 }
1812
1813 if (!i || args[2][i]) {
1814 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1815 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1816 file, linenum, args[0], args[1]);
1817 err_code |= ERR_ALERT | ERR_FATAL;
1818 goto out;
1819 }
1820 }
1821
Christopher Fauletb15625a2021-04-12 21:31:45 +02001822 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1823 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001824 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001825 char *desc = NULL;
1826
1827 if (*args[2]) {
1828 int i, len=0;
1829 char *d;
1830
1831 for (i = 2; *args[i]; i++)
1832 len += strlen(args[i]) + 1;
1833
1834 desc = d = calloc(1, len);
1835
1836 d += snprintf(d, desc + len - d, "%s", args[2]);
1837 for (i = 3; *args[i]; i++)
1838 d += snprintf(d, desc + len - d, " %s", args[i]);
1839 }
1840
1841 if (!*args[2] && !global.desc)
1842 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1843 file, linenum, args[1]);
1844 else {
1845 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1846 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001847 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001848 }
1849 free(desc);
1850 }
1851 } else {
1852stats_error_parsing:
1853 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1854 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1855 err_code |= ERR_ALERT | ERR_FATAL;
1856 goto out;
1857 }
1858 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001859 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001860 int optnum;
1861
1862 if (*(args[1]) == '\0') {
1863 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1864 file, linenum, args[0]);
1865 err_code |= ERR_ALERT | ERR_FATAL;
1866 goto out;
1867 }
1868
1869 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001870 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001871 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1872 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1873 file, linenum, cfg_opts[optnum].name);
1874 err_code |= ERR_ALERT | ERR_FATAL;
1875 goto out;
1876 }
1877 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1878 goto out;
1879
1880 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1881 err_code |= ERR_WARN;
1882 goto out;
1883 }
1884
1885 curproxy->no_options &= ~cfg_opts[optnum].val;
1886 curproxy->options &= ~cfg_opts[optnum].val;
1887
1888 switch (kwm) {
1889 case KWM_STD:
1890 curproxy->options |= cfg_opts[optnum].val;
1891 break;
1892 case KWM_NO:
1893 curproxy->no_options |= cfg_opts[optnum].val;
1894 break;
1895 case KWM_DEF: /* already cleared */
1896 break;
1897 }
1898
1899 goto out;
1900 }
1901 }
1902
1903 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001904 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001905 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1906 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1907 file, linenum, cfg_opts2[optnum].name);
1908 err_code |= ERR_ALERT | ERR_FATAL;
1909 goto out;
1910 }
1911 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1912 goto out;
1913 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1914 err_code |= ERR_WARN;
1915 goto out;
1916 }
1917
Christopher Faulet31930372019-07-15 10:16:58 +02001918 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001919 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001920 if (kwm ==KWM_NO) {
1921 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1922 " The HTX mode is now the only supported mode.\n",
1923 file, linenum, cfg_opts2[optnum].name);
1924 err_code |= ERR_WARN;
1925 }
Christopher Faulet31930372019-07-15 10:16:58 +02001926 goto out;
1927 }
1928
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001929 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1930 curproxy->options2 &= ~cfg_opts2[optnum].val;
1931
1932 switch (kwm) {
1933 case KWM_STD:
1934 curproxy->options2 |= cfg_opts2[optnum].val;
1935 break;
1936 case KWM_NO:
1937 curproxy->no_options2 |= cfg_opts2[optnum].val;
1938 break;
1939 case KWM_DEF: /* already cleared */
1940 break;
1941 }
1942 goto out;
1943 }
1944 }
1945
1946 /* HTTP options override each other. They can be cancelled using
1947 * "no option xxx" which only switches to default mode if the mode
1948 * was this one (useful for cancelling options set in defaults
1949 * sections).
1950 */
1951 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001952 if (strcmp(args[1], "forceclose") == 0) {
1953 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1954 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1955 file, linenum, args[1]);
1956 err_code |= ERR_WARN;
1957 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001958 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1959 goto out;
1960 if (kwm == KWM_STD) {
1961 curproxy->options &= ~PR_O_HTTP_MODE;
1962 curproxy->options |= PR_O_HTTP_CLO;
1963 goto out;
1964 }
1965 else if (kwm == KWM_NO) {
1966 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1967 curproxy->options &= ~PR_O_HTTP_MODE;
1968 goto out;
1969 }
1970 }
1971 else if (strcmp(args[1], "http-server-close") == 0) {
1972 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1973 goto out;
1974 if (kwm == KWM_STD) {
1975 curproxy->options &= ~PR_O_HTTP_MODE;
1976 curproxy->options |= PR_O_HTTP_SCL;
1977 goto out;
1978 }
1979 else if (kwm == KWM_NO) {
1980 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1981 curproxy->options &= ~PR_O_HTTP_MODE;
1982 goto out;
1983 }
1984 }
1985 else if (strcmp(args[1], "http-keep-alive") == 0) {
1986 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1987 goto out;
1988 if (kwm == KWM_STD) {
1989 curproxy->options &= ~PR_O_HTTP_MODE;
1990 curproxy->options |= PR_O_HTTP_KAL;
1991 goto out;
1992 }
1993 else if (kwm == KWM_NO) {
1994 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1995 curproxy->options &= ~PR_O_HTTP_MODE;
1996 goto out;
1997 }
1998 }
1999 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002000 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2001 file, linenum, args[1]);
2002 err_code |= ERR_WARN;
2003 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002004 }
2005
2006 /* Redispatch can take an integer argument that control when the
2007 * resispatch occurs. All values are relative to the retries option.
2008 * This can be cancelled using "no option xxx".
2009 */
2010 if (strcmp(args[1], "redispatch") == 0) {
2011 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2012 err_code |= ERR_WARN;
2013 goto out;
2014 }
2015
2016 curproxy->no_options &= ~PR_O_REDISP;
2017 curproxy->options &= ~PR_O_REDISP;
2018
2019 switch (kwm) {
2020 case KWM_STD:
2021 curproxy->options |= PR_O_REDISP;
2022 curproxy->redispatch_after = -1;
2023 if(*args[2]) {
2024 curproxy->redispatch_after = atol(args[2]);
2025 }
2026 break;
2027 case KWM_NO:
2028 curproxy->no_options |= PR_O_REDISP;
2029 curproxy->redispatch_after = 0;
2030 break;
2031 case KWM_DEF: /* already cleared */
2032 break;
2033 }
2034 goto out;
2035 }
2036
2037 if (kwm != KWM_STD) {
2038 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2039 file, linenum, args[1]);
2040 err_code |= ERR_ALERT | ERR_FATAL;
2041 goto out;
2042 }
2043
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002044 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002045 char *logformat;
2046 /* generate a complete HTTP log */
2047 logformat = default_http_log_format;
2048 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002049 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002050 curproxy->options2 |= PR_O2_CLFLOG;
2051 logformat = clf_http_log_format;
2052 } else {
2053 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2054 err_code |= ERR_ALERT | ERR_FATAL;
2055 goto out;
2056 }
2057 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2058 goto out;
2059 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002060 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002061 char *oldlogformat = "log-format";
2062 char *clflogformat = "";
2063
2064 if (curproxy->conf.logformat_string == default_http_log_format)
2065 oldlogformat = "option httplog";
2066 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2067 oldlogformat = "option tcplog";
2068 else if (curproxy->conf.logformat_string == clf_http_log_format)
2069 oldlogformat = "option httplog clf";
2070 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 &&
2077 curproxy->conf.logformat_string != clf_http_log_format)
2078 free(curproxy->conf.logformat_string);
2079 curproxy->conf.logformat_string = logformat;
2080
2081 free(curproxy->conf.lfs_file);
2082 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2083 curproxy->conf.lfs_line = curproxy->conf.args.line;
2084
Willy Tarreau5d095c22021-02-12 10:15:59 +01002085 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002086 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2087 file, linenum, curproxy->id);
2088 err_code |= ERR_WARN;
2089 }
2090 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002091 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002092 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002093 char *oldlogformat = "log-format";
2094
2095 if (curproxy->conf.logformat_string == default_http_log_format)
2096 oldlogformat = "option httplog";
2097 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2098 oldlogformat = "option tcplog";
2099 else if (curproxy->conf.logformat_string == clf_http_log_format)
2100 oldlogformat = "option httplog clf";
2101 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2102 file, linenum, oldlogformat);
2103 }
2104 /* generate a detailed TCP log */
2105 if (curproxy->conf.logformat_string != default_http_log_format &&
2106 curproxy->conf.logformat_string != default_tcp_log_format &&
2107 curproxy->conf.logformat_string != clf_http_log_format)
2108 free(curproxy->conf.logformat_string);
2109 curproxy->conf.logformat_string = default_tcp_log_format;
2110
2111 free(curproxy->conf.lfs_file);
2112 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2113 curproxy->conf.lfs_line = curproxy->conf.args.line;
2114
2115 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2116 goto out;
2117
Willy Tarreau5d095c22021-02-12 10:15:59 +01002118 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002119 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2120 file, linenum, curproxy->id);
2121 err_code |= ERR_WARN;
2122 }
2123 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002124 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002125 /* enable TCP keep-alives on client and server streams */
2126 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2127 err_code |= ERR_WARN;
2128
2129 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2130 goto out;
2131
2132 if (curproxy->cap & PR_CAP_FE)
2133 curproxy->options |= PR_O_TCP_CLI_KA;
2134 if (curproxy->cap & PR_CAP_BE)
2135 curproxy->options |= PR_O_TCP_SRV_KA;
2136 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002137 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002138 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002139 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002140 goto out;
2141 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002142 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002143 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002144 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002145 goto out;
2146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002147 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002148 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002149 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002150 goto out;
2151 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002152 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002153 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002154 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002155 goto out;
2156 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002157 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002158 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002159 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002160 goto out;
2161 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002162 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002163 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002164 if (err_code & ERR_FATAL)
2165 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002166 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002167 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002168 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002169 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002170 goto out;
2171 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002172 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002173 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002174 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002175 goto out;
2176 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002177 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002178 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002179 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002180 goto out;
2181 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002182 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002183 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002184 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002185 goto out;
2186 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002187 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002188 int cur_arg;
2189
2190 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002191 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002192 */
2193
2194 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2195
2196 free(curproxy->fwdfor_hdr_name);
2197 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002198 if (!curproxy->fwdfor_hdr_name)
2199 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002200 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002201 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002202
2203 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2204 cur_arg = 2;
2205 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002206 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002207 unsigned char mask;
2208 int i;
2209
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002210 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002211 if (*(args[cur_arg+1]) &&
2212 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2213 curproxy->except_xff_net.family = AF_INET;
2214 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2215 }
2216 else if (*(args[cur_arg+1]) &&
2217 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2218 curproxy->except_xff_net.family = AF_INET6;
2219 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2220 for (i = 0; i < 16; i++)
2221 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2222 }
2223 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002224 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2225 file, linenum, args[0], args[1], args[cur_arg]);
2226 err_code |= ERR_ALERT | ERR_FATAL;
2227 goto out;
2228 }
2229 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002230 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002231 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002232 /* suboption header - needs additional argument for it */
2233 if (*(args[cur_arg+1]) == 0) {
2234 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2235 file, linenum, args[0], args[1], args[cur_arg]);
2236 err_code |= ERR_ALERT | ERR_FATAL;
2237 goto out;
2238 }
2239 free(curproxy->fwdfor_hdr_name);
2240 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002241 if (!curproxy->fwdfor_hdr_name)
2242 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002243 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2244 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002245 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002246 curproxy->options &= ~PR_O_FF_ALWAYS;
2247 cur_arg += 1;
2248 } else {
2249 /* unknown suboption - catchall */
2250 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2251 file, linenum, args[0], args[1]);
2252 err_code |= ERR_ALERT | ERR_FATAL;
2253 goto out;
2254 }
2255 } /* end while loop */
2256 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002257 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002258 int cur_arg;
2259
2260 /* insert x-original-to field, but not for the IP address listed as an except.
2261 * set default options (ie: bitfield, header name, etc)
2262 */
2263
2264 curproxy->options |= PR_O_ORGTO;
2265
2266 free(curproxy->orgto_hdr_name);
2267 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002268 if (!curproxy->orgto_hdr_name)
2269 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002270 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002271 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002272
2273 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2274 cur_arg = 2;
2275 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002276 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002277 unsigned char mask;
2278 int i;
2279
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002280 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002281 if (*(args[cur_arg+1]) &&
2282 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2283 curproxy->except_xot_net.family = AF_INET;
2284 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2285 }
2286 else if (*(args[cur_arg+1]) &&
2287 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2288 curproxy->except_xot_net.family = AF_INET6;
2289 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2290 for (i = 0; i < 16; i++)
2291 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2292 }
2293 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002294 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2295 file, linenum, args[0], args[1], args[cur_arg]);
2296 err_code |= ERR_ALERT | ERR_FATAL;
2297 goto out;
2298 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002299 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002300 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002301 /* suboption header - needs additional argument for it */
2302 if (*(args[cur_arg+1]) == 0) {
2303 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2304 file, linenum, args[0], args[1], args[cur_arg]);
2305 err_code |= ERR_ALERT | ERR_FATAL;
2306 goto out;
2307 }
2308 free(curproxy->orgto_hdr_name);
2309 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002310 if (!curproxy->orgto_hdr_name)
2311 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002312 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2313 cur_arg += 2;
2314 } else {
2315 /* unknown suboption - catchall */
2316 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2317 file, linenum, args[0], args[1]);
2318 err_code |= ERR_ALERT | ERR_FATAL;
2319 goto out;
2320 }
2321 } /* end while loop */
2322 }
2323 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002324 const char *best = proxy_find_best_option(args[1], common_options);
2325
2326 if (best)
2327 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2328 else
2329 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2330
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002331 err_code |= ERR_ALERT | ERR_FATAL;
2332 goto out;
2333 }
2334 goto out;
2335 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002336 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002337 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2338 err_code |= ERR_WARN;
2339
2340 if (*(args[1]) == 0) {
2341 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2342 err_code |= ERR_ALERT | ERR_FATAL;
2343 goto out;
2344 }
2345 free(curproxy->defbe.name);
2346 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002347 if (!curproxy->defbe.name)
2348 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002349
2350 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2351 goto out;
2352 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002353 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002354 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 +01002355
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002356 err_code |= ERR_ALERT | ERR_FATAL;
2357 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002358 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002359 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002360 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2361 err_code |= ERR_WARN;
2362
2363 if (strcmp(args[1], "never") == 0) {
2364 /* enable a graceful server shutdown on an HTTP 404 response */
2365 curproxy->options &= ~PR_O_REUSE_MASK;
2366 curproxy->options |= PR_O_REUSE_NEVR;
2367 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2368 goto out;
2369 }
2370 else if (strcmp(args[1], "safe") == 0) {
2371 /* enable a graceful server shutdown on an HTTP 404 response */
2372 curproxy->options &= ~PR_O_REUSE_MASK;
2373 curproxy->options |= PR_O_REUSE_SAFE;
2374 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2375 goto out;
2376 }
2377 else if (strcmp(args[1], "aggressive") == 0) {
2378 curproxy->options &= ~PR_O_REUSE_MASK;
2379 curproxy->options |= PR_O_REUSE_AGGR;
2380 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2381 goto out;
2382 }
2383 else if (strcmp(args[1], "always") == 0) {
2384 /* enable a graceful server shutdown on an HTTP 404 response */
2385 curproxy->options &= ~PR_O_REUSE_MASK;
2386 curproxy->options |= PR_O_REUSE_ALWS;
2387 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2388 goto out;
2389 }
2390 else {
2391 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2392 err_code |= ERR_ALERT | ERR_FATAL;
2393 goto out;
2394 }
2395 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002396 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002397 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002398 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2399 err_code |= ERR_ALERT | ERR_FATAL;
2400 goto out;
2401 }
2402
2403 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2404 err_code |= ERR_WARN;
2405
2406 if (strcmp(args[1], "fail") == 0) {
2407 /* add a condition to fail monitor requests */
2408 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2409 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2410 file, linenum, args[0], args[1]);
2411 err_code |= ERR_ALERT | ERR_FATAL;
2412 goto out;
2413 }
2414
2415 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2416 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2417 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2418 file, linenum, args[0], args[1], errmsg);
2419 err_code |= ERR_ALERT | ERR_FATAL;
2420 goto out;
2421 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002422 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002423 }
2424 else {
2425 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2426 err_code |= ERR_ALERT | ERR_FATAL;
2427 goto out;
2428 }
2429 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002430#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002431 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002432 /* enable transparent proxy connections */
2433 curproxy->options |= PR_O_TRANSP;
2434 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2435 goto out;
2436 }
2437#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002438 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002439 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2440 err_code |= ERR_WARN;
2441
2442 if (*(args[1]) == 0) {
2443 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2444 err_code |= ERR_ALERT | ERR_FATAL;
2445 goto out;
2446 }
2447 curproxy->maxconn = atol(args[1]);
2448 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2449 goto out;
2450 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002451 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002452 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2453 err_code |= ERR_WARN;
2454
2455 if (*(args[1]) == 0) {
2456 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2457 err_code |= ERR_ALERT | ERR_FATAL;
2458 goto out;
2459 }
2460 curproxy->backlog = atol(args[1]);
2461 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2462 goto out;
2463 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002464 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002465 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2466 err_code |= ERR_WARN;
2467
2468 if (*(args[1]) == 0) {
2469 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2470 err_code |= ERR_ALERT | ERR_FATAL;
2471 goto out;
2472 }
2473 curproxy->fullconn = atol(args[1]);
2474 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2475 goto out;
2476 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002477 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002478 if (*(args[1]) == 0) {
2479 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2480 err_code |= ERR_ALERT | ERR_FATAL;
2481 goto out;
2482 }
2483 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002484 if (err == PARSE_TIME_OVER) {
2485 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2486 file, linenum, args[1]);
2487 err_code |= ERR_ALERT | ERR_FATAL;
2488 goto out;
2489 }
2490 else if (err == PARSE_TIME_UNDER) {
2491 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2492 file, linenum, args[1]);
2493 err_code |= ERR_ALERT | ERR_FATAL;
2494 goto out;
2495 }
2496 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002497 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2498 file, linenum, *err);
2499 err_code |= ERR_ALERT | ERR_FATAL;
2500 goto out;
2501 }
2502 curproxy->grace = val;
2503 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2504 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002505
2506 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2507 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002508 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002509 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002510 struct sockaddr_storage *sk;
2511 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002512
Willy Tarreau5d095c22021-02-12 10:15:59 +01002513 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002514 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2515 err_code |= ERR_ALERT | ERR_FATAL;
2516 goto out;
2517 }
2518 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2519 err_code |= ERR_WARN;
2520
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002521 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2522 &errmsg, NULL, NULL,
2523 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 +01002524 if (!sk) {
2525 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2526 err_code |= ERR_ALERT | ERR_FATAL;
2527 goto out;
2528 }
2529
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002530 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2531 goto out;
2532
2533 curproxy->dispatch_addr = *sk;
2534 curproxy->options |= PR_O_DISPATCH;
2535 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002536 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002537 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2538 err_code |= ERR_WARN;
2539
2540 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2541 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2542 err_code |= ERR_ALERT | ERR_FATAL;
2543 goto out;
2544 }
2545 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002546 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002547 /**
2548 * The syntax for hash-type config element is
2549 * hash-type {map-based|consistent} [[<algo>] avalanche]
2550 *
2551 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2552 */
2553 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2554
2555 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2556 err_code |= ERR_WARN;
2557
2558 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2559 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2560 }
2561 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2562 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2563 }
2564 else if (strcmp(args[1], "avalanche") == 0) {
2565 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]);
2566 err_code |= ERR_ALERT | ERR_FATAL;
2567 goto out;
2568 }
2569 else {
2570 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2571 err_code |= ERR_ALERT | ERR_FATAL;
2572 goto out;
2573 }
2574
2575 /* set the hash function to use */
2576 if (!*args[2]) {
2577 /* the default algo is sdbm */
2578 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2579
2580 /* if consistent with no argument, then avalanche modifier is also applied */
2581 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2582 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2583 } else {
2584 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002585 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002586 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2587 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002588 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002589 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2590 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002591 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002592 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2593 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002594 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002595 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2596 }
2597 else {
2598 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2599 err_code |= ERR_ALERT | ERR_FATAL;
2600 goto out;
2601 }
2602
2603 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002604 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002605 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2606 }
2607 else if (*args[3]) {
2608 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2609 err_code |= ERR_ALERT | ERR_FATAL;
2610 goto out;
2611 }
2612 }
2613 }
2614 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2615 if (*(args[1]) == 0) {
2616 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2617 err_code |= ERR_ALERT | ERR_FATAL;
2618 goto out;
2619 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002620 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2621 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002622 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2623 err_code |= ERR_ALERT | ERR_FATAL;
2624 goto out;
2625 }
2626 }
2627 else if (strcmp(args[0], "unique-id-format") == 0) {
2628 if (!*(args[1])) {
2629 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2630 err_code |= ERR_ALERT | ERR_FATAL;
2631 goto out;
2632 }
2633 if (*(args[2])) {
2634 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2635 err_code |= ERR_ALERT | ERR_FATAL;
2636 goto out;
2637 }
2638 free(curproxy->conf.uniqueid_format_string);
2639 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002640 if (!curproxy->conf.uniqueid_format_string)
2641 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002642
2643 free(curproxy->conf.uif_file);
2644 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2645 curproxy->conf.uif_line = curproxy->conf.args.line;
2646 }
2647
2648 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002649 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002650 if (!*(args[1])) {
2651 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2652 err_code |= ERR_ALERT | ERR_FATAL;
2653 goto out;
2654 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002655 copy = strdup(args[1]);
2656 if (copy == NULL) {
2657 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2658 err_code |= ERR_ALERT | ERR_FATAL;
2659 goto out;
2660 }
2661
2662 istfree(&curproxy->header_unique_id);
2663 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002664 }
2665
2666 else if (strcmp(args[0], "log-format") == 0) {
2667 if (!*(args[1])) {
2668 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2669 err_code |= ERR_ALERT | ERR_FATAL;
2670 goto out;
2671 }
2672 if (*(args[2])) {
2673 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2674 err_code |= ERR_ALERT | ERR_FATAL;
2675 goto out;
2676 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002677 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002678 char *oldlogformat = "log-format";
2679
2680 if (curproxy->conf.logformat_string == default_http_log_format)
2681 oldlogformat = "option httplog";
2682 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2683 oldlogformat = "option tcplog";
2684 else if (curproxy->conf.logformat_string == clf_http_log_format)
2685 oldlogformat = "option httplog clf";
2686 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2687 file, linenum, oldlogformat);
2688 }
2689 if (curproxy->conf.logformat_string != default_http_log_format &&
2690 curproxy->conf.logformat_string != default_tcp_log_format &&
2691 curproxy->conf.logformat_string != clf_http_log_format)
2692 free(curproxy->conf.logformat_string);
2693 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002694 if (!curproxy->conf.logformat_string)
2695 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002696
2697 free(curproxy->conf.lfs_file);
2698 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2699 curproxy->conf.lfs_line = curproxy->conf.args.line;
2700
2701 /* get a chance to improve log-format error reporting by
2702 * reporting the correct line-number when possible.
2703 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002704 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002705 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2706 file, linenum, curproxy->id);
2707 err_code |= ERR_WARN;
2708 }
2709 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002710 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002711 if (!*(args[1])) {
2712 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2713 err_code |= ERR_ALERT | ERR_FATAL;
2714 goto out;
2715 }
2716 if (*(args[2])) {
2717 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2718 err_code |= ERR_ALERT | ERR_FATAL;
2719 goto out;
2720 }
2721
2722 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2723 free(curproxy->conf.logformat_sd_string);
2724 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002725 if (!curproxy->conf.logformat_sd_string)
2726 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002727
2728 free(curproxy->conf.lfsd_file);
2729 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2730 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2731
2732 /* get a chance to improve log-format-sd error reporting by
2733 * reporting the correct line-number when possible.
2734 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002735 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002736 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2737 file, linenum, curproxy->id);
2738 err_code |= ERR_WARN;
2739 }
2740 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002741 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002742 if (*(args[1]) == 0) {
2743 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2744 err_code |= ERR_ALERT | ERR_FATAL;
2745 goto out;
2746 }
2747 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002748 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2749 if (b_orig(&curproxy->log_tag) == NULL) {
2750 chunk_destroy(&curproxy->log_tag);
2751 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2752 err_code |= ERR_ALERT | ERR_FATAL;
2753 goto out;
2754 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002755 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002756 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002757 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002758 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2759 err_code |= ERR_ALERT | ERR_FATAL;
2760 goto out;
2761 }
2762 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002763 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002764 int cur_arg;
2765 int port1, port2;
2766 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002767
2768 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2769 err_code |= ERR_WARN;
2770
2771 if (!*args[1]) {
2772 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2773 file, linenum, "source", "usesrc", "interface");
2774 err_code |= ERR_ALERT | ERR_FATAL;
2775 goto out;
2776 }
2777
Christopher Faulet31930372019-07-15 10:16:58 +02002778 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002779 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002780 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002781 curproxy->conn_src.iface_len = 0;
2782
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002783 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2784 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002785 if (!sk) {
2786 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2787 file, linenum, args[0], args[1], errmsg);
2788 err_code |= ERR_ALERT | ERR_FATAL;
2789 goto out;
2790 }
2791
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002792 curproxy->conn_src.source_addr = *sk;
2793 curproxy->conn_src.opts |= CO_SRC_BIND;
2794
2795 cur_arg = 2;
2796 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002797 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002798#if defined(CONFIG_HAP_TRANSPARENT)
2799 if (!*args[cur_arg + 1]) {
2800 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2801 file, linenum, "usesrc");
2802 err_code |= ERR_ALERT | ERR_FATAL;
2803 goto out;
2804 }
2805
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002806 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002807 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2808 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002809 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002810 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2811 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2812 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2813 char *name, *end;
2814
2815 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002816 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002817 name++;
2818
2819 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002820 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002821 end++;
2822
2823 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2824 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002825 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002826 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002827 if (!curproxy->conn_src.bind_hdr_name)
2828 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002829 curproxy->conn_src.bind_hdr_len = end - name;
2830 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2831 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2832 curproxy->conn_src.bind_hdr_occ = -1;
2833
2834 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002835 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002836 end++;
2837 if (*end == ',') {
2838 end++;
2839 name = end;
2840 if (*end == '-')
2841 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002842 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002843 end++;
2844 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2845 }
2846
2847 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2848 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2849 " occurrences values smaller than %d.\n",
2850 file, linenum, MAX_HDR_HISTORY);
2851 err_code |= ERR_ALERT | ERR_FATAL;
2852 goto out;
2853 }
2854 } else {
2855 struct sockaddr_storage *sk;
2856
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002857 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2858 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002859 if (!sk) {
2860 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2861 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2862 err_code |= ERR_ALERT | ERR_FATAL;
2863 goto out;
2864 }
2865
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002866 curproxy->conn_src.tproxy_addr = *sk;
2867 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2868 }
2869 global.last_checks |= LSTCHK_NETADM;
2870#else /* no TPROXY support */
2871 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2872 file, linenum, "usesrc");
2873 err_code |= ERR_ALERT | ERR_FATAL;
2874 goto out;
2875#endif
2876 cur_arg += 2;
2877 continue;
2878 }
2879
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002880 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002881#ifdef SO_BINDTODEVICE
2882 if (!*args[cur_arg + 1]) {
2883 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2884 file, linenum, args[0]);
2885 err_code |= ERR_ALERT | ERR_FATAL;
2886 goto out;
2887 }
2888 free(curproxy->conn_src.iface_name);
2889 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002890 if (!curproxy->conn_src.iface_name)
2891 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002892 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2893 global.last_checks |= LSTCHK_NETADM;
2894#else
2895 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2896 file, linenum, args[0], args[cur_arg]);
2897 err_code |= ERR_ALERT | ERR_FATAL;
2898 goto out;
2899#endif
2900 cur_arg += 2;
2901 continue;
2902 }
2903 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2904 file, linenum, args[0], "interface", "usesrc");
2905 err_code |= ERR_ALERT | ERR_FATAL;
2906 goto out;
2907 }
2908 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002909 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002910 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2911 file, linenum, "usesrc", "source");
2912 err_code |= ERR_ALERT | ERR_FATAL;
2913 goto out;
2914 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002915 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 +02002916 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002917 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002918 file, linenum, args[0]);
2919 err_code |= ERR_ALERT | ERR_FATAL;
2920 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002921 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002922 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002923 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2924 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2925 err_code |= ERR_ALERT | ERR_FATAL;
2926 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002927 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002928 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002929 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2930 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2931 err_code |= ERR_ALERT | ERR_FATAL;
2932 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002933 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002934 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002935 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2936 err_code |= ERR_ALERT | ERR_FATAL;
2937 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002938 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002939 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002940 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2941 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2942 err_code |= ERR_ALERT | ERR_FATAL;
2943 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002944 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002945 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002946 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2947 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2948 err_code |= ERR_ALERT | ERR_FATAL;
2949 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002950 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002951 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002952 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2953 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2954 err_code |= ERR_ALERT | ERR_FATAL;
2955 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002956 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002957 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002958 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2959 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2960 err_code |= ERR_ALERT | ERR_FATAL;
2961 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002962 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002963 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 +02002964 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2965 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2966 err_code |= ERR_ALERT | ERR_FATAL;
2967 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002968 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002969 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002970 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2971 err_code |= ERR_ALERT | ERR_FATAL;
2972 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002973 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002974 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 +02002975 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2976 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2977 err_code |= ERR_ALERT | ERR_FATAL;
2978 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002979 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002980 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 +02002981 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2982 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2983 err_code |= ERR_ALERT | ERR_FATAL;
2984 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002985 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002986 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002987 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2988 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2989 err_code |= ERR_ALERT | ERR_FATAL;
2990 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002991 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002992 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 +02002993 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2994 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2995 err_code |= ERR_ALERT | ERR_FATAL;
2996 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002997 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002998 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002999 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3000 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3001 err_code |= ERR_ALERT | ERR_FATAL;
3002 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003003 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003004 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003005 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3006 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3007 err_code |= ERR_ALERT | ERR_FATAL;
3008 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003009 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003010 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303011 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003012 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3013 err_code |= ERR_ALERT | ERR_FATAL;
3014 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003015 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003016 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003017 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3018 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3019 err_code |= ERR_ALERT | ERR_FATAL;
3020 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003021 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003022 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003023 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3024 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3025 err_code |= ERR_ALERT | ERR_FATAL;
3026 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003027 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003028 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003029 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3030 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3031 err_code |= ERR_ALERT | ERR_FATAL;
3032 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003033 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003034 else {
3035 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003036 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003037 int index;
3038
3039 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3040 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3041 if (kwl->kw[index].section != CFG_LISTEN)
3042 continue;
3043 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003044 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003045 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003046 err_code |= ERR_ALERT | ERR_FATAL;
3047 goto out;
3048 }
3049
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003050 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003051 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003052 if (rc < 0) {
3053 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3054 err_code |= ERR_ALERT | ERR_FATAL;
3055 goto out;
3056 }
3057 else if (rc > 0) {
3058 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3059 err_code |= ERR_WARN;
3060 goto out;
3061 }
3062 goto out;
3063 }
3064 }
3065 }
3066
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003067 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3068 if (best)
3069 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3070 else
3071 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003072 err_code |= ERR_ALERT | ERR_FATAL;
3073 goto out;
3074 }
3075 out:
3076 free(errmsg);
3077 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003078
3079 alloc_error:
3080 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3081 err_code |= ERR_ALERT | ERR_ABORT;
3082 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003083}