blob: 56cab535a401ababaa949be05b08dc1a8ad4cc3e [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 Tarreau7d0c1432021-02-12 12:29:28 +010036
37static struct proxy defproxy; /* fake proxy used to assign default values on all instances */
38
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010039/* Report a warning if a rule is placed after a 'tcp-request session' rule.
40 * Return 1 if the warning has been emitted, otherwise 0.
41 */
42int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
43{
44 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
45 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
46 file, line, arg);
47 return 1;
48 }
49 return 0;
50}
51
52/* Report a warning if a rule is placed after a 'tcp-request content' rule.
53 * Return 1 if the warning has been emitted, otherwise 0.
54 */
55int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
56{
57 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
58 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
59 file, line, arg);
60 return 1;
61 }
62 return 0;
63}
64
65/* Report a warning if a rule is placed after a 'monitor fail' rule.
66 * Return 1 if the warning has been emitted, otherwise 0.
67 */
68int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
69{
70 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
71 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
72 file, line, arg);
73 return 1;
74 }
75 return 0;
76}
77
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010078/* Report a warning if a rule is placed after an 'http_request' rule.
79 * Return 1 if the warning has been emitted, otherwise 0.
80 */
81int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
82{
83 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
84 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
85 file, line, arg);
86 return 1;
87 }
88 return 0;
89}
90
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010091/* Report a warning if a rule is placed after a redirect rule.
92 * Return 1 if the warning has been emitted, otherwise 0.
93 */
94int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
95{
96 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
97 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
98 file, line, arg);
99 return 1;
100 }
101 return 0;
102}
103
104/* Report a warning if a rule is placed after a 'use_backend' rule.
105 * Return 1 if the warning has been emitted, otherwise 0.
106 */
107int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
108{
109 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
110 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
111 file, line, arg);
112 return 1;
113 }
114 return 0;
115}
116
117/* Report a warning if a rule is placed after a 'use-server' rule.
118 * Return 1 if the warning has been emitted, otherwise 0.
119 */
120int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
121{
122 if (!LIST_ISEMPTY(&proxy->server_rules)) {
123 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
124 file, line, arg);
125 return 1;
126 }
127 return 0;
128}
129
130/* report a warning if a redirect rule is dangerously placed */
131int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
132{
133 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
134 warnif_rule_after_use_server(proxy, file, line, arg);
135}
136
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100137/* report a warning if an http-request rule is dangerously placed */
138int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
139{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200140 return warnif_rule_after_redirect(proxy, file, line, arg) ||
141 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100142}
143
144/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200145int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100146{
147 return warnif_rule_after_http_req(proxy, file, line, arg) ||
148 warnif_misplaced_http_req(proxy, file, line, arg);
149}
150
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100151/* report a warning if a "tcp request content" rule is dangerously placed */
152int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
153{
154 return warnif_rule_after_monitor(proxy, file, line, arg) ||
155 warnif_misplaced_monitor(proxy, file, line, arg);
156}
157
158/* report a warning if a "tcp request session" rule is dangerously placed */
159int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
160{
161 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
162 warnif_misplaced_tcp_cont(proxy, file, line, arg);
163}
164
165/* report a warning if a "tcp request connection" rule is dangerously placed */
166int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
167{
168 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
169 warnif_misplaced_tcp_sess(proxy, file, line, arg);
170}
171
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100172int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
173{
174 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100175 static struct proxy *curr_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100176 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100177 int rc;
178 unsigned val;
179 int err_code = 0;
180 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100181 char *errmsg = NULL;
182 struct bind_conf *bind_conf;
183
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100184 if (defproxy.obj_type != OBJ_TYPE_PROXY) {
185 /* defproxy not initialized yet */
186 init_new_proxy(&defproxy);
187 proxy_preset_defaults(&defproxy);
188 }
189
Willy Tarreauab3410c2021-02-12 12:17:30 +0100190 if (!curr_defproxy)
191 curr_defproxy = &defproxy;
192
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100193 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100194 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100195 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100196 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100197 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100198 rc = PR_CAP_BE;
Willy Tarreau80dc6fe2021-02-12 09:43:33 +0100199 else if (strcmp(args[0], "defaults") == 0)
200 rc = PR_CAP_DEF;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100201 else
202 rc = PR_CAP_NONE;
203
Willy Tarreau80dc6fe2021-02-12 09:43:33 +0100204 if (rc & PR_CAP_LISTEN) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100205 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100206 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 file, linenum, args[0]);
208 err_code |= ERR_ALERT | ERR_ABORT;
209 goto out;
210 }
211
212 err = invalid_char(args[1]);
213 if (err) {
214 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
215 file, linenum, *err, args[0], args[1]);
216 err_code |= ERR_ALERT | ERR_FATAL;
217 }
218
219 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
220 if (curproxy) {
221 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
222 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
223 curproxy->id, curproxy->conf.file, curproxy->conf.line);
224 err_code |= ERR_ALERT | ERR_FATAL;
225 }
226
Emeric Brunb0c331f2020-10-07 17:05:59 +0200227 curproxy = log_forward_by_name(args[1]);
228 if (curproxy) {
229 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
230 file, linenum, proxy_cap_str(rc), args[1],
231 curproxy->id, curproxy->conf.file, curproxy->conf.line);
232 err_code |= ERR_ALERT | ERR_FATAL;
233 }
234
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100235 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100236 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100237 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
238 goto out;
239 }
240
Willy Tarreauab3410c2021-02-12 12:17:30 +0100241 curproxy = alloc_new_proxy(args[1], rc, file, linenum, curr_defproxy, &errmsg);
Willy Tarreau76838932021-02-12 08:49:47 +0100242 if (!curproxy) {
243 /* message already printed by alloc_new_proxy() */
244 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
245 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100246 goto out;
247 }
Willy Tarreau76838932021-02-12 08:49:47 +0100248 curproxy->next = proxies_list;
249 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100250
251 goto out;
252 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100253 else if (strcmp(args[0], "defaults") == 0) { /* use this one to assign default values */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100254 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
255 err_code |= ERR_ABORT;
256 goto out;
257 }
258
Willy Tarreaua3320a02021-02-12 10:38:49 +0100259 /* let's first free previous defaults */
Willy Tarreauab3410c2021-02-12 12:17:30 +0100260 proxy_free_defaults(curr_defproxy);
261 init_new_proxy(curr_defproxy);
262 proxy_preset_defaults(curr_defproxy);
263 curproxy = curr_defproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100264 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
265 curproxy->conf.args.line = curproxy->conf.line = linenum;
Willy Tarreau80dc6fe2021-02-12 09:43:33 +0100266 defproxy.cap = PR_CAP_DEF | PR_CAP_LISTEN; /* all caps for now */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100267 goto out;
268 }
269 else if (curproxy == NULL) {
270 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
271 err_code |= ERR_ALERT | ERR_FATAL;
272 goto out;
273 }
274
275 /* update the current file and line being parsed */
276 curproxy->conf.args.file = curproxy->conf.file;
277 curproxy->conf.args.line = linenum;
278
279 /* Now let's parse the proxy-specific keywords */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100280 if (strcmp(args[0], "server") == 0 ||
281 strcmp(args[0], "default-server") == 0 ||
282 strcmp(args[0], "server-template") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +0100283 err_code |= parse_server(file, linenum, args, curproxy, curr_defproxy, 1, 0, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100284 if (err_code & ERR_FATAL)
285 goto out;
286 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100287 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100288 struct listener *l;
289 int cur_arg;
290
Willy Tarreau5d095c22021-02-12 10:15:59 +0100291 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100292 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
293 err_code |= ERR_ALERT | ERR_FATAL;
294 goto out;
295 }
296 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
297 err_code |= ERR_WARN;
298
299 if (!*(args[1])) {
300 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
301 file, linenum, args[0]);
302 err_code |= ERR_ALERT | ERR_FATAL;
303 goto out;
304 }
305
306 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
307
308 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200309 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
310 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
311 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100312
313 /* NOTE: the following line might create several listeners if there
314 * are comma-separated IPs or port ranges. So all further processing
315 * will have to be applied to all listeners created after last_listen.
316 */
317 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
318 if (errmsg && *errmsg) {
319 indent_msg(&errmsg, 2);
320 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
321 }
322 else
323 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
324 file, linenum, args[0], args[1]);
325 err_code |= ERR_ALERT | ERR_FATAL;
326 goto out;
327 }
328
329 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
330 /* Set default global rights and owner for unix bind */
331 global.maxsock++;
332 }
333
334 cur_arg = 2;
335 while (*(args[cur_arg])) {
336 static int bind_dumped;
337 struct bind_kw *kw;
338 char *err;
339
340 kw = bind_find_kw(args[cur_arg]);
341 if (kw) {
342 char *err = NULL;
343 int code;
344
345 if (!kw->parse) {
346 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
347 file, linenum, args[0], args[1], args[cur_arg]);
348 cur_arg += 1 + kw->skip ;
349 err_code |= ERR_ALERT | ERR_FATAL;
350 goto out;
351 }
352
353 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
354 err_code |= code;
355
356 if (code) {
357 if (err && *err) {
358 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200359 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
360 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
361 else
362 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100363 }
364 else
365 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
366 file, linenum, args[0], args[1], args[cur_arg]);
367 if (code & ERR_FATAL) {
368 free(err);
369 cur_arg += 1 + kw->skip;
370 goto out;
371 }
372 }
373 free(err);
374 cur_arg += 1 + kw->skip;
375 continue;
376 }
377
378 err = NULL;
379 if (!bind_dumped) {
380 bind_dump_kws(&err);
381 indent_msg(&err, 4);
382 bind_dumped = 1;
383 }
384
385 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
386 file, linenum, args[0], args[1], args[cur_arg],
387 err ? " Registered keywords :" : "", err ? err : "");
388 free(err);
389
390 err_code |= ERR_ALERT | ERR_FATAL;
391 goto out;
392 }
393 goto out;
394 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100395 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200396 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]);
397 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100398 goto out;
399 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100400 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100401 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
402 err_code |= ERR_WARN;
403
404 if (alertif_too_many_args(1, file, linenum, args, &err_code))
405 goto out;
406
407 if (!*args[1]) {
408 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
409 file, linenum, args[0]);
410 err_code |= ERR_ALERT | ERR_FATAL;
411 goto out;
412 }
413
414 free(curproxy->monitor_uri);
415 curproxy->monitor_uri_len = strlen(args[1]);
416 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
417 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
418 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
419
420 goto out;
421 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100422 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100423 if (alertif_too_many_args(1, file, linenum, args, &err_code))
424 goto out;
425
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100426 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
427 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
428 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200429 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
430 err_code |= ERR_ALERT | ERR_FATAL;
431 goto out;
432 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100433 else {
434 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
435 err_code |= ERR_ALERT | ERR_FATAL;
436 goto out;
437 }
438 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100439 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100440 struct eb32_node *node;
441
Willy Tarreau5d095c22021-02-12 10:15:59 +0100442 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100443 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
444 file, linenum, args[0]);
445 err_code |= ERR_ALERT | ERR_FATAL;
446 goto out;
447 }
448
449 if (alertif_too_many_args(1, file, linenum, args, &err_code))
450 goto out;
451
452 if (!*args[1]) {
453 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
454 file, linenum, args[0]);
455 err_code |= ERR_ALERT | ERR_FATAL;
456 goto out;
457 }
458
459 curproxy->uuid = atol(args[1]);
460 curproxy->conf.id.key = curproxy->uuid;
461 curproxy->options |= PR_O_FORCED_ID;
462
463 if (curproxy->uuid <= 0) {
464 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
465 file, linenum);
466 err_code |= ERR_ALERT | ERR_FATAL;
467 goto out;
468 }
469
470 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
471 if (node) {
472 struct proxy *target = container_of(node, struct proxy, conf.id);
473 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
474 file, linenum, proxy_type_str(curproxy), curproxy->id,
475 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
476 err_code |= ERR_ALERT | ERR_FATAL;
477 goto out;
478 }
479 eb32_insert(&used_proxy_id, &curproxy->conf.id);
480 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100481 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100482 int i, len=0;
483 char *d;
484
Willy Tarreau5d095c22021-02-12 10:15:59 +0100485 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100486 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
487 file, linenum, args[0]);
488 err_code |= ERR_ALERT | ERR_FATAL;
489 goto out;
490 }
491
492 if (!*args[1]) {
493 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
494 file, linenum, args[0]);
495 return -1;
496 }
497
498 for (i = 1; *args[i]; i++)
499 len += strlen(args[i]) + 1;
500
501 d = calloc(1, len);
502 curproxy->desc = d;
503
504 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
505 for (i = 2; *args[i]; i++)
506 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
507
508 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100509 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100510 if (alertif_too_many_args(0, file, linenum, args, &err_code))
511 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200512 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100513 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100514 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100515 if (alertif_too_many_args(0, file, linenum, args, &err_code))
516 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200517 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100518 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100519 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100520 int cur_arg = 1;
521 unsigned long set = 0;
522
523 while (*args[cur_arg]) {
524 if (strcmp(args[cur_arg], "all") == 0) {
525 set = 0;
526 break;
527 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100528 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100529 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
530 err_code |= ERR_ALERT | ERR_FATAL;
531 goto out;
532 }
533 cur_arg++;
534 }
535 curproxy->bind_proc = set;
536 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100537 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100538 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100539 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
540 err_code |= ERR_ALERT | ERR_FATAL;
541 goto out;
542 }
543
544 err = invalid_char(args[1]);
545 if (err) {
546 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
547 file, linenum, *err, args[1]);
548 err_code |= ERR_ALERT | ERR_FATAL;
549 goto out;
550 }
551
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100552 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100553 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100554 "logical disjunction within a condition.\n",
555 file, linenum, args[1]);
556 err_code |= ERR_ALERT | ERR_FATAL;
557 goto out;
558 }
559
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100560 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
561 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
562 file, linenum, args[1], errmsg);
563 err_code |= ERR_ALERT | ERR_FATAL;
564 goto out;
565 }
566 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100567 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100568
569 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
570 err_code |= ERR_WARN;
571
572 if (*(args[1]) == 0) {
573 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
574 file, linenum, args[0]);
575 err_code |= ERR_ALERT | ERR_FATAL;
576 goto out;
577 }
578 free(curproxy->dyncookie_key);
579 curproxy->dyncookie_key = strdup(args[1]);
580 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100581 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100582 int cur_arg;
583
584 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
585 err_code |= ERR_WARN;
586
587 if (*(args[1]) == 0) {
588 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
589 file, linenum, args[0]);
590 err_code |= ERR_ALERT | ERR_FATAL;
591 goto out;
592 }
593
594 curproxy->ck_opts = 0;
595 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
596 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
597 free(curproxy->cookie_name);
598 curproxy->cookie_name = strdup(args[1]);
599 curproxy->cookie_len = strlen(curproxy->cookie_name);
600
601 cur_arg = 2;
602 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100603 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100604 curproxy->ck_opts |= PR_CK_RW;
605 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100606 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100607 curproxy->ck_opts |= PR_CK_IND;
608 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100609 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100610 curproxy->ck_opts |= PR_CK_INS;
611 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100612 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100613 curproxy->ck_opts |= PR_CK_NOC;
614 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100615 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100616 curproxy->ck_opts |= PR_CK_POST;
617 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100618 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100619 curproxy->ck_opts |= PR_CK_PSV;
620 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100621 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100622 curproxy->ck_opts |= PR_CK_PFX;
623 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100624 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100625 curproxy->ck_opts |= PR_CK_HTTPONLY;
626 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100627 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100628 curproxy->ck_opts |= PR_CK_SECURE;
629 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100630 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100631 if (!*args[cur_arg + 1]) {
632 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
633 file, linenum, args[cur_arg]);
634 err_code |= ERR_ALERT | ERR_FATAL;
635 goto out;
636 }
637
Joao Moraise1583752019-10-30 21:04:00 -0300638 if (!strchr(args[cur_arg + 1], '.')) {
639 /* rfc6265, 5.2.3 The Domain Attribute */
640 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
641 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100642 file, linenum, args[cur_arg + 1]);
643 err_code |= ERR_WARN;
644 }
645
646 err = invalid_domainchar(args[cur_arg + 1]);
647 if (err) {
648 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
649 file, linenum, *err, args[cur_arg + 1]);
650 err_code |= ERR_ALERT | ERR_FATAL;
651 goto out;
652 }
653
654 if (!curproxy->cookie_domain) {
655 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
656 } else {
657 /* one domain was already specified, add another one by
658 * building the string which will be returned along with
659 * the cookie.
660 */
661 char *new_ptr;
662 int new_len = strlen(curproxy->cookie_domain) +
663 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
664 new_ptr = malloc(new_len);
665 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
666 free(curproxy->cookie_domain);
667 curproxy->cookie_domain = new_ptr;
668 }
669 cur_arg++;
670 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100671 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100672 unsigned int maxidle;
673 const char *res;
674
675 if (!*args[cur_arg + 1]) {
676 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
677 file, linenum, args[cur_arg]);
678 err_code |= ERR_ALERT | ERR_FATAL;
679 goto out;
680 }
681
682 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200683 if (res == PARSE_TIME_OVER) {
684 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
685 file, linenum, args[cur_arg+1], args[cur_arg]);
686 err_code |= ERR_ALERT | ERR_FATAL;
687 goto out;
688 }
689 else if (res == PARSE_TIME_UNDER) {
690 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
691 file, linenum, args[cur_arg+1], args[cur_arg]);
692 err_code |= ERR_ALERT | ERR_FATAL;
693 goto out;
694 }
695 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100696 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
697 file, linenum, *res, args[cur_arg]);
698 err_code |= ERR_ALERT | ERR_FATAL;
699 goto out;
700 }
701 curproxy->cookie_maxidle = maxidle;
702 cur_arg++;
703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100704 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100705 unsigned int maxlife;
706 const char *res;
707
708 if (!*args[cur_arg + 1]) {
709 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
710 file, linenum, args[cur_arg]);
711 err_code |= ERR_ALERT | ERR_FATAL;
712 goto out;
713 }
714
Willy Tarreau9faebe32019-06-07 19:00:37 +0200715
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100716 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200717 if (res == PARSE_TIME_OVER) {
718 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
719 file, linenum, args[cur_arg+1], args[cur_arg]);
720 err_code |= ERR_ALERT | ERR_FATAL;
721 goto out;
722 }
723 else if (res == PARSE_TIME_UNDER) {
724 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
725 file, linenum, args[cur_arg+1], args[cur_arg]);
726 err_code |= ERR_ALERT | ERR_FATAL;
727 goto out;
728 }
729 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100730 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
731 file, linenum, *res, args[cur_arg]);
732 err_code |= ERR_ALERT | ERR_FATAL;
733 goto out;
734 }
735 curproxy->cookie_maxlife = maxlife;
736 cur_arg++;
737 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100738 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100739
740 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
741 err_code |= ERR_WARN;
742 curproxy->ck_opts |= PR_CK_DYNAMIC;
743 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100744 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100745 char *val;
746 if (!*args[cur_arg + 1]) {
747 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
748 file, linenum, args[cur_arg]);
749 err_code |= ERR_ALERT | ERR_FATAL;
750 goto out;
751 }
752 val = args[cur_arg + 1];
753 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100754 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100755 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
756 file, linenum, *val);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760 val++;
761 }
762 /* don't add ';' for the first attribute */
763 if (!curproxy->cookie_attrs)
764 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
765 else
766 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
767 cur_arg++;
768 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100769
770 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100771 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 +0100772 file, linenum, args[0]);
773 err_code |= ERR_ALERT | ERR_FATAL;
774 goto out;
775 }
776 cur_arg++;
777 }
778 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
779 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
780 file, linenum);
781 err_code |= ERR_ALERT | ERR_FATAL;
782 }
783
784 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
785 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
786 file, linenum);
787 err_code |= ERR_ALERT | ERR_FATAL;
788 }
789
790 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
791 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
792 file, linenum);
793 err_code |= ERR_ALERT | ERR_FATAL;
794 }
795 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100796 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100797 if (*(args[1]) == 0) {
798 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
799 file, linenum, args[0]);
800 err_code |= ERR_ALERT | ERR_FATAL;
801 goto out;
802 }
803
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100804 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100805 if (*(args[1]) == 0) {
806 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
807 file, linenum, args[1]);
808 err_code |= ERR_ALERT | ERR_FATAL;
809 goto out;
810 }
811 free(curproxy->email_alert.from);
812 curproxy->email_alert.from = strdup(args[2]);
813 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100814 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100815 if (*(args[1]) == 0) {
816 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
817 file, linenum, args[1]);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821 free(curproxy->email_alert.mailers.name);
822 curproxy->email_alert.mailers.name = strdup(args[2]);
823 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100824 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100825 if (*(args[1]) == 0) {
826 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
827 file, linenum, args[1]);
828 err_code |= ERR_ALERT | ERR_FATAL;
829 goto out;
830 }
831 free(curproxy->email_alert.myhostname);
832 curproxy->email_alert.myhostname = strdup(args[2]);
833 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100834 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100835 curproxy->email_alert.level = get_log_level(args[2]);
836 if (curproxy->email_alert.level < 0) {
837 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
838 file, linenum, args[1], args[2]);
839 err_code |= ERR_ALERT | ERR_FATAL;
840 goto out;
841 }
842 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100843 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100844 if (*(args[1]) == 0) {
845 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
846 file, linenum, args[1]);
847 err_code |= ERR_ALERT | ERR_FATAL;
848 goto out;
849 }
850 free(curproxy->email_alert.to);
851 curproxy->email_alert.to = strdup(args[2]);
852 }
853 else {
854 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
855 file, linenum, args[1]);
856 err_code |= ERR_ALERT | ERR_FATAL;
857 goto out;
858 }
859 /* Indicate that the email_alert is at least partially configured */
860 curproxy->email_alert.set = 1;
861 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100862 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100863 if (*(args[1]) == 0) {
864 ha_alert("parsing [%s:%d] : missing persist method.\n",
865 file, linenum);
866 err_code |= ERR_ALERT | ERR_FATAL;
867 goto out;
868 }
869
870 if (!strncmp(args[1], "rdp-cookie", 10)) {
871 curproxy->options2 |= PR_O2_RDPC_PRST;
872
873 if (*(args[1] + 10) == '(') { /* cookie name */
874 const char *beg, *end;
875
876 beg = args[1] + 11;
877 end = strchr(beg, ')');
878
879 if (alertif_too_many_args(1, file, linenum, args, &err_code))
880 goto out;
881
882 if (!end || end == beg) {
883 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
884 file, linenum);
885 err_code |= ERR_ALERT | ERR_FATAL;
886 goto out;
887 }
888
889 free(curproxy->rdp_cookie_name);
890 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
891 curproxy->rdp_cookie_len = end-beg;
892 }
893 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
894 free(curproxy->rdp_cookie_name);
895 curproxy->rdp_cookie_name = strdup("msts");
896 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
897 }
898 else { /* syntax */
899 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
900 file, linenum);
901 err_code |= ERR_ALERT | ERR_FATAL;
902 goto out;
903 }
904 }
905 else {
906 ha_alert("parsing [%s:%d] : unknown persist method.\n",
907 file, linenum);
908 err_code |= ERR_ALERT | ERR_FATAL;
909 goto out;
910 }
911 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100912 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +0200913 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 +0100914 err_code |= ERR_ALERT | ERR_FATAL;
915 goto out;
916 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100917 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100918 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
919 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100920 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100921 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
922 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100923 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 +0100924 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100926 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100927 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
928 }
929 else {
930 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
931 file, linenum, args[0], args[1]);
932 err_code |= ERR_ALERT | ERR_FATAL;
933 goto out;
934 }
935 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100936 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100937 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
938 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100939 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100940 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +0100941
942 free(curproxy->server_state_file_name);
943 curproxy->server_state_file_name = NULL;
944
945 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100946 curproxy->server_state_file_name = strdup(curproxy->id);
947 else
948 curproxy->server_state_file_name = strdup(args[1]);
949 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100950 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100951 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
952 err_code |= ERR_WARN;
953 if (*(args[1]) == 0) {
954 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
955 file, linenum, args[0]);
956 err_code |= ERR_ALERT | ERR_FATAL;
957 goto out;
958 }
959 curproxy->max_out_conns = atoi(args[1]);
960 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100961 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100962 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
963 err_code |= ERR_WARN;
964
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100965 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100966 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100967 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 goto out;
970 }
971
972 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
973 goto out;
974
975 if (*(args[4]) == 0) {
976 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
977 file, linenum, args[0]);
978 err_code |= ERR_ALERT | ERR_FATAL;
979 goto out;
980 }
981 free(curproxy->capture_name);
982 curproxy->capture_name = strdup(args[2]);
983 curproxy->capture_namelen = strlen(curproxy->capture_name);
984 curproxy->capture_len = atol(args[4]);
985 curproxy->to_log |= LW_COOKIE;
986 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100987 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100988 struct cap_hdr *hdr;
989
Willy Tarreau5d095c22021-02-12 10:15:59 +0100990 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100991 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
992 err_code |= ERR_ALERT | ERR_FATAL;
993 goto out;
994 }
995
996 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
997 goto out;
998
999 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1000 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1001 file, linenum, args[0], args[1]);
1002 err_code |= ERR_ALERT | ERR_FATAL;
1003 goto out;
1004 }
1005
1006 hdr = calloc(1, sizeof(*hdr));
1007 hdr->next = curproxy->req_cap;
1008 hdr->name = strdup(args[3]);
1009 hdr->namelen = strlen(args[3]);
1010 hdr->len = atol(args[5]);
1011 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1012 hdr->index = curproxy->nb_req_cap++;
1013 curproxy->req_cap = hdr;
1014 curproxy->to_log |= LW_REQHDR;
1015 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001016 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001017 struct cap_hdr *hdr;
1018
Willy Tarreau5d095c22021-02-12 10:15:59 +01001019 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001020 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1021 err_code |= ERR_ALERT | ERR_FATAL;
1022 goto out;
1023 }
1024
1025 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1026 goto out;
1027
1028 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1029 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1030 file, linenum, args[0], args[1]);
1031 err_code |= ERR_ALERT | ERR_FATAL;
1032 goto out;
1033 }
1034 hdr = calloc(1, sizeof(*hdr));
1035 hdr->next = curproxy->rsp_cap;
1036 hdr->name = strdup(args[3]);
1037 hdr->namelen = strlen(args[3]);
1038 hdr->len = atol(args[5]);
1039 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1040 hdr->index = curproxy->nb_rsp_cap++;
1041 curproxy->rsp_cap = hdr;
1042 curproxy->to_log |= LW_RSPHDR;
1043 }
1044 else {
1045 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1046 file, linenum, args[0]);
1047 err_code |= ERR_ALERT | ERR_FATAL;
1048 goto out;
1049 }
1050 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001051 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001052 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1053 err_code |= ERR_WARN;
1054
1055 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1056 goto out;
1057
1058 if (*(args[1]) == 0) {
1059 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1060 file, linenum, args[0]);
1061 err_code |= ERR_ALERT | ERR_FATAL;
1062 goto out;
1063 }
1064 curproxy->conn_retries = atol(args[1]);
1065 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001066 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001067 struct act_rule *rule;
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' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1071 err_code |= ERR_ALERT | ERR_FATAL;
1072 goto out;
1073 }
1074
1075 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1076 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001077 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001078 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1079 file, linenum, args[0]);
1080 err_code |= ERR_WARN;
1081 }
1082
1083 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1084
1085 if (!rule) {
1086 err_code |= ERR_ALERT | ERR_ABORT;
1087 goto out;
1088 }
1089
1090 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1091 err_code |= warnif_cond_conflicts(rule->cond,
1092 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1093 file, linenum);
1094
1095 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1096 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001097 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001098 struct act_rule *rule;
1099
Willy Tarreau5d095c22021-02-12 10:15:59 +01001100 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001101 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1102 err_code |= ERR_ALERT | ERR_FATAL;
1103 goto out;
1104 }
1105
1106 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1107 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001108 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001109 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1110 file, linenum, args[0]);
1111 err_code |= ERR_WARN;
1112 }
1113
1114 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1115
1116 if (!rule) {
1117 err_code |= ERR_ALERT | ERR_ABORT;
1118 goto out;
1119 }
1120
1121 err_code |= warnif_cond_conflicts(rule->cond,
1122 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1123 file, linenum);
1124
1125 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1126 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001127 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001128 struct act_rule *rule;
1129
Willy Tarreau5d095c22021-02-12 10:15:59 +01001130 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001131 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1132 err_code |= ERR_ALERT | ERR_FATAL;
1133 goto out;
1134 }
1135
1136 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1137 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1138 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1139 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1140 file, linenum, args[0]);
1141 err_code |= ERR_WARN;
1142 }
1143
1144 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1145
1146 if (!rule) {
1147 err_code |= ERR_ALERT | ERR_ABORT;
1148 goto out;
1149 }
1150
1151 err_code |= warnif_cond_conflicts(rule->cond,
1152 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1153 file, linenum);
1154
1155 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1156 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001157 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001158 /* set the header name and length into the proxy structure */
1159 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1160 err_code |= ERR_WARN;
1161
1162 if (!*args[1]) {
1163 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1164 file, linenum, args[0]);
1165 err_code |= ERR_ALERT | ERR_FATAL;
1166 goto out;
1167 }
1168
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001169 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001170 free(curproxy->server_id_hdr_name);
1171 curproxy->server_id_hdr_name = strdup(args[1]);
1172 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001173 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 +01001174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001175 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001176 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 +01001177
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001178 err_code |= ERR_ALERT | ERR_FATAL;
1179 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001180 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001181 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001182 struct redirect_rule *rule;
1183
Willy Tarreau5d095c22021-02-12 10:15:59 +01001184 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001185 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1186 err_code |= ERR_ALERT | ERR_FATAL;
1187 goto out;
1188 }
1189
1190 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1191 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1192 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1193 err_code |= ERR_ALERT | ERR_FATAL;
1194 goto out;
1195 }
1196
1197 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1198 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1199 err_code |= warnif_cond_conflicts(rule->cond,
1200 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1201 file, linenum);
1202 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001203 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001204 struct switching_rule *rule;
1205
Willy Tarreau5d095c22021-02-12 10:15:59 +01001206 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001207 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1208 err_code |= ERR_ALERT | ERR_FATAL;
1209 goto out;
1210 }
1211
1212 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1213 err_code |= ERR_WARN;
1214
1215 if (*(args[1]) == 0) {
1216 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1217 err_code |= ERR_ALERT | ERR_FATAL;
1218 goto out;
1219 }
1220
1221 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1222 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1223 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1224 file, linenum, errmsg);
1225 err_code |= ERR_ALERT | ERR_FATAL;
1226 goto out;
1227 }
1228
1229 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1230 }
1231 else if (*args[2]) {
1232 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1233 file, linenum, args[2]);
1234 err_code |= ERR_ALERT | ERR_FATAL;
1235 goto out;
1236 }
1237
1238 rule = calloc(1, sizeof(*rule));
1239 if (!rule) {
1240 ha_alert("Out of memory error.\n");
1241 goto out;
1242 }
1243 rule->cond = cond;
1244 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001245 if (!rule->be.name) {
1246 ha_alert("Out of memory error.\n");
1247 goto out;
1248 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001249 rule->line = linenum;
1250 rule->file = strdup(file);
1251 if (!rule->file) {
1252 ha_alert("Out of memory error.\n");
1253 goto out;
1254 }
1255 LIST_INIT(&rule->list);
1256 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1257 }
1258 else if (strcmp(args[0], "use-server") == 0) {
1259 struct server_rule *rule;
1260
Willy Tarreau5d095c22021-02-12 10:15:59 +01001261 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001262 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1263 err_code |= ERR_ALERT | ERR_FATAL;
1264 goto out;
1265 }
1266
1267 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1268 err_code |= ERR_WARN;
1269
1270 if (*(args[1]) == 0) {
1271 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1272 err_code |= ERR_ALERT | ERR_FATAL;
1273 goto out;
1274 }
1275
1276 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1277 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1278 file, linenum, args[0]);
1279 err_code |= ERR_ALERT | ERR_FATAL;
1280 goto out;
1281 }
1282
1283 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1284 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1285 file, linenum, errmsg);
1286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
1289
1290 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1291
1292 rule = calloc(1, sizeof(*rule));
1293 rule->cond = cond;
1294 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001295 rule->line = linenum;
1296 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001297 LIST_INIT(&rule->list);
1298 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1299 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1300 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001301 else if ((strcmp(args[0], "force-persist") == 0) ||
1302 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001303 struct persist_rule *rule;
1304
Willy Tarreau5d095c22021-02-12 10:15:59 +01001305 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001306 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1307 err_code |= ERR_ALERT | ERR_FATAL;
1308 goto out;
1309 }
1310
1311 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1312 err_code |= ERR_WARN;
1313
1314 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1315 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1316 file, linenum, args[0]);
1317 err_code |= ERR_ALERT | ERR_FATAL;
1318 goto out;
1319 }
1320
1321 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1322 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1323 file, linenum, args[0], errmsg);
1324 err_code |= ERR_ALERT | ERR_FATAL;
1325 goto out;
1326 }
1327
1328 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1329 * where force-persist is applied.
1330 */
1331 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1332
1333 rule = calloc(1, sizeof(*rule));
1334 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001335 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001336 rule->type = PERSIST_TYPE_FORCE;
1337 } else {
1338 rule->type = PERSIST_TYPE_IGNORE;
1339 }
1340 LIST_INIT(&rule->list);
1341 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1342 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001343 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001344 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001345
Willy Tarreau5d095c22021-02-12 10:15:59 +01001346 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001347 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1348 file, linenum);
1349 err_code |= ERR_ALERT | ERR_FATAL;
1350 goto out;
1351 }
1352
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001353 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001354 if (other) {
1355 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 +01001356 file, linenum, curproxy->id,
1357 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1358 other->proxy ? other->id : other->peers.p->id,
1359 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001360 err_code |= ERR_ALERT | ERR_FATAL;
1361 goto out;
1362 }
1363
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001364 curproxy->table = calloc(1, sizeof *curproxy->table);
1365 if (!curproxy->table) {
1366 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1367 file, linenum, args[0], args[1]);
1368 err_code |= ERR_ALERT | ERR_FATAL;
1369 goto out;
1370 }
1371
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001372 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1373 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001374 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001375 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001376
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001377 /* Store the proxy in the stick-table. */
1378 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001379
1380 stktable_store_name(curproxy->table);
1381 curproxy->table->next = stktables_list;
1382 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001383
1384 /* Add this proxy to the list of proxies which refer to its stick-table. */
1385 if (curproxy->table->proxies_list != curproxy) {
1386 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1387 curproxy->table->proxies_list = curproxy;
1388 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001389 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001390 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001391 struct sticking_rule *rule;
1392 struct sample_expr *expr;
1393 int myidx = 0;
1394 const char *name = NULL;
1395 int flags;
1396
Willy Tarreau5d095c22021-02-12 10:15:59 +01001397 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001398 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1399 err_code |= ERR_ALERT | ERR_FATAL;
1400 goto out;
1401 }
1402
1403 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1404 err_code |= ERR_WARN;
1405 goto out;
1406 }
1407
1408 myidx++;
1409 if ((strcmp(args[myidx], "store") == 0) ||
1410 (strcmp(args[myidx], "store-request") == 0)) {
1411 myidx++;
1412 flags = STK_IS_STORE;
1413 }
1414 else if (strcmp(args[myidx], "store-response") == 0) {
1415 myidx++;
1416 flags = STK_IS_STORE | STK_ON_RSP;
1417 }
1418 else if (strcmp(args[myidx], "match") == 0) {
1419 myidx++;
1420 flags = STK_IS_MATCH;
1421 }
1422 else if (strcmp(args[myidx], "on") == 0) {
1423 myidx++;
1424 flags = STK_IS_MATCH | STK_IS_STORE;
1425 }
1426 else {
1427 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1428 err_code |= ERR_ALERT | ERR_FATAL;
1429 goto out;
1430 }
1431
1432 if (*(args[myidx]) == 0) {
1433 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1434 err_code |= ERR_ALERT | ERR_FATAL;
1435 goto out;
1436 }
1437
1438 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001439 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001440 if (!expr) {
1441 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1442 err_code |= ERR_ALERT | ERR_FATAL;
1443 goto out;
1444 }
1445
1446 if (flags & STK_ON_RSP) {
1447 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1448 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1449 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1450 err_code |= ERR_ALERT | ERR_FATAL;
1451 free(expr);
1452 goto out;
1453 }
1454 } else {
1455 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1456 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1457 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1458 err_code |= ERR_ALERT | ERR_FATAL;
1459 free(expr);
1460 goto out;
1461 }
1462 }
1463
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001464 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001465 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1466
1467 if (strcmp(args[myidx], "table") == 0) {
1468 myidx++;
1469 name = args[myidx++];
1470 }
1471
1472 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1473 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1474 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1475 file, linenum, args[0], errmsg);
1476 err_code |= ERR_ALERT | ERR_FATAL;
1477 free(expr);
1478 goto out;
1479 }
1480 }
1481 else if (*(args[myidx])) {
1482 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1483 file, linenum, args[0], args[myidx]);
1484 err_code |= ERR_ALERT | ERR_FATAL;
1485 free(expr);
1486 goto out;
1487 }
1488 if (flags & STK_ON_RSP)
1489 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1490 else
1491 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1492
1493 rule = calloc(1, sizeof(*rule));
1494 rule->cond = cond;
1495 rule->expr = expr;
1496 rule->flags = flags;
1497 rule->table.name = name ? strdup(name) : NULL;
1498 LIST_INIT(&rule->list);
1499 if (flags & STK_ON_RSP)
1500 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1501 else
1502 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1503 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001504 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001505 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001506 curproxy->uri_auth = NULL; /* we must detach from the default config */
1507
1508 if (!*args[1]) {
1509 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001510 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001511 struct stats_admin_rule *rule;
1512
Willy Tarreau5d095c22021-02-12 10:15:59 +01001513 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001514 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1515 err_code |= ERR_ALERT | ERR_FATAL;
1516 goto out;
1517 }
1518
1519 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1520 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1521 err_code |= ERR_ALERT | ERR_ABORT;
1522 goto out;
1523 }
1524
1525 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1526 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1527 file, linenum, args[0], args[1]);
1528 err_code |= ERR_ALERT | ERR_FATAL;
1529 goto out;
1530 }
1531 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1532 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1533 file, linenum, args[0], args[1], errmsg);
1534 err_code |= ERR_ALERT | ERR_FATAL;
1535 goto out;
1536 }
1537
1538 err_code |= warnif_cond_conflicts(cond,
1539 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1540 file, linenum);
1541
1542 rule = calloc(1, sizeof(*rule));
1543 rule->cond = cond;
1544 LIST_INIT(&rule->list);
1545 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001546 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001547 if (*(args[2]) == 0) {
1548 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1549 err_code |= ERR_ALERT | ERR_FATAL;
1550 goto out;
1551 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1552 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1553 err_code |= ERR_ALERT | ERR_ABORT;
1554 goto out;
1555 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001556 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001557 if (*(args[2]) == 0) {
1558 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1559 err_code |= ERR_ALERT | ERR_FATAL;
1560 goto out;
1561 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1562 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1563 err_code |= ERR_ALERT | ERR_ABORT;
1564 goto out;
1565 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001566 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001567 unsigned interval;
1568
1569 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001570 if (err == PARSE_TIME_OVER) {
1571 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1572 file, linenum, args[2]);
1573 err_code |= ERR_ALERT | ERR_FATAL;
1574 goto out;
1575 }
1576 else if (err == PARSE_TIME_UNDER) {
1577 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1578 file, linenum, args[2]);
1579 err_code |= ERR_ALERT | ERR_FATAL;
1580 goto out;
1581 }
1582 else if (err) {
1583 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001584 file, linenum, *err);
1585 err_code |= ERR_ALERT | ERR_FATAL;
1586 goto out;
1587 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1588 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1589 err_code |= ERR_ALERT | ERR_ABORT;
1590 goto out;
1591 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001592 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001593 struct act_rule *rule;
1594
Willy Tarreau5d095c22021-02-12 10:15:59 +01001595 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001596 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1597 err_code |= ERR_ALERT | ERR_FATAL;
1598 goto out;
1599 }
1600
1601 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1602 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1603 err_code |= ERR_ALERT | ERR_ABORT;
1604 goto out;
1605 }
1606
1607 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1608 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1609 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1610 file, linenum, args[0]);
1611 err_code |= ERR_WARN;
1612 }
1613
1614 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1615
1616 if (!rule) {
1617 err_code |= ERR_ALERT | ERR_ABORT;
1618 goto out;
1619 }
1620
1621 err_code |= warnif_cond_conflicts(rule->cond,
1622 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1623 file, linenum);
1624 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1625
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001626 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001627 if (*(args[2]) == 0) {
1628 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1629 err_code |= ERR_ALERT | ERR_FATAL;
1630 goto out;
1631 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1632 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1633 err_code |= ERR_ALERT | ERR_ABORT;
1634 goto out;
1635 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001636 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001637 if (*(args[2]) == 0) {
1638 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1639 err_code |= ERR_ALERT | ERR_FATAL;
1640 goto out;
1641 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1642 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1643 err_code |= ERR_ALERT | ERR_ABORT;
1644 goto out;
1645 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001646 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001647 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1648 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1649 err_code |= ERR_ALERT | ERR_ABORT;
1650 goto out;
1651 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001652 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001653 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001654 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1655 err_code |= ERR_ALERT | ERR_ABORT;
1656 goto out;
1657 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001658 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001659 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001660 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1661 err_code |= ERR_ALERT | ERR_ABORT;
1662 goto out;
1663 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001664 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001665 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1666 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1667 err_code |= ERR_ALERT | ERR_ABORT;
1668 goto out;
1669 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001670 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001671
1672 if (*args[2]) {
1673 int i;
1674 char c;
1675
1676 for (i=0; args[2][i]; i++) {
1677 c = args[2][i];
1678 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1679 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1680 break;
1681 }
1682
1683 if (!i || args[2][i]) {
1684 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1685 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1686 file, linenum, args[0], args[1]);
1687 err_code |= ERR_ALERT | ERR_FATAL;
1688 goto out;
1689 }
1690 }
1691
1692 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1693 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1694 err_code |= ERR_ALERT | ERR_ABORT;
1695 goto out;
1696 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001697 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001698 char *desc = NULL;
1699
1700 if (*args[2]) {
1701 int i, len=0;
1702 char *d;
1703
1704 for (i = 2; *args[i]; i++)
1705 len += strlen(args[i]) + 1;
1706
1707 desc = d = calloc(1, len);
1708
1709 d += snprintf(d, desc + len - d, "%s", args[2]);
1710 for (i = 3; *args[i]; i++)
1711 d += snprintf(d, desc + len - d, " %s", args[i]);
1712 }
1713
1714 if (!*args[2] && !global.desc)
1715 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1716 file, linenum, args[1]);
1717 else {
1718 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1719 free(desc);
1720 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1721 err_code |= ERR_ALERT | ERR_ABORT;
1722 goto out;
1723 }
1724 free(desc);
1725 }
1726 } else {
1727stats_error_parsing:
1728 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1729 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1730 err_code |= ERR_ALERT | ERR_FATAL;
1731 goto out;
1732 }
1733 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001734 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001735 int optnum;
1736
1737 if (*(args[1]) == '\0') {
1738 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1739 file, linenum, args[0]);
1740 err_code |= ERR_ALERT | ERR_FATAL;
1741 goto out;
1742 }
1743
1744 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001745 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001746 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1747 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1748 file, linenum, cfg_opts[optnum].name);
1749 err_code |= ERR_ALERT | ERR_FATAL;
1750 goto out;
1751 }
1752 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1753 goto out;
1754
1755 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1756 err_code |= ERR_WARN;
1757 goto out;
1758 }
1759
1760 curproxy->no_options &= ~cfg_opts[optnum].val;
1761 curproxy->options &= ~cfg_opts[optnum].val;
1762
1763 switch (kwm) {
1764 case KWM_STD:
1765 curproxy->options |= cfg_opts[optnum].val;
1766 break;
1767 case KWM_NO:
1768 curproxy->no_options |= cfg_opts[optnum].val;
1769 break;
1770 case KWM_DEF: /* already cleared */
1771 break;
1772 }
1773
1774 goto out;
1775 }
1776 }
1777
1778 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001779 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001780 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1781 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1782 file, linenum, cfg_opts2[optnum].name);
1783 err_code |= ERR_ALERT | ERR_FATAL;
1784 goto out;
1785 }
1786 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1787 goto out;
1788 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1789 err_code |= ERR_WARN;
1790 goto out;
1791 }
1792
Christopher Faulet31930372019-07-15 10:16:58 +02001793 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001794 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02001795 if (kwm ==KWM_NO) {
1796 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
1797 " The HTX mode is now the only supported mode.\n",
1798 file, linenum, cfg_opts2[optnum].name);
1799 err_code |= ERR_WARN;
1800 }
Christopher Faulet31930372019-07-15 10:16:58 +02001801 goto out;
1802 }
1803
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001804 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1805 curproxy->options2 &= ~cfg_opts2[optnum].val;
1806
1807 switch (kwm) {
1808 case KWM_STD:
1809 curproxy->options2 |= cfg_opts2[optnum].val;
1810 break;
1811 case KWM_NO:
1812 curproxy->no_options2 |= cfg_opts2[optnum].val;
1813 break;
1814 case KWM_DEF: /* already cleared */
1815 break;
1816 }
1817 goto out;
1818 }
1819 }
1820
1821 /* HTTP options override each other. They can be cancelled using
1822 * "no option xxx" which only switches to default mode if the mode
1823 * was this one (useful for cancelling options set in defaults
1824 * sections).
1825 */
1826 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02001827 if (strcmp(args[1], "forceclose") == 0) {
1828 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
1829 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
1830 file, linenum, args[1]);
1831 err_code |= ERR_WARN;
1832 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001833 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1834 goto out;
1835 if (kwm == KWM_STD) {
1836 curproxy->options &= ~PR_O_HTTP_MODE;
1837 curproxy->options |= PR_O_HTTP_CLO;
1838 goto out;
1839 }
1840 else if (kwm == KWM_NO) {
1841 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1842 curproxy->options &= ~PR_O_HTTP_MODE;
1843 goto out;
1844 }
1845 }
1846 else if (strcmp(args[1], "http-server-close") == 0) {
1847 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1848 goto out;
1849 if (kwm == KWM_STD) {
1850 curproxy->options &= ~PR_O_HTTP_MODE;
1851 curproxy->options |= PR_O_HTTP_SCL;
1852 goto out;
1853 }
1854 else if (kwm == KWM_NO) {
1855 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1856 curproxy->options &= ~PR_O_HTTP_MODE;
1857 goto out;
1858 }
1859 }
1860 else if (strcmp(args[1], "http-keep-alive") == 0) {
1861 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1862 goto out;
1863 if (kwm == KWM_STD) {
1864 curproxy->options &= ~PR_O_HTTP_MODE;
1865 curproxy->options |= PR_O_HTTP_KAL;
1866 goto out;
1867 }
1868 else if (kwm == KWM_NO) {
1869 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1870 curproxy->options &= ~PR_O_HTTP_MODE;
1871 goto out;
1872 }
1873 }
1874 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001875 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
1876 file, linenum, args[1]);
1877 err_code |= ERR_WARN;
1878 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001879 }
1880
1881 /* Redispatch can take an integer argument that control when the
1882 * resispatch occurs. All values are relative to the retries option.
1883 * This can be cancelled using "no option xxx".
1884 */
1885 if (strcmp(args[1], "redispatch") == 0) {
1886 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
1887 err_code |= ERR_WARN;
1888 goto out;
1889 }
1890
1891 curproxy->no_options &= ~PR_O_REDISP;
1892 curproxy->options &= ~PR_O_REDISP;
1893
1894 switch (kwm) {
1895 case KWM_STD:
1896 curproxy->options |= PR_O_REDISP;
1897 curproxy->redispatch_after = -1;
1898 if(*args[2]) {
1899 curproxy->redispatch_after = atol(args[2]);
1900 }
1901 break;
1902 case KWM_NO:
1903 curproxy->no_options |= PR_O_REDISP;
1904 curproxy->redispatch_after = 0;
1905 break;
1906 case KWM_DEF: /* already cleared */
1907 break;
1908 }
1909 goto out;
1910 }
1911
1912 if (kwm != KWM_STD) {
1913 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
1914 file, linenum, args[1]);
1915 err_code |= ERR_ALERT | ERR_FATAL;
1916 goto out;
1917 }
1918
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001919 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001920 char *logformat;
1921 /* generate a complete HTTP log */
1922 logformat = default_http_log_format;
1923 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001924 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001925 curproxy->options2 |= PR_O2_CLFLOG;
1926 logformat = clf_http_log_format;
1927 } else {
1928 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
1929 err_code |= ERR_ALERT | ERR_FATAL;
1930 goto out;
1931 }
1932 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
1933 goto out;
1934 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01001935 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001936 char *oldlogformat = "log-format";
1937 char *clflogformat = "";
1938
1939 if (curproxy->conf.logformat_string == default_http_log_format)
1940 oldlogformat = "option httplog";
1941 else if (curproxy->conf.logformat_string == default_tcp_log_format)
1942 oldlogformat = "option tcplog";
1943 else if (curproxy->conf.logformat_string == clf_http_log_format)
1944 oldlogformat = "option httplog clf";
1945 if (logformat == clf_http_log_format)
1946 clflogformat = " clf";
1947 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
1948 file, linenum, clflogformat, oldlogformat);
1949 }
1950 if (curproxy->conf.logformat_string != default_http_log_format &&
1951 curproxy->conf.logformat_string != default_tcp_log_format &&
1952 curproxy->conf.logformat_string != clf_http_log_format)
1953 free(curproxy->conf.logformat_string);
1954 curproxy->conf.logformat_string = logformat;
1955
1956 free(curproxy->conf.lfs_file);
1957 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
1958 curproxy->conf.lfs_line = curproxy->conf.args.line;
1959
Willy Tarreau5d095c22021-02-12 10:15:59 +01001960 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001961 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
1962 file, linenum, curproxy->id);
1963 err_code |= ERR_WARN;
1964 }
1965 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001966 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01001967 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001968 char *oldlogformat = "log-format";
1969
1970 if (curproxy->conf.logformat_string == default_http_log_format)
1971 oldlogformat = "option httplog";
1972 else if (curproxy->conf.logformat_string == default_tcp_log_format)
1973 oldlogformat = "option tcplog";
1974 else if (curproxy->conf.logformat_string == clf_http_log_format)
1975 oldlogformat = "option httplog clf";
1976 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
1977 file, linenum, oldlogformat);
1978 }
1979 /* generate a detailed TCP log */
1980 if (curproxy->conf.logformat_string != default_http_log_format &&
1981 curproxy->conf.logformat_string != default_tcp_log_format &&
1982 curproxy->conf.logformat_string != clf_http_log_format)
1983 free(curproxy->conf.logformat_string);
1984 curproxy->conf.logformat_string = default_tcp_log_format;
1985
1986 free(curproxy->conf.lfs_file);
1987 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
1988 curproxy->conf.lfs_line = curproxy->conf.args.line;
1989
1990 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1991 goto out;
1992
Willy Tarreau5d095c22021-02-12 10:15:59 +01001993 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001994 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
1995 file, linenum, curproxy->id);
1996 err_code |= ERR_WARN;
1997 }
1998 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001999 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002000 /* enable TCP keep-alives on client and server streams */
2001 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2002 err_code |= ERR_WARN;
2003
2004 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2005 goto out;
2006
2007 if (curproxy->cap & PR_CAP_FE)
2008 curproxy->options |= PR_O_TCP_CLI_KA;
2009 if (curproxy->cap & PR_CAP_BE)
2010 curproxy->options |= PR_O_TCP_SRV_KA;
2011 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002012 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002013 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002014 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002015 goto out;
2016 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002017 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002018 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002019 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002020 goto out;
2021 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002022 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002023 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002024 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002025 goto out;
2026 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002027 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002028 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002029 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002030 goto out;
2031 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002032 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002033 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002034 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002035 goto out;
2036 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002037 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002038 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002039 if (err_code & ERR_FATAL)
2040 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002041 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002042 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002043 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002044 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002045 goto out;
2046 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002047 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002048 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002049 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002050 goto out;
2051 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002052 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002053 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002054 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002055 goto out;
2056 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002057 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002058 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002059 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002060 goto out;
2061 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002062 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002063 int cur_arg;
2064
2065 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002066 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002067 */
2068
2069 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2070
2071 free(curproxy->fwdfor_hdr_name);
2072 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2073 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2074
2075 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2076 cur_arg = 2;
2077 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002078 if (strcmp(args[cur_arg], "except") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002079 /* suboption except - needs additional argument for it */
2080 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2081 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2082 file, linenum, args[0], args[1], args[cur_arg]);
2083 err_code |= ERR_ALERT | ERR_FATAL;
2084 goto out;
2085 }
2086 /* flush useless bits */
2087 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2088 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002089 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002090 /* suboption header - needs additional argument for it */
2091 if (*(args[cur_arg+1]) == 0) {
2092 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2093 file, linenum, args[0], args[1], args[cur_arg]);
2094 err_code |= ERR_ALERT | ERR_FATAL;
2095 goto out;
2096 }
2097 free(curproxy->fwdfor_hdr_name);
2098 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2099 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2100 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002101 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002102 curproxy->options &= ~PR_O_FF_ALWAYS;
2103 cur_arg += 1;
2104 } else {
2105 /* unknown suboption - catchall */
2106 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2107 file, linenum, args[0], args[1]);
2108 err_code |= ERR_ALERT | ERR_FATAL;
2109 goto out;
2110 }
2111 } /* end while loop */
2112 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002113 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002114 int cur_arg;
2115
2116 /* insert x-original-to field, but not for the IP address listed as an except.
2117 * set default options (ie: bitfield, header name, etc)
2118 */
2119
2120 curproxy->options |= PR_O_ORGTO;
2121
2122 free(curproxy->orgto_hdr_name);
2123 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2124 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2125
2126 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2127 cur_arg = 2;
2128 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002129 if (strcmp(args[cur_arg], "except") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002130 /* suboption except - needs additional argument for it */
2131 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2132 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2133 file, linenum, args[0], args[1], args[cur_arg]);
2134 err_code |= ERR_ALERT | ERR_FATAL;
2135 goto out;
2136 }
2137 /* flush useless bits */
2138 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2139 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002140 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002141 /* suboption header - needs additional argument for it */
2142 if (*(args[cur_arg+1]) == 0) {
2143 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2144 file, linenum, args[0], args[1], args[cur_arg]);
2145 err_code |= ERR_ALERT | ERR_FATAL;
2146 goto out;
2147 }
2148 free(curproxy->orgto_hdr_name);
2149 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2150 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2151 cur_arg += 2;
2152 } else {
2153 /* unknown suboption - catchall */
2154 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2155 file, linenum, args[0], args[1]);
2156 err_code |= ERR_ALERT | ERR_FATAL;
2157 goto out;
2158 }
2159 } /* end while loop */
2160 }
2161 else {
2162 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2163 err_code |= ERR_ALERT | ERR_FATAL;
2164 goto out;
2165 }
2166 goto out;
2167 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002168 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002169 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2170 err_code |= ERR_WARN;
2171
2172 if (*(args[1]) == 0) {
2173 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2174 err_code |= ERR_ALERT | ERR_FATAL;
2175 goto out;
2176 }
2177 free(curproxy->defbe.name);
2178 curproxy->defbe.name = strdup(args[1]);
2179
2180 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2181 goto out;
2182 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002183 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002184 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 +01002185
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002186 err_code |= ERR_ALERT | ERR_FATAL;
2187 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002188 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002189 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002190 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2191 err_code |= ERR_WARN;
2192
2193 if (strcmp(args[1], "never") == 0) {
2194 /* enable a graceful server shutdown on an HTTP 404 response */
2195 curproxy->options &= ~PR_O_REUSE_MASK;
2196 curproxy->options |= PR_O_REUSE_NEVR;
2197 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2198 goto out;
2199 }
2200 else if (strcmp(args[1], "safe") == 0) {
2201 /* enable a graceful server shutdown on an HTTP 404 response */
2202 curproxy->options &= ~PR_O_REUSE_MASK;
2203 curproxy->options |= PR_O_REUSE_SAFE;
2204 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2205 goto out;
2206 }
2207 else if (strcmp(args[1], "aggressive") == 0) {
2208 curproxy->options &= ~PR_O_REUSE_MASK;
2209 curproxy->options |= PR_O_REUSE_AGGR;
2210 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2211 goto out;
2212 }
2213 else if (strcmp(args[1], "always") == 0) {
2214 /* enable a graceful server shutdown on an HTTP 404 response */
2215 curproxy->options &= ~PR_O_REUSE_MASK;
2216 curproxy->options |= PR_O_REUSE_ALWS;
2217 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2218 goto out;
2219 }
2220 else {
2221 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2222 err_code |= ERR_ALERT | ERR_FATAL;
2223 goto out;
2224 }
2225 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002226 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002227 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002228 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2229 err_code |= ERR_ALERT | ERR_FATAL;
2230 goto out;
2231 }
2232
2233 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2234 err_code |= ERR_WARN;
2235
2236 if (strcmp(args[1], "fail") == 0) {
2237 /* add a condition to fail monitor requests */
2238 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2239 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2240 file, linenum, args[0], args[1]);
2241 err_code |= ERR_ALERT | ERR_FATAL;
2242 goto out;
2243 }
2244
2245 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2246 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2247 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2248 file, linenum, args[0], args[1], errmsg);
2249 err_code |= ERR_ALERT | ERR_FATAL;
2250 goto out;
2251 }
2252 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2253 }
2254 else {
2255 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2256 err_code |= ERR_ALERT | ERR_FATAL;
2257 goto out;
2258 }
2259 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002260#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002261 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002262 /* enable transparent proxy connections */
2263 curproxy->options |= PR_O_TRANSP;
2264 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2265 goto out;
2266 }
2267#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002268 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002269 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2270 err_code |= ERR_WARN;
2271
2272 if (*(args[1]) == 0) {
2273 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2274 err_code |= ERR_ALERT | ERR_FATAL;
2275 goto out;
2276 }
2277 curproxy->maxconn = atol(args[1]);
2278 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2279 goto out;
2280 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002281 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002282 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2283 err_code |= ERR_WARN;
2284
2285 if (*(args[1]) == 0) {
2286 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2287 err_code |= ERR_ALERT | ERR_FATAL;
2288 goto out;
2289 }
2290 curproxy->backlog = atol(args[1]);
2291 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2292 goto out;
2293 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002294 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002295 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2296 err_code |= ERR_WARN;
2297
2298 if (*(args[1]) == 0) {
2299 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2300 err_code |= ERR_ALERT | ERR_FATAL;
2301 goto out;
2302 }
2303 curproxy->fullconn = atol(args[1]);
2304 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2305 goto out;
2306 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002307 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002308 if (*(args[1]) == 0) {
2309 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2310 err_code |= ERR_ALERT | ERR_FATAL;
2311 goto out;
2312 }
2313 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002314 if (err == PARSE_TIME_OVER) {
2315 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2316 file, linenum, args[1]);
2317 err_code |= ERR_ALERT | ERR_FATAL;
2318 goto out;
2319 }
2320 else if (err == PARSE_TIME_UNDER) {
2321 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2322 file, linenum, args[1]);
2323 err_code |= ERR_ALERT | ERR_FATAL;
2324 goto out;
2325 }
2326 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002327 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2328 file, linenum, *err);
2329 err_code |= ERR_ALERT | ERR_FATAL;
2330 goto out;
2331 }
2332 curproxy->grace = val;
2333 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2334 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002335
2336 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2337 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002338 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002339 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002340 struct sockaddr_storage *sk;
2341 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002342
Willy Tarreau5d095c22021-02-12 10:15:59 +01002343 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002344 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2345 err_code |= ERR_ALERT | ERR_FATAL;
2346 goto out;
2347 }
2348 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2349 err_code |= ERR_WARN;
2350
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002351 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2352 &errmsg, NULL, NULL,
2353 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 +01002354 if (!sk) {
2355 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2356 err_code |= ERR_ALERT | ERR_FATAL;
2357 goto out;
2358 }
2359
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002360 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2361 goto out;
2362
2363 curproxy->dispatch_addr = *sk;
2364 curproxy->options |= PR_O_DISPATCH;
2365 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002366 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002367 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2368 err_code |= ERR_WARN;
2369
2370 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2371 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2372 err_code |= ERR_ALERT | ERR_FATAL;
2373 goto out;
2374 }
2375 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002376 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002377 /**
2378 * The syntax for hash-type config element is
2379 * hash-type {map-based|consistent} [[<algo>] avalanche]
2380 *
2381 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2382 */
2383 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2384
2385 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2386 err_code |= ERR_WARN;
2387
2388 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2389 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2390 }
2391 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2392 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2393 }
2394 else if (strcmp(args[1], "avalanche") == 0) {
2395 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]);
2396 err_code |= ERR_ALERT | ERR_FATAL;
2397 goto out;
2398 }
2399 else {
2400 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2401 err_code |= ERR_ALERT | ERR_FATAL;
2402 goto out;
2403 }
2404
2405 /* set the hash function to use */
2406 if (!*args[2]) {
2407 /* the default algo is sdbm */
2408 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2409
2410 /* if consistent with no argument, then avalanche modifier is also applied */
2411 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2412 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2413 } else {
2414 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002415 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002416 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2417 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002418 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002419 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2420 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002421 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002422 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2423 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002424 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002425 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2426 }
2427 else {
2428 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2429 err_code |= ERR_ALERT | ERR_FATAL;
2430 goto out;
2431 }
2432
2433 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002434 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002435 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2436 }
2437 else if (*args[3]) {
2438 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2439 err_code |= ERR_ALERT | ERR_FATAL;
2440 goto out;
2441 }
2442 }
2443 }
2444 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2445 if (*(args[1]) == 0) {
2446 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2447 err_code |= ERR_ALERT | ERR_FATAL;
2448 goto out;
2449 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002450 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2451 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002452 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2453 err_code |= ERR_ALERT | ERR_FATAL;
2454 goto out;
2455 }
2456 }
2457 else if (strcmp(args[0], "unique-id-format") == 0) {
2458 if (!*(args[1])) {
2459 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2460 err_code |= ERR_ALERT | ERR_FATAL;
2461 goto out;
2462 }
2463 if (*(args[2])) {
2464 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2465 err_code |= ERR_ALERT | ERR_FATAL;
2466 goto out;
2467 }
2468 free(curproxy->conf.uniqueid_format_string);
2469 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2470
2471 free(curproxy->conf.uif_file);
2472 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2473 curproxy->conf.uif_line = curproxy->conf.args.line;
2474 }
2475
2476 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002477 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002478 if (!*(args[1])) {
2479 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2480 err_code |= ERR_ALERT | ERR_FATAL;
2481 goto out;
2482 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002483 copy = strdup(args[1]);
2484 if (copy == NULL) {
2485 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2486 err_code |= ERR_ALERT | ERR_FATAL;
2487 goto out;
2488 }
2489
2490 istfree(&curproxy->header_unique_id);
2491 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002492 }
2493
2494 else if (strcmp(args[0], "log-format") == 0) {
2495 if (!*(args[1])) {
2496 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2497 err_code |= ERR_ALERT | ERR_FATAL;
2498 goto out;
2499 }
2500 if (*(args[2])) {
2501 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2502 err_code |= ERR_ALERT | ERR_FATAL;
2503 goto out;
2504 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002505 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002506 char *oldlogformat = "log-format";
2507
2508 if (curproxy->conf.logformat_string == default_http_log_format)
2509 oldlogformat = "option httplog";
2510 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2511 oldlogformat = "option tcplog";
2512 else if (curproxy->conf.logformat_string == clf_http_log_format)
2513 oldlogformat = "option httplog clf";
2514 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2515 file, linenum, oldlogformat);
2516 }
2517 if (curproxy->conf.logformat_string != default_http_log_format &&
2518 curproxy->conf.logformat_string != default_tcp_log_format &&
2519 curproxy->conf.logformat_string != clf_http_log_format)
2520 free(curproxy->conf.logformat_string);
2521 curproxy->conf.logformat_string = strdup(args[1]);
2522
2523 free(curproxy->conf.lfs_file);
2524 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2525 curproxy->conf.lfs_line = curproxy->conf.args.line;
2526
2527 /* get a chance to improve log-format error reporting by
2528 * reporting the correct line-number when possible.
2529 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002530 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002531 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2532 file, linenum, curproxy->id);
2533 err_code |= ERR_WARN;
2534 }
2535 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002536 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002537 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
2548 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2549 free(curproxy->conf.logformat_sd_string);
2550 curproxy->conf.logformat_sd_string = strdup(args[1]);
2551
2552 free(curproxy->conf.lfsd_file);
2553 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2554 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2555
2556 /* get a chance to improve log-format-sd error reporting by
2557 * reporting the correct line-number when possible.
2558 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002559 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002560 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2561 file, linenum, curproxy->id);
2562 err_code |= ERR_WARN;
2563 }
2564 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002565 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002566 if (*(args[1]) == 0) {
2567 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2568 err_code |= ERR_ALERT | ERR_FATAL;
2569 goto out;
2570 }
2571 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002572 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2573 if (b_orig(&curproxy->log_tag) == NULL) {
2574 chunk_destroy(&curproxy->log_tag);
2575 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2576 err_code |= ERR_ALERT | ERR_FATAL;
2577 goto out;
2578 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002579 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002580 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002581 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2582 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2583 err_code |= ERR_ALERT | ERR_FATAL;
2584 goto out;
2585 }
2586 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002587 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002588 int cur_arg;
2589 int port1, port2;
2590 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002591
2592 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2593 err_code |= ERR_WARN;
2594
2595 if (!*args[1]) {
2596 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2597 file, linenum, "source", "usesrc", "interface");
2598 err_code |= ERR_ALERT | ERR_FATAL;
2599 goto out;
2600 }
2601
Christopher Faulet31930372019-07-15 10:16:58 +02002602 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002603 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2604 free(curproxy->conn_src.iface_name);
2605 curproxy->conn_src.iface_name = NULL;
2606 curproxy->conn_src.iface_len = 0;
2607
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002608 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2609 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002610 if (!sk) {
2611 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2612 file, linenum, args[0], args[1], errmsg);
2613 err_code |= ERR_ALERT | ERR_FATAL;
2614 goto out;
2615 }
2616
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002617 curproxy->conn_src.source_addr = *sk;
2618 curproxy->conn_src.opts |= CO_SRC_BIND;
2619
2620 cur_arg = 2;
2621 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002622 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002623#if defined(CONFIG_HAP_TRANSPARENT)
2624 if (!*args[cur_arg + 1]) {
2625 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2626 file, linenum, "usesrc");
2627 err_code |= ERR_ALERT | ERR_FATAL;
2628 goto out;
2629 }
2630
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002631 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002632 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2633 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002634 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002635 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2636 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2637 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2638 char *name, *end;
2639
2640 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002641 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002642 name++;
2643
2644 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002645 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002646 end++;
2647
2648 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2649 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002650 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002651 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2652 curproxy->conn_src.bind_hdr_len = end - name;
2653 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2654 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2655 curproxy->conn_src.bind_hdr_occ = -1;
2656
2657 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002658 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002659 end++;
2660 if (*end == ',') {
2661 end++;
2662 name = end;
2663 if (*end == '-')
2664 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002665 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002666 end++;
2667 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2668 }
2669
2670 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2671 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2672 " occurrences values smaller than %d.\n",
2673 file, linenum, MAX_HDR_HISTORY);
2674 err_code |= ERR_ALERT | ERR_FATAL;
2675 goto out;
2676 }
2677 } else {
2678 struct sockaddr_storage *sk;
2679
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002680 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2681 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002682 if (!sk) {
2683 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2684 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2685 err_code |= ERR_ALERT | ERR_FATAL;
2686 goto out;
2687 }
2688
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002689 curproxy->conn_src.tproxy_addr = *sk;
2690 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2691 }
2692 global.last_checks |= LSTCHK_NETADM;
2693#else /* no TPROXY support */
2694 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2695 file, linenum, "usesrc");
2696 err_code |= ERR_ALERT | ERR_FATAL;
2697 goto out;
2698#endif
2699 cur_arg += 2;
2700 continue;
2701 }
2702
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002703 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002704#ifdef SO_BINDTODEVICE
2705 if (!*args[cur_arg + 1]) {
2706 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2707 file, linenum, args[0]);
2708 err_code |= ERR_ALERT | ERR_FATAL;
2709 goto out;
2710 }
2711 free(curproxy->conn_src.iface_name);
2712 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2713 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2714 global.last_checks |= LSTCHK_NETADM;
2715#else
2716 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2717 file, linenum, args[0], args[cur_arg]);
2718 err_code |= ERR_ALERT | ERR_FATAL;
2719 goto out;
2720#endif
2721 cur_arg += 2;
2722 continue;
2723 }
2724 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2725 file, linenum, args[0], "interface", "usesrc");
2726 err_code |= ERR_ALERT | ERR_FATAL;
2727 goto out;
2728 }
2729 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002730 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002731 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2732 file, linenum, "usesrc", "source");
2733 err_code |= ERR_ALERT | ERR_FATAL;
2734 goto out;
2735 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002736 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 +02002737 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002738 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002739 file, linenum, args[0]);
2740 err_code |= ERR_ALERT | ERR_FATAL;
2741 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002742 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002743 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002744 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2745 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2746 err_code |= ERR_ALERT | ERR_FATAL;
2747 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002748 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002749 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002750 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2751 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2752 err_code |= ERR_ALERT | ERR_FATAL;
2753 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002754 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002755 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002756 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2757 err_code |= ERR_ALERT | ERR_FATAL;
2758 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002759 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002760 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002761 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2762 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2763 err_code |= ERR_ALERT | ERR_FATAL;
2764 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002765 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002766 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002767 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2768 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2769 err_code |= ERR_ALERT | ERR_FATAL;
2770 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002771 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002772 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002773 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2774 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2775 err_code |= ERR_ALERT | ERR_FATAL;
2776 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002777 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002778 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002779 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2780 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2781 err_code |= ERR_ALERT | ERR_FATAL;
2782 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002783 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002784 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 +02002785 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2786 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2787 err_code |= ERR_ALERT | ERR_FATAL;
2788 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002789 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002790 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002791 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2792 err_code |= ERR_ALERT | ERR_FATAL;
2793 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002794 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002795 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 +02002796 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2797 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2798 err_code |= ERR_ALERT | ERR_FATAL;
2799 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002800 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002801 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 +02002802 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2803 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2804 err_code |= ERR_ALERT | ERR_FATAL;
2805 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002806 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002807 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002808 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2809 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2810 err_code |= ERR_ALERT | ERR_FATAL;
2811 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002812 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002813 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 +02002814 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2815 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2816 err_code |= ERR_ALERT | ERR_FATAL;
2817 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002818 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002819 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002820 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2821 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2822 err_code |= ERR_ALERT | ERR_FATAL;
2823 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002824 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002825 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002826 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2827 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2828 err_code |= ERR_ALERT | ERR_FATAL;
2829 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002830 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002831 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302832 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002833 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2834 err_code |= ERR_ALERT | ERR_FATAL;
2835 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002836 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002837 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002838 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2839 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2840 err_code |= ERR_ALERT | ERR_FATAL;
2841 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002842 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002843 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002844 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2845 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2846 err_code |= ERR_ALERT | ERR_FATAL;
2847 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002848 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002849 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002850 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2851 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2852 err_code |= ERR_ALERT | ERR_FATAL;
2853 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002854 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002855 else {
2856 struct cfg_kw_list *kwl;
2857 int index;
2858
2859 list_for_each_entry(kwl, &cfg_keywords.list, list) {
2860 for (index = 0; kwl->kw[index].kw != NULL; index++) {
2861 if (kwl->kw[index].section != CFG_LISTEN)
2862 continue;
2863 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
2864 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01002865 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002866 if (rc < 0) {
2867 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2868 err_code |= ERR_ALERT | ERR_FATAL;
2869 goto out;
2870 }
2871 else if (rc > 0) {
2872 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
2873 err_code |= ERR_WARN;
2874 goto out;
2875 }
2876 goto out;
2877 }
2878 }
2879 }
2880
2881 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
2882 err_code |= ERR_ALERT | ERR_FATAL;
2883 goto out;
2884 }
2885 out:
2886 free(errmsg);
2887 return err_code;
2888}