blob: 07878330f67e3fb3e501e3ec8e5a5eada0ae041b [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>
34#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010035
Willy Tarreauc0ff6792021-03-12 09:14:19 +010036/* some keywords that are still being parsed using strcmp() and are not
37 * registered anywhere. They are used as suggestions for mistyped words.
38 */
39static const char *common_kw_list[] = {
40 "listen", "frontend", "backend", "defaults", "server",
41 "default-server", "server-template", "bind", "monitor-net",
42 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
43 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
44 "persist", "appsession", "load-server-state-from-file",
45 "server-state-file-name", "max-session-srv-conns", "capture",
46 "retries", "http-request", "http-response", "http-after-response",
47 "http-send-name-header", "block", "redirect", "use_backend",
48 "use-server", "force-persist", "ignore-persist", "force-persist",
49 "stick-table", "stick", "stats", "option", "default_backend",
50 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
51 "fullconn", "grace", "dispatch", "balance", "hash-type",
52 "hash-balance-factor", "unique-id-format", "unique-id-header",
53 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
54 NULL /* must be last */
55};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010056
Willy Tarreau31a3cea2021-03-15 11:11:55 +010057static const char *common_options[] = {
58 "httpclose", "forceclose", "http-server-close", "http-keep-alive",
59 "http-tunnel", "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
60 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
61 "mysql-check", "ldap-check", "spop-check", "tcp-check",
62 "external-check", "forwardfor", "original-to",
63 NULL /* must be last */
64};
65
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010066/* Report a warning if a rule is placed after a 'tcp-request session' rule.
67 * Return 1 if the warning has been emitted, otherwise 0.
68 */
69int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
70{
71 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
72 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
73 file, line, arg);
74 return 1;
75 }
76 return 0;
77}
78
79/* Report a warning if a rule is placed after a 'tcp-request content' rule.
80 * Return 1 if the warning has been emitted, otherwise 0.
81 */
82int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
83{
84 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
85 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
86 file, line, arg);
87 return 1;
88 }
89 return 0;
90}
91
92/* Report a warning if a rule is placed after a 'monitor fail' rule.
93 * Return 1 if the warning has been emitted, otherwise 0.
94 */
95int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
96{
97 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
98 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
99 file, line, arg);
100 return 1;
101 }
102 return 0;
103}
104
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100105/* Report a warning if a rule is placed after an 'http_request' rule.
106 * Return 1 if the warning has been emitted, otherwise 0.
107 */
108int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
109{
110 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
111 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
112 file, line, arg);
113 return 1;
114 }
115 return 0;
116}
117
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100118/* Report a warning if a rule is placed after a redirect rule.
119 * Return 1 if the warning has been emitted, otherwise 0.
120 */
121int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
122{
123 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
124 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
125 file, line, arg);
126 return 1;
127 }
128 return 0;
129}
130
131/* Report a warning if a rule is placed after a 'use_backend' rule.
132 * Return 1 if the warning has been emitted, otherwise 0.
133 */
134int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
135{
136 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
137 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
138 file, line, arg);
139 return 1;
140 }
141 return 0;
142}
143
144/* Report a warning if a rule is placed after a 'use-server' rule.
145 * Return 1 if the warning has been emitted, otherwise 0.
146 */
147int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
148{
149 if (!LIST_ISEMPTY(&proxy->server_rules)) {
150 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
151 file, line, arg);
152 return 1;
153 }
154 return 0;
155}
156
157/* report a warning if a redirect rule is dangerously placed */
158int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
159{
160 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
161 warnif_rule_after_use_server(proxy, file, line, arg);
162}
163
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100164/* report a warning if an http-request rule is dangerously placed */
165int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
166{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200167 return warnif_rule_after_redirect(proxy, file, line, arg) ||
168 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100169}
170
171/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200172int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100173{
174 return warnif_rule_after_http_req(proxy, file, line, arg) ||
175 warnif_misplaced_http_req(proxy, file, line, arg);
176}
177
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100178/* report a warning if a "tcp request content" rule is dangerously placed */
179int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
180{
181 return warnif_rule_after_monitor(proxy, file, line, arg) ||
182 warnif_misplaced_monitor(proxy, file, line, arg);
183}
184
185/* report a warning if a "tcp request session" rule is dangerously placed */
186int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
187{
188 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
189 warnif_misplaced_tcp_cont(proxy, file, line, arg);
190}
191
192/* report a warning if a "tcp request connection" rule is dangerously placed */
193int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
194{
195 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
196 warnif_misplaced_tcp_sess(proxy, file, line, arg);
197}
198
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100199int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
200{
201 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100202 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100203 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100204 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100205 int rc;
206 unsigned val;
207 int err_code = 0;
208 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100209 char *errmsg = NULL;
210 struct bind_conf *bind_conf;
211
Willy Tarreaue90904d2021-02-12 14:08:31 +0100212 if (!last_defproxy) {
213 /* we need a default proxy and none was created yet */
214 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, "INIT", 0, NULL, &errmsg);
215 curr_defproxy = last_defproxy;
216 if (!last_defproxy) {
217 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
218 err_code |= ERR_ALERT | ERR_ABORT;
219 goto out;
220 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100221 }
222
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100223 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100224 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100225 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100226 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100228 rc = PR_CAP_BE;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100229 else if (strcmp(args[0], "defaults") == 0) {
230 /* "defaults" must first delete the last no-name defaults if any */
231 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
232 curr_defproxy = NULL;
233 rc = PR_CAP_DEF | PR_CAP_LISTEN;
234 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100235 else
236 rc = PR_CAP_NONE;
237
Willy Tarreaue90904d2021-02-12 14:08:31 +0100238 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100239 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100240 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100241 file, linenum, args[0]);
242 err_code |= ERR_ALERT | ERR_ABORT;
243 goto out;
244 }
245
246 err = invalid_char(args[1]);
247 if (err) {
248 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
249 file, linenum, *err, args[0], args[1]);
250 err_code |= ERR_ALERT | ERR_FATAL;
251 }
252
253 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
254 if (curproxy) {
255 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
256 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
257 curproxy->id, curproxy->conf.file, curproxy->conf.line);
258 err_code |= ERR_ALERT | ERR_FATAL;
259 }
260
Emeric Brunb0c331f2020-10-07 17:05:59 +0200261 curproxy = log_forward_by_name(args[1]);
262 if (curproxy) {
263 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
264 file, linenum, proxy_cap_str(rc), args[1],
265 curproxy->id, curproxy->conf.file, curproxy->conf.line);
266 err_code |= ERR_ALERT | ERR_FATAL;
267 }
268
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100269 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
270 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100271 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100272 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
273 goto out;
274 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100275 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100276
Willy Tarreaue90904d2021-02-12 14:08:31 +0100277 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100278 const char *name = args[1];
279 int arg = 2;
280
281 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
282 // also support "defaults from blah" (no name then)
283 arg = 1;
284 name = "";
285 }
286
287 /* only regular proxies inherit from the previous defaults section */
288 if (!(rc & PR_CAP_DEF))
289 curr_defproxy = last_defproxy;
290
291 if (strcmp(args[arg], "from") == 0) {
292 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
293
294 if (!curr_defproxy) {
295 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
296 err_code |= ERR_ALERT | ERR_ABORT;
297 goto out;
298 }
299
300 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
301 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
302
303 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
304 file, linenum, args[arg+1], proxy_cap_str(rc), name,
305 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
306 err_code |= ERR_ALERT | ERR_FATAL;
307 }
308
309 err = invalid_char(args[arg+1]);
310 if (err) {
311 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",
312 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
313 err_code |= ERR_ALERT | ERR_FATAL;
314 }
315 }
316
317 curproxy = alloc_new_proxy(name, rc, file, linenum, curr_defproxy, &errmsg);
Willy Tarreau76838932021-02-12 08:49:47 +0100318 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100319 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
320 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100321 goto out;
322 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100323
Willy Tarreaue90904d2021-02-12 14:08:31 +0100324 if (rc & PR_CAP_DEF) {
325 /* last and current proxies must be updated to this one */
326 curr_defproxy = last_defproxy = curproxy;
327 } else {
328 /* regular proxies are in a list */
329 curproxy->next = proxies_list;
330 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100331 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100332 goto out;
333 }
334 else if (curproxy == NULL) {
335 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
336 err_code |= ERR_ALERT | ERR_FATAL;
337 goto out;
338 }
339
340 /* update the current file and line being parsed */
341 curproxy->conf.args.file = curproxy->conf.file;
342 curproxy->conf.args.line = linenum;
343
344 /* Now let's parse the proxy-specific keywords */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100345 if (strcmp(args[0], "server") == 0 ||
346 strcmp(args[0], "default-server") == 0 ||
347 strcmp(args[0], "server-template") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +0100348 err_code |= parse_server(file, linenum, args, curproxy, curr_defproxy, 1, 0, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100349 if (err_code & ERR_FATAL)
350 goto out;
351 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100352 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100353 struct listener *l;
354 int cur_arg;
355
Willy Tarreau5d095c22021-02-12 10:15:59 +0100356 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100357 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
358 err_code |= ERR_ALERT | ERR_FATAL;
359 goto out;
360 }
361 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
362 err_code |= ERR_WARN;
363
364 if (!*(args[1])) {
365 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
366 file, linenum, args[0]);
367 err_code |= ERR_ALERT | ERR_FATAL;
368 goto out;
369 }
370
371 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
372
373 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200374 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
375 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
376 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100377
378 /* NOTE: the following line might create several listeners if there
379 * are comma-separated IPs or port ranges. So all further processing
380 * will have to be applied to all listeners created after last_listen.
381 */
382 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
383 if (errmsg && *errmsg) {
384 indent_msg(&errmsg, 2);
385 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
386 }
387 else
388 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
389 file, linenum, args[0], args[1]);
390 err_code |= ERR_ALERT | ERR_FATAL;
391 goto out;
392 }
393
394 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
395 /* Set default global rights and owner for unix bind */
396 global.maxsock++;
397 }
398
399 cur_arg = 2;
400 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100401 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100402 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100403
404 kw = bind_find_kw(args[cur_arg]);
405 if (kw) {
406 char *err = NULL;
407 int code;
408
409 if (!kw->parse) {
410 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
411 file, linenum, args[0], args[1], args[cur_arg]);
412 cur_arg += 1 + kw->skip ;
413 err_code |= ERR_ALERT | ERR_FATAL;
414 goto out;
415 }
416
417 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
418 err_code |= code;
419
420 if (code) {
421 if (err && *err) {
422 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200423 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
424 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
425 else
426 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100427 }
428 else
429 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
430 file, linenum, args[0], args[1], args[cur_arg]);
431 if (code & ERR_FATAL) {
432 free(err);
433 cur_arg += 1 + kw->skip;
434 goto out;
435 }
436 }
437 free(err);
438 cur_arg += 1 + kw->skip;
439 continue;
440 }
441
Willy Tarreau433b05f2021-03-12 10:14:07 +0100442 best = bind_find_best_kw(args[cur_arg]);
443 if (best)
444 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
445 file, linenum, args[0], args[1], args[cur_arg], best);
446 else
447 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
448 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100449
450 err_code |= ERR_ALERT | ERR_FATAL;
451 goto out;
452 }
453 goto out;
454 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100455 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200456 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]);
457 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100458 goto out;
459 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100460 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100461 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
462 err_code |= ERR_WARN;
463
464 if (alertif_too_many_args(1, file, linenum, args, &err_code))
465 goto out;
466
467 if (!*args[1]) {
468 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
469 file, linenum, args[0]);
470 err_code |= ERR_ALERT | ERR_FATAL;
471 goto out;
472 }
473
474 free(curproxy->monitor_uri);
475 curproxy->monitor_uri_len = strlen(args[1]);
476 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
477 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
478 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
479
480 goto out;
481 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100482 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100483 if (alertif_too_many_args(1, file, linenum, args, &err_code))
484 goto out;
485
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100486 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
487 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
488 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200489 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
490 err_code |= ERR_ALERT | ERR_FATAL;
491 goto out;
492 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100493 else {
494 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
495 err_code |= ERR_ALERT | ERR_FATAL;
496 goto out;
497 }
498 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100499 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100500 struct eb32_node *node;
501
Willy Tarreau5d095c22021-02-12 10:15:59 +0100502 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100503 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
504 file, linenum, args[0]);
505 err_code |= ERR_ALERT | ERR_FATAL;
506 goto out;
507 }
508
509 if (alertif_too_many_args(1, file, linenum, args, &err_code))
510 goto out;
511
512 if (!*args[1]) {
513 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
514 file, linenum, args[0]);
515 err_code |= ERR_ALERT | ERR_FATAL;
516 goto out;
517 }
518
519 curproxy->uuid = atol(args[1]);
520 curproxy->conf.id.key = curproxy->uuid;
521 curproxy->options |= PR_O_FORCED_ID;
522
523 if (curproxy->uuid <= 0) {
524 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
525 file, linenum);
526 err_code |= ERR_ALERT | ERR_FATAL;
527 goto out;
528 }
529
530 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
531 if (node) {
532 struct proxy *target = container_of(node, struct proxy, conf.id);
533 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
534 file, linenum, proxy_type_str(curproxy), curproxy->id,
535 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
536 err_code |= ERR_ALERT | ERR_FATAL;
537 goto out;
538 }
539 eb32_insert(&used_proxy_id, &curproxy->conf.id);
540 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100541 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100542 int i, len=0;
543 char *d;
544
Willy Tarreau5d095c22021-02-12 10:15:59 +0100545 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100546 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
547 file, linenum, args[0]);
548 err_code |= ERR_ALERT | ERR_FATAL;
549 goto out;
550 }
551
552 if (!*args[1]) {
553 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
554 file, linenum, args[0]);
555 return -1;
556 }
557
558 for (i = 1; *args[i]; i++)
559 len += strlen(args[i]) + 1;
560
561 d = calloc(1, len);
562 curproxy->desc = d;
563
564 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
565 for (i = 2; *args[i]; i++)
566 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
567
568 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100569 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100570 if (alertif_too_many_args(0, file, linenum, args, &err_code))
571 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200572 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100573 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100574 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100575 if (alertif_too_many_args(0, file, linenum, args, &err_code))
576 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200577 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100578 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100579 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100580 int cur_arg = 1;
581 unsigned long set = 0;
582
583 while (*args[cur_arg]) {
584 if (strcmp(args[cur_arg], "all") == 0) {
585 set = 0;
586 break;
587 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100588 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100589 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
590 err_code |= ERR_ALERT | ERR_FATAL;
591 goto out;
592 }
593 cur_arg++;
594 }
595 curproxy->bind_proc = set;
596 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100597 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100598 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100599 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
600 err_code |= ERR_ALERT | ERR_FATAL;
601 goto out;
602 }
603
604 err = invalid_char(args[1]);
605 if (err) {
606 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
607 file, linenum, *err, args[1]);
608 err_code |= ERR_ALERT | ERR_FATAL;
609 goto out;
610 }
611
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100612 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100613 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100614 "logical disjunction within a condition.\n",
615 file, linenum, args[1]);
616 err_code |= ERR_ALERT | ERR_FATAL;
617 goto out;
618 }
619
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100620 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
621 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
622 file, linenum, args[1], errmsg);
623 err_code |= ERR_ALERT | ERR_FATAL;
624 goto out;
625 }
626 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100627 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100628
629 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
630 err_code |= ERR_WARN;
631
632 if (*(args[1]) == 0) {
633 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
634 file, linenum, args[0]);
635 err_code |= ERR_ALERT | ERR_FATAL;
636 goto out;
637 }
638 free(curproxy->dyncookie_key);
639 curproxy->dyncookie_key = strdup(args[1]);
640 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100641 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100642 int cur_arg;
643
644 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
645 err_code |= ERR_WARN;
646
647 if (*(args[1]) == 0) {
648 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
649 file, linenum, args[0]);
650 err_code |= ERR_ALERT | ERR_FATAL;
651 goto out;
652 }
653
654 curproxy->ck_opts = 0;
655 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100656 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100657 free(curproxy->cookie_name);
658 curproxy->cookie_name = strdup(args[1]);
659 curproxy->cookie_len = strlen(curproxy->cookie_name);
660
661 cur_arg = 2;
662 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100663 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100664 curproxy->ck_opts |= PR_CK_RW;
665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100666 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100667 curproxy->ck_opts |= PR_CK_IND;
668 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100669 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100670 curproxy->ck_opts |= PR_CK_INS;
671 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100672 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100673 curproxy->ck_opts |= PR_CK_NOC;
674 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100675 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100676 curproxy->ck_opts |= PR_CK_POST;
677 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100678 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100679 curproxy->ck_opts |= PR_CK_PSV;
680 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100681 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100682 curproxy->ck_opts |= PR_CK_PFX;
683 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100684 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100685 curproxy->ck_opts |= PR_CK_HTTPONLY;
686 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100687 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100688 curproxy->ck_opts |= PR_CK_SECURE;
689 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100690 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100691 if (!*args[cur_arg + 1]) {
692 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
693 file, linenum, args[cur_arg]);
694 err_code |= ERR_ALERT | ERR_FATAL;
695 goto out;
696 }
697
Joao Moraise1583752019-10-30 21:04:00 -0300698 if (!strchr(args[cur_arg + 1], '.')) {
699 /* rfc6265, 5.2.3 The Domain Attribute */
700 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
701 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100702 file, linenum, args[cur_arg + 1]);
703 err_code |= ERR_WARN;
704 }
705
706 err = invalid_domainchar(args[cur_arg + 1]);
707 if (err) {
708 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
709 file, linenum, *err, args[cur_arg + 1]);
710 err_code |= ERR_ALERT | ERR_FATAL;
711 goto out;
712 }
713
714 if (!curproxy->cookie_domain) {
715 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
716 } else {
717 /* one domain was already specified, add another one by
718 * building the string which will be returned along with
719 * the cookie.
720 */
721 char *new_ptr;
722 int new_len = strlen(curproxy->cookie_domain) +
723 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
724 new_ptr = malloc(new_len);
725 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
726 free(curproxy->cookie_domain);
727 curproxy->cookie_domain = new_ptr;
728 }
729 cur_arg++;
730 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100731 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100732 unsigned int maxidle;
733 const char *res;
734
735 if (!*args[cur_arg + 1]) {
736 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
737 file, linenum, args[cur_arg]);
738 err_code |= ERR_ALERT | ERR_FATAL;
739 goto out;
740 }
741
742 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200743 if (res == PARSE_TIME_OVER) {
744 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
745 file, linenum, args[cur_arg+1], args[cur_arg]);
746 err_code |= ERR_ALERT | ERR_FATAL;
747 goto out;
748 }
749 else if (res == PARSE_TIME_UNDER) {
750 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
751 file, linenum, args[cur_arg+1], args[cur_arg]);
752 err_code |= ERR_ALERT | ERR_FATAL;
753 goto out;
754 }
755 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100756 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
757 file, linenum, *res, args[cur_arg]);
758 err_code |= ERR_ALERT | ERR_FATAL;
759 goto out;
760 }
761 curproxy->cookie_maxidle = maxidle;
762 cur_arg++;
763 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100764 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100765 unsigned int maxlife;
766 const char *res;
767
768 if (!*args[cur_arg + 1]) {
769 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
770 file, linenum, args[cur_arg]);
771 err_code |= ERR_ALERT | ERR_FATAL;
772 goto out;
773 }
774
Willy Tarreau9faebe32019-06-07 19:00:37 +0200775
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100776 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200777 if (res == PARSE_TIME_OVER) {
778 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
779 file, linenum, args[cur_arg+1], args[cur_arg]);
780 err_code |= ERR_ALERT | ERR_FATAL;
781 goto out;
782 }
783 else if (res == PARSE_TIME_UNDER) {
784 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
785 file, linenum, args[cur_arg+1], args[cur_arg]);
786 err_code |= ERR_ALERT | ERR_FATAL;
787 goto out;
788 }
789 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100790 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
791 file, linenum, *res, args[cur_arg]);
792 err_code |= ERR_ALERT | ERR_FATAL;
793 goto out;
794 }
795 curproxy->cookie_maxlife = maxlife;
796 cur_arg++;
797 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100798 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100799
800 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
801 err_code |= ERR_WARN;
802 curproxy->ck_opts |= PR_CK_DYNAMIC;
803 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100804 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100805 char *val;
806 if (!*args[cur_arg + 1]) {
807 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
808 file, linenum, args[cur_arg]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812 val = args[cur_arg + 1];
813 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100814 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100815 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
816 file, linenum, *val);
817 err_code |= ERR_ALERT | ERR_FATAL;
818 goto out;
819 }
820 val++;
821 }
822 /* don't add ';' for the first attribute */
823 if (!curproxy->cookie_attrs)
824 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
825 else
826 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
827 cur_arg++;
828 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100829
830 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100831 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 +0100832 file, linenum, args[0]);
833 err_code |= ERR_ALERT | ERR_FATAL;
834 goto out;
835 }
836 cur_arg++;
837 }
838 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
839 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
840 file, linenum);
841 err_code |= ERR_ALERT | ERR_FATAL;
842 }
843
844 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
845 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
846 file, linenum);
847 err_code |= ERR_ALERT | ERR_FATAL;
848 }
849
850 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
851 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
852 file, linenum);
853 err_code |= ERR_ALERT | ERR_FATAL;
854 }
855 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100856 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100857 if (*(args[1]) == 0) {
858 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
859 file, linenum, args[0]);
860 err_code |= ERR_ALERT | ERR_FATAL;
861 goto out;
862 }
863
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100864 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100865 if (*(args[1]) == 0) {
866 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
867 file, linenum, args[1]);
868 err_code |= ERR_ALERT | ERR_FATAL;
869 goto out;
870 }
871 free(curproxy->email_alert.from);
872 curproxy->email_alert.from = strdup(args[2]);
873 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100874 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100875 if (*(args[1]) == 0) {
876 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
877 file, linenum, args[1]);
878 err_code |= ERR_ALERT | ERR_FATAL;
879 goto out;
880 }
881 free(curproxy->email_alert.mailers.name);
882 curproxy->email_alert.mailers.name = strdup(args[2]);
883 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100884 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100885 if (*(args[1]) == 0) {
886 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
887 file, linenum, args[1]);
888 err_code |= ERR_ALERT | ERR_FATAL;
889 goto out;
890 }
891 free(curproxy->email_alert.myhostname);
892 curproxy->email_alert.myhostname = strdup(args[2]);
893 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100894 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100895 curproxy->email_alert.level = get_log_level(args[2]);
896 if (curproxy->email_alert.level < 0) {
897 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
898 file, linenum, args[1], args[2]);
899 err_code |= ERR_ALERT | ERR_FATAL;
900 goto out;
901 }
902 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100903 else if (strcmp(args[1], "to") == 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.to);
911 curproxy->email_alert.to = strdup(args[2]);
912 }
913 else {
914 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
915 file, linenum, args[1]);
916 err_code |= ERR_ALERT | ERR_FATAL;
917 goto out;
918 }
919 /* Indicate that the email_alert is at least partially configured */
920 curproxy->email_alert.set = 1;
921 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100922 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100923 if (*(args[1]) == 0) {
924 ha_alert("parsing [%s:%d] : missing persist method.\n",
925 file, linenum);
926 err_code |= ERR_ALERT | ERR_FATAL;
927 goto out;
928 }
929
930 if (!strncmp(args[1], "rdp-cookie", 10)) {
931 curproxy->options2 |= PR_O2_RDPC_PRST;
932
933 if (*(args[1] + 10) == '(') { /* cookie name */
934 const char *beg, *end;
935
936 beg = args[1] + 11;
937 end = strchr(beg, ')');
938
939 if (alertif_too_many_args(1, file, linenum, args, &err_code))
940 goto out;
941
942 if (!end || end == beg) {
943 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
944 file, linenum);
945 err_code |= ERR_ALERT | ERR_FATAL;
946 goto out;
947 }
948
949 free(curproxy->rdp_cookie_name);
950 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
951 curproxy->rdp_cookie_len = end-beg;
952 }
953 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
954 free(curproxy->rdp_cookie_name);
955 curproxy->rdp_cookie_name = strdup("msts");
956 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
957 }
958 else { /* syntax */
959 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
960 file, linenum);
961 err_code |= ERR_ALERT | ERR_FATAL;
962 goto out;
963 }
964 }
965 else {
966 ha_alert("parsing [%s:%d] : unknown persist method.\n",
967 file, linenum);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 goto out;
970 }
971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100972 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +0200973 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 +0100974 err_code |= ERR_ALERT | ERR_FATAL;
975 goto out;
976 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100977 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100978 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
979 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100980 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100981 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
982 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100983 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 +0100984 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
985 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100986 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100987 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
988 }
989 else {
990 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
991 file, linenum, args[0], args[1]);
992 err_code |= ERR_ALERT | ERR_FATAL;
993 goto out;
994 }
995 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100996 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100997 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
998 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100999 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001000 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001001
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001002 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001003
1004 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001005 curproxy->server_state_file_name = strdup(curproxy->id);
1006 else
1007 curproxy->server_state_file_name = strdup(args[1]);
1008 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001009 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001010 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1011 err_code |= ERR_WARN;
1012 if (*(args[1]) == 0) {
1013 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1014 file, linenum, args[0]);
1015 err_code |= ERR_ALERT | ERR_FATAL;
1016 goto out;
1017 }
1018 curproxy->max_out_conns = atoi(args[1]);
1019 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001020 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001021 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1022 err_code |= ERR_WARN;
1023
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001024 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001025 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001026 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1027 err_code |= ERR_ALERT | ERR_FATAL;
1028 goto out;
1029 }
1030
1031 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1032 goto out;
1033
1034 if (*(args[4]) == 0) {
1035 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1036 file, linenum, args[0]);
1037 err_code |= ERR_ALERT | ERR_FATAL;
1038 goto out;
1039 }
1040 free(curproxy->capture_name);
1041 curproxy->capture_name = strdup(args[2]);
1042 curproxy->capture_namelen = strlen(curproxy->capture_name);
1043 curproxy->capture_len = atol(args[4]);
1044 curproxy->to_log |= LW_COOKIE;
1045 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001046 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001047 struct cap_hdr *hdr;
1048
Willy Tarreau5d095c22021-02-12 10:15:59 +01001049 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001050 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1051 err_code |= ERR_ALERT | ERR_FATAL;
1052 goto out;
1053 }
1054
1055 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1056 goto out;
1057
1058 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1059 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1060 file, linenum, args[0], args[1]);
1061 err_code |= ERR_ALERT | ERR_FATAL;
1062 goto out;
1063 }
1064
1065 hdr = calloc(1, sizeof(*hdr));
1066 hdr->next = curproxy->req_cap;
1067 hdr->name = strdup(args[3]);
1068 hdr->namelen = strlen(args[3]);
1069 hdr->len = atol(args[5]);
1070 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1071 hdr->index = curproxy->nb_req_cap++;
1072 curproxy->req_cap = hdr;
1073 curproxy->to_log |= LW_REQHDR;
1074 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001075 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001076 struct cap_hdr *hdr;
1077
Willy Tarreau5d095c22021-02-12 10:15:59 +01001078 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001079 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1080 err_code |= ERR_ALERT | ERR_FATAL;
1081 goto out;
1082 }
1083
1084 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1085 goto out;
1086
1087 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1088 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1089 file, linenum, args[0], args[1]);
1090 err_code |= ERR_ALERT | ERR_FATAL;
1091 goto out;
1092 }
1093 hdr = calloc(1, sizeof(*hdr));
1094 hdr->next = curproxy->rsp_cap;
1095 hdr->name = strdup(args[3]);
1096 hdr->namelen = strlen(args[3]);
1097 hdr->len = atol(args[5]);
1098 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1099 hdr->index = curproxy->nb_rsp_cap++;
1100 curproxy->rsp_cap = hdr;
1101 curproxy->to_log |= LW_RSPHDR;
1102 }
1103 else {
1104 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1105 file, linenum, args[0]);
1106 err_code |= ERR_ALERT | ERR_FATAL;
1107 goto out;
1108 }
1109 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001110 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001111 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1112 err_code |= ERR_WARN;
1113
1114 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1115 goto out;
1116
1117 if (*(args[1]) == 0) {
1118 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1119 file, linenum, args[0]);
1120 err_code |= ERR_ALERT | ERR_FATAL;
1121 goto out;
1122 }
1123 curproxy->conn_retries = atol(args[1]);
1124 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001125 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001126 struct act_rule *rule;
1127
Willy Tarreau5d095c22021-02-12 10:15:59 +01001128 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001129 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1130 err_code |= ERR_ALERT | ERR_FATAL;
1131 goto out;
1132 }
1133
1134 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1135 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001136 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001137 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1138 file, linenum, args[0]);
1139 err_code |= ERR_WARN;
1140 }
1141
1142 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1143
1144 if (!rule) {
1145 err_code |= ERR_ALERT | ERR_ABORT;
1146 goto out;
1147 }
1148
1149 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1150 err_code |= warnif_cond_conflicts(rule->cond,
1151 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1152 file, linenum);
1153
1154 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1155 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001156 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001157 struct act_rule *rule;
1158
Willy Tarreau5d095c22021-02-12 10:15:59 +01001159 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001160 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1161 err_code |= ERR_ALERT | ERR_FATAL;
1162 goto out;
1163 }
1164
1165 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1166 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001167 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001168 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1169 file, linenum, args[0]);
1170 err_code |= ERR_WARN;
1171 }
1172
1173 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1174
1175 if (!rule) {
1176 err_code |= ERR_ALERT | ERR_ABORT;
1177 goto out;
1178 }
1179
1180 err_code |= warnif_cond_conflicts(rule->cond,
1181 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1182 file, linenum);
1183
1184 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1185 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001186 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001187 struct act_rule *rule;
1188
Willy Tarreau5d095c22021-02-12 10:15:59 +01001189 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001190 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1191 err_code |= ERR_ALERT | ERR_FATAL;
1192 goto out;
1193 }
1194
1195 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1196 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1197 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1198 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1199 file, linenum, args[0]);
1200 err_code |= ERR_WARN;
1201 }
1202
1203 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1204
1205 if (!rule) {
1206 err_code |= ERR_ALERT | ERR_ABORT;
1207 goto out;
1208 }
1209
1210 err_code |= warnif_cond_conflicts(rule->cond,
1211 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1212 file, linenum);
1213
1214 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1215 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001216 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001217 /* set the header name and length into the proxy structure */
1218 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1219 err_code |= ERR_WARN;
1220
1221 if (!*args[1]) {
1222 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1223 file, linenum, args[0]);
1224 err_code |= ERR_ALERT | ERR_FATAL;
1225 goto out;
1226 }
1227
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001228 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001229 free(curproxy->server_id_hdr_name);
1230 curproxy->server_id_hdr_name = strdup(args[1]);
1231 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001232 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 +01001233 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001234 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001235 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 +01001236
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001237 err_code |= ERR_ALERT | ERR_FATAL;
1238 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001239 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001240 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001241 struct redirect_rule *rule;
1242
Willy Tarreau5d095c22021-02-12 10:15:59 +01001243 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001244 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1245 err_code |= ERR_ALERT | ERR_FATAL;
1246 goto out;
1247 }
1248
1249 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1250 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1251 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1252 err_code |= ERR_ALERT | ERR_FATAL;
1253 goto out;
1254 }
1255
1256 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1257 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1258 err_code |= warnif_cond_conflicts(rule->cond,
1259 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1260 file, linenum);
1261 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001262 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001263 struct switching_rule *rule;
1264
Willy Tarreau5d095c22021-02-12 10:15:59 +01001265 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001266 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1267 err_code |= ERR_ALERT | ERR_FATAL;
1268 goto out;
1269 }
1270
1271 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1272 err_code |= ERR_WARN;
1273
1274 if (*(args[1]) == 0) {
1275 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1276 err_code |= ERR_ALERT | ERR_FATAL;
1277 goto out;
1278 }
1279
1280 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1281 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1282 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1283 file, linenum, errmsg);
1284 err_code |= ERR_ALERT | ERR_FATAL;
1285 goto out;
1286 }
1287
1288 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1289 }
1290 else if (*args[2]) {
1291 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1292 file, linenum, args[2]);
1293 err_code |= ERR_ALERT | ERR_FATAL;
1294 goto out;
1295 }
1296
1297 rule = calloc(1, sizeof(*rule));
1298 if (!rule) {
1299 ha_alert("Out of memory error.\n");
1300 goto out;
1301 }
1302 rule->cond = cond;
1303 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001304 if (!rule->be.name) {
1305 ha_alert("Out of memory error.\n");
1306 goto out;
1307 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001308 rule->line = linenum;
1309 rule->file = strdup(file);
1310 if (!rule->file) {
1311 ha_alert("Out of memory error.\n");
1312 goto out;
1313 }
1314 LIST_INIT(&rule->list);
1315 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1316 }
1317 else if (strcmp(args[0], "use-server") == 0) {
1318 struct server_rule *rule;
1319
Willy Tarreau5d095c22021-02-12 10:15:59 +01001320 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001321 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325
1326 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1327 err_code |= ERR_WARN;
1328
1329 if (*(args[1]) == 0) {
1330 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1331 err_code |= ERR_ALERT | ERR_FATAL;
1332 goto out;
1333 }
1334
1335 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1336 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1337 file, linenum, args[0]);
1338 err_code |= ERR_ALERT | ERR_FATAL;
1339 goto out;
1340 }
1341
1342 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1343 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1344 file, linenum, errmsg);
1345 err_code |= ERR_ALERT | ERR_FATAL;
1346 goto out;
1347 }
1348
1349 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1350
1351 rule = calloc(1, sizeof(*rule));
1352 rule->cond = cond;
1353 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001354 rule->line = linenum;
1355 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001356 LIST_INIT(&rule->list);
1357 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1358 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1359 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001360 else if ((strcmp(args[0], "force-persist") == 0) ||
1361 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001362 struct persist_rule *rule;
1363
Willy Tarreau5d095c22021-02-12 10:15:59 +01001364 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001365 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1366 err_code |= ERR_ALERT | ERR_FATAL;
1367 goto out;
1368 }
1369
1370 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1371 err_code |= ERR_WARN;
1372
1373 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1374 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1375 file, linenum, args[0]);
1376 err_code |= ERR_ALERT | ERR_FATAL;
1377 goto out;
1378 }
1379
1380 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1381 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1382 file, linenum, args[0], errmsg);
1383 err_code |= ERR_ALERT | ERR_FATAL;
1384 goto out;
1385 }
1386
1387 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1388 * where force-persist is applied.
1389 */
1390 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1391
1392 rule = calloc(1, sizeof(*rule));
1393 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001394 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001395 rule->type = PERSIST_TYPE_FORCE;
1396 } else {
1397 rule->type = PERSIST_TYPE_IGNORE;
1398 }
1399 LIST_INIT(&rule->list);
1400 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1401 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001402 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001403 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001404
Willy Tarreau5d095c22021-02-12 10:15:59 +01001405 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001406 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1407 file, linenum);
1408 err_code |= ERR_ALERT | ERR_FATAL;
1409 goto out;
1410 }
1411
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001412 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001413 if (other) {
1414 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 +01001415 file, linenum, curproxy->id,
1416 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1417 other->proxy ? other->id : other->peers.p->id,
1418 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001419 err_code |= ERR_ALERT | ERR_FATAL;
1420 goto out;
1421 }
1422
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001423 curproxy->table = calloc(1, sizeof *curproxy->table);
1424 if (!curproxy->table) {
1425 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1426 file, linenum, args[0], args[1]);
1427 err_code |= ERR_ALERT | ERR_FATAL;
1428 goto out;
1429 }
1430
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001431 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1432 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001433 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001434 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001435
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001436 /* Store the proxy in the stick-table. */
1437 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001438
1439 stktable_store_name(curproxy->table);
1440 curproxy->table->next = stktables_list;
1441 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001442
1443 /* Add this proxy to the list of proxies which refer to its stick-table. */
1444 if (curproxy->table->proxies_list != curproxy) {
1445 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1446 curproxy->table->proxies_list = curproxy;
1447 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001449 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001450 struct sticking_rule *rule;
1451 struct sample_expr *expr;
1452 int myidx = 0;
1453 const char *name = NULL;
1454 int flags;
1455
Willy Tarreau5d095c22021-02-12 10:15:59 +01001456 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001457 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1458 err_code |= ERR_ALERT | ERR_FATAL;
1459 goto out;
1460 }
1461
1462 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1463 err_code |= ERR_WARN;
1464 goto out;
1465 }
1466
1467 myidx++;
1468 if ((strcmp(args[myidx], "store") == 0) ||
1469 (strcmp(args[myidx], "store-request") == 0)) {
1470 myidx++;
1471 flags = STK_IS_STORE;
1472 }
1473 else if (strcmp(args[myidx], "store-response") == 0) {
1474 myidx++;
1475 flags = STK_IS_STORE | STK_ON_RSP;
1476 }
1477 else if (strcmp(args[myidx], "match") == 0) {
1478 myidx++;
1479 flags = STK_IS_MATCH;
1480 }
1481 else if (strcmp(args[myidx], "on") == 0) {
1482 myidx++;
1483 flags = STK_IS_MATCH | STK_IS_STORE;
1484 }
1485 else {
1486 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1487 err_code |= ERR_ALERT | ERR_FATAL;
1488 goto out;
1489 }
1490
1491 if (*(args[myidx]) == 0) {
1492 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1493 err_code |= ERR_ALERT | ERR_FATAL;
1494 goto out;
1495 }
1496
1497 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001498 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001499 if (!expr) {
1500 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1501 err_code |= ERR_ALERT | ERR_FATAL;
1502 goto out;
1503 }
1504
1505 if (flags & STK_ON_RSP) {
1506 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1507 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1508 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1509 err_code |= ERR_ALERT | ERR_FATAL;
1510 free(expr);
1511 goto out;
1512 }
1513 } else {
1514 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1515 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1516 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1517 err_code |= ERR_ALERT | ERR_FATAL;
1518 free(expr);
1519 goto out;
1520 }
1521 }
1522
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001523 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001524 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1525
1526 if (strcmp(args[myidx], "table") == 0) {
1527 myidx++;
1528 name = args[myidx++];
1529 }
1530
1531 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1532 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1533 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1534 file, linenum, args[0], errmsg);
1535 err_code |= ERR_ALERT | ERR_FATAL;
1536 free(expr);
1537 goto out;
1538 }
1539 }
1540 else if (*(args[myidx])) {
1541 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1542 file, linenum, args[0], args[myidx]);
1543 err_code |= ERR_ALERT | ERR_FATAL;
1544 free(expr);
1545 goto out;
1546 }
1547 if (flags & STK_ON_RSP)
1548 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1549 else
1550 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1551
1552 rule = calloc(1, sizeof(*rule));
1553 rule->cond = cond;
1554 rule->expr = expr;
1555 rule->flags = flags;
1556 rule->table.name = name ? strdup(name) : NULL;
1557 LIST_INIT(&rule->list);
1558 if (flags & STK_ON_RSP)
1559 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1560 else
1561 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1562 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001563 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001564 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001565 curproxy->uri_auth = NULL; /* we must detach from the default config */
1566
1567 if (!*args[1]) {
1568 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001569 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001570 struct stats_admin_rule *rule;
1571
Willy Tarreau5d095c22021-02-12 10:15:59 +01001572 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001573 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1574 err_code |= ERR_ALERT | ERR_FATAL;
1575 goto out;
1576 }
1577
1578 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1579 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1580 err_code |= ERR_ALERT | ERR_ABORT;
1581 goto out;
1582 }
1583
1584 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1585 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1586 file, linenum, args[0], args[1]);
1587 err_code |= ERR_ALERT | ERR_FATAL;
1588 goto out;
1589 }
1590 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1591 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1592 file, linenum, args[0], args[1], errmsg);
1593 err_code |= ERR_ALERT | ERR_FATAL;
1594 goto out;
1595 }
1596
1597 err_code |= warnif_cond_conflicts(cond,
1598 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1599 file, linenum);
1600
1601 rule = calloc(1, sizeof(*rule));
1602 rule->cond = cond;
1603 LIST_INIT(&rule->list);
1604 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001605 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001606 if (*(args[2]) == 0) {
1607 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1608 err_code |= ERR_ALERT | ERR_FATAL;
1609 goto out;
1610 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1611 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1612 err_code |= ERR_ALERT | ERR_ABORT;
1613 goto out;
1614 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001615 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001616 if (*(args[2]) == 0) {
1617 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1618 err_code |= ERR_ALERT | ERR_FATAL;
1619 goto out;
1620 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1621 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1622 err_code |= ERR_ALERT | ERR_ABORT;
1623 goto out;
1624 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001625 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001626 unsigned interval;
1627
1628 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001629 if (err == PARSE_TIME_OVER) {
1630 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1631 file, linenum, args[2]);
1632 err_code |= ERR_ALERT | ERR_FATAL;
1633 goto out;
1634 }
1635 else if (err == PARSE_TIME_UNDER) {
1636 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1637 file, linenum, args[2]);
1638 err_code |= ERR_ALERT | ERR_FATAL;
1639 goto out;
1640 }
1641 else if (err) {
1642 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001643 file, linenum, *err);
1644 err_code |= ERR_ALERT | ERR_FATAL;
1645 goto out;
1646 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1647 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1648 err_code |= ERR_ALERT | ERR_ABORT;
1649 goto out;
1650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001651 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001652 struct act_rule *rule;
1653
Willy Tarreau5d095c22021-02-12 10:15:59 +01001654 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001655 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1656 err_code |= ERR_ALERT | ERR_FATAL;
1657 goto out;
1658 }
1659
1660 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1661 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1662 err_code |= ERR_ALERT | ERR_ABORT;
1663 goto out;
1664 }
1665
1666 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1667 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1668 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1669 file, linenum, args[0]);
1670 err_code |= ERR_WARN;
1671 }
1672
1673 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1674
1675 if (!rule) {
1676 err_code |= ERR_ALERT | ERR_ABORT;
1677 goto out;
1678 }
1679
1680 err_code |= warnif_cond_conflicts(rule->cond,
1681 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1682 file, linenum);
1683 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1684
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001685 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001686 if (*(args[2]) == 0) {
1687 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1688 err_code |= ERR_ALERT | ERR_FATAL;
1689 goto out;
1690 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1691 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1692 err_code |= ERR_ALERT | ERR_ABORT;
1693 goto out;
1694 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001695 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001696 if (*(args[2]) == 0) {
1697 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1698 err_code |= ERR_ALERT | ERR_FATAL;
1699 goto out;
1700 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1701 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1702 err_code |= ERR_ALERT | ERR_ABORT;
1703 goto out;
1704 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001705 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1707 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1708 err_code |= ERR_ALERT | ERR_ABORT;
1709 goto out;
1710 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001711 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001712 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001713 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1714 err_code |= ERR_ALERT | ERR_ABORT;
1715 goto out;
1716 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001717 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001718 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001719 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1720 err_code |= ERR_ALERT | ERR_ABORT;
1721 goto out;
1722 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001723 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001724 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1725 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1726 err_code |= ERR_ALERT | ERR_ABORT;
1727 goto out;
1728 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001729 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001730
1731 if (*args[2]) {
1732 int i;
1733 char c;
1734
1735 for (i=0; args[2][i]; i++) {
1736 c = args[2][i];
1737 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1738 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1739 break;
1740 }
1741
1742 if (!i || args[2][i]) {
1743 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1744 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1745 file, linenum, args[0], args[1]);
1746 err_code |= ERR_ALERT | ERR_FATAL;
1747 goto out;
1748 }
1749 }
1750
1751 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1752 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1753 err_code |= ERR_ALERT | ERR_ABORT;
1754 goto out;
1755 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001756 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001757 char *desc = NULL;
1758
1759 if (*args[2]) {
1760 int i, len=0;
1761 char *d;
1762
1763 for (i = 2; *args[i]; i++)
1764 len += strlen(args[i]) + 1;
1765
1766 desc = d = calloc(1, len);
1767
1768 d += snprintf(d, desc + len - d, "%s", args[2]);
1769 for (i = 3; *args[i]; i++)
1770 d += snprintf(d, desc + len - d, " %s", args[i]);
1771 }
1772
1773 if (!*args[2] && !global.desc)
1774 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1775 file, linenum, args[1]);
1776 else {
1777 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1778 free(desc);
1779 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1780 err_code |= ERR_ALERT | ERR_ABORT;
1781 goto out;
1782 }
1783 free(desc);
1784 }
1785 } else {
1786stats_error_parsing:
1787 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1788 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1789 err_code |= ERR_ALERT | ERR_FATAL;
1790 goto out;
1791 }
1792 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001793 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001794 int optnum;
1795
1796 if (*(args[1]) == '\0') {
1797 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1798 file, linenum, args[0]);
1799 err_code |= ERR_ALERT | ERR_FATAL;
1800 goto out;
1801 }
1802
1803 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001804 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001805 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1806 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1807 file, linenum, cfg_opts[optnum].name);
1808 err_code |= ERR_ALERT | ERR_FATAL;
1809 goto out;
1810 }
1811 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1812 goto out;
1813
1814 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1815 err_code |= ERR_WARN;
1816 goto out;
1817 }
1818
1819 curproxy->no_options &= ~cfg_opts[optnum].val;
1820 curproxy->options &= ~cfg_opts[optnum].val;
1821
1822 switch (kwm) {
1823 case KWM_STD:
1824 curproxy->options |= cfg_opts[optnum].val;
1825 break;
1826 case KWM_NO:
1827 curproxy->no_options |= cfg_opts[optnum].val;
1828 break;
1829 case KWM_DEF: /* already cleared */
1830 break;
1831 }
1832
1833 goto out;
1834 }
1835 }
1836
1837 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001838 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001839 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1840 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1841 file, linenum, cfg_opts2[optnum].name);
1842 err_code |= ERR_ALERT | ERR_FATAL;
1843 goto out;
1844 }
1845 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1846 goto out;
1847 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1848 err_code |= ERR_WARN;
1849 goto out;
1850 }
1851
Christopher Faulet31930372019-07-15 10:16:58 +02001852 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001853 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001854 if (kwm ==KWM_NO) {
1855 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1856 " The HTX mode is now the only supported mode.\n",
1857 file, linenum, cfg_opts2[optnum].name);
1858 err_code |= ERR_WARN;
1859 }
Christopher Faulet31930372019-07-15 10:16:58 +02001860 goto out;
1861 }
1862
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001863 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1864 curproxy->options2 &= ~cfg_opts2[optnum].val;
1865
1866 switch (kwm) {
1867 case KWM_STD:
1868 curproxy->options2 |= cfg_opts2[optnum].val;
1869 break;
1870 case KWM_NO:
1871 curproxy->no_options2 |= cfg_opts2[optnum].val;
1872 break;
1873 case KWM_DEF: /* already cleared */
1874 break;
1875 }
1876 goto out;
1877 }
1878 }
1879
1880 /* HTTP options override each other. They can be cancelled using
1881 * "no option xxx" which only switches to default mode if the mode
1882 * was this one (useful for cancelling options set in defaults
1883 * sections).
1884 */
1885 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001886 if (strcmp(args[1], "forceclose") == 0) {
1887 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1888 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1889 file, linenum, args[1]);
1890 err_code |= ERR_WARN;
1891 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001892 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1893 goto out;
1894 if (kwm == KWM_STD) {
1895 curproxy->options &= ~PR_O_HTTP_MODE;
1896 curproxy->options |= PR_O_HTTP_CLO;
1897 goto out;
1898 }
1899 else if (kwm == KWM_NO) {
1900 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1901 curproxy->options &= ~PR_O_HTTP_MODE;
1902 goto out;
1903 }
1904 }
1905 else if (strcmp(args[1], "http-server-close") == 0) {
1906 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1907 goto out;
1908 if (kwm == KWM_STD) {
1909 curproxy->options &= ~PR_O_HTTP_MODE;
1910 curproxy->options |= PR_O_HTTP_SCL;
1911 goto out;
1912 }
1913 else if (kwm == KWM_NO) {
1914 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1915 curproxy->options &= ~PR_O_HTTP_MODE;
1916 goto out;
1917 }
1918 }
1919 else if (strcmp(args[1], "http-keep-alive") == 0) {
1920 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1921 goto out;
1922 if (kwm == KWM_STD) {
1923 curproxy->options &= ~PR_O_HTTP_MODE;
1924 curproxy->options |= PR_O_HTTP_KAL;
1925 goto out;
1926 }
1927 else if (kwm == KWM_NO) {
1928 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1929 curproxy->options &= ~PR_O_HTTP_MODE;
1930 goto out;
1931 }
1932 }
1933 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001934 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
1935 file, linenum, args[1]);
1936 err_code |= ERR_WARN;
1937 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001938 }
1939
1940 /* Redispatch can take an integer argument that control when the
1941 * resispatch occurs. All values are relative to the retries option.
1942 * This can be cancelled using "no option xxx".
1943 */
1944 if (strcmp(args[1], "redispatch") == 0) {
1945 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
1946 err_code |= ERR_WARN;
1947 goto out;
1948 }
1949
1950 curproxy->no_options &= ~PR_O_REDISP;
1951 curproxy->options &= ~PR_O_REDISP;
1952
1953 switch (kwm) {
1954 case KWM_STD:
1955 curproxy->options |= PR_O_REDISP;
1956 curproxy->redispatch_after = -1;
1957 if(*args[2]) {
1958 curproxy->redispatch_after = atol(args[2]);
1959 }
1960 break;
1961 case KWM_NO:
1962 curproxy->no_options |= PR_O_REDISP;
1963 curproxy->redispatch_after = 0;
1964 break;
1965 case KWM_DEF: /* already cleared */
1966 break;
1967 }
1968 goto out;
1969 }
1970
1971 if (kwm != KWM_STD) {
1972 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
1973 file, linenum, args[1]);
1974 err_code |= ERR_ALERT | ERR_FATAL;
1975 goto out;
1976 }
1977
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001978 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001979 char *logformat;
1980 /* generate a complete HTTP log */
1981 logformat = default_http_log_format;
1982 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001983 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001984 curproxy->options2 |= PR_O2_CLFLOG;
1985 logformat = clf_http_log_format;
1986 } else {
1987 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
1988 err_code |= ERR_ALERT | ERR_FATAL;
1989 goto out;
1990 }
1991 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
1992 goto out;
1993 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01001994 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001995 char *oldlogformat = "log-format";
1996 char *clflogformat = "";
1997
1998 if (curproxy->conf.logformat_string == default_http_log_format)
1999 oldlogformat = "option httplog";
2000 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2001 oldlogformat = "option tcplog";
2002 else if (curproxy->conf.logformat_string == clf_http_log_format)
2003 oldlogformat = "option httplog clf";
2004 if (logformat == clf_http_log_format)
2005 clflogformat = " clf";
2006 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2007 file, linenum, clflogformat, oldlogformat);
2008 }
2009 if (curproxy->conf.logformat_string != default_http_log_format &&
2010 curproxy->conf.logformat_string != default_tcp_log_format &&
2011 curproxy->conf.logformat_string != clf_http_log_format)
2012 free(curproxy->conf.logformat_string);
2013 curproxy->conf.logformat_string = logformat;
2014
2015 free(curproxy->conf.lfs_file);
2016 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2017 curproxy->conf.lfs_line = curproxy->conf.args.line;
2018
Willy Tarreau5d095c22021-02-12 10:15:59 +01002019 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002020 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2021 file, linenum, curproxy->id);
2022 err_code |= ERR_WARN;
2023 }
2024 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002025 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002026 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002027 char *oldlogformat = "log-format";
2028
2029 if (curproxy->conf.logformat_string == default_http_log_format)
2030 oldlogformat = "option httplog";
2031 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2032 oldlogformat = "option tcplog";
2033 else if (curproxy->conf.logformat_string == clf_http_log_format)
2034 oldlogformat = "option httplog clf";
2035 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2036 file, linenum, oldlogformat);
2037 }
2038 /* generate a detailed TCP log */
2039 if (curproxy->conf.logformat_string != default_http_log_format &&
2040 curproxy->conf.logformat_string != default_tcp_log_format &&
2041 curproxy->conf.logformat_string != clf_http_log_format)
2042 free(curproxy->conf.logformat_string);
2043 curproxy->conf.logformat_string = default_tcp_log_format;
2044
2045 free(curproxy->conf.lfs_file);
2046 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2047 curproxy->conf.lfs_line = curproxy->conf.args.line;
2048
2049 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2050 goto out;
2051
Willy Tarreau5d095c22021-02-12 10:15:59 +01002052 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002053 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2054 file, linenum, curproxy->id);
2055 err_code |= ERR_WARN;
2056 }
2057 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002058 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002059 /* enable TCP keep-alives on client and server streams */
2060 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2061 err_code |= ERR_WARN;
2062
2063 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2064 goto out;
2065
2066 if (curproxy->cap & PR_CAP_FE)
2067 curproxy->options |= PR_O_TCP_CLI_KA;
2068 if (curproxy->cap & PR_CAP_BE)
2069 curproxy->options |= PR_O_TCP_SRV_KA;
2070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002071 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002072 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002073 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002074 goto out;
2075 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002076 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002077 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002078 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002079 goto out;
2080 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002081 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002082 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002083 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002084 goto out;
2085 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002086 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002087 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002088 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002089 goto out;
2090 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002091 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002092 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002093 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002094 goto out;
2095 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002096 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002097 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002098 if (err_code & ERR_FATAL)
2099 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002100 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002101 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002102 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002103 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002104 goto out;
2105 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002106 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002107 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002108 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002109 goto out;
2110 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002111 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002112 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002113 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002114 goto out;
2115 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002116 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002117 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002118 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002119 goto out;
2120 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002121 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002122 int cur_arg;
2123
2124 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002125 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002126 */
2127
2128 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2129
2130 free(curproxy->fwdfor_hdr_name);
2131 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2132 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002133 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002134
2135 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2136 cur_arg = 2;
2137 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002138 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002139 unsigned char mask;
2140 int i;
2141
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002142 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002143 if (*(args[cur_arg+1]) &&
2144 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2145 curproxy->except_xff_net.family = AF_INET;
2146 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2147 }
2148 else if (*(args[cur_arg+1]) &&
2149 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2150 curproxy->except_xff_net.family = AF_INET6;
2151 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2152 for (i = 0; i < 16; i++)
2153 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2154 }
2155 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002156 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2157 file, linenum, args[0], args[1], args[cur_arg]);
2158 err_code |= ERR_ALERT | ERR_FATAL;
2159 goto out;
2160 }
2161 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002162 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002163 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002164 /* suboption header - needs additional argument for it */
2165 if (*(args[cur_arg+1]) == 0) {
2166 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2167 file, linenum, args[0], args[1], args[cur_arg]);
2168 err_code |= ERR_ALERT | ERR_FATAL;
2169 goto out;
2170 }
2171 free(curproxy->fwdfor_hdr_name);
2172 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2173 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2174 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002175 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002176 curproxy->options &= ~PR_O_FF_ALWAYS;
2177 cur_arg += 1;
2178 } else {
2179 /* unknown suboption - catchall */
2180 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2181 file, linenum, args[0], args[1]);
2182 err_code |= ERR_ALERT | ERR_FATAL;
2183 goto out;
2184 }
2185 } /* end while loop */
2186 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002187 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002188 int cur_arg;
2189
2190 /* insert x-original-to field, but not for the IP address listed as an except.
2191 * set default options (ie: bitfield, header name, etc)
2192 */
2193
2194 curproxy->options |= PR_O_ORGTO;
2195
2196 free(curproxy->orgto_hdr_name);
2197 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2198 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002199 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002200
2201 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2202 cur_arg = 2;
2203 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002204 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002205 unsigned char mask;
2206 int i;
2207
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002208 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002209 if (*(args[cur_arg+1]) &&
2210 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2211 curproxy->except_xot_net.family = AF_INET;
2212 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2213 }
2214 else if (*(args[cur_arg+1]) &&
2215 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2216 curproxy->except_xot_net.family = AF_INET6;
2217 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2218 for (i = 0; i < 16; i++)
2219 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2220 }
2221 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002222 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2223 file, linenum, args[0], args[1], args[cur_arg]);
2224 err_code |= ERR_ALERT | ERR_FATAL;
2225 goto out;
2226 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002227 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002228 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002229 /* suboption header - needs additional argument for it */
2230 if (*(args[cur_arg+1]) == 0) {
2231 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2232 file, linenum, args[0], args[1], args[cur_arg]);
2233 err_code |= ERR_ALERT | ERR_FATAL;
2234 goto out;
2235 }
2236 free(curproxy->orgto_hdr_name);
2237 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2238 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2239 cur_arg += 2;
2240 } else {
2241 /* unknown suboption - catchall */
2242 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2243 file, linenum, args[0], args[1]);
2244 err_code |= ERR_ALERT | ERR_FATAL;
2245 goto out;
2246 }
2247 } /* end while loop */
2248 }
2249 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002250 const char *best = proxy_find_best_option(args[1], common_options);
2251
2252 if (best)
2253 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2254 else
2255 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2256
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002257 err_code |= ERR_ALERT | ERR_FATAL;
2258 goto out;
2259 }
2260 goto out;
2261 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002262 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002263 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2264 err_code |= ERR_WARN;
2265
2266 if (*(args[1]) == 0) {
2267 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2268 err_code |= ERR_ALERT | ERR_FATAL;
2269 goto out;
2270 }
2271 free(curproxy->defbe.name);
2272 curproxy->defbe.name = strdup(args[1]);
2273
2274 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2275 goto out;
2276 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002277 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002278 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 +01002279
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002280 err_code |= ERR_ALERT | ERR_FATAL;
2281 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002282 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002283 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002284 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2285 err_code |= ERR_WARN;
2286
2287 if (strcmp(args[1], "never") == 0) {
2288 /* enable a graceful server shutdown on an HTTP 404 response */
2289 curproxy->options &= ~PR_O_REUSE_MASK;
2290 curproxy->options |= PR_O_REUSE_NEVR;
2291 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2292 goto out;
2293 }
2294 else if (strcmp(args[1], "safe") == 0) {
2295 /* enable a graceful server shutdown on an HTTP 404 response */
2296 curproxy->options &= ~PR_O_REUSE_MASK;
2297 curproxy->options |= PR_O_REUSE_SAFE;
2298 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2299 goto out;
2300 }
2301 else if (strcmp(args[1], "aggressive") == 0) {
2302 curproxy->options &= ~PR_O_REUSE_MASK;
2303 curproxy->options |= PR_O_REUSE_AGGR;
2304 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2305 goto out;
2306 }
2307 else if (strcmp(args[1], "always") == 0) {
2308 /* enable a graceful server shutdown on an HTTP 404 response */
2309 curproxy->options &= ~PR_O_REUSE_MASK;
2310 curproxy->options |= PR_O_REUSE_ALWS;
2311 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2312 goto out;
2313 }
2314 else {
2315 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2316 err_code |= ERR_ALERT | ERR_FATAL;
2317 goto out;
2318 }
2319 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002320 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002321 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002322 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2323 err_code |= ERR_ALERT | ERR_FATAL;
2324 goto out;
2325 }
2326
2327 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2328 err_code |= ERR_WARN;
2329
2330 if (strcmp(args[1], "fail") == 0) {
2331 /* add a condition to fail monitor requests */
2332 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2333 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2334 file, linenum, args[0], args[1]);
2335 err_code |= ERR_ALERT | ERR_FATAL;
2336 goto out;
2337 }
2338
2339 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2340 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2341 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2342 file, linenum, args[0], args[1], errmsg);
2343 err_code |= ERR_ALERT | ERR_FATAL;
2344 goto out;
2345 }
2346 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2347 }
2348 else {
2349 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2350 err_code |= ERR_ALERT | ERR_FATAL;
2351 goto out;
2352 }
2353 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002354#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002355 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002356 /* enable transparent proxy connections */
2357 curproxy->options |= PR_O_TRANSP;
2358 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2359 goto out;
2360 }
2361#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002362 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002363 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2364 err_code |= ERR_WARN;
2365
2366 if (*(args[1]) == 0) {
2367 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2368 err_code |= ERR_ALERT | ERR_FATAL;
2369 goto out;
2370 }
2371 curproxy->maxconn = atol(args[1]);
2372 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2373 goto out;
2374 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002375 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002376 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2377 err_code |= ERR_WARN;
2378
2379 if (*(args[1]) == 0) {
2380 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2381 err_code |= ERR_ALERT | ERR_FATAL;
2382 goto out;
2383 }
2384 curproxy->backlog = atol(args[1]);
2385 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2386 goto out;
2387 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002388 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002389 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2390 err_code |= ERR_WARN;
2391
2392 if (*(args[1]) == 0) {
2393 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2394 err_code |= ERR_ALERT | ERR_FATAL;
2395 goto out;
2396 }
2397 curproxy->fullconn = atol(args[1]);
2398 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2399 goto out;
2400 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002401 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002402 if (*(args[1]) == 0) {
2403 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2404 err_code |= ERR_ALERT | ERR_FATAL;
2405 goto out;
2406 }
2407 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002408 if (err == PARSE_TIME_OVER) {
2409 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2410 file, linenum, args[1]);
2411 err_code |= ERR_ALERT | ERR_FATAL;
2412 goto out;
2413 }
2414 else if (err == PARSE_TIME_UNDER) {
2415 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2416 file, linenum, args[1]);
2417 err_code |= ERR_ALERT | ERR_FATAL;
2418 goto out;
2419 }
2420 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002421 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2422 file, linenum, *err);
2423 err_code |= ERR_ALERT | ERR_FATAL;
2424 goto out;
2425 }
2426 curproxy->grace = val;
2427 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2428 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002429
2430 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2431 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002432 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002433 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002434 struct sockaddr_storage *sk;
2435 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002436
Willy Tarreau5d095c22021-02-12 10:15:59 +01002437 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002438 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2439 err_code |= ERR_ALERT | ERR_FATAL;
2440 goto out;
2441 }
2442 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2443 err_code |= ERR_WARN;
2444
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002445 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2446 &errmsg, NULL, NULL,
2447 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 +01002448 if (!sk) {
2449 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2450 err_code |= ERR_ALERT | ERR_FATAL;
2451 goto out;
2452 }
2453
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002454 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2455 goto out;
2456
2457 curproxy->dispatch_addr = *sk;
2458 curproxy->options |= PR_O_DISPATCH;
2459 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002460 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002461 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2462 err_code |= ERR_WARN;
2463
2464 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2465 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2466 err_code |= ERR_ALERT | ERR_FATAL;
2467 goto out;
2468 }
2469 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002470 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002471 /**
2472 * The syntax for hash-type config element is
2473 * hash-type {map-based|consistent} [[<algo>] avalanche]
2474 *
2475 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2476 */
2477 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2478
2479 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2480 err_code |= ERR_WARN;
2481
2482 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2483 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2484 }
2485 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2486 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2487 }
2488 else if (strcmp(args[1], "avalanche") == 0) {
2489 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]);
2490 err_code |= ERR_ALERT | ERR_FATAL;
2491 goto out;
2492 }
2493 else {
2494 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2495 err_code |= ERR_ALERT | ERR_FATAL;
2496 goto out;
2497 }
2498
2499 /* set the hash function to use */
2500 if (!*args[2]) {
2501 /* the default algo is sdbm */
2502 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2503
2504 /* if consistent with no argument, then avalanche modifier is also applied */
2505 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2506 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2507 } else {
2508 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002509 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002510 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2511 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002512 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002513 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2514 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002515 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002516 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2517 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002518 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002519 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2520 }
2521 else {
2522 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2523 err_code |= ERR_ALERT | ERR_FATAL;
2524 goto out;
2525 }
2526
2527 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002528 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002529 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2530 }
2531 else if (*args[3]) {
2532 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2533 err_code |= ERR_ALERT | ERR_FATAL;
2534 goto out;
2535 }
2536 }
2537 }
2538 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2539 if (*(args[1]) == 0) {
2540 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2541 err_code |= ERR_ALERT | ERR_FATAL;
2542 goto out;
2543 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002544 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2545 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002546 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2547 err_code |= ERR_ALERT | ERR_FATAL;
2548 goto out;
2549 }
2550 }
2551 else if (strcmp(args[0], "unique-id-format") == 0) {
2552 if (!*(args[1])) {
2553 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2554 err_code |= ERR_ALERT | ERR_FATAL;
2555 goto out;
2556 }
2557 if (*(args[2])) {
2558 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2559 err_code |= ERR_ALERT | ERR_FATAL;
2560 goto out;
2561 }
2562 free(curproxy->conf.uniqueid_format_string);
2563 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2564
2565 free(curproxy->conf.uif_file);
2566 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2567 curproxy->conf.uif_line = curproxy->conf.args.line;
2568 }
2569
2570 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002571 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002572 if (!*(args[1])) {
2573 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2574 err_code |= ERR_ALERT | ERR_FATAL;
2575 goto out;
2576 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002577 copy = strdup(args[1]);
2578 if (copy == NULL) {
2579 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2580 err_code |= ERR_ALERT | ERR_FATAL;
2581 goto out;
2582 }
2583
2584 istfree(&curproxy->header_unique_id);
2585 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002586 }
2587
2588 else if (strcmp(args[0], "log-format") == 0) {
2589 if (!*(args[1])) {
2590 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2591 err_code |= ERR_ALERT | ERR_FATAL;
2592 goto out;
2593 }
2594 if (*(args[2])) {
2595 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2596 err_code |= ERR_ALERT | ERR_FATAL;
2597 goto out;
2598 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002599 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002600 char *oldlogformat = "log-format";
2601
2602 if (curproxy->conf.logformat_string == default_http_log_format)
2603 oldlogformat = "option httplog";
2604 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2605 oldlogformat = "option tcplog";
2606 else if (curproxy->conf.logformat_string == clf_http_log_format)
2607 oldlogformat = "option httplog clf";
2608 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2609 file, linenum, oldlogformat);
2610 }
2611 if (curproxy->conf.logformat_string != default_http_log_format &&
2612 curproxy->conf.logformat_string != default_tcp_log_format &&
2613 curproxy->conf.logformat_string != clf_http_log_format)
2614 free(curproxy->conf.logformat_string);
2615 curproxy->conf.logformat_string = strdup(args[1]);
2616
2617 free(curproxy->conf.lfs_file);
2618 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2619 curproxy->conf.lfs_line = curproxy->conf.args.line;
2620
2621 /* get a chance to improve log-format error reporting by
2622 * reporting the correct line-number when possible.
2623 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002624 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002625 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2626 file, linenum, curproxy->id);
2627 err_code |= ERR_WARN;
2628 }
2629 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002630 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002631 if (!*(args[1])) {
2632 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2633 err_code |= ERR_ALERT | ERR_FATAL;
2634 goto out;
2635 }
2636 if (*(args[2])) {
2637 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2638 err_code |= ERR_ALERT | ERR_FATAL;
2639 goto out;
2640 }
2641
2642 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2643 free(curproxy->conf.logformat_sd_string);
2644 curproxy->conf.logformat_sd_string = strdup(args[1]);
2645
2646 free(curproxy->conf.lfsd_file);
2647 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2648 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2649
2650 /* get a chance to improve log-format-sd error reporting by
2651 * reporting the correct line-number when possible.
2652 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002653 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002654 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2655 file, linenum, curproxy->id);
2656 err_code |= ERR_WARN;
2657 }
2658 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002659 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002660 if (*(args[1]) == 0) {
2661 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2662 err_code |= ERR_ALERT | ERR_FATAL;
2663 goto out;
2664 }
2665 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002666 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2667 if (b_orig(&curproxy->log_tag) == NULL) {
2668 chunk_destroy(&curproxy->log_tag);
2669 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2670 err_code |= ERR_ALERT | ERR_FATAL;
2671 goto out;
2672 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002673 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002674 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002675 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2676 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2677 err_code |= ERR_ALERT | ERR_FATAL;
2678 goto out;
2679 }
2680 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002681 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002682 int cur_arg;
2683 int port1, port2;
2684 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002685
2686 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2687 err_code |= ERR_WARN;
2688
2689 if (!*args[1]) {
2690 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2691 file, linenum, "source", "usesrc", "interface");
2692 err_code |= ERR_ALERT | ERR_FATAL;
2693 goto out;
2694 }
2695
Christopher Faulet31930372019-07-15 10:16:58 +02002696 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002697 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002698 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002699 curproxy->conn_src.iface_len = 0;
2700
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002701 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2702 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002703 if (!sk) {
2704 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2705 file, linenum, args[0], args[1], errmsg);
2706 err_code |= ERR_ALERT | ERR_FATAL;
2707 goto out;
2708 }
2709
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002710 curproxy->conn_src.source_addr = *sk;
2711 curproxy->conn_src.opts |= CO_SRC_BIND;
2712
2713 cur_arg = 2;
2714 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002715 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002716#if defined(CONFIG_HAP_TRANSPARENT)
2717 if (!*args[cur_arg + 1]) {
2718 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2719 file, linenum, "usesrc");
2720 err_code |= ERR_ALERT | ERR_FATAL;
2721 goto out;
2722 }
2723
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002724 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002725 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2726 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002727 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002728 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2729 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2730 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2731 char *name, *end;
2732
2733 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002734 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002735 name++;
2736
2737 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002738 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002739 end++;
2740
2741 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2742 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002743 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002744 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2745 curproxy->conn_src.bind_hdr_len = end - name;
2746 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2747 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2748 curproxy->conn_src.bind_hdr_occ = -1;
2749
2750 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002751 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002752 end++;
2753 if (*end == ',') {
2754 end++;
2755 name = end;
2756 if (*end == '-')
2757 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002758 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002759 end++;
2760 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2761 }
2762
2763 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2764 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2765 " occurrences values smaller than %d.\n",
2766 file, linenum, MAX_HDR_HISTORY);
2767 err_code |= ERR_ALERT | ERR_FATAL;
2768 goto out;
2769 }
2770 } else {
2771 struct sockaddr_storage *sk;
2772
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002773 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2774 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002775 if (!sk) {
2776 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2777 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2778 err_code |= ERR_ALERT | ERR_FATAL;
2779 goto out;
2780 }
2781
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002782 curproxy->conn_src.tproxy_addr = *sk;
2783 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2784 }
2785 global.last_checks |= LSTCHK_NETADM;
2786#else /* no TPROXY support */
2787 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2788 file, linenum, "usesrc");
2789 err_code |= ERR_ALERT | ERR_FATAL;
2790 goto out;
2791#endif
2792 cur_arg += 2;
2793 continue;
2794 }
2795
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002796 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002797#ifdef SO_BINDTODEVICE
2798 if (!*args[cur_arg + 1]) {
2799 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2800 file, linenum, args[0]);
2801 err_code |= ERR_ALERT | ERR_FATAL;
2802 goto out;
2803 }
2804 free(curproxy->conn_src.iface_name);
2805 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2806 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2807 global.last_checks |= LSTCHK_NETADM;
2808#else
2809 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2810 file, linenum, args[0], args[cur_arg]);
2811 err_code |= ERR_ALERT | ERR_FATAL;
2812 goto out;
2813#endif
2814 cur_arg += 2;
2815 continue;
2816 }
2817 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2818 file, linenum, args[0], "interface", "usesrc");
2819 err_code |= ERR_ALERT | ERR_FATAL;
2820 goto out;
2821 }
2822 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002823 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002824 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2825 file, linenum, "usesrc", "source");
2826 err_code |= ERR_ALERT | ERR_FATAL;
2827 goto out;
2828 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002829 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 +02002830 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002831 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002832 file, linenum, args[0]);
2833 err_code |= ERR_ALERT | ERR_FATAL;
2834 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002835 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002836 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002837 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2838 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2839 err_code |= ERR_ALERT | ERR_FATAL;
2840 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002841 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002842 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002843 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2844 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2845 err_code |= ERR_ALERT | ERR_FATAL;
2846 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002847 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002848 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002849 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2850 err_code |= ERR_ALERT | ERR_FATAL;
2851 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002852 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002853 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002854 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2855 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2856 err_code |= ERR_ALERT | ERR_FATAL;
2857 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002858 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002859 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002860 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2861 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2862 err_code |= ERR_ALERT | ERR_FATAL;
2863 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002864 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002865 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002866 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2867 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2868 err_code |= ERR_ALERT | ERR_FATAL;
2869 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002870 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002871 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002872 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2873 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2874 err_code |= ERR_ALERT | ERR_FATAL;
2875 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002876 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002877 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 +02002878 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2879 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2880 err_code |= ERR_ALERT | ERR_FATAL;
2881 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002882 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002883 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002884 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2885 err_code |= ERR_ALERT | ERR_FATAL;
2886 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002887 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002888 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 +02002889 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2890 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2891 err_code |= ERR_ALERT | ERR_FATAL;
2892 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002893 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002894 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 +02002895 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2896 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2897 err_code |= ERR_ALERT | ERR_FATAL;
2898 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002899 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002900 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002901 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2902 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2903 err_code |= ERR_ALERT | ERR_FATAL;
2904 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002905 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002906 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 +02002907 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2908 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2909 err_code |= ERR_ALERT | ERR_FATAL;
2910 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002911 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002912 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002913 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2914 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2915 err_code |= ERR_ALERT | ERR_FATAL;
2916 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002917 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002918 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002919 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2920 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2921 err_code |= ERR_ALERT | ERR_FATAL;
2922 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002923 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002924 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302925 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002926 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2927 err_code |= ERR_ALERT | ERR_FATAL;
2928 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002929 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002930 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002931 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2932 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2933 err_code |= ERR_ALERT | ERR_FATAL;
2934 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002935 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002936 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002937 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2938 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2939 err_code |= ERR_ALERT | ERR_FATAL;
2940 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002941 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002942 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002943 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2944 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2945 err_code |= ERR_ALERT | ERR_FATAL;
2946 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002947 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002948 else {
2949 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002950 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002951 int index;
2952
2953 list_for_each_entry(kwl, &cfg_keywords.list, list) {
2954 for (index = 0; kwl->kw[index].kw != NULL; index++) {
2955 if (kwl->kw[index].section != CFG_LISTEN)
2956 continue;
2957 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
2958 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01002959 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002960 if (rc < 0) {
2961 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2962 err_code |= ERR_ALERT | ERR_FATAL;
2963 goto out;
2964 }
2965 else if (rc > 0) {
2966 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2967 err_code |= ERR_WARN;
2968 goto out;
2969 }
2970 goto out;
2971 }
2972 }
2973 }
2974
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002975 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
2976 if (best)
2977 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
2978 else
2979 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002980 err_code |= ERR_ALERT | ERR_FATAL;
2981 goto out;
2982 }
2983 out:
2984 free(errmsg);
2985 return err_code;
2986}