blob: b60741aed036939201591b7d391333ec95c290c4 [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 Tarreau3a1f5fd2018-11-11 15:40:36 +010057/* Report a warning if a rule is placed after a 'tcp-request session' rule.
58 * Return 1 if the warning has been emitted, otherwise 0.
59 */
60int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
61{
62 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
63 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
64 file, line, arg);
65 return 1;
66 }
67 return 0;
68}
69
70/* Report a warning if a rule is placed after a 'tcp-request content' rule.
71 * Return 1 if the warning has been emitted, otherwise 0.
72 */
73int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
74{
75 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
76 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
77 file, line, arg);
78 return 1;
79 }
80 return 0;
81}
82
83/* Report a warning if a rule is placed after a 'monitor fail' rule.
84 * Return 1 if the warning has been emitted, otherwise 0.
85 */
86int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
87{
88 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
89 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
90 file, line, arg);
91 return 1;
92 }
93 return 0;
94}
95
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010096/* Report a warning if a rule is placed after an 'http_request' rule.
97 * Return 1 if the warning has been emitted, otherwise 0.
98 */
99int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
100{
101 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
102 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
103 file, line, arg);
104 return 1;
105 }
106 return 0;
107}
108
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100109/* Report a warning if a rule is placed after a redirect rule.
110 * Return 1 if the warning has been emitted, otherwise 0.
111 */
112int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
113{
114 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
115 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
116 file, line, arg);
117 return 1;
118 }
119 return 0;
120}
121
122/* Report a warning if a rule is placed after a 'use_backend' rule.
123 * Return 1 if the warning has been emitted, otherwise 0.
124 */
125int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
126{
127 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
128 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
129 file, line, arg);
130 return 1;
131 }
132 return 0;
133}
134
135/* Report a warning if a rule is placed after a 'use-server' rule.
136 * Return 1 if the warning has been emitted, otherwise 0.
137 */
138int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
139{
140 if (!LIST_ISEMPTY(&proxy->server_rules)) {
141 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
142 file, line, arg);
143 return 1;
144 }
145 return 0;
146}
147
148/* report a warning if a redirect rule is dangerously placed */
149int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
150{
151 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
152 warnif_rule_after_use_server(proxy, file, line, arg);
153}
154
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100155/* report a warning if an http-request rule is dangerously placed */
156int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
157{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200158 return warnif_rule_after_redirect(proxy, file, line, arg) ||
159 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100160}
161
162/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200163int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100164{
165 return warnif_rule_after_http_req(proxy, file, line, arg) ||
166 warnif_misplaced_http_req(proxy, file, line, arg);
167}
168
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100169/* report a warning if a "tcp request content" rule is dangerously placed */
170int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
171{
172 return warnif_rule_after_monitor(proxy, file, line, arg) ||
173 warnif_misplaced_monitor(proxy, file, line, arg);
174}
175
176/* report a warning if a "tcp request session" rule is dangerously placed */
177int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
178{
179 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
180 warnif_misplaced_tcp_cont(proxy, file, line, arg);
181}
182
183/* report a warning if a "tcp request connection" rule is dangerously placed */
184int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
185{
186 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
187 warnif_misplaced_tcp_sess(proxy, file, line, arg);
188}
189
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100190int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
191{
192 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100193 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100194 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100195 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100196 int rc;
197 unsigned val;
198 int err_code = 0;
199 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100200 char *errmsg = NULL;
201 struct bind_conf *bind_conf;
202
Willy Tarreaue90904d2021-02-12 14:08:31 +0100203 if (!last_defproxy) {
204 /* we need a default proxy and none was created yet */
205 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, "INIT", 0, NULL, &errmsg);
206 curr_defproxy = last_defproxy;
207 if (!last_defproxy) {
208 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
209 err_code |= ERR_ALERT | ERR_ABORT;
210 goto out;
211 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100212 }
213
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100214 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100215 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100216 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100217 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100218 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100219 rc = PR_CAP_BE;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100220 else if (strcmp(args[0], "defaults") == 0) {
221 /* "defaults" must first delete the last no-name defaults if any */
222 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
223 curr_defproxy = NULL;
224 rc = PR_CAP_DEF | PR_CAP_LISTEN;
225 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100226 else
227 rc = PR_CAP_NONE;
228
Willy Tarreaue90904d2021-02-12 14:08:31 +0100229 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100230 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100231 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100232 file, linenum, args[0]);
233 err_code |= ERR_ALERT | ERR_ABORT;
234 goto out;
235 }
236
237 err = invalid_char(args[1]);
238 if (err) {
239 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
240 file, linenum, *err, args[0], args[1]);
241 err_code |= ERR_ALERT | ERR_FATAL;
242 }
243
244 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
245 if (curproxy) {
246 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
247 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
248 curproxy->id, curproxy->conf.file, curproxy->conf.line);
249 err_code |= ERR_ALERT | ERR_FATAL;
250 }
251
Emeric Brunb0c331f2020-10-07 17:05:59 +0200252 curproxy = log_forward_by_name(args[1]);
253 if (curproxy) {
254 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
255 file, linenum, proxy_cap_str(rc), args[1],
256 curproxy->id, curproxy->conf.file, curproxy->conf.line);
257 err_code |= ERR_ALERT | ERR_FATAL;
258 }
259
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100260 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
261 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100262 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100263 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
264 goto out;
265 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100266 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100267
Willy Tarreaue90904d2021-02-12 14:08:31 +0100268 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100269 const char *name = args[1];
270 int arg = 2;
271
272 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
273 // also support "defaults from blah" (no name then)
274 arg = 1;
275 name = "";
276 }
277
278 /* only regular proxies inherit from the previous defaults section */
279 if (!(rc & PR_CAP_DEF))
280 curr_defproxy = last_defproxy;
281
282 if (strcmp(args[arg], "from") == 0) {
283 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
284
285 if (!curr_defproxy) {
286 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
287 err_code |= ERR_ALERT | ERR_ABORT;
288 goto out;
289 }
290
291 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
292 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
293
294 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
295 file, linenum, args[arg+1], proxy_cap_str(rc), name,
296 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
297 err_code |= ERR_ALERT | ERR_FATAL;
298 }
299
300 err = invalid_char(args[arg+1]);
301 if (err) {
302 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",
303 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
304 err_code |= ERR_ALERT | ERR_FATAL;
305 }
306 }
307
308 curproxy = alloc_new_proxy(name, rc, file, linenum, curr_defproxy, &errmsg);
Willy Tarreau76838932021-02-12 08:49:47 +0100309 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100310 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
311 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100312 goto out;
313 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100314
Willy Tarreaue90904d2021-02-12 14:08:31 +0100315 if (rc & PR_CAP_DEF) {
316 /* last and current proxies must be updated to this one */
317 curr_defproxy = last_defproxy = curproxy;
318 } else {
319 /* regular proxies are in a list */
320 curproxy->next = proxies_list;
321 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100322 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100323 goto out;
324 }
325 else if (curproxy == NULL) {
326 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
327 err_code |= ERR_ALERT | ERR_FATAL;
328 goto out;
329 }
330
331 /* update the current file and line being parsed */
332 curproxy->conf.args.file = curproxy->conf.file;
333 curproxy->conf.args.line = linenum;
334
335 /* Now let's parse the proxy-specific keywords */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100336 if (strcmp(args[0], "server") == 0 ||
337 strcmp(args[0], "default-server") == 0 ||
338 strcmp(args[0], "server-template") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +0100339 err_code |= parse_server(file, linenum, args, curproxy, curr_defproxy, 1, 0, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100340 if (err_code & ERR_FATAL)
341 goto out;
342 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100343 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100344 struct listener *l;
345 int cur_arg;
346
Willy Tarreau5d095c22021-02-12 10:15:59 +0100347 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100348 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
349 err_code |= ERR_ALERT | ERR_FATAL;
350 goto out;
351 }
352 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
353 err_code |= ERR_WARN;
354
355 if (!*(args[1])) {
356 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
357 file, linenum, args[0]);
358 err_code |= ERR_ALERT | ERR_FATAL;
359 goto out;
360 }
361
362 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
363
364 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200365 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
366 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
367 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100368
369 /* NOTE: the following line might create several listeners if there
370 * are comma-separated IPs or port ranges. So all further processing
371 * will have to be applied to all listeners created after last_listen.
372 */
373 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
374 if (errmsg && *errmsg) {
375 indent_msg(&errmsg, 2);
376 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
377 }
378 else
379 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
380 file, linenum, args[0], args[1]);
381 err_code |= ERR_ALERT | ERR_FATAL;
382 goto out;
383 }
384
385 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
386 /* Set default global rights and owner for unix bind */
387 global.maxsock++;
388 }
389
390 cur_arg = 2;
391 while (*(args[cur_arg])) {
392 static int bind_dumped;
393 struct bind_kw *kw;
394 char *err;
395
396 kw = bind_find_kw(args[cur_arg]);
397 if (kw) {
398 char *err = NULL;
399 int code;
400
401 if (!kw->parse) {
402 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
403 file, linenum, args[0], args[1], args[cur_arg]);
404 cur_arg += 1 + kw->skip ;
405 err_code |= ERR_ALERT | ERR_FATAL;
406 goto out;
407 }
408
409 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
410 err_code |= code;
411
412 if (code) {
413 if (err && *err) {
414 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200415 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
416 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
417 else
418 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100419 }
420 else
421 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
422 file, linenum, args[0], args[1], args[cur_arg]);
423 if (code & ERR_FATAL) {
424 free(err);
425 cur_arg += 1 + kw->skip;
426 goto out;
427 }
428 }
429 free(err);
430 cur_arg += 1 + kw->skip;
431 continue;
432 }
433
434 err = NULL;
435 if (!bind_dumped) {
436 bind_dump_kws(&err);
437 indent_msg(&err, 4);
438 bind_dumped = 1;
439 }
440
441 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
442 file, linenum, args[0], args[1], args[cur_arg],
443 err ? " Registered keywords :" : "", err ? err : "");
444 free(err);
445
446 err_code |= ERR_ALERT | ERR_FATAL;
447 goto out;
448 }
449 goto out;
450 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100451 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200452 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]);
453 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100454 goto out;
455 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100456 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100457 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
458 err_code |= ERR_WARN;
459
460 if (alertif_too_many_args(1, file, linenum, args, &err_code))
461 goto out;
462
463 if (!*args[1]) {
464 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
465 file, linenum, args[0]);
466 err_code |= ERR_ALERT | ERR_FATAL;
467 goto out;
468 }
469
470 free(curproxy->monitor_uri);
471 curproxy->monitor_uri_len = strlen(args[1]);
472 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
473 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
474 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
475
476 goto out;
477 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100478 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100479 if (alertif_too_many_args(1, file, linenum, args, &err_code))
480 goto out;
481
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100482 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
483 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
484 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200485 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
486 err_code |= ERR_ALERT | ERR_FATAL;
487 goto out;
488 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100489 else {
490 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
491 err_code |= ERR_ALERT | ERR_FATAL;
492 goto out;
493 }
494 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100495 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100496 struct eb32_node *node;
497
Willy Tarreau5d095c22021-02-12 10:15:59 +0100498 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100499 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
500 file, linenum, args[0]);
501 err_code |= ERR_ALERT | ERR_FATAL;
502 goto out;
503 }
504
505 if (alertif_too_many_args(1, file, linenum, args, &err_code))
506 goto out;
507
508 if (!*args[1]) {
509 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
510 file, linenum, args[0]);
511 err_code |= ERR_ALERT | ERR_FATAL;
512 goto out;
513 }
514
515 curproxy->uuid = atol(args[1]);
516 curproxy->conf.id.key = curproxy->uuid;
517 curproxy->options |= PR_O_FORCED_ID;
518
519 if (curproxy->uuid <= 0) {
520 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
521 file, linenum);
522 err_code |= ERR_ALERT | ERR_FATAL;
523 goto out;
524 }
525
526 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
527 if (node) {
528 struct proxy *target = container_of(node, struct proxy, conf.id);
529 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
530 file, linenum, proxy_type_str(curproxy), curproxy->id,
531 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
532 err_code |= ERR_ALERT | ERR_FATAL;
533 goto out;
534 }
535 eb32_insert(&used_proxy_id, &curproxy->conf.id);
536 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100537 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100538 int i, len=0;
539 char *d;
540
Willy Tarreau5d095c22021-02-12 10:15:59 +0100541 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100542 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
543 file, linenum, args[0]);
544 err_code |= ERR_ALERT | ERR_FATAL;
545 goto out;
546 }
547
548 if (!*args[1]) {
549 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
550 file, linenum, args[0]);
551 return -1;
552 }
553
554 for (i = 1; *args[i]; i++)
555 len += strlen(args[i]) + 1;
556
557 d = calloc(1, len);
558 curproxy->desc = d;
559
560 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
561 for (i = 2; *args[i]; i++)
562 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
563
564 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100565 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100566 if (alertif_too_many_args(0, file, linenum, args, &err_code))
567 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200568 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100569 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100570 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100571 if (alertif_too_many_args(0, file, linenum, args, &err_code))
572 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200573 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100574 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100575 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100576 int cur_arg = 1;
577 unsigned long set = 0;
578
579 while (*args[cur_arg]) {
580 if (strcmp(args[cur_arg], "all") == 0) {
581 set = 0;
582 break;
583 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100584 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100585 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
586 err_code |= ERR_ALERT | ERR_FATAL;
587 goto out;
588 }
589 cur_arg++;
590 }
591 curproxy->bind_proc = set;
592 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100593 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100594 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100595 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
596 err_code |= ERR_ALERT | ERR_FATAL;
597 goto out;
598 }
599
600 err = invalid_char(args[1]);
601 if (err) {
602 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
603 file, linenum, *err, args[1]);
604 err_code |= ERR_ALERT | ERR_FATAL;
605 goto out;
606 }
607
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100608 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100609 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100610 "logical disjunction within a condition.\n",
611 file, linenum, args[1]);
612 err_code |= ERR_ALERT | ERR_FATAL;
613 goto out;
614 }
615
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100616 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
617 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
618 file, linenum, args[1], errmsg);
619 err_code |= ERR_ALERT | ERR_FATAL;
620 goto out;
621 }
622 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100623 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100624
625 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
626 err_code |= ERR_WARN;
627
628 if (*(args[1]) == 0) {
629 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
630 file, linenum, args[0]);
631 err_code |= ERR_ALERT | ERR_FATAL;
632 goto out;
633 }
634 free(curproxy->dyncookie_key);
635 curproxy->dyncookie_key = strdup(args[1]);
636 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100637 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100638 int cur_arg;
639
640 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
641 err_code |= ERR_WARN;
642
643 if (*(args[1]) == 0) {
644 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
645 file, linenum, args[0]);
646 err_code |= ERR_ALERT | ERR_FATAL;
647 goto out;
648 }
649
650 curproxy->ck_opts = 0;
651 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100652 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100653 free(curproxy->cookie_name);
654 curproxy->cookie_name = strdup(args[1]);
655 curproxy->cookie_len = strlen(curproxy->cookie_name);
656
657 cur_arg = 2;
658 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100659 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100660 curproxy->ck_opts |= PR_CK_RW;
661 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100662 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100663 curproxy->ck_opts |= PR_CK_IND;
664 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100665 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100666 curproxy->ck_opts |= PR_CK_INS;
667 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100668 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100669 curproxy->ck_opts |= PR_CK_NOC;
670 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100671 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100672 curproxy->ck_opts |= PR_CK_POST;
673 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100674 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100675 curproxy->ck_opts |= PR_CK_PSV;
676 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100677 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100678 curproxy->ck_opts |= PR_CK_PFX;
679 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100680 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100681 curproxy->ck_opts |= PR_CK_HTTPONLY;
682 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100683 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100684 curproxy->ck_opts |= PR_CK_SECURE;
685 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100686 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100687 if (!*args[cur_arg + 1]) {
688 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
689 file, linenum, args[cur_arg]);
690 err_code |= ERR_ALERT | ERR_FATAL;
691 goto out;
692 }
693
Joao Moraise1583752019-10-30 21:04:00 -0300694 if (!strchr(args[cur_arg + 1], '.')) {
695 /* rfc6265, 5.2.3 The Domain Attribute */
696 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
697 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100698 file, linenum, args[cur_arg + 1]);
699 err_code |= ERR_WARN;
700 }
701
702 err = invalid_domainchar(args[cur_arg + 1]);
703 if (err) {
704 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
705 file, linenum, *err, args[cur_arg + 1]);
706 err_code |= ERR_ALERT | ERR_FATAL;
707 goto out;
708 }
709
710 if (!curproxy->cookie_domain) {
711 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
712 } else {
713 /* one domain was already specified, add another one by
714 * building the string which will be returned along with
715 * the cookie.
716 */
717 char *new_ptr;
718 int new_len = strlen(curproxy->cookie_domain) +
719 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
720 new_ptr = malloc(new_len);
721 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
722 free(curproxy->cookie_domain);
723 curproxy->cookie_domain = new_ptr;
724 }
725 cur_arg++;
726 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100727 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100728 unsigned int maxidle;
729 const char *res;
730
731 if (!*args[cur_arg + 1]) {
732 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
733 file, linenum, args[cur_arg]);
734 err_code |= ERR_ALERT | ERR_FATAL;
735 goto out;
736 }
737
738 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200739 if (res == PARSE_TIME_OVER) {
740 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
741 file, linenum, args[cur_arg+1], args[cur_arg]);
742 err_code |= ERR_ALERT | ERR_FATAL;
743 goto out;
744 }
745 else if (res == PARSE_TIME_UNDER) {
746 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
747 file, linenum, args[cur_arg+1], args[cur_arg]);
748 err_code |= ERR_ALERT | ERR_FATAL;
749 goto out;
750 }
751 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100752 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
753 file, linenum, *res, args[cur_arg]);
754 err_code |= ERR_ALERT | ERR_FATAL;
755 goto out;
756 }
757 curproxy->cookie_maxidle = maxidle;
758 cur_arg++;
759 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100760 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100761 unsigned int maxlife;
762 const char *res;
763
764 if (!*args[cur_arg + 1]) {
765 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
766 file, linenum, args[cur_arg]);
767 err_code |= ERR_ALERT | ERR_FATAL;
768 goto out;
769 }
770
Willy Tarreau9faebe32019-06-07 19:00:37 +0200771
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100772 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200773 if (res == PARSE_TIME_OVER) {
774 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
775 file, linenum, args[cur_arg+1], args[cur_arg]);
776 err_code |= ERR_ALERT | ERR_FATAL;
777 goto out;
778 }
779 else if (res == PARSE_TIME_UNDER) {
780 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
781 file, linenum, args[cur_arg+1], args[cur_arg]);
782 err_code |= ERR_ALERT | ERR_FATAL;
783 goto out;
784 }
785 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100786 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
787 file, linenum, *res, args[cur_arg]);
788 err_code |= ERR_ALERT | ERR_FATAL;
789 goto out;
790 }
791 curproxy->cookie_maxlife = maxlife;
792 cur_arg++;
793 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100794 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100795
796 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
797 err_code |= ERR_WARN;
798 curproxy->ck_opts |= PR_CK_DYNAMIC;
799 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100800 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100801 char *val;
802 if (!*args[cur_arg + 1]) {
803 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
804 file, linenum, args[cur_arg]);
805 err_code |= ERR_ALERT | ERR_FATAL;
806 goto out;
807 }
808 val = args[cur_arg + 1];
809 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100810 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100811 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
812 file, linenum, *val);
813 err_code |= ERR_ALERT | ERR_FATAL;
814 goto out;
815 }
816 val++;
817 }
818 /* don't add ';' for the first attribute */
819 if (!curproxy->cookie_attrs)
820 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
821 else
822 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
823 cur_arg++;
824 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100825
826 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100827 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 +0100828 file, linenum, args[0]);
829 err_code |= ERR_ALERT | ERR_FATAL;
830 goto out;
831 }
832 cur_arg++;
833 }
834 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
835 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
836 file, linenum);
837 err_code |= ERR_ALERT | ERR_FATAL;
838 }
839
840 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
841 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
842 file, linenum);
843 err_code |= ERR_ALERT | ERR_FATAL;
844 }
845
846 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
847 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
848 file, linenum);
849 err_code |= ERR_ALERT | ERR_FATAL;
850 }
851 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100852 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100853 if (*(args[1]) == 0) {
854 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
855 file, linenum, args[0]);
856 err_code |= ERR_ALERT | ERR_FATAL;
857 goto out;
858 }
859
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100860 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100861 if (*(args[1]) == 0) {
862 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
863 file, linenum, args[1]);
864 err_code |= ERR_ALERT | ERR_FATAL;
865 goto out;
866 }
867 free(curproxy->email_alert.from);
868 curproxy->email_alert.from = strdup(args[2]);
869 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100870 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100871 if (*(args[1]) == 0) {
872 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
873 file, linenum, args[1]);
874 err_code |= ERR_ALERT | ERR_FATAL;
875 goto out;
876 }
877 free(curproxy->email_alert.mailers.name);
878 curproxy->email_alert.mailers.name = strdup(args[2]);
879 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100880 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100881 if (*(args[1]) == 0) {
882 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
883 file, linenum, args[1]);
884 err_code |= ERR_ALERT | ERR_FATAL;
885 goto out;
886 }
887 free(curproxy->email_alert.myhostname);
888 curproxy->email_alert.myhostname = strdup(args[2]);
889 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100890 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100891 curproxy->email_alert.level = get_log_level(args[2]);
892 if (curproxy->email_alert.level < 0) {
893 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
894 file, linenum, args[1], args[2]);
895 err_code |= ERR_ALERT | ERR_FATAL;
896 goto out;
897 }
898 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100899 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100900 if (*(args[1]) == 0) {
901 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
902 file, linenum, args[1]);
903 err_code |= ERR_ALERT | ERR_FATAL;
904 goto out;
905 }
906 free(curproxy->email_alert.to);
907 curproxy->email_alert.to = strdup(args[2]);
908 }
909 else {
910 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
911 file, linenum, args[1]);
912 err_code |= ERR_ALERT | ERR_FATAL;
913 goto out;
914 }
915 /* Indicate that the email_alert is at least partially configured */
916 curproxy->email_alert.set = 1;
917 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100918 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100919 if (*(args[1]) == 0) {
920 ha_alert("parsing [%s:%d] : missing persist method.\n",
921 file, linenum);
922 err_code |= ERR_ALERT | ERR_FATAL;
923 goto out;
924 }
925
926 if (!strncmp(args[1], "rdp-cookie", 10)) {
927 curproxy->options2 |= PR_O2_RDPC_PRST;
928
929 if (*(args[1] + 10) == '(') { /* cookie name */
930 const char *beg, *end;
931
932 beg = args[1] + 11;
933 end = strchr(beg, ')');
934
935 if (alertif_too_many_args(1, file, linenum, args, &err_code))
936 goto out;
937
938 if (!end || end == beg) {
939 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
940 file, linenum);
941 err_code |= ERR_ALERT | ERR_FATAL;
942 goto out;
943 }
944
945 free(curproxy->rdp_cookie_name);
946 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
947 curproxy->rdp_cookie_len = end-beg;
948 }
949 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
950 free(curproxy->rdp_cookie_name);
951 curproxy->rdp_cookie_name = strdup("msts");
952 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
953 }
954 else { /* syntax */
955 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
956 file, linenum);
957 err_code |= ERR_ALERT | ERR_FATAL;
958 goto out;
959 }
960 }
961 else {
962 ha_alert("parsing [%s:%d] : unknown persist method.\n",
963 file, linenum);
964 err_code |= ERR_ALERT | ERR_FATAL;
965 goto out;
966 }
967 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100968 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +0200969 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 +0100970 err_code |= ERR_ALERT | ERR_FATAL;
971 goto out;
972 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100973 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100974 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
975 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100976 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100977 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
978 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100979 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 +0100980 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
981 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100982 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100983 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
984 }
985 else {
986 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
987 file, linenum, args[0], args[1]);
988 err_code |= ERR_ALERT | ERR_FATAL;
989 goto out;
990 }
991 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100992 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100993 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
994 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100995 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100996 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100997
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100998 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +0100999
1000 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001001 curproxy->server_state_file_name = strdup(curproxy->id);
1002 else
1003 curproxy->server_state_file_name = strdup(args[1]);
1004 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001005 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001006 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1007 err_code |= ERR_WARN;
1008 if (*(args[1]) == 0) {
1009 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1010 file, linenum, args[0]);
1011 err_code |= ERR_ALERT | ERR_FATAL;
1012 goto out;
1013 }
1014 curproxy->max_out_conns = atoi(args[1]);
1015 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001016 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001017 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1018 err_code |= ERR_WARN;
1019
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001020 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001021 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001022 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1023 err_code |= ERR_ALERT | ERR_FATAL;
1024 goto out;
1025 }
1026
1027 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1028 goto out;
1029
1030 if (*(args[4]) == 0) {
1031 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1032 file, linenum, args[0]);
1033 err_code |= ERR_ALERT | ERR_FATAL;
1034 goto out;
1035 }
1036 free(curproxy->capture_name);
1037 curproxy->capture_name = strdup(args[2]);
1038 curproxy->capture_namelen = strlen(curproxy->capture_name);
1039 curproxy->capture_len = atol(args[4]);
1040 curproxy->to_log |= LW_COOKIE;
1041 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001042 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001043 struct cap_hdr *hdr;
1044
Willy Tarreau5d095c22021-02-12 10:15:59 +01001045 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001046 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1047 err_code |= ERR_ALERT | ERR_FATAL;
1048 goto out;
1049 }
1050
1051 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1052 goto out;
1053
1054 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1055 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1056 file, linenum, args[0], args[1]);
1057 err_code |= ERR_ALERT | ERR_FATAL;
1058 goto out;
1059 }
1060
1061 hdr = calloc(1, sizeof(*hdr));
1062 hdr->next = curproxy->req_cap;
1063 hdr->name = strdup(args[3]);
1064 hdr->namelen = strlen(args[3]);
1065 hdr->len = atol(args[5]);
1066 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1067 hdr->index = curproxy->nb_req_cap++;
1068 curproxy->req_cap = hdr;
1069 curproxy->to_log |= LW_REQHDR;
1070 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001071 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001072 struct cap_hdr *hdr;
1073
Willy Tarreau5d095c22021-02-12 10:15:59 +01001074 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001075 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1076 err_code |= ERR_ALERT | ERR_FATAL;
1077 goto out;
1078 }
1079
1080 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1081 goto out;
1082
1083 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1084 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1085 file, linenum, args[0], args[1]);
1086 err_code |= ERR_ALERT | ERR_FATAL;
1087 goto out;
1088 }
1089 hdr = calloc(1, sizeof(*hdr));
1090 hdr->next = curproxy->rsp_cap;
1091 hdr->name = strdup(args[3]);
1092 hdr->namelen = strlen(args[3]);
1093 hdr->len = atol(args[5]);
1094 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1095 hdr->index = curproxy->nb_rsp_cap++;
1096 curproxy->rsp_cap = hdr;
1097 curproxy->to_log |= LW_RSPHDR;
1098 }
1099 else {
1100 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1101 file, linenum, args[0]);
1102 err_code |= ERR_ALERT | ERR_FATAL;
1103 goto out;
1104 }
1105 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001106 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001107 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1108 err_code |= ERR_WARN;
1109
1110 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1111 goto out;
1112
1113 if (*(args[1]) == 0) {
1114 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1115 file, linenum, args[0]);
1116 err_code |= ERR_ALERT | ERR_FATAL;
1117 goto out;
1118 }
1119 curproxy->conn_retries = atol(args[1]);
1120 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001121 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001122 struct act_rule *rule;
1123
Willy Tarreau5d095c22021-02-12 10:15:59 +01001124 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001125 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1126 err_code |= ERR_ALERT | ERR_FATAL;
1127 goto out;
1128 }
1129
1130 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1131 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001132 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001133 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1134 file, linenum, args[0]);
1135 err_code |= ERR_WARN;
1136 }
1137
1138 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1139
1140 if (!rule) {
1141 err_code |= ERR_ALERT | ERR_ABORT;
1142 goto out;
1143 }
1144
1145 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1146 err_code |= warnif_cond_conflicts(rule->cond,
1147 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1148 file, linenum);
1149
1150 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1151 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001152 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001153 struct act_rule *rule;
1154
Willy Tarreau5d095c22021-02-12 10:15:59 +01001155 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001156 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1157 err_code |= ERR_ALERT | ERR_FATAL;
1158 goto out;
1159 }
1160
1161 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1162 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001163 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001164 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1165 file, linenum, args[0]);
1166 err_code |= ERR_WARN;
1167 }
1168
1169 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1170
1171 if (!rule) {
1172 err_code |= ERR_ALERT | ERR_ABORT;
1173 goto out;
1174 }
1175
1176 err_code |= warnif_cond_conflicts(rule->cond,
1177 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1178 file, linenum);
1179
1180 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1181 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001182 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001183 struct act_rule *rule;
1184
Willy Tarreau5d095c22021-02-12 10:15:59 +01001185 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001186 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1187 err_code |= ERR_ALERT | ERR_FATAL;
1188 goto out;
1189 }
1190
1191 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1192 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1193 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1194 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1195 file, linenum, args[0]);
1196 err_code |= ERR_WARN;
1197 }
1198
1199 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1200
1201 if (!rule) {
1202 err_code |= ERR_ALERT | ERR_ABORT;
1203 goto out;
1204 }
1205
1206 err_code |= warnif_cond_conflicts(rule->cond,
1207 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1208 file, linenum);
1209
1210 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1211 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001212 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001213 /* set the header name and length into the proxy structure */
1214 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1215 err_code |= ERR_WARN;
1216
1217 if (!*args[1]) {
1218 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1219 file, linenum, args[0]);
1220 err_code |= ERR_ALERT | ERR_FATAL;
1221 goto out;
1222 }
1223
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001224 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001225 free(curproxy->server_id_hdr_name);
1226 curproxy->server_id_hdr_name = strdup(args[1]);
1227 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001228 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 +01001229 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001230 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001231 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 +01001232
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001233 err_code |= ERR_ALERT | ERR_FATAL;
1234 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001235 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001236 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001237 struct redirect_rule *rule;
1238
Willy Tarreau5d095c22021-02-12 10:15:59 +01001239 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001240 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1241 err_code |= ERR_ALERT | ERR_FATAL;
1242 goto out;
1243 }
1244
1245 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1246 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1247 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1248 err_code |= ERR_ALERT | ERR_FATAL;
1249 goto out;
1250 }
1251
1252 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1253 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1254 err_code |= warnif_cond_conflicts(rule->cond,
1255 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1256 file, linenum);
1257 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001258 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001259 struct switching_rule *rule;
1260
Willy Tarreau5d095c22021-02-12 10:15:59 +01001261 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001262 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1263 err_code |= ERR_ALERT | ERR_FATAL;
1264 goto out;
1265 }
1266
1267 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1268 err_code |= ERR_WARN;
1269
1270 if (*(args[1]) == 0) {
1271 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1272 err_code |= ERR_ALERT | ERR_FATAL;
1273 goto out;
1274 }
1275
1276 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1277 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1278 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1279 file, linenum, errmsg);
1280 err_code |= ERR_ALERT | ERR_FATAL;
1281 goto out;
1282 }
1283
1284 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1285 }
1286 else if (*args[2]) {
1287 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1288 file, linenum, args[2]);
1289 err_code |= ERR_ALERT | ERR_FATAL;
1290 goto out;
1291 }
1292
1293 rule = calloc(1, sizeof(*rule));
1294 if (!rule) {
1295 ha_alert("Out of memory error.\n");
1296 goto out;
1297 }
1298 rule->cond = cond;
1299 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001300 if (!rule->be.name) {
1301 ha_alert("Out of memory error.\n");
1302 goto out;
1303 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001304 rule->line = linenum;
1305 rule->file = strdup(file);
1306 if (!rule->file) {
1307 ha_alert("Out of memory error.\n");
1308 goto out;
1309 }
1310 LIST_INIT(&rule->list);
1311 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1312 }
1313 else if (strcmp(args[0], "use-server") == 0) {
1314 struct server_rule *rule;
1315
Willy Tarreau5d095c22021-02-12 10:15:59 +01001316 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001317 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1318 err_code |= ERR_ALERT | ERR_FATAL;
1319 goto out;
1320 }
1321
1322 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1323 err_code |= ERR_WARN;
1324
1325 if (*(args[1]) == 0) {
1326 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1327 err_code |= ERR_ALERT | ERR_FATAL;
1328 goto out;
1329 }
1330
1331 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1332 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1333 file, linenum, args[0]);
1334 err_code |= ERR_ALERT | ERR_FATAL;
1335 goto out;
1336 }
1337
1338 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1339 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1340 file, linenum, errmsg);
1341 err_code |= ERR_ALERT | ERR_FATAL;
1342 goto out;
1343 }
1344
1345 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1346
1347 rule = calloc(1, sizeof(*rule));
1348 rule->cond = cond;
1349 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001350 rule->line = linenum;
1351 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001352 LIST_INIT(&rule->list);
1353 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1354 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1355 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001356 else if ((strcmp(args[0], "force-persist") == 0) ||
1357 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001358 struct persist_rule *rule;
1359
Willy Tarreau5d095c22021-02-12 10:15:59 +01001360 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001361 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1362 err_code |= ERR_ALERT | ERR_FATAL;
1363 goto out;
1364 }
1365
1366 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1367 err_code |= ERR_WARN;
1368
1369 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1370 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1371 file, linenum, args[0]);
1372 err_code |= ERR_ALERT | ERR_FATAL;
1373 goto out;
1374 }
1375
1376 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1377 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1378 file, linenum, args[0], errmsg);
1379 err_code |= ERR_ALERT | ERR_FATAL;
1380 goto out;
1381 }
1382
1383 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1384 * where force-persist is applied.
1385 */
1386 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1387
1388 rule = calloc(1, sizeof(*rule));
1389 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001390 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001391 rule->type = PERSIST_TYPE_FORCE;
1392 } else {
1393 rule->type = PERSIST_TYPE_IGNORE;
1394 }
1395 LIST_INIT(&rule->list);
1396 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1397 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001398 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001399 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001400
Willy Tarreau5d095c22021-02-12 10:15:59 +01001401 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001402 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1403 file, linenum);
1404 err_code |= ERR_ALERT | ERR_FATAL;
1405 goto out;
1406 }
1407
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001408 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001409 if (other) {
1410 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 +01001411 file, linenum, curproxy->id,
1412 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1413 other->proxy ? other->id : other->peers.p->id,
1414 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001415 err_code |= ERR_ALERT | ERR_FATAL;
1416 goto out;
1417 }
1418
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001419 curproxy->table = calloc(1, sizeof *curproxy->table);
1420 if (!curproxy->table) {
1421 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1422 file, linenum, args[0], args[1]);
1423 err_code |= ERR_ALERT | ERR_FATAL;
1424 goto out;
1425 }
1426
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001427 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1428 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001429 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001430 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001431
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001432 /* Store the proxy in the stick-table. */
1433 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001434
1435 stktable_store_name(curproxy->table);
1436 curproxy->table->next = stktables_list;
1437 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001438
1439 /* Add this proxy to the list of proxies which refer to its stick-table. */
1440 if (curproxy->table->proxies_list != curproxy) {
1441 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1442 curproxy->table->proxies_list = curproxy;
1443 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001444 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001445 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001446 struct sticking_rule *rule;
1447 struct sample_expr *expr;
1448 int myidx = 0;
1449 const char *name = NULL;
1450 int flags;
1451
Willy Tarreau5d095c22021-02-12 10:15:59 +01001452 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001453 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1454 err_code |= ERR_ALERT | ERR_FATAL;
1455 goto out;
1456 }
1457
1458 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1459 err_code |= ERR_WARN;
1460 goto out;
1461 }
1462
1463 myidx++;
1464 if ((strcmp(args[myidx], "store") == 0) ||
1465 (strcmp(args[myidx], "store-request") == 0)) {
1466 myidx++;
1467 flags = STK_IS_STORE;
1468 }
1469 else if (strcmp(args[myidx], "store-response") == 0) {
1470 myidx++;
1471 flags = STK_IS_STORE | STK_ON_RSP;
1472 }
1473 else if (strcmp(args[myidx], "match") == 0) {
1474 myidx++;
1475 flags = STK_IS_MATCH;
1476 }
1477 else if (strcmp(args[myidx], "on") == 0) {
1478 myidx++;
1479 flags = STK_IS_MATCH | STK_IS_STORE;
1480 }
1481 else {
1482 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1483 err_code |= ERR_ALERT | ERR_FATAL;
1484 goto out;
1485 }
1486
1487 if (*(args[myidx]) == 0) {
1488 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1489 err_code |= ERR_ALERT | ERR_FATAL;
1490 goto out;
1491 }
1492
1493 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001494 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001495 if (!expr) {
1496 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1497 err_code |= ERR_ALERT | ERR_FATAL;
1498 goto out;
1499 }
1500
1501 if (flags & STK_ON_RSP) {
1502 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1503 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1504 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1505 err_code |= ERR_ALERT | ERR_FATAL;
1506 free(expr);
1507 goto out;
1508 }
1509 } else {
1510 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1511 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1512 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1513 err_code |= ERR_ALERT | ERR_FATAL;
1514 free(expr);
1515 goto out;
1516 }
1517 }
1518
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001519 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001520 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1521
1522 if (strcmp(args[myidx], "table") == 0) {
1523 myidx++;
1524 name = args[myidx++];
1525 }
1526
1527 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1528 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1529 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1530 file, linenum, args[0], errmsg);
1531 err_code |= ERR_ALERT | ERR_FATAL;
1532 free(expr);
1533 goto out;
1534 }
1535 }
1536 else if (*(args[myidx])) {
1537 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1538 file, linenum, args[0], args[myidx]);
1539 err_code |= ERR_ALERT | ERR_FATAL;
1540 free(expr);
1541 goto out;
1542 }
1543 if (flags & STK_ON_RSP)
1544 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1545 else
1546 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1547
1548 rule = calloc(1, sizeof(*rule));
1549 rule->cond = cond;
1550 rule->expr = expr;
1551 rule->flags = flags;
1552 rule->table.name = name ? strdup(name) : NULL;
1553 LIST_INIT(&rule->list);
1554 if (flags & STK_ON_RSP)
1555 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1556 else
1557 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1558 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001559 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001560 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001561 curproxy->uri_auth = NULL; /* we must detach from the default config */
1562
1563 if (!*args[1]) {
1564 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001565 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001566 struct stats_admin_rule *rule;
1567
Willy Tarreau5d095c22021-02-12 10:15:59 +01001568 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001569 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1570 err_code |= ERR_ALERT | ERR_FATAL;
1571 goto out;
1572 }
1573
1574 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1575 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1576 err_code |= ERR_ALERT | ERR_ABORT;
1577 goto out;
1578 }
1579
1580 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1581 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1582 file, linenum, args[0], args[1]);
1583 err_code |= ERR_ALERT | ERR_FATAL;
1584 goto out;
1585 }
1586 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1587 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1588 file, linenum, args[0], args[1], errmsg);
1589 err_code |= ERR_ALERT | ERR_FATAL;
1590 goto out;
1591 }
1592
1593 err_code |= warnif_cond_conflicts(cond,
1594 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1595 file, linenum);
1596
1597 rule = calloc(1, sizeof(*rule));
1598 rule->cond = cond;
1599 LIST_INIT(&rule->list);
1600 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001601 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001602 if (*(args[2]) == 0) {
1603 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1604 err_code |= ERR_ALERT | ERR_FATAL;
1605 goto out;
1606 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1607 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1608 err_code |= ERR_ALERT | ERR_ABORT;
1609 goto out;
1610 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001611 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001612 if (*(args[2]) == 0) {
1613 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1614 err_code |= ERR_ALERT | ERR_FATAL;
1615 goto out;
1616 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1617 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1618 err_code |= ERR_ALERT | ERR_ABORT;
1619 goto out;
1620 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001621 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001622 unsigned interval;
1623
1624 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001625 if (err == PARSE_TIME_OVER) {
1626 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1627 file, linenum, args[2]);
1628 err_code |= ERR_ALERT | ERR_FATAL;
1629 goto out;
1630 }
1631 else if (err == PARSE_TIME_UNDER) {
1632 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1633 file, linenum, args[2]);
1634 err_code |= ERR_ALERT | ERR_FATAL;
1635 goto out;
1636 }
1637 else if (err) {
1638 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001639 file, linenum, *err);
1640 err_code |= ERR_ALERT | ERR_FATAL;
1641 goto out;
1642 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1643 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1644 err_code |= ERR_ALERT | ERR_ABORT;
1645 goto out;
1646 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001647 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001648 struct act_rule *rule;
1649
Willy Tarreau5d095c22021-02-12 10:15:59 +01001650 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001651 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1652 err_code |= ERR_ALERT | ERR_FATAL;
1653 goto out;
1654 }
1655
1656 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1657 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1658 err_code |= ERR_ALERT | ERR_ABORT;
1659 goto out;
1660 }
1661
1662 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1663 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1664 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1665 file, linenum, args[0]);
1666 err_code |= ERR_WARN;
1667 }
1668
1669 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1670
1671 if (!rule) {
1672 err_code |= ERR_ALERT | ERR_ABORT;
1673 goto out;
1674 }
1675
1676 err_code |= warnif_cond_conflicts(rule->cond,
1677 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1678 file, linenum);
1679 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1680
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001681 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001682 if (*(args[2]) == 0) {
1683 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1684 err_code |= ERR_ALERT | ERR_FATAL;
1685 goto out;
1686 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1687 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1688 err_code |= ERR_ALERT | ERR_ABORT;
1689 goto out;
1690 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001691 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001692 if (*(args[2]) == 0) {
1693 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1694 err_code |= ERR_ALERT | ERR_FATAL;
1695 goto out;
1696 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1697 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1698 err_code |= ERR_ALERT | ERR_ABORT;
1699 goto out;
1700 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001701 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001702 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1703 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1704 err_code |= ERR_ALERT | ERR_ABORT;
1705 goto out;
1706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001707 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001708 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001709 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1710 err_code |= ERR_ALERT | ERR_ABORT;
1711 goto out;
1712 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001713 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001714 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001715 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1716 err_code |= ERR_ALERT | ERR_ABORT;
1717 goto out;
1718 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001719 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001720 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1721 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1722 err_code |= ERR_ALERT | ERR_ABORT;
1723 goto out;
1724 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001725 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001726
1727 if (*args[2]) {
1728 int i;
1729 char c;
1730
1731 for (i=0; args[2][i]; i++) {
1732 c = args[2][i];
1733 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1734 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1735 break;
1736 }
1737
1738 if (!i || args[2][i]) {
1739 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1740 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1741 file, linenum, args[0], args[1]);
1742 err_code |= ERR_ALERT | ERR_FATAL;
1743 goto out;
1744 }
1745 }
1746
1747 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1748 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1749 err_code |= ERR_ALERT | ERR_ABORT;
1750 goto out;
1751 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001752 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001753 char *desc = NULL;
1754
1755 if (*args[2]) {
1756 int i, len=0;
1757 char *d;
1758
1759 for (i = 2; *args[i]; i++)
1760 len += strlen(args[i]) + 1;
1761
1762 desc = d = calloc(1, len);
1763
1764 d += snprintf(d, desc + len - d, "%s", args[2]);
1765 for (i = 3; *args[i]; i++)
1766 d += snprintf(d, desc + len - d, " %s", args[i]);
1767 }
1768
1769 if (!*args[2] && !global.desc)
1770 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1771 file, linenum, args[1]);
1772 else {
1773 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1774 free(desc);
1775 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1776 err_code |= ERR_ALERT | ERR_ABORT;
1777 goto out;
1778 }
1779 free(desc);
1780 }
1781 } else {
1782stats_error_parsing:
1783 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1784 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1785 err_code |= ERR_ALERT | ERR_FATAL;
1786 goto out;
1787 }
1788 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001789 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001790 int optnum;
1791
1792 if (*(args[1]) == '\0') {
1793 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1794 file, linenum, args[0]);
1795 err_code |= ERR_ALERT | ERR_FATAL;
1796 goto out;
1797 }
1798
1799 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001800 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001801 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1802 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1803 file, linenum, cfg_opts[optnum].name);
1804 err_code |= ERR_ALERT | ERR_FATAL;
1805 goto out;
1806 }
1807 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1808 goto out;
1809
1810 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1811 err_code |= ERR_WARN;
1812 goto out;
1813 }
1814
1815 curproxy->no_options &= ~cfg_opts[optnum].val;
1816 curproxy->options &= ~cfg_opts[optnum].val;
1817
1818 switch (kwm) {
1819 case KWM_STD:
1820 curproxy->options |= cfg_opts[optnum].val;
1821 break;
1822 case KWM_NO:
1823 curproxy->no_options |= cfg_opts[optnum].val;
1824 break;
1825 case KWM_DEF: /* already cleared */
1826 break;
1827 }
1828
1829 goto out;
1830 }
1831 }
1832
1833 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001834 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001835 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1836 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1837 file, linenum, cfg_opts2[optnum].name);
1838 err_code |= ERR_ALERT | ERR_FATAL;
1839 goto out;
1840 }
1841 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1842 goto out;
1843 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1844 err_code |= ERR_WARN;
1845 goto out;
1846 }
1847
Christopher Faulet31930372019-07-15 10:16:58 +02001848 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001849 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001850 if (kwm ==KWM_NO) {
1851 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1852 " The HTX mode is now the only supported mode.\n",
1853 file, linenum, cfg_opts2[optnum].name);
1854 err_code |= ERR_WARN;
1855 }
Christopher Faulet31930372019-07-15 10:16:58 +02001856 goto out;
1857 }
1858
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001859 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1860 curproxy->options2 &= ~cfg_opts2[optnum].val;
1861
1862 switch (kwm) {
1863 case KWM_STD:
1864 curproxy->options2 |= cfg_opts2[optnum].val;
1865 break;
1866 case KWM_NO:
1867 curproxy->no_options2 |= cfg_opts2[optnum].val;
1868 break;
1869 case KWM_DEF: /* already cleared */
1870 break;
1871 }
1872 goto out;
1873 }
1874 }
1875
1876 /* HTTP options override each other. They can be cancelled using
1877 * "no option xxx" which only switches to default mode if the mode
1878 * was this one (useful for cancelling options set in defaults
1879 * sections).
1880 */
1881 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001882 if (strcmp(args[1], "forceclose") == 0) {
1883 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1884 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1885 file, linenum, args[1]);
1886 err_code |= ERR_WARN;
1887 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001888 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1889 goto out;
1890 if (kwm == KWM_STD) {
1891 curproxy->options &= ~PR_O_HTTP_MODE;
1892 curproxy->options |= PR_O_HTTP_CLO;
1893 goto out;
1894 }
1895 else if (kwm == KWM_NO) {
1896 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1897 curproxy->options &= ~PR_O_HTTP_MODE;
1898 goto out;
1899 }
1900 }
1901 else if (strcmp(args[1], "http-server-close") == 0) {
1902 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1903 goto out;
1904 if (kwm == KWM_STD) {
1905 curproxy->options &= ~PR_O_HTTP_MODE;
1906 curproxy->options |= PR_O_HTTP_SCL;
1907 goto out;
1908 }
1909 else if (kwm == KWM_NO) {
1910 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1911 curproxy->options &= ~PR_O_HTTP_MODE;
1912 goto out;
1913 }
1914 }
1915 else if (strcmp(args[1], "http-keep-alive") == 0) {
1916 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1917 goto out;
1918 if (kwm == KWM_STD) {
1919 curproxy->options &= ~PR_O_HTTP_MODE;
1920 curproxy->options |= PR_O_HTTP_KAL;
1921 goto out;
1922 }
1923 else if (kwm == KWM_NO) {
1924 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1925 curproxy->options &= ~PR_O_HTTP_MODE;
1926 goto out;
1927 }
1928 }
1929 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001930 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
1931 file, linenum, args[1]);
1932 err_code |= ERR_WARN;
1933 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001934 }
1935
1936 /* Redispatch can take an integer argument that control when the
1937 * resispatch occurs. All values are relative to the retries option.
1938 * This can be cancelled using "no option xxx".
1939 */
1940 if (strcmp(args[1], "redispatch") == 0) {
1941 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
1942 err_code |= ERR_WARN;
1943 goto out;
1944 }
1945
1946 curproxy->no_options &= ~PR_O_REDISP;
1947 curproxy->options &= ~PR_O_REDISP;
1948
1949 switch (kwm) {
1950 case KWM_STD:
1951 curproxy->options |= PR_O_REDISP;
1952 curproxy->redispatch_after = -1;
1953 if(*args[2]) {
1954 curproxy->redispatch_after = atol(args[2]);
1955 }
1956 break;
1957 case KWM_NO:
1958 curproxy->no_options |= PR_O_REDISP;
1959 curproxy->redispatch_after = 0;
1960 break;
1961 case KWM_DEF: /* already cleared */
1962 break;
1963 }
1964 goto out;
1965 }
1966
1967 if (kwm != KWM_STD) {
1968 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
1969 file, linenum, args[1]);
1970 err_code |= ERR_ALERT | ERR_FATAL;
1971 goto out;
1972 }
1973
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001974 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001975 char *logformat;
1976 /* generate a complete HTTP log */
1977 logformat = default_http_log_format;
1978 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001979 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001980 curproxy->options2 |= PR_O2_CLFLOG;
1981 logformat = clf_http_log_format;
1982 } else {
1983 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
1984 err_code |= ERR_ALERT | ERR_FATAL;
1985 goto out;
1986 }
1987 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
1988 goto out;
1989 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01001990 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001991 char *oldlogformat = "log-format";
1992 char *clflogformat = "";
1993
1994 if (curproxy->conf.logformat_string == default_http_log_format)
1995 oldlogformat = "option httplog";
1996 else if (curproxy->conf.logformat_string == default_tcp_log_format)
1997 oldlogformat = "option tcplog";
1998 else if (curproxy->conf.logformat_string == clf_http_log_format)
1999 oldlogformat = "option httplog clf";
2000 if (logformat == clf_http_log_format)
2001 clflogformat = " clf";
2002 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2003 file, linenum, clflogformat, oldlogformat);
2004 }
2005 if (curproxy->conf.logformat_string != default_http_log_format &&
2006 curproxy->conf.logformat_string != default_tcp_log_format &&
2007 curproxy->conf.logformat_string != clf_http_log_format)
2008 free(curproxy->conf.logformat_string);
2009 curproxy->conf.logformat_string = logformat;
2010
2011 free(curproxy->conf.lfs_file);
2012 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2013 curproxy->conf.lfs_line = curproxy->conf.args.line;
2014
Willy Tarreau5d095c22021-02-12 10:15:59 +01002015 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002016 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2017 file, linenum, curproxy->id);
2018 err_code |= ERR_WARN;
2019 }
2020 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002021 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002022 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002023 char *oldlogformat = "log-format";
2024
2025 if (curproxy->conf.logformat_string == default_http_log_format)
2026 oldlogformat = "option httplog";
2027 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2028 oldlogformat = "option tcplog";
2029 else if (curproxy->conf.logformat_string == clf_http_log_format)
2030 oldlogformat = "option httplog clf";
2031 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2032 file, linenum, oldlogformat);
2033 }
2034 /* generate a detailed TCP log */
2035 if (curproxy->conf.logformat_string != default_http_log_format &&
2036 curproxy->conf.logformat_string != default_tcp_log_format &&
2037 curproxy->conf.logformat_string != clf_http_log_format)
2038 free(curproxy->conf.logformat_string);
2039 curproxy->conf.logformat_string = default_tcp_log_format;
2040
2041 free(curproxy->conf.lfs_file);
2042 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2043 curproxy->conf.lfs_line = curproxy->conf.args.line;
2044
2045 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2046 goto out;
2047
Willy Tarreau5d095c22021-02-12 10:15:59 +01002048 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002049 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2050 file, linenum, curproxy->id);
2051 err_code |= ERR_WARN;
2052 }
2053 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002054 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002055 /* enable TCP keep-alives on client and server streams */
2056 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2057 err_code |= ERR_WARN;
2058
2059 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2060 goto out;
2061
2062 if (curproxy->cap & PR_CAP_FE)
2063 curproxy->options |= PR_O_TCP_CLI_KA;
2064 if (curproxy->cap & PR_CAP_BE)
2065 curproxy->options |= PR_O_TCP_SRV_KA;
2066 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002067 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002068 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002069 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002070 goto out;
2071 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002072 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002073 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002074 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002075 goto out;
2076 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002077 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002078 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002079 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002080 goto out;
2081 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002082 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002083 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002084 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002085 goto out;
2086 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002087 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002088 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002089 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002090 goto out;
2091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002092 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002093 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002094 if (err_code & ERR_FATAL)
2095 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002096 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002097 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002098 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002099 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002100 goto out;
2101 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002102 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002103 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002104 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002105 goto out;
2106 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002107 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002108 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002109 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002110 goto out;
2111 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002112 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002113 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002114 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002115 goto out;
2116 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002117 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002118 int cur_arg;
2119
2120 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002121 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002122 */
2123
2124 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2125
2126 free(curproxy->fwdfor_hdr_name);
2127 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2128 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002129 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002130
2131 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2132 cur_arg = 2;
2133 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002134 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002135 unsigned char mask;
2136 int i;
2137
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002138 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002139 if (*(args[cur_arg+1]) &&
2140 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2141 curproxy->except_xff_net.family = AF_INET;
2142 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2143 }
2144 else if (*(args[cur_arg+1]) &&
2145 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2146 curproxy->except_xff_net.family = AF_INET6;
2147 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2148 for (i = 0; i < 16; i++)
2149 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2150 }
2151 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002152 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2153 file, linenum, args[0], args[1], args[cur_arg]);
2154 err_code |= ERR_ALERT | ERR_FATAL;
2155 goto out;
2156 }
2157 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002158 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002159 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002160 /* suboption header - needs additional argument for it */
2161 if (*(args[cur_arg+1]) == 0) {
2162 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2163 file, linenum, args[0], args[1], args[cur_arg]);
2164 err_code |= ERR_ALERT | ERR_FATAL;
2165 goto out;
2166 }
2167 free(curproxy->fwdfor_hdr_name);
2168 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2169 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2170 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002171 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002172 curproxy->options &= ~PR_O_FF_ALWAYS;
2173 cur_arg += 1;
2174 } else {
2175 /* unknown suboption - catchall */
2176 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2177 file, linenum, args[0], args[1]);
2178 err_code |= ERR_ALERT | ERR_FATAL;
2179 goto out;
2180 }
2181 } /* end while loop */
2182 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002183 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002184 int cur_arg;
2185
2186 /* insert x-original-to field, but not for the IP address listed as an except.
2187 * set default options (ie: bitfield, header name, etc)
2188 */
2189
2190 curproxy->options |= PR_O_ORGTO;
2191
2192 free(curproxy->orgto_hdr_name);
2193 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2194 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002195 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002196
2197 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2198 cur_arg = 2;
2199 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002200 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002201 unsigned char mask;
2202 int i;
2203
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002204 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002205 if (*(args[cur_arg+1]) &&
2206 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2207 curproxy->except_xot_net.family = AF_INET;
2208 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2209 }
2210 else if (*(args[cur_arg+1]) &&
2211 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2212 curproxy->except_xot_net.family = AF_INET6;
2213 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2214 for (i = 0; i < 16; i++)
2215 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2216 }
2217 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002218 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2219 file, linenum, args[0], args[1], args[cur_arg]);
2220 err_code |= ERR_ALERT | ERR_FATAL;
2221 goto out;
2222 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002223 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002224 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002225 /* suboption header - needs additional argument for it */
2226 if (*(args[cur_arg+1]) == 0) {
2227 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2228 file, linenum, args[0], args[1], args[cur_arg]);
2229 err_code |= ERR_ALERT | ERR_FATAL;
2230 goto out;
2231 }
2232 free(curproxy->orgto_hdr_name);
2233 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2234 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2235 cur_arg += 2;
2236 } else {
2237 /* unknown suboption - catchall */
2238 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2239 file, linenum, args[0], args[1]);
2240 err_code |= ERR_ALERT | ERR_FATAL;
2241 goto out;
2242 }
2243 } /* end while loop */
2244 }
2245 else {
2246 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2247 err_code |= ERR_ALERT | ERR_FATAL;
2248 goto out;
2249 }
2250 goto out;
2251 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002252 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002253 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2254 err_code |= ERR_WARN;
2255
2256 if (*(args[1]) == 0) {
2257 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2258 err_code |= ERR_ALERT | ERR_FATAL;
2259 goto out;
2260 }
2261 free(curproxy->defbe.name);
2262 curproxy->defbe.name = strdup(args[1]);
2263
2264 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2265 goto out;
2266 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002267 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002268 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 +01002269
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002270 err_code |= ERR_ALERT | ERR_FATAL;
2271 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002272 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002273 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002274 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2275 err_code |= ERR_WARN;
2276
2277 if (strcmp(args[1], "never") == 0) {
2278 /* enable a graceful server shutdown on an HTTP 404 response */
2279 curproxy->options &= ~PR_O_REUSE_MASK;
2280 curproxy->options |= PR_O_REUSE_NEVR;
2281 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2282 goto out;
2283 }
2284 else if (strcmp(args[1], "safe") == 0) {
2285 /* enable a graceful server shutdown on an HTTP 404 response */
2286 curproxy->options &= ~PR_O_REUSE_MASK;
2287 curproxy->options |= PR_O_REUSE_SAFE;
2288 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2289 goto out;
2290 }
2291 else if (strcmp(args[1], "aggressive") == 0) {
2292 curproxy->options &= ~PR_O_REUSE_MASK;
2293 curproxy->options |= PR_O_REUSE_AGGR;
2294 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2295 goto out;
2296 }
2297 else if (strcmp(args[1], "always") == 0) {
2298 /* enable a graceful server shutdown on an HTTP 404 response */
2299 curproxy->options &= ~PR_O_REUSE_MASK;
2300 curproxy->options |= PR_O_REUSE_ALWS;
2301 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2302 goto out;
2303 }
2304 else {
2305 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2306 err_code |= ERR_ALERT | ERR_FATAL;
2307 goto out;
2308 }
2309 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002310 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002311 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002312 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2313 err_code |= ERR_ALERT | ERR_FATAL;
2314 goto out;
2315 }
2316
2317 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2318 err_code |= ERR_WARN;
2319
2320 if (strcmp(args[1], "fail") == 0) {
2321 /* add a condition to fail monitor requests */
2322 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2323 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2324 file, linenum, args[0], args[1]);
2325 err_code |= ERR_ALERT | ERR_FATAL;
2326 goto out;
2327 }
2328
2329 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2330 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2331 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2332 file, linenum, args[0], args[1], errmsg);
2333 err_code |= ERR_ALERT | ERR_FATAL;
2334 goto out;
2335 }
2336 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2337 }
2338 else {
2339 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2340 err_code |= ERR_ALERT | ERR_FATAL;
2341 goto out;
2342 }
2343 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002344#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002345 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002346 /* enable transparent proxy connections */
2347 curproxy->options |= PR_O_TRANSP;
2348 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2349 goto out;
2350 }
2351#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002352 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002353 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2354 err_code |= ERR_WARN;
2355
2356 if (*(args[1]) == 0) {
2357 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2358 err_code |= ERR_ALERT | ERR_FATAL;
2359 goto out;
2360 }
2361 curproxy->maxconn = atol(args[1]);
2362 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2363 goto out;
2364 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002365 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002366 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2367 err_code |= ERR_WARN;
2368
2369 if (*(args[1]) == 0) {
2370 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2371 err_code |= ERR_ALERT | ERR_FATAL;
2372 goto out;
2373 }
2374 curproxy->backlog = atol(args[1]);
2375 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2376 goto out;
2377 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002378 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002379 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2380 err_code |= ERR_WARN;
2381
2382 if (*(args[1]) == 0) {
2383 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2384 err_code |= ERR_ALERT | ERR_FATAL;
2385 goto out;
2386 }
2387 curproxy->fullconn = atol(args[1]);
2388 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2389 goto out;
2390 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002391 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002392 if (*(args[1]) == 0) {
2393 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2394 err_code |= ERR_ALERT | ERR_FATAL;
2395 goto out;
2396 }
2397 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002398 if (err == PARSE_TIME_OVER) {
2399 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2400 file, linenum, args[1]);
2401 err_code |= ERR_ALERT | ERR_FATAL;
2402 goto out;
2403 }
2404 else if (err == PARSE_TIME_UNDER) {
2405 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2406 file, linenum, args[1]);
2407 err_code |= ERR_ALERT | ERR_FATAL;
2408 goto out;
2409 }
2410 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002411 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2412 file, linenum, *err);
2413 err_code |= ERR_ALERT | ERR_FATAL;
2414 goto out;
2415 }
2416 curproxy->grace = val;
2417 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2418 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002419
2420 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2421 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002422 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002423 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002424 struct sockaddr_storage *sk;
2425 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002426
Willy Tarreau5d095c22021-02-12 10:15:59 +01002427 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002428 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2429 err_code |= ERR_ALERT | ERR_FATAL;
2430 goto out;
2431 }
2432 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2433 err_code |= ERR_WARN;
2434
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002435 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2436 &errmsg, NULL, NULL,
2437 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 +01002438 if (!sk) {
2439 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2440 err_code |= ERR_ALERT | ERR_FATAL;
2441 goto out;
2442 }
2443
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002444 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2445 goto out;
2446
2447 curproxy->dispatch_addr = *sk;
2448 curproxy->options |= PR_O_DISPATCH;
2449 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002450 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002451 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2452 err_code |= ERR_WARN;
2453
2454 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2455 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2456 err_code |= ERR_ALERT | ERR_FATAL;
2457 goto out;
2458 }
2459 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002460 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002461 /**
2462 * The syntax for hash-type config element is
2463 * hash-type {map-based|consistent} [[<algo>] avalanche]
2464 *
2465 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2466 */
2467 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2468
2469 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2470 err_code |= ERR_WARN;
2471
2472 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2473 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2474 }
2475 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2476 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2477 }
2478 else if (strcmp(args[1], "avalanche") == 0) {
2479 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]);
2480 err_code |= ERR_ALERT | ERR_FATAL;
2481 goto out;
2482 }
2483 else {
2484 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2485 err_code |= ERR_ALERT | ERR_FATAL;
2486 goto out;
2487 }
2488
2489 /* set the hash function to use */
2490 if (!*args[2]) {
2491 /* the default algo is sdbm */
2492 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2493
2494 /* if consistent with no argument, then avalanche modifier is also applied */
2495 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2496 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2497 } else {
2498 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002499 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002500 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2501 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002502 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002503 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2504 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002505 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002506 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2507 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002508 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002509 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2510 }
2511 else {
2512 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2513 err_code |= ERR_ALERT | ERR_FATAL;
2514 goto out;
2515 }
2516
2517 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002518 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002519 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2520 }
2521 else if (*args[3]) {
2522 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2523 err_code |= ERR_ALERT | ERR_FATAL;
2524 goto out;
2525 }
2526 }
2527 }
2528 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2529 if (*(args[1]) == 0) {
2530 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2531 err_code |= ERR_ALERT | ERR_FATAL;
2532 goto out;
2533 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002534 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2535 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002536 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2537 err_code |= ERR_ALERT | ERR_FATAL;
2538 goto out;
2539 }
2540 }
2541 else if (strcmp(args[0], "unique-id-format") == 0) {
2542 if (!*(args[1])) {
2543 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2544 err_code |= ERR_ALERT | ERR_FATAL;
2545 goto out;
2546 }
2547 if (*(args[2])) {
2548 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2549 err_code |= ERR_ALERT | ERR_FATAL;
2550 goto out;
2551 }
2552 free(curproxy->conf.uniqueid_format_string);
2553 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2554
2555 free(curproxy->conf.uif_file);
2556 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2557 curproxy->conf.uif_line = curproxy->conf.args.line;
2558 }
2559
2560 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002561 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002562 if (!*(args[1])) {
2563 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2564 err_code |= ERR_ALERT | ERR_FATAL;
2565 goto out;
2566 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002567 copy = strdup(args[1]);
2568 if (copy == NULL) {
2569 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2570 err_code |= ERR_ALERT | ERR_FATAL;
2571 goto out;
2572 }
2573
2574 istfree(&curproxy->header_unique_id);
2575 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002576 }
2577
2578 else if (strcmp(args[0], "log-format") == 0) {
2579 if (!*(args[1])) {
2580 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2581 err_code |= ERR_ALERT | ERR_FATAL;
2582 goto out;
2583 }
2584 if (*(args[2])) {
2585 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2586 err_code |= ERR_ALERT | ERR_FATAL;
2587 goto out;
2588 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002589 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002590 char *oldlogformat = "log-format";
2591
2592 if (curproxy->conf.logformat_string == default_http_log_format)
2593 oldlogformat = "option httplog";
2594 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2595 oldlogformat = "option tcplog";
2596 else if (curproxy->conf.logformat_string == clf_http_log_format)
2597 oldlogformat = "option httplog clf";
2598 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2599 file, linenum, oldlogformat);
2600 }
2601 if (curproxy->conf.logformat_string != default_http_log_format &&
2602 curproxy->conf.logformat_string != default_tcp_log_format &&
2603 curproxy->conf.logformat_string != clf_http_log_format)
2604 free(curproxy->conf.logformat_string);
2605 curproxy->conf.logformat_string = strdup(args[1]);
2606
2607 free(curproxy->conf.lfs_file);
2608 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2609 curproxy->conf.lfs_line = curproxy->conf.args.line;
2610
2611 /* get a chance to improve log-format error reporting by
2612 * reporting the correct line-number when possible.
2613 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002614 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002615 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2616 file, linenum, curproxy->id);
2617 err_code |= ERR_WARN;
2618 }
2619 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002620 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002621 if (!*(args[1])) {
2622 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2623 err_code |= ERR_ALERT | ERR_FATAL;
2624 goto out;
2625 }
2626 if (*(args[2])) {
2627 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2628 err_code |= ERR_ALERT | ERR_FATAL;
2629 goto out;
2630 }
2631
2632 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2633 free(curproxy->conf.logformat_sd_string);
2634 curproxy->conf.logformat_sd_string = strdup(args[1]);
2635
2636 free(curproxy->conf.lfsd_file);
2637 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2638 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2639
2640 /* get a chance to improve log-format-sd error reporting by
2641 * reporting the correct line-number when possible.
2642 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002643 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002644 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2645 file, linenum, curproxy->id);
2646 err_code |= ERR_WARN;
2647 }
2648 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002649 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002650 if (*(args[1]) == 0) {
2651 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2652 err_code |= ERR_ALERT | ERR_FATAL;
2653 goto out;
2654 }
2655 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002656 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2657 if (b_orig(&curproxy->log_tag) == NULL) {
2658 chunk_destroy(&curproxy->log_tag);
2659 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2660 err_code |= ERR_ALERT | ERR_FATAL;
2661 goto out;
2662 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002663 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002664 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002665 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2666 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2667 err_code |= ERR_ALERT | ERR_FATAL;
2668 goto out;
2669 }
2670 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002671 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002672 int cur_arg;
2673 int port1, port2;
2674 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002675
2676 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2677 err_code |= ERR_WARN;
2678
2679 if (!*args[1]) {
2680 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2681 file, linenum, "source", "usesrc", "interface");
2682 err_code |= ERR_ALERT | ERR_FATAL;
2683 goto out;
2684 }
2685
Christopher Faulet31930372019-07-15 10:16:58 +02002686 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002687 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002688 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002689 curproxy->conn_src.iface_len = 0;
2690
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002691 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2692 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002693 if (!sk) {
2694 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2695 file, linenum, args[0], args[1], errmsg);
2696 err_code |= ERR_ALERT | ERR_FATAL;
2697 goto out;
2698 }
2699
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002700 curproxy->conn_src.source_addr = *sk;
2701 curproxy->conn_src.opts |= CO_SRC_BIND;
2702
2703 cur_arg = 2;
2704 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002705 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002706#if defined(CONFIG_HAP_TRANSPARENT)
2707 if (!*args[cur_arg + 1]) {
2708 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2709 file, linenum, "usesrc");
2710 err_code |= ERR_ALERT | ERR_FATAL;
2711 goto out;
2712 }
2713
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002714 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002715 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2716 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002717 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002718 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2719 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2720 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2721 char *name, *end;
2722
2723 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002724 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002725 name++;
2726
2727 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002728 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002729 end++;
2730
2731 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2732 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002733 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002734 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2735 curproxy->conn_src.bind_hdr_len = end - name;
2736 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2737 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2738 curproxy->conn_src.bind_hdr_occ = -1;
2739
2740 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002741 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002742 end++;
2743 if (*end == ',') {
2744 end++;
2745 name = end;
2746 if (*end == '-')
2747 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002748 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002749 end++;
2750 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2751 }
2752
2753 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2754 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2755 " occurrences values smaller than %d.\n",
2756 file, linenum, MAX_HDR_HISTORY);
2757 err_code |= ERR_ALERT | ERR_FATAL;
2758 goto out;
2759 }
2760 } else {
2761 struct sockaddr_storage *sk;
2762
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002763 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2764 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002765 if (!sk) {
2766 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2767 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2768 err_code |= ERR_ALERT | ERR_FATAL;
2769 goto out;
2770 }
2771
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002772 curproxy->conn_src.tproxy_addr = *sk;
2773 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2774 }
2775 global.last_checks |= LSTCHK_NETADM;
2776#else /* no TPROXY support */
2777 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2778 file, linenum, "usesrc");
2779 err_code |= ERR_ALERT | ERR_FATAL;
2780 goto out;
2781#endif
2782 cur_arg += 2;
2783 continue;
2784 }
2785
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002786 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002787#ifdef SO_BINDTODEVICE
2788 if (!*args[cur_arg + 1]) {
2789 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2790 file, linenum, args[0]);
2791 err_code |= ERR_ALERT | ERR_FATAL;
2792 goto out;
2793 }
2794 free(curproxy->conn_src.iface_name);
2795 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2796 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2797 global.last_checks |= LSTCHK_NETADM;
2798#else
2799 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2800 file, linenum, args[0], args[cur_arg]);
2801 err_code |= ERR_ALERT | ERR_FATAL;
2802 goto out;
2803#endif
2804 cur_arg += 2;
2805 continue;
2806 }
2807 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2808 file, linenum, args[0], "interface", "usesrc");
2809 err_code |= ERR_ALERT | ERR_FATAL;
2810 goto out;
2811 }
2812 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002813 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002814 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2815 file, linenum, "usesrc", "source");
2816 err_code |= ERR_ALERT | ERR_FATAL;
2817 goto out;
2818 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002819 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 +02002820 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002821 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002822 file, linenum, args[0]);
2823 err_code |= ERR_ALERT | ERR_FATAL;
2824 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002825 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002826 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002827 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2828 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2829 err_code |= ERR_ALERT | ERR_FATAL;
2830 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002831 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002832 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002833 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2834 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2835 err_code |= ERR_ALERT | ERR_FATAL;
2836 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002837 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002838 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002839 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2840 err_code |= ERR_ALERT | ERR_FATAL;
2841 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002842 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002843 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002844 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2845 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2846 err_code |= ERR_ALERT | ERR_FATAL;
2847 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002848 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002849 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002850 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2851 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2852 err_code |= ERR_ALERT | ERR_FATAL;
2853 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002854 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002855 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002856 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2857 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2858 err_code |= ERR_ALERT | ERR_FATAL;
2859 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002860 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002861 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002862 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2863 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2864 err_code |= ERR_ALERT | ERR_FATAL;
2865 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002866 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002867 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 +02002868 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2869 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2870 err_code |= ERR_ALERT | ERR_FATAL;
2871 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002872 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002873 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002874 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2875 err_code |= ERR_ALERT | ERR_FATAL;
2876 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002877 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002878 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 +02002879 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2880 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2881 err_code |= ERR_ALERT | ERR_FATAL;
2882 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002883 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002884 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 +02002885 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2886 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2887 err_code |= ERR_ALERT | ERR_FATAL;
2888 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002889 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002890 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002891 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2892 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2893 err_code |= ERR_ALERT | ERR_FATAL;
2894 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002895 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002896 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 +02002897 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2898 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2899 err_code |= ERR_ALERT | ERR_FATAL;
2900 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002901 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002902 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002903 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2904 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2905 err_code |= ERR_ALERT | ERR_FATAL;
2906 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002907 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002908 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002909 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2910 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2911 err_code |= ERR_ALERT | ERR_FATAL;
2912 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002913 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002914 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302915 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002916 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2917 err_code |= ERR_ALERT | ERR_FATAL;
2918 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002919 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002920 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002921 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2922 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2923 err_code |= ERR_ALERT | ERR_FATAL;
2924 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002926 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002927 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2928 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2929 err_code |= ERR_ALERT | ERR_FATAL;
2930 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002931 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002932 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002933 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2934 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2935 err_code |= ERR_ALERT | ERR_FATAL;
2936 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002937 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002938 else {
2939 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002940 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002941 int index;
2942
2943 list_for_each_entry(kwl, &cfg_keywords.list, list) {
2944 for (index = 0; kwl->kw[index].kw != NULL; index++) {
2945 if (kwl->kw[index].section != CFG_LISTEN)
2946 continue;
2947 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
2948 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01002949 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002950 if (rc < 0) {
2951 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2952 err_code |= ERR_ALERT | ERR_FATAL;
2953 goto out;
2954 }
2955 else if (rc > 0) {
2956 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2957 err_code |= ERR_WARN;
2958 goto out;
2959 }
2960 goto out;
2961 }
2962 }
2963 }
2964
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002965 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
2966 if (best)
2967 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
2968 else
2969 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002970 err_code |= ERR_ALERT | ERR_FATAL;
2971 goto out;
2972 }
2973 out:
2974 free(errmsg);
2975 return err_code;
2976}