blob: ac5002536abbe0f20c01cdedf3d402659488a9b3 [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])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100392 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100393 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100394
395 kw = bind_find_kw(args[cur_arg]);
396 if (kw) {
397 char *err = NULL;
398 int code;
399
400 if (!kw->parse) {
401 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
402 file, linenum, args[0], args[1], args[cur_arg]);
403 cur_arg += 1 + kw->skip ;
404 err_code |= ERR_ALERT | ERR_FATAL;
405 goto out;
406 }
407
408 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
409 err_code |= code;
410
411 if (code) {
412 if (err && *err) {
413 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200414 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
415 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
416 else
417 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100418 }
419 else
420 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
421 file, linenum, args[0], args[1], args[cur_arg]);
422 if (code & ERR_FATAL) {
423 free(err);
424 cur_arg += 1 + kw->skip;
425 goto out;
426 }
427 }
428 free(err);
429 cur_arg += 1 + kw->skip;
430 continue;
431 }
432
Willy Tarreau433b05f2021-03-12 10:14:07 +0100433 best = bind_find_best_kw(args[cur_arg]);
434 if (best)
435 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
436 file, linenum, args[0], args[1], args[cur_arg], best);
437 else
438 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
439 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100440
441 err_code |= ERR_ALERT | ERR_FATAL;
442 goto out;
443 }
444 goto out;
445 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100446 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200447 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]);
448 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100449 goto out;
450 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100451 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100452 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
453 err_code |= ERR_WARN;
454
455 if (alertif_too_many_args(1, file, linenum, args, &err_code))
456 goto out;
457
458 if (!*args[1]) {
459 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
460 file, linenum, args[0]);
461 err_code |= ERR_ALERT | ERR_FATAL;
462 goto out;
463 }
464
465 free(curproxy->monitor_uri);
466 curproxy->monitor_uri_len = strlen(args[1]);
467 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
468 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
469 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
470
471 goto out;
472 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100473 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100474 if (alertif_too_many_args(1, file, linenum, args, &err_code))
475 goto out;
476
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100477 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
478 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
479 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200480 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
481 err_code |= ERR_ALERT | ERR_FATAL;
482 goto out;
483 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100484 else {
485 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
486 err_code |= ERR_ALERT | ERR_FATAL;
487 goto out;
488 }
489 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100490 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100491 struct eb32_node *node;
492
Willy Tarreau5d095c22021-02-12 10:15:59 +0100493 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100494 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
495 file, linenum, args[0]);
496 err_code |= ERR_ALERT | ERR_FATAL;
497 goto out;
498 }
499
500 if (alertif_too_many_args(1, file, linenum, args, &err_code))
501 goto out;
502
503 if (!*args[1]) {
504 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
505 file, linenum, args[0]);
506 err_code |= ERR_ALERT | ERR_FATAL;
507 goto out;
508 }
509
510 curproxy->uuid = atol(args[1]);
511 curproxy->conf.id.key = curproxy->uuid;
512 curproxy->options |= PR_O_FORCED_ID;
513
514 if (curproxy->uuid <= 0) {
515 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
516 file, linenum);
517 err_code |= ERR_ALERT | ERR_FATAL;
518 goto out;
519 }
520
521 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
522 if (node) {
523 struct proxy *target = container_of(node, struct proxy, conf.id);
524 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
525 file, linenum, proxy_type_str(curproxy), curproxy->id,
526 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
527 err_code |= ERR_ALERT | ERR_FATAL;
528 goto out;
529 }
530 eb32_insert(&used_proxy_id, &curproxy->conf.id);
531 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100532 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100533 int i, len=0;
534 char *d;
535
Willy Tarreau5d095c22021-02-12 10:15:59 +0100536 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100537 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
538 file, linenum, args[0]);
539 err_code |= ERR_ALERT | ERR_FATAL;
540 goto out;
541 }
542
543 if (!*args[1]) {
544 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
545 file, linenum, args[0]);
546 return -1;
547 }
548
549 for (i = 1; *args[i]; i++)
550 len += strlen(args[i]) + 1;
551
552 d = calloc(1, len);
553 curproxy->desc = d;
554
555 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
556 for (i = 2; *args[i]; i++)
557 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
558
559 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100560 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100561 if (alertif_too_many_args(0, file, linenum, args, &err_code))
562 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200563 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100564 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100565 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
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 = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100569 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100570 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100571 int cur_arg = 1;
572 unsigned long set = 0;
573
574 while (*args[cur_arg]) {
575 if (strcmp(args[cur_arg], "all") == 0) {
576 set = 0;
577 break;
578 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100579 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100580 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
581 err_code |= ERR_ALERT | ERR_FATAL;
582 goto out;
583 }
584 cur_arg++;
585 }
586 curproxy->bind_proc = set;
587 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100588 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100589 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100590 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
591 err_code |= ERR_ALERT | ERR_FATAL;
592 goto out;
593 }
594
595 err = invalid_char(args[1]);
596 if (err) {
597 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
598 file, linenum, *err, args[1]);
599 err_code |= ERR_ALERT | ERR_FATAL;
600 goto out;
601 }
602
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100603 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100604 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100605 "logical disjunction within a condition.\n",
606 file, linenum, args[1]);
607 err_code |= ERR_ALERT | ERR_FATAL;
608 goto out;
609 }
610
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100611 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
612 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
613 file, linenum, args[1], errmsg);
614 err_code |= ERR_ALERT | ERR_FATAL;
615 goto out;
616 }
617 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100618 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100619
620 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
621 err_code |= ERR_WARN;
622
623 if (*(args[1]) == 0) {
624 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
625 file, linenum, args[0]);
626 err_code |= ERR_ALERT | ERR_FATAL;
627 goto out;
628 }
629 free(curproxy->dyncookie_key);
630 curproxy->dyncookie_key = strdup(args[1]);
631 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100632 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100633 int cur_arg;
634
635 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
636 err_code |= ERR_WARN;
637
638 if (*(args[1]) == 0) {
639 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
640 file, linenum, args[0]);
641 err_code |= ERR_ALERT | ERR_FATAL;
642 goto out;
643 }
644
645 curproxy->ck_opts = 0;
646 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100647 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100648 free(curproxy->cookie_name);
649 curproxy->cookie_name = strdup(args[1]);
650 curproxy->cookie_len = strlen(curproxy->cookie_name);
651
652 cur_arg = 2;
653 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100654 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100655 curproxy->ck_opts |= PR_CK_RW;
656 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100657 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100658 curproxy->ck_opts |= PR_CK_IND;
659 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100660 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100661 curproxy->ck_opts |= PR_CK_INS;
662 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100663 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100664 curproxy->ck_opts |= PR_CK_NOC;
665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100666 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100667 curproxy->ck_opts |= PR_CK_POST;
668 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100669 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100670 curproxy->ck_opts |= PR_CK_PSV;
671 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100672 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100673 curproxy->ck_opts |= PR_CK_PFX;
674 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100675 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100676 curproxy->ck_opts |= PR_CK_HTTPONLY;
677 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100678 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100679 curproxy->ck_opts |= PR_CK_SECURE;
680 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100681 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100682 if (!*args[cur_arg + 1]) {
683 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
684 file, linenum, args[cur_arg]);
685 err_code |= ERR_ALERT | ERR_FATAL;
686 goto out;
687 }
688
Joao Moraise1583752019-10-30 21:04:00 -0300689 if (!strchr(args[cur_arg + 1], '.')) {
690 /* rfc6265, 5.2.3 The Domain Attribute */
691 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
692 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100693 file, linenum, args[cur_arg + 1]);
694 err_code |= ERR_WARN;
695 }
696
697 err = invalid_domainchar(args[cur_arg + 1]);
698 if (err) {
699 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
700 file, linenum, *err, args[cur_arg + 1]);
701 err_code |= ERR_ALERT | ERR_FATAL;
702 goto out;
703 }
704
705 if (!curproxy->cookie_domain) {
706 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
707 } else {
708 /* one domain was already specified, add another one by
709 * building the string which will be returned along with
710 * the cookie.
711 */
712 char *new_ptr;
713 int new_len = strlen(curproxy->cookie_domain) +
714 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
715 new_ptr = malloc(new_len);
716 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
717 free(curproxy->cookie_domain);
718 curproxy->cookie_domain = new_ptr;
719 }
720 cur_arg++;
721 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100722 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100723 unsigned int maxidle;
724 const char *res;
725
726 if (!*args[cur_arg + 1]) {
727 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
728 file, linenum, args[cur_arg]);
729 err_code |= ERR_ALERT | ERR_FATAL;
730 goto out;
731 }
732
733 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200734 if (res == PARSE_TIME_OVER) {
735 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
736 file, linenum, args[cur_arg+1], args[cur_arg]);
737 err_code |= ERR_ALERT | ERR_FATAL;
738 goto out;
739 }
740 else if (res == PARSE_TIME_UNDER) {
741 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
742 file, linenum, args[cur_arg+1], args[cur_arg]);
743 err_code |= ERR_ALERT | ERR_FATAL;
744 goto out;
745 }
746 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100747 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
748 file, linenum, *res, args[cur_arg]);
749 err_code |= ERR_ALERT | ERR_FATAL;
750 goto out;
751 }
752 curproxy->cookie_maxidle = maxidle;
753 cur_arg++;
754 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100755 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100756 unsigned int maxlife;
757 const char *res;
758
759 if (!*args[cur_arg + 1]) {
760 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
761 file, linenum, args[cur_arg]);
762 err_code |= ERR_ALERT | ERR_FATAL;
763 goto out;
764 }
765
Willy Tarreau9faebe32019-06-07 19:00:37 +0200766
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100767 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200768 if (res == PARSE_TIME_OVER) {
769 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
770 file, linenum, args[cur_arg+1], args[cur_arg]);
771 err_code |= ERR_ALERT | ERR_FATAL;
772 goto out;
773 }
774 else if (res == PARSE_TIME_UNDER) {
775 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
776 file, linenum, args[cur_arg+1], args[cur_arg]);
777 err_code |= ERR_ALERT | ERR_FATAL;
778 goto out;
779 }
780 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100781 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
782 file, linenum, *res, args[cur_arg]);
783 err_code |= ERR_ALERT | ERR_FATAL;
784 goto out;
785 }
786 curproxy->cookie_maxlife = maxlife;
787 cur_arg++;
788 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100789 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100790
791 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
792 err_code |= ERR_WARN;
793 curproxy->ck_opts |= PR_CK_DYNAMIC;
794 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100795 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100796 char *val;
797 if (!*args[cur_arg + 1]) {
798 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
799 file, linenum, args[cur_arg]);
800 err_code |= ERR_ALERT | ERR_FATAL;
801 goto out;
802 }
803 val = args[cur_arg + 1];
804 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100805 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100806 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
807 file, linenum, *val);
808 err_code |= ERR_ALERT | ERR_FATAL;
809 goto out;
810 }
811 val++;
812 }
813 /* don't add ';' for the first attribute */
814 if (!curproxy->cookie_attrs)
815 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
816 else
817 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
818 cur_arg++;
819 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100820
821 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100822 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 +0100823 file, linenum, args[0]);
824 err_code |= ERR_ALERT | ERR_FATAL;
825 goto out;
826 }
827 cur_arg++;
828 }
829 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
830 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
831 file, linenum);
832 err_code |= ERR_ALERT | ERR_FATAL;
833 }
834
835 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
836 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
837 file, linenum);
838 err_code |= ERR_ALERT | ERR_FATAL;
839 }
840
841 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
842 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
843 file, linenum);
844 err_code |= ERR_ALERT | ERR_FATAL;
845 }
846 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100847 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100848 if (*(args[1]) == 0) {
849 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
850 file, linenum, args[0]);
851 err_code |= ERR_ALERT | ERR_FATAL;
852 goto out;
853 }
854
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100855 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100856 if (*(args[1]) == 0) {
857 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
858 file, linenum, args[1]);
859 err_code |= ERR_ALERT | ERR_FATAL;
860 goto out;
861 }
862 free(curproxy->email_alert.from);
863 curproxy->email_alert.from = strdup(args[2]);
864 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100865 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100866 if (*(args[1]) == 0) {
867 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
868 file, linenum, args[1]);
869 err_code |= ERR_ALERT | ERR_FATAL;
870 goto out;
871 }
872 free(curproxy->email_alert.mailers.name);
873 curproxy->email_alert.mailers.name = strdup(args[2]);
874 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100875 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100876 if (*(args[1]) == 0) {
877 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
878 file, linenum, args[1]);
879 err_code |= ERR_ALERT | ERR_FATAL;
880 goto out;
881 }
882 free(curproxy->email_alert.myhostname);
883 curproxy->email_alert.myhostname = strdup(args[2]);
884 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100885 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100886 curproxy->email_alert.level = get_log_level(args[2]);
887 if (curproxy->email_alert.level < 0) {
888 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
889 file, linenum, args[1], args[2]);
890 err_code |= ERR_ALERT | ERR_FATAL;
891 goto out;
892 }
893 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100894 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100895 if (*(args[1]) == 0) {
896 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
897 file, linenum, args[1]);
898 err_code |= ERR_ALERT | ERR_FATAL;
899 goto out;
900 }
901 free(curproxy->email_alert.to);
902 curproxy->email_alert.to = strdup(args[2]);
903 }
904 else {
905 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
906 file, linenum, args[1]);
907 err_code |= ERR_ALERT | ERR_FATAL;
908 goto out;
909 }
910 /* Indicate that the email_alert is at least partially configured */
911 curproxy->email_alert.set = 1;
912 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100913 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100914 if (*(args[1]) == 0) {
915 ha_alert("parsing [%s:%d] : missing persist method.\n",
916 file, linenum);
917 err_code |= ERR_ALERT | ERR_FATAL;
918 goto out;
919 }
920
921 if (!strncmp(args[1], "rdp-cookie", 10)) {
922 curproxy->options2 |= PR_O2_RDPC_PRST;
923
924 if (*(args[1] + 10) == '(') { /* cookie name */
925 const char *beg, *end;
926
927 beg = args[1] + 11;
928 end = strchr(beg, ')');
929
930 if (alertif_too_many_args(1, file, linenum, args, &err_code))
931 goto out;
932
933 if (!end || end == beg) {
934 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
935 file, linenum);
936 err_code |= ERR_ALERT | ERR_FATAL;
937 goto out;
938 }
939
940 free(curproxy->rdp_cookie_name);
941 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
942 curproxy->rdp_cookie_len = end-beg;
943 }
944 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
945 free(curproxy->rdp_cookie_name);
946 curproxy->rdp_cookie_name = strdup("msts");
947 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
948 }
949 else { /* syntax */
950 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
951 file, linenum);
952 err_code |= ERR_ALERT | ERR_FATAL;
953 goto out;
954 }
955 }
956 else {
957 ha_alert("parsing [%s:%d] : unknown persist method.\n",
958 file, linenum);
959 err_code |= ERR_ALERT | ERR_FATAL;
960 goto out;
961 }
962 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100963 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +0200964 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 +0100965 err_code |= ERR_ALERT | ERR_FATAL;
966 goto out;
967 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100968 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100969 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
970 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100971 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100972 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
973 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100974 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 +0100975 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
976 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100977 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100978 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
979 }
980 else {
981 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
982 file, linenum, args[0], args[1]);
983 err_code |= ERR_ALERT | ERR_FATAL;
984 goto out;
985 }
986 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100987 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100988 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
989 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100990 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100991 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100992
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100993 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +0100994
995 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100996 curproxy->server_state_file_name = strdup(curproxy->id);
997 else
998 curproxy->server_state_file_name = strdup(args[1]);
999 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001000 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001001 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1002 err_code |= ERR_WARN;
1003 if (*(args[1]) == 0) {
1004 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1005 file, linenum, args[0]);
1006 err_code |= ERR_ALERT | ERR_FATAL;
1007 goto out;
1008 }
1009 curproxy->max_out_conns = atoi(args[1]);
1010 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001011 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001012 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1013 err_code |= ERR_WARN;
1014
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001015 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001016 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001017 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1018 err_code |= ERR_ALERT | ERR_FATAL;
1019 goto out;
1020 }
1021
1022 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1023 goto out;
1024
1025 if (*(args[4]) == 0) {
1026 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1027 file, linenum, args[0]);
1028 err_code |= ERR_ALERT | ERR_FATAL;
1029 goto out;
1030 }
1031 free(curproxy->capture_name);
1032 curproxy->capture_name = strdup(args[2]);
1033 curproxy->capture_namelen = strlen(curproxy->capture_name);
1034 curproxy->capture_len = atol(args[4]);
1035 curproxy->to_log |= LW_COOKIE;
1036 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001037 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001038 struct cap_hdr *hdr;
1039
Willy Tarreau5d095c22021-02-12 10:15:59 +01001040 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001041 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1042 err_code |= ERR_ALERT | ERR_FATAL;
1043 goto out;
1044 }
1045
1046 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1047 goto out;
1048
1049 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1050 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1051 file, linenum, args[0], args[1]);
1052 err_code |= ERR_ALERT | ERR_FATAL;
1053 goto out;
1054 }
1055
1056 hdr = calloc(1, sizeof(*hdr));
1057 hdr->next = curproxy->req_cap;
1058 hdr->name = strdup(args[3]);
1059 hdr->namelen = strlen(args[3]);
1060 hdr->len = atol(args[5]);
1061 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1062 hdr->index = curproxy->nb_req_cap++;
1063 curproxy->req_cap = hdr;
1064 curproxy->to_log |= LW_REQHDR;
1065 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001066 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001067 struct cap_hdr *hdr;
1068
Willy Tarreau5d095c22021-02-12 10:15:59 +01001069 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001070 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1071 err_code |= ERR_ALERT | ERR_FATAL;
1072 goto out;
1073 }
1074
1075 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1076 goto out;
1077
1078 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1079 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1080 file, linenum, args[0], args[1]);
1081 err_code |= ERR_ALERT | ERR_FATAL;
1082 goto out;
1083 }
1084 hdr = calloc(1, sizeof(*hdr));
1085 hdr->next = curproxy->rsp_cap;
1086 hdr->name = strdup(args[3]);
1087 hdr->namelen = strlen(args[3]);
1088 hdr->len = atol(args[5]);
1089 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1090 hdr->index = curproxy->nb_rsp_cap++;
1091 curproxy->rsp_cap = hdr;
1092 curproxy->to_log |= LW_RSPHDR;
1093 }
1094 else {
1095 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1096 file, linenum, args[0]);
1097 err_code |= ERR_ALERT | ERR_FATAL;
1098 goto out;
1099 }
1100 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001101 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001102 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1103 err_code |= ERR_WARN;
1104
1105 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1106 goto out;
1107
1108 if (*(args[1]) == 0) {
1109 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1110 file, linenum, args[0]);
1111 err_code |= ERR_ALERT | ERR_FATAL;
1112 goto out;
1113 }
1114 curproxy->conn_retries = atol(args[1]);
1115 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001116 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001117 struct act_rule *rule;
1118
Willy Tarreau5d095c22021-02-12 10:15:59 +01001119 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001120 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1121 err_code |= ERR_ALERT | ERR_FATAL;
1122 goto out;
1123 }
1124
1125 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1126 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001127 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001128 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1129 file, linenum, args[0]);
1130 err_code |= ERR_WARN;
1131 }
1132
1133 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1134
1135 if (!rule) {
1136 err_code |= ERR_ALERT | ERR_ABORT;
1137 goto out;
1138 }
1139
1140 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1141 err_code |= warnif_cond_conflicts(rule->cond,
1142 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1143 file, linenum);
1144
1145 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001147 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001148 struct act_rule *rule;
1149
Willy Tarreau5d095c22021-02-12 10:15:59 +01001150 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001151 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1152 err_code |= ERR_ALERT | ERR_FATAL;
1153 goto out;
1154 }
1155
1156 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1157 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001158 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001159 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1160 file, linenum, args[0]);
1161 err_code |= ERR_WARN;
1162 }
1163
1164 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1165
1166 if (!rule) {
1167 err_code |= ERR_ALERT | ERR_ABORT;
1168 goto out;
1169 }
1170
1171 err_code |= warnif_cond_conflicts(rule->cond,
1172 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1173 file, linenum);
1174
1175 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1176 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001177 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001178 struct act_rule *rule;
1179
Willy Tarreau5d095c22021-02-12 10:15:59 +01001180 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001181 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1182 err_code |= ERR_ALERT | ERR_FATAL;
1183 goto out;
1184 }
1185
1186 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1187 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1188 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1189 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1190 file, linenum, args[0]);
1191 err_code |= ERR_WARN;
1192 }
1193
1194 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1195
1196 if (!rule) {
1197 err_code |= ERR_ALERT | ERR_ABORT;
1198 goto out;
1199 }
1200
1201 err_code |= warnif_cond_conflicts(rule->cond,
1202 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1203 file, linenum);
1204
1205 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1206 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001207 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001208 /* set the header name and length into the proxy structure */
1209 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1210 err_code |= ERR_WARN;
1211
1212 if (!*args[1]) {
1213 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1214 file, linenum, args[0]);
1215 err_code |= ERR_ALERT | ERR_FATAL;
1216 goto out;
1217 }
1218
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001219 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001220 free(curproxy->server_id_hdr_name);
1221 curproxy->server_id_hdr_name = strdup(args[1]);
1222 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001223 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 +01001224 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001225 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001226 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 +01001227
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001228 err_code |= ERR_ALERT | ERR_FATAL;
1229 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001230 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001231 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001232 struct redirect_rule *rule;
1233
Willy Tarreau5d095c22021-02-12 10:15:59 +01001234 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001235 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1236 err_code |= ERR_ALERT | ERR_FATAL;
1237 goto out;
1238 }
1239
1240 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1241 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1242 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1243 err_code |= ERR_ALERT | ERR_FATAL;
1244 goto out;
1245 }
1246
1247 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1248 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1249 err_code |= warnif_cond_conflicts(rule->cond,
1250 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1251 file, linenum);
1252 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001253 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001254 struct switching_rule *rule;
1255
Willy Tarreau5d095c22021-02-12 10:15:59 +01001256 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001257 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1258 err_code |= ERR_ALERT | ERR_FATAL;
1259 goto out;
1260 }
1261
1262 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1263 err_code |= ERR_WARN;
1264
1265 if (*(args[1]) == 0) {
1266 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1267 err_code |= ERR_ALERT | ERR_FATAL;
1268 goto out;
1269 }
1270
1271 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1272 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1273 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1274 file, linenum, errmsg);
1275 err_code |= ERR_ALERT | ERR_FATAL;
1276 goto out;
1277 }
1278
1279 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1280 }
1281 else if (*args[2]) {
1282 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1283 file, linenum, args[2]);
1284 err_code |= ERR_ALERT | ERR_FATAL;
1285 goto out;
1286 }
1287
1288 rule = calloc(1, sizeof(*rule));
1289 if (!rule) {
1290 ha_alert("Out of memory error.\n");
1291 goto out;
1292 }
1293 rule->cond = cond;
1294 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001295 if (!rule->be.name) {
1296 ha_alert("Out of memory error.\n");
1297 goto out;
1298 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001299 rule->line = linenum;
1300 rule->file = strdup(file);
1301 if (!rule->file) {
1302 ha_alert("Out of memory error.\n");
1303 goto out;
1304 }
1305 LIST_INIT(&rule->list);
1306 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1307 }
1308 else if (strcmp(args[0], "use-server") == 0) {
1309 struct server_rule *rule;
1310
Willy Tarreau5d095c22021-02-12 10:15:59 +01001311 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001312 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1313 err_code |= ERR_ALERT | ERR_FATAL;
1314 goto out;
1315 }
1316
1317 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1318 err_code |= ERR_WARN;
1319
1320 if (*(args[1]) == 0) {
1321 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325
1326 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1327 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1328 file, linenum, args[0]);
1329 err_code |= ERR_ALERT | ERR_FATAL;
1330 goto out;
1331 }
1332
1333 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1334 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1335 file, linenum, errmsg);
1336 err_code |= ERR_ALERT | ERR_FATAL;
1337 goto out;
1338 }
1339
1340 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1341
1342 rule = calloc(1, sizeof(*rule));
1343 rule->cond = cond;
1344 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001345 rule->line = linenum;
1346 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001347 LIST_INIT(&rule->list);
1348 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1349 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1350 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001351 else if ((strcmp(args[0], "force-persist") == 0) ||
1352 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001353 struct persist_rule *rule;
1354
Willy Tarreau5d095c22021-02-12 10:15:59 +01001355 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001356 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1357 err_code |= ERR_ALERT | ERR_FATAL;
1358 goto out;
1359 }
1360
1361 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1362 err_code |= ERR_WARN;
1363
1364 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1365 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1366 file, linenum, args[0]);
1367 err_code |= ERR_ALERT | ERR_FATAL;
1368 goto out;
1369 }
1370
1371 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1372 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1373 file, linenum, args[0], errmsg);
1374 err_code |= ERR_ALERT | ERR_FATAL;
1375 goto out;
1376 }
1377
1378 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1379 * where force-persist is applied.
1380 */
1381 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1382
1383 rule = calloc(1, sizeof(*rule));
1384 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001385 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001386 rule->type = PERSIST_TYPE_FORCE;
1387 } else {
1388 rule->type = PERSIST_TYPE_IGNORE;
1389 }
1390 LIST_INIT(&rule->list);
1391 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1392 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001393 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001394 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001395
Willy Tarreau5d095c22021-02-12 10:15:59 +01001396 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001397 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1398 file, linenum);
1399 err_code |= ERR_ALERT | ERR_FATAL;
1400 goto out;
1401 }
1402
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001403 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001404 if (other) {
1405 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 +01001406 file, linenum, curproxy->id,
1407 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1408 other->proxy ? other->id : other->peers.p->id,
1409 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001410 err_code |= ERR_ALERT | ERR_FATAL;
1411 goto out;
1412 }
1413
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001414 curproxy->table = calloc(1, sizeof *curproxy->table);
1415 if (!curproxy->table) {
1416 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1417 file, linenum, args[0], args[1]);
1418 err_code |= ERR_ALERT | ERR_FATAL;
1419 goto out;
1420 }
1421
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001422 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1423 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001424 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001425 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001426
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001427 /* Store the proxy in the stick-table. */
1428 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001429
1430 stktable_store_name(curproxy->table);
1431 curproxy->table->next = stktables_list;
1432 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001433
1434 /* Add this proxy to the list of proxies which refer to its stick-table. */
1435 if (curproxy->table->proxies_list != curproxy) {
1436 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1437 curproxy->table->proxies_list = curproxy;
1438 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001439 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001440 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001441 struct sticking_rule *rule;
1442 struct sample_expr *expr;
1443 int myidx = 0;
1444 const char *name = NULL;
1445 int flags;
1446
Willy Tarreau5d095c22021-02-12 10:15:59 +01001447 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1449 err_code |= ERR_ALERT | ERR_FATAL;
1450 goto out;
1451 }
1452
1453 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1454 err_code |= ERR_WARN;
1455 goto out;
1456 }
1457
1458 myidx++;
1459 if ((strcmp(args[myidx], "store") == 0) ||
1460 (strcmp(args[myidx], "store-request") == 0)) {
1461 myidx++;
1462 flags = STK_IS_STORE;
1463 }
1464 else if (strcmp(args[myidx], "store-response") == 0) {
1465 myidx++;
1466 flags = STK_IS_STORE | STK_ON_RSP;
1467 }
1468 else if (strcmp(args[myidx], "match") == 0) {
1469 myidx++;
1470 flags = STK_IS_MATCH;
1471 }
1472 else if (strcmp(args[myidx], "on") == 0) {
1473 myidx++;
1474 flags = STK_IS_MATCH | STK_IS_STORE;
1475 }
1476 else {
1477 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1478 err_code |= ERR_ALERT | ERR_FATAL;
1479 goto out;
1480 }
1481
1482 if (*(args[myidx]) == 0) {
1483 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1484 err_code |= ERR_ALERT | ERR_FATAL;
1485 goto out;
1486 }
1487
1488 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001489 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001490 if (!expr) {
1491 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1492 err_code |= ERR_ALERT | ERR_FATAL;
1493 goto out;
1494 }
1495
1496 if (flags & STK_ON_RSP) {
1497 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1498 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1499 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1500 err_code |= ERR_ALERT | ERR_FATAL;
1501 free(expr);
1502 goto out;
1503 }
1504 } else {
1505 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1506 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1507 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1508 err_code |= ERR_ALERT | ERR_FATAL;
1509 free(expr);
1510 goto out;
1511 }
1512 }
1513
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001514 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001515 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1516
1517 if (strcmp(args[myidx], "table") == 0) {
1518 myidx++;
1519 name = args[myidx++];
1520 }
1521
1522 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1523 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1524 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1525 file, linenum, args[0], errmsg);
1526 err_code |= ERR_ALERT | ERR_FATAL;
1527 free(expr);
1528 goto out;
1529 }
1530 }
1531 else if (*(args[myidx])) {
1532 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1533 file, linenum, args[0], args[myidx]);
1534 err_code |= ERR_ALERT | ERR_FATAL;
1535 free(expr);
1536 goto out;
1537 }
1538 if (flags & STK_ON_RSP)
1539 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1540 else
1541 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1542
1543 rule = calloc(1, sizeof(*rule));
1544 rule->cond = cond;
1545 rule->expr = expr;
1546 rule->flags = flags;
1547 rule->table.name = name ? strdup(name) : NULL;
1548 LIST_INIT(&rule->list);
1549 if (flags & STK_ON_RSP)
1550 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1551 else
1552 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1553 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001554 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001555 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001556 curproxy->uri_auth = NULL; /* we must detach from the default config */
1557
1558 if (!*args[1]) {
1559 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001560 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001561 struct stats_admin_rule *rule;
1562
Willy Tarreau5d095c22021-02-12 10:15:59 +01001563 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001564 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1565 err_code |= ERR_ALERT | ERR_FATAL;
1566 goto out;
1567 }
1568
1569 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1570 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1571 err_code |= ERR_ALERT | ERR_ABORT;
1572 goto out;
1573 }
1574
1575 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1576 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1577 file, linenum, args[0], args[1]);
1578 err_code |= ERR_ALERT | ERR_FATAL;
1579 goto out;
1580 }
1581 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1582 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1583 file, linenum, args[0], args[1], errmsg);
1584 err_code |= ERR_ALERT | ERR_FATAL;
1585 goto out;
1586 }
1587
1588 err_code |= warnif_cond_conflicts(cond,
1589 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1590 file, linenum);
1591
1592 rule = calloc(1, sizeof(*rule));
1593 rule->cond = cond;
1594 LIST_INIT(&rule->list);
1595 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001596 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001597 if (*(args[2]) == 0) {
1598 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1599 err_code |= ERR_ALERT | ERR_FATAL;
1600 goto out;
1601 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1602 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1603 err_code |= ERR_ALERT | ERR_ABORT;
1604 goto out;
1605 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001606 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001607 if (*(args[2]) == 0) {
1608 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1609 err_code |= ERR_ALERT | ERR_FATAL;
1610 goto out;
1611 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1612 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1613 err_code |= ERR_ALERT | ERR_ABORT;
1614 goto out;
1615 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001616 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001617 unsigned interval;
1618
1619 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001620 if (err == PARSE_TIME_OVER) {
1621 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1622 file, linenum, args[2]);
1623 err_code |= ERR_ALERT | ERR_FATAL;
1624 goto out;
1625 }
1626 else if (err == PARSE_TIME_UNDER) {
1627 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1628 file, linenum, args[2]);
1629 err_code |= ERR_ALERT | ERR_FATAL;
1630 goto out;
1631 }
1632 else if (err) {
1633 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001634 file, linenum, *err);
1635 err_code |= ERR_ALERT | ERR_FATAL;
1636 goto out;
1637 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1638 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1639 err_code |= ERR_ALERT | ERR_ABORT;
1640 goto out;
1641 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001642 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001643 struct act_rule *rule;
1644
Willy Tarreau5d095c22021-02-12 10:15:59 +01001645 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001646 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1647 err_code |= ERR_ALERT | ERR_FATAL;
1648 goto out;
1649 }
1650
1651 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1652 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1653 err_code |= ERR_ALERT | ERR_ABORT;
1654 goto out;
1655 }
1656
1657 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1658 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1659 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1660 file, linenum, args[0]);
1661 err_code |= ERR_WARN;
1662 }
1663
1664 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1665
1666 if (!rule) {
1667 err_code |= ERR_ALERT | ERR_ABORT;
1668 goto out;
1669 }
1670
1671 err_code |= warnif_cond_conflicts(rule->cond,
1672 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1673 file, linenum);
1674 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1675
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001676 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001677 if (*(args[2]) == 0) {
1678 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1679 err_code |= ERR_ALERT | ERR_FATAL;
1680 goto out;
1681 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1682 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1683 err_code |= ERR_ALERT | ERR_ABORT;
1684 goto out;
1685 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001686 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001687 if (*(args[2]) == 0) {
1688 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1689 err_code |= ERR_ALERT | ERR_FATAL;
1690 goto out;
1691 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1692 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1693 err_code |= ERR_ALERT | ERR_ABORT;
1694 goto out;
1695 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001696 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001697 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1698 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1699 err_code |= ERR_ALERT | ERR_ABORT;
1700 goto out;
1701 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001702 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001703 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001704 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1705 err_code |= ERR_ALERT | ERR_ABORT;
1706 goto out;
1707 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001708 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001709 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001710 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1711 err_code |= ERR_ALERT | ERR_ABORT;
1712 goto out;
1713 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001714 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001715 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1716 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1717 err_code |= ERR_ALERT | ERR_ABORT;
1718 goto out;
1719 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001720 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001721
1722 if (*args[2]) {
1723 int i;
1724 char c;
1725
1726 for (i=0; args[2][i]; i++) {
1727 c = args[2][i];
1728 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1729 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1730 break;
1731 }
1732
1733 if (!i || args[2][i]) {
1734 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1735 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1736 file, linenum, args[0], args[1]);
1737 err_code |= ERR_ALERT | ERR_FATAL;
1738 goto out;
1739 }
1740 }
1741
1742 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1743 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1744 err_code |= ERR_ALERT | ERR_ABORT;
1745 goto out;
1746 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001747 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001748 char *desc = NULL;
1749
1750 if (*args[2]) {
1751 int i, len=0;
1752 char *d;
1753
1754 for (i = 2; *args[i]; i++)
1755 len += strlen(args[i]) + 1;
1756
1757 desc = d = calloc(1, len);
1758
1759 d += snprintf(d, desc + len - d, "%s", args[2]);
1760 for (i = 3; *args[i]; i++)
1761 d += snprintf(d, desc + len - d, " %s", args[i]);
1762 }
1763
1764 if (!*args[2] && !global.desc)
1765 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1766 file, linenum, args[1]);
1767 else {
1768 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1769 free(desc);
1770 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1771 err_code |= ERR_ALERT | ERR_ABORT;
1772 goto out;
1773 }
1774 free(desc);
1775 }
1776 } else {
1777stats_error_parsing:
1778 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1779 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1780 err_code |= ERR_ALERT | ERR_FATAL;
1781 goto out;
1782 }
1783 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001784 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001785 int optnum;
1786
1787 if (*(args[1]) == '\0') {
1788 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1789 file, linenum, args[0]);
1790 err_code |= ERR_ALERT | ERR_FATAL;
1791 goto out;
1792 }
1793
1794 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001795 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001796 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1797 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1798 file, linenum, cfg_opts[optnum].name);
1799 err_code |= ERR_ALERT | ERR_FATAL;
1800 goto out;
1801 }
1802 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1803 goto out;
1804
1805 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1806 err_code |= ERR_WARN;
1807 goto out;
1808 }
1809
1810 curproxy->no_options &= ~cfg_opts[optnum].val;
1811 curproxy->options &= ~cfg_opts[optnum].val;
1812
1813 switch (kwm) {
1814 case KWM_STD:
1815 curproxy->options |= cfg_opts[optnum].val;
1816 break;
1817 case KWM_NO:
1818 curproxy->no_options |= cfg_opts[optnum].val;
1819 break;
1820 case KWM_DEF: /* already cleared */
1821 break;
1822 }
1823
1824 goto out;
1825 }
1826 }
1827
1828 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001829 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001830 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1831 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1832 file, linenum, cfg_opts2[optnum].name);
1833 err_code |= ERR_ALERT | ERR_FATAL;
1834 goto out;
1835 }
1836 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1837 goto out;
1838 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1839 err_code |= ERR_WARN;
1840 goto out;
1841 }
1842
Christopher Faulet31930372019-07-15 10:16:58 +02001843 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001844 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001845 if (kwm ==KWM_NO) {
1846 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1847 " The HTX mode is now the only supported mode.\n",
1848 file, linenum, cfg_opts2[optnum].name);
1849 err_code |= ERR_WARN;
1850 }
Christopher Faulet31930372019-07-15 10:16:58 +02001851 goto out;
1852 }
1853
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001854 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1855 curproxy->options2 &= ~cfg_opts2[optnum].val;
1856
1857 switch (kwm) {
1858 case KWM_STD:
1859 curproxy->options2 |= cfg_opts2[optnum].val;
1860 break;
1861 case KWM_NO:
1862 curproxy->no_options2 |= cfg_opts2[optnum].val;
1863 break;
1864 case KWM_DEF: /* already cleared */
1865 break;
1866 }
1867 goto out;
1868 }
1869 }
1870
1871 /* HTTP options override each other. They can be cancelled using
1872 * "no option xxx" which only switches to default mode if the mode
1873 * was this one (useful for cancelling options set in defaults
1874 * sections).
1875 */
1876 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001877 if (strcmp(args[1], "forceclose") == 0) {
1878 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1879 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1880 file, linenum, args[1]);
1881 err_code |= ERR_WARN;
1882 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001883 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1884 goto out;
1885 if (kwm == KWM_STD) {
1886 curproxy->options &= ~PR_O_HTTP_MODE;
1887 curproxy->options |= PR_O_HTTP_CLO;
1888 goto out;
1889 }
1890 else if (kwm == KWM_NO) {
1891 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1892 curproxy->options &= ~PR_O_HTTP_MODE;
1893 goto out;
1894 }
1895 }
1896 else if (strcmp(args[1], "http-server-close") == 0) {
1897 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1898 goto out;
1899 if (kwm == KWM_STD) {
1900 curproxy->options &= ~PR_O_HTTP_MODE;
1901 curproxy->options |= PR_O_HTTP_SCL;
1902 goto out;
1903 }
1904 else if (kwm == KWM_NO) {
1905 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1906 curproxy->options &= ~PR_O_HTTP_MODE;
1907 goto out;
1908 }
1909 }
1910 else if (strcmp(args[1], "http-keep-alive") == 0) {
1911 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1912 goto out;
1913 if (kwm == KWM_STD) {
1914 curproxy->options &= ~PR_O_HTTP_MODE;
1915 curproxy->options |= PR_O_HTTP_KAL;
1916 goto out;
1917 }
1918 else if (kwm == KWM_NO) {
1919 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1920 curproxy->options &= ~PR_O_HTTP_MODE;
1921 goto out;
1922 }
1923 }
1924 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001925 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
1926 file, linenum, args[1]);
1927 err_code |= ERR_WARN;
1928 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001929 }
1930
1931 /* Redispatch can take an integer argument that control when the
1932 * resispatch occurs. All values are relative to the retries option.
1933 * This can be cancelled using "no option xxx".
1934 */
1935 if (strcmp(args[1], "redispatch") == 0) {
1936 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
1937 err_code |= ERR_WARN;
1938 goto out;
1939 }
1940
1941 curproxy->no_options &= ~PR_O_REDISP;
1942 curproxy->options &= ~PR_O_REDISP;
1943
1944 switch (kwm) {
1945 case KWM_STD:
1946 curproxy->options |= PR_O_REDISP;
1947 curproxy->redispatch_after = -1;
1948 if(*args[2]) {
1949 curproxy->redispatch_after = atol(args[2]);
1950 }
1951 break;
1952 case KWM_NO:
1953 curproxy->no_options |= PR_O_REDISP;
1954 curproxy->redispatch_after = 0;
1955 break;
1956 case KWM_DEF: /* already cleared */
1957 break;
1958 }
1959 goto out;
1960 }
1961
1962 if (kwm != KWM_STD) {
1963 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
1964 file, linenum, args[1]);
1965 err_code |= ERR_ALERT | ERR_FATAL;
1966 goto out;
1967 }
1968
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001969 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001970 char *logformat;
1971 /* generate a complete HTTP log */
1972 logformat = default_http_log_format;
1973 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001974 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001975 curproxy->options2 |= PR_O2_CLFLOG;
1976 logformat = clf_http_log_format;
1977 } else {
1978 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
1979 err_code |= ERR_ALERT | ERR_FATAL;
1980 goto out;
1981 }
1982 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
1983 goto out;
1984 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01001985 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001986 char *oldlogformat = "log-format";
1987 char *clflogformat = "";
1988
1989 if (curproxy->conf.logformat_string == default_http_log_format)
1990 oldlogformat = "option httplog";
1991 else if (curproxy->conf.logformat_string == default_tcp_log_format)
1992 oldlogformat = "option tcplog";
1993 else if (curproxy->conf.logformat_string == clf_http_log_format)
1994 oldlogformat = "option httplog clf";
1995 if (logformat == clf_http_log_format)
1996 clflogformat = " clf";
1997 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
1998 file, linenum, clflogformat, oldlogformat);
1999 }
2000 if (curproxy->conf.logformat_string != default_http_log_format &&
2001 curproxy->conf.logformat_string != default_tcp_log_format &&
2002 curproxy->conf.logformat_string != clf_http_log_format)
2003 free(curproxy->conf.logformat_string);
2004 curproxy->conf.logformat_string = logformat;
2005
2006 free(curproxy->conf.lfs_file);
2007 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2008 curproxy->conf.lfs_line = curproxy->conf.args.line;
2009
Willy Tarreau5d095c22021-02-12 10:15:59 +01002010 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002011 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2012 file, linenum, curproxy->id);
2013 err_code |= ERR_WARN;
2014 }
2015 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002016 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002017 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002018 char *oldlogformat = "log-format";
2019
2020 if (curproxy->conf.logformat_string == default_http_log_format)
2021 oldlogformat = "option httplog";
2022 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2023 oldlogformat = "option tcplog";
2024 else if (curproxy->conf.logformat_string == clf_http_log_format)
2025 oldlogformat = "option httplog clf";
2026 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2027 file, linenum, oldlogformat);
2028 }
2029 /* generate a detailed TCP log */
2030 if (curproxy->conf.logformat_string != default_http_log_format &&
2031 curproxy->conf.logformat_string != default_tcp_log_format &&
2032 curproxy->conf.logformat_string != clf_http_log_format)
2033 free(curproxy->conf.logformat_string);
2034 curproxy->conf.logformat_string = default_tcp_log_format;
2035
2036 free(curproxy->conf.lfs_file);
2037 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2038 curproxy->conf.lfs_line = curproxy->conf.args.line;
2039
2040 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2041 goto out;
2042
Willy Tarreau5d095c22021-02-12 10:15:59 +01002043 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002044 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2045 file, linenum, curproxy->id);
2046 err_code |= ERR_WARN;
2047 }
2048 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002049 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002050 /* enable TCP keep-alives on client and server streams */
2051 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2052 err_code |= ERR_WARN;
2053
2054 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2055 goto out;
2056
2057 if (curproxy->cap & PR_CAP_FE)
2058 curproxy->options |= PR_O_TCP_CLI_KA;
2059 if (curproxy->cap & PR_CAP_BE)
2060 curproxy->options |= PR_O_TCP_SRV_KA;
2061 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002062 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002063 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002064 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002065 goto out;
2066 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002067 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002068 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +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], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002073 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +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], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002078 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +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], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002083 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +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], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002088 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002089 if (err_code & ERR_FATAL)
2090 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002092 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002093 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002094 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002095 goto out;
2096 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002097 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002098 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +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], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002103 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +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], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002108 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +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], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002113 int cur_arg;
2114
2115 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002116 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002117 */
2118
2119 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2120
2121 free(curproxy->fwdfor_hdr_name);
2122 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2123 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002124 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002125
2126 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2127 cur_arg = 2;
2128 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002129 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002130 unsigned char mask;
2131 int i;
2132
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002133 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002134 if (*(args[cur_arg+1]) &&
2135 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2136 curproxy->except_xff_net.family = AF_INET;
2137 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2138 }
2139 else if (*(args[cur_arg+1]) &&
2140 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2141 curproxy->except_xff_net.family = AF_INET6;
2142 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2143 for (i = 0; i < 16; i++)
2144 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2145 }
2146 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002147 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2148 file, linenum, args[0], args[1], args[cur_arg]);
2149 err_code |= ERR_ALERT | ERR_FATAL;
2150 goto out;
2151 }
2152 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002153 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002154 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002155 /* suboption header - needs additional argument for it */
2156 if (*(args[cur_arg+1]) == 0) {
2157 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2158 file, linenum, args[0], args[1], args[cur_arg]);
2159 err_code |= ERR_ALERT | ERR_FATAL;
2160 goto out;
2161 }
2162 free(curproxy->fwdfor_hdr_name);
2163 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2164 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2165 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002166 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002167 curproxy->options &= ~PR_O_FF_ALWAYS;
2168 cur_arg += 1;
2169 } else {
2170 /* unknown suboption - catchall */
2171 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2172 file, linenum, args[0], args[1]);
2173 err_code |= ERR_ALERT | ERR_FATAL;
2174 goto out;
2175 }
2176 } /* end while loop */
2177 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002178 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002179 int cur_arg;
2180
2181 /* insert x-original-to field, but not for the IP address listed as an except.
2182 * set default options (ie: bitfield, header name, etc)
2183 */
2184
2185 curproxy->options |= PR_O_ORGTO;
2186
2187 free(curproxy->orgto_hdr_name);
2188 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2189 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002190 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002191
2192 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2193 cur_arg = 2;
2194 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002195 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002196 unsigned char mask;
2197 int i;
2198
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002199 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002200 if (*(args[cur_arg+1]) &&
2201 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2202 curproxy->except_xot_net.family = AF_INET;
2203 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2204 }
2205 else if (*(args[cur_arg+1]) &&
2206 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2207 curproxy->except_xot_net.family = AF_INET6;
2208 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2209 for (i = 0; i < 16; i++)
2210 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2211 }
2212 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002213 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2214 file, linenum, args[0], args[1], args[cur_arg]);
2215 err_code |= ERR_ALERT | ERR_FATAL;
2216 goto out;
2217 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002218 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002219 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002220 /* suboption header - needs additional argument for it */
2221 if (*(args[cur_arg+1]) == 0) {
2222 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2223 file, linenum, args[0], args[1], args[cur_arg]);
2224 err_code |= ERR_ALERT | ERR_FATAL;
2225 goto out;
2226 }
2227 free(curproxy->orgto_hdr_name);
2228 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2229 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2230 cur_arg += 2;
2231 } else {
2232 /* unknown suboption - catchall */
2233 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2234 file, linenum, args[0], args[1]);
2235 err_code |= ERR_ALERT | ERR_FATAL;
2236 goto out;
2237 }
2238 } /* end while loop */
2239 }
2240 else {
2241 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2242 err_code |= ERR_ALERT | ERR_FATAL;
2243 goto out;
2244 }
2245 goto out;
2246 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002247 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002248 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2249 err_code |= ERR_WARN;
2250
2251 if (*(args[1]) == 0) {
2252 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2253 err_code |= ERR_ALERT | ERR_FATAL;
2254 goto out;
2255 }
2256 free(curproxy->defbe.name);
2257 curproxy->defbe.name = strdup(args[1]);
2258
2259 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2260 goto out;
2261 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002262 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002263 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 +01002264
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002265 err_code |= ERR_ALERT | ERR_FATAL;
2266 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002267 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002268 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2270 err_code |= ERR_WARN;
2271
2272 if (strcmp(args[1], "never") == 0) {
2273 /* enable a graceful server shutdown on an HTTP 404 response */
2274 curproxy->options &= ~PR_O_REUSE_MASK;
2275 curproxy->options |= PR_O_REUSE_NEVR;
2276 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2277 goto out;
2278 }
2279 else if (strcmp(args[1], "safe") == 0) {
2280 /* enable a graceful server shutdown on an HTTP 404 response */
2281 curproxy->options &= ~PR_O_REUSE_MASK;
2282 curproxy->options |= PR_O_REUSE_SAFE;
2283 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2284 goto out;
2285 }
2286 else if (strcmp(args[1], "aggressive") == 0) {
2287 curproxy->options &= ~PR_O_REUSE_MASK;
2288 curproxy->options |= PR_O_REUSE_AGGR;
2289 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2290 goto out;
2291 }
2292 else if (strcmp(args[1], "always") == 0) {
2293 /* enable a graceful server shutdown on an HTTP 404 response */
2294 curproxy->options &= ~PR_O_REUSE_MASK;
2295 curproxy->options |= PR_O_REUSE_ALWS;
2296 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2297 goto out;
2298 }
2299 else {
2300 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2301 err_code |= ERR_ALERT | ERR_FATAL;
2302 goto out;
2303 }
2304 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002305 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002306 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002307 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2308 err_code |= ERR_ALERT | ERR_FATAL;
2309 goto out;
2310 }
2311
2312 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2313 err_code |= ERR_WARN;
2314
2315 if (strcmp(args[1], "fail") == 0) {
2316 /* add a condition to fail monitor requests */
2317 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2318 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2319 file, linenum, args[0], args[1]);
2320 err_code |= ERR_ALERT | ERR_FATAL;
2321 goto out;
2322 }
2323
2324 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2325 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2326 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2327 file, linenum, args[0], args[1], errmsg);
2328 err_code |= ERR_ALERT | ERR_FATAL;
2329 goto out;
2330 }
2331 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2332 }
2333 else {
2334 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2335 err_code |= ERR_ALERT | ERR_FATAL;
2336 goto out;
2337 }
2338 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002339#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002340 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002341 /* enable transparent proxy connections */
2342 curproxy->options |= PR_O_TRANSP;
2343 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2344 goto out;
2345 }
2346#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002347 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002348 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2349 err_code |= ERR_WARN;
2350
2351 if (*(args[1]) == 0) {
2352 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2353 err_code |= ERR_ALERT | ERR_FATAL;
2354 goto out;
2355 }
2356 curproxy->maxconn = atol(args[1]);
2357 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2358 goto out;
2359 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002360 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002361 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2362 err_code |= ERR_WARN;
2363
2364 if (*(args[1]) == 0) {
2365 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2366 err_code |= ERR_ALERT | ERR_FATAL;
2367 goto out;
2368 }
2369 curproxy->backlog = atol(args[1]);
2370 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2371 goto out;
2372 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002373 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002374 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2375 err_code |= ERR_WARN;
2376
2377 if (*(args[1]) == 0) {
2378 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2379 err_code |= ERR_ALERT | ERR_FATAL;
2380 goto out;
2381 }
2382 curproxy->fullconn = atol(args[1]);
2383 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2384 goto out;
2385 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002386 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002387 if (*(args[1]) == 0) {
2388 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2389 err_code |= ERR_ALERT | ERR_FATAL;
2390 goto out;
2391 }
2392 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002393 if (err == PARSE_TIME_OVER) {
2394 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2395 file, linenum, args[1]);
2396 err_code |= ERR_ALERT | ERR_FATAL;
2397 goto out;
2398 }
2399 else if (err == PARSE_TIME_UNDER) {
2400 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2401 file, linenum, args[1]);
2402 err_code |= ERR_ALERT | ERR_FATAL;
2403 goto out;
2404 }
2405 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002406 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2407 file, linenum, *err);
2408 err_code |= ERR_ALERT | ERR_FATAL;
2409 goto out;
2410 }
2411 curproxy->grace = val;
2412 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2413 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002414
2415 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2416 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002417 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002418 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002419 struct sockaddr_storage *sk;
2420 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002421
Willy Tarreau5d095c22021-02-12 10:15:59 +01002422 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002423 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2424 err_code |= ERR_ALERT | ERR_FATAL;
2425 goto out;
2426 }
2427 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2428 err_code |= ERR_WARN;
2429
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002430 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2431 &errmsg, NULL, NULL,
2432 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 +01002433 if (!sk) {
2434 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2435 err_code |= ERR_ALERT | ERR_FATAL;
2436 goto out;
2437 }
2438
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002439 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2440 goto out;
2441
2442 curproxy->dispatch_addr = *sk;
2443 curproxy->options |= PR_O_DISPATCH;
2444 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002445 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002446 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2447 err_code |= ERR_WARN;
2448
2449 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2450 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2451 err_code |= ERR_ALERT | ERR_FATAL;
2452 goto out;
2453 }
2454 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002455 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002456 /**
2457 * The syntax for hash-type config element is
2458 * hash-type {map-based|consistent} [[<algo>] avalanche]
2459 *
2460 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2461 */
2462 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2463
2464 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2465 err_code |= ERR_WARN;
2466
2467 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2468 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2469 }
2470 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2471 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2472 }
2473 else if (strcmp(args[1], "avalanche") == 0) {
2474 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]);
2475 err_code |= ERR_ALERT | ERR_FATAL;
2476 goto out;
2477 }
2478 else {
2479 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2480 err_code |= ERR_ALERT | ERR_FATAL;
2481 goto out;
2482 }
2483
2484 /* set the hash function to use */
2485 if (!*args[2]) {
2486 /* the default algo is sdbm */
2487 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2488
2489 /* if consistent with no argument, then avalanche modifier is also applied */
2490 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2491 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2492 } else {
2493 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002494 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002495 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2496 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002497 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002498 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2499 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002500 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002501 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2502 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002503 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002504 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2505 }
2506 else {
2507 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2508 err_code |= ERR_ALERT | ERR_FATAL;
2509 goto out;
2510 }
2511
2512 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002513 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002514 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2515 }
2516 else if (*args[3]) {
2517 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2518 err_code |= ERR_ALERT | ERR_FATAL;
2519 goto out;
2520 }
2521 }
2522 }
2523 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2524 if (*(args[1]) == 0) {
2525 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2526 err_code |= ERR_ALERT | ERR_FATAL;
2527 goto out;
2528 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002529 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2530 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002531 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2532 err_code |= ERR_ALERT | ERR_FATAL;
2533 goto out;
2534 }
2535 }
2536 else if (strcmp(args[0], "unique-id-format") == 0) {
2537 if (!*(args[1])) {
2538 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2539 err_code |= ERR_ALERT | ERR_FATAL;
2540 goto out;
2541 }
2542 if (*(args[2])) {
2543 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2544 err_code |= ERR_ALERT | ERR_FATAL;
2545 goto out;
2546 }
2547 free(curproxy->conf.uniqueid_format_string);
2548 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2549
2550 free(curproxy->conf.uif_file);
2551 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2552 curproxy->conf.uif_line = curproxy->conf.args.line;
2553 }
2554
2555 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002556 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002557 if (!*(args[1])) {
2558 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2559 err_code |= ERR_ALERT | ERR_FATAL;
2560 goto out;
2561 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002562 copy = strdup(args[1]);
2563 if (copy == NULL) {
2564 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2565 err_code |= ERR_ALERT | ERR_FATAL;
2566 goto out;
2567 }
2568
2569 istfree(&curproxy->header_unique_id);
2570 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002571 }
2572
2573 else if (strcmp(args[0], "log-format") == 0) {
2574 if (!*(args[1])) {
2575 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2576 err_code |= ERR_ALERT | ERR_FATAL;
2577 goto out;
2578 }
2579 if (*(args[2])) {
2580 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2581 err_code |= ERR_ALERT | ERR_FATAL;
2582 goto out;
2583 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002584 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002585 char *oldlogformat = "log-format";
2586
2587 if (curproxy->conf.logformat_string == default_http_log_format)
2588 oldlogformat = "option httplog";
2589 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2590 oldlogformat = "option tcplog";
2591 else if (curproxy->conf.logformat_string == clf_http_log_format)
2592 oldlogformat = "option httplog clf";
2593 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2594 file, linenum, oldlogformat);
2595 }
2596 if (curproxy->conf.logformat_string != default_http_log_format &&
2597 curproxy->conf.logformat_string != default_tcp_log_format &&
2598 curproxy->conf.logformat_string != clf_http_log_format)
2599 free(curproxy->conf.logformat_string);
2600 curproxy->conf.logformat_string = strdup(args[1]);
2601
2602 free(curproxy->conf.lfs_file);
2603 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2604 curproxy->conf.lfs_line = curproxy->conf.args.line;
2605
2606 /* get a chance to improve log-format error reporting by
2607 * reporting the correct line-number when possible.
2608 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002609 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002610 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2611 file, linenum, curproxy->id);
2612 err_code |= ERR_WARN;
2613 }
2614 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002615 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002616 if (!*(args[1])) {
2617 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2618 err_code |= ERR_ALERT | ERR_FATAL;
2619 goto out;
2620 }
2621 if (*(args[2])) {
2622 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2623 err_code |= ERR_ALERT | ERR_FATAL;
2624 goto out;
2625 }
2626
2627 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2628 free(curproxy->conf.logformat_sd_string);
2629 curproxy->conf.logformat_sd_string = strdup(args[1]);
2630
2631 free(curproxy->conf.lfsd_file);
2632 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2633 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2634
2635 /* get a chance to improve log-format-sd error reporting by
2636 * reporting the correct line-number when possible.
2637 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002638 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002639 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2640 file, linenum, curproxy->id);
2641 err_code |= ERR_WARN;
2642 }
2643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002644 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002645 if (*(args[1]) == 0) {
2646 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2647 err_code |= ERR_ALERT | ERR_FATAL;
2648 goto out;
2649 }
2650 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002651 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2652 if (b_orig(&curproxy->log_tag) == NULL) {
2653 chunk_destroy(&curproxy->log_tag);
2654 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2655 err_code |= ERR_ALERT | ERR_FATAL;
2656 goto out;
2657 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002658 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002659 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002660 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2661 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2662 err_code |= ERR_ALERT | ERR_FATAL;
2663 goto out;
2664 }
2665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002666 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002667 int cur_arg;
2668 int port1, port2;
2669 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002670
2671 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2672 err_code |= ERR_WARN;
2673
2674 if (!*args[1]) {
2675 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2676 file, linenum, "source", "usesrc", "interface");
2677 err_code |= ERR_ALERT | ERR_FATAL;
2678 goto out;
2679 }
2680
Christopher Faulet31930372019-07-15 10:16:58 +02002681 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002682 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002683 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002684 curproxy->conn_src.iface_len = 0;
2685
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002686 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2687 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002688 if (!sk) {
2689 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2690 file, linenum, args[0], args[1], errmsg);
2691 err_code |= ERR_ALERT | ERR_FATAL;
2692 goto out;
2693 }
2694
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002695 curproxy->conn_src.source_addr = *sk;
2696 curproxy->conn_src.opts |= CO_SRC_BIND;
2697
2698 cur_arg = 2;
2699 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002700 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002701#if defined(CONFIG_HAP_TRANSPARENT)
2702 if (!*args[cur_arg + 1]) {
2703 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2704 file, linenum, "usesrc");
2705 err_code |= ERR_ALERT | ERR_FATAL;
2706 goto out;
2707 }
2708
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002709 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002710 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2711 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002712 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002713 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2714 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2715 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2716 char *name, *end;
2717
2718 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002719 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002720 name++;
2721
2722 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002723 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002724 end++;
2725
2726 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2727 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002728 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002729 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2730 curproxy->conn_src.bind_hdr_len = end - name;
2731 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2732 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2733 curproxy->conn_src.bind_hdr_occ = -1;
2734
2735 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002736 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002737 end++;
2738 if (*end == ',') {
2739 end++;
2740 name = end;
2741 if (*end == '-')
2742 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002743 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002744 end++;
2745 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2746 }
2747
2748 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2749 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2750 " occurrences values smaller than %d.\n",
2751 file, linenum, MAX_HDR_HISTORY);
2752 err_code |= ERR_ALERT | ERR_FATAL;
2753 goto out;
2754 }
2755 } else {
2756 struct sockaddr_storage *sk;
2757
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002758 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2759 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002760 if (!sk) {
2761 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2762 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2763 err_code |= ERR_ALERT | ERR_FATAL;
2764 goto out;
2765 }
2766
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002767 curproxy->conn_src.tproxy_addr = *sk;
2768 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2769 }
2770 global.last_checks |= LSTCHK_NETADM;
2771#else /* no TPROXY support */
2772 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2773 file, linenum, "usesrc");
2774 err_code |= ERR_ALERT | ERR_FATAL;
2775 goto out;
2776#endif
2777 cur_arg += 2;
2778 continue;
2779 }
2780
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002781 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002782#ifdef SO_BINDTODEVICE
2783 if (!*args[cur_arg + 1]) {
2784 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2785 file, linenum, args[0]);
2786 err_code |= ERR_ALERT | ERR_FATAL;
2787 goto out;
2788 }
2789 free(curproxy->conn_src.iface_name);
2790 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2791 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2792 global.last_checks |= LSTCHK_NETADM;
2793#else
2794 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2795 file, linenum, args[0], args[cur_arg]);
2796 err_code |= ERR_ALERT | ERR_FATAL;
2797 goto out;
2798#endif
2799 cur_arg += 2;
2800 continue;
2801 }
2802 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2803 file, linenum, args[0], "interface", "usesrc");
2804 err_code |= ERR_ALERT | ERR_FATAL;
2805 goto out;
2806 }
2807 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002808 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002809 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2810 file, linenum, "usesrc", "source");
2811 err_code |= ERR_ALERT | ERR_FATAL;
2812 goto out;
2813 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002814 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 +02002815 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002816 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002817 file, linenum, args[0]);
2818 err_code |= ERR_ALERT | ERR_FATAL;
2819 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002820 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002821 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002822 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2823 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2824 err_code |= ERR_ALERT | ERR_FATAL;
2825 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002826 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002827 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002828 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2829 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2830 err_code |= ERR_ALERT | ERR_FATAL;
2831 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002832 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002833 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002834 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\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], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002839 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2840 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2841 err_code |= ERR_ALERT | ERR_FATAL;
2842 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002843 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002844 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002845 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2846 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2847 err_code |= ERR_ALERT | ERR_FATAL;
2848 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002849 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002850 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002851 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2852 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2853 err_code |= ERR_ALERT | ERR_FATAL;
2854 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002855 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002856 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002857 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2858 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2859 err_code |= ERR_ALERT | ERR_FATAL;
2860 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002861 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002862 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 +02002863 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2864 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2865 err_code |= ERR_ALERT | ERR_FATAL;
2866 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002867 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002868 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002869 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\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], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002874 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2875 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2876 err_code |= ERR_ALERT | ERR_FATAL;
2877 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002878 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002879 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 +02002880 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2881 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2882 err_code |= ERR_ALERT | ERR_FATAL;
2883 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002884 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002885 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002886 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2887 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2888 err_code |= ERR_ALERT | ERR_FATAL;
2889 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002890 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002891 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 +02002892 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2893 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2894 err_code |= ERR_ALERT | ERR_FATAL;
2895 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002896 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002897 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002898 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2899 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2900 err_code |= ERR_ALERT | ERR_FATAL;
2901 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002902 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002903 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002904 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2905 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2906 err_code |= ERR_ALERT | ERR_FATAL;
2907 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002908 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002909 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302910 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002911 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2912 err_code |= ERR_ALERT | ERR_FATAL;
2913 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002914 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002915 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002916 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2917 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2918 err_code |= ERR_ALERT | ERR_FATAL;
2919 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002920 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002921 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002922 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2923 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2924 err_code |= ERR_ALERT | ERR_FATAL;
2925 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002926 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002927 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002928 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2929 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2930 err_code |= ERR_ALERT | ERR_FATAL;
2931 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002932 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002933 else {
2934 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002935 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002936 int index;
2937
2938 list_for_each_entry(kwl, &cfg_keywords.list, list) {
2939 for (index = 0; kwl->kw[index].kw != NULL; index++) {
2940 if (kwl->kw[index].section != CFG_LISTEN)
2941 continue;
2942 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
2943 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01002944 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002945 if (rc < 0) {
2946 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2947 err_code |= ERR_ALERT | ERR_FATAL;
2948 goto out;
2949 }
2950 else if (rc > 0) {
2951 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2952 err_code |= ERR_WARN;
2953 goto out;
2954 }
2955 goto out;
2956 }
2957 }
2958 }
2959
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002960 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
2961 if (best)
2962 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
2963 else
2964 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002965 err_code |= ERR_ALERT | ERR_FATAL;
2966 goto out;
2967 }
2968 out:
2969 free(errmsg);
2970 return err_code;
2971}