blob: 1111b743f46fb5c479393babc382d953619bf9dc [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
14#include <common/cfgparse.h>
15#include <common/uri_auth.h>
16
17#include <types/capture.h>
18#include <types/compression.h>
Willy Tarreau708c4162019-10-09 10:19:16 +020019#include <types/stats.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010020
21#include <proto/acl.h>
22#include <proto/checks.h>
23#include <proto/connection.h>
Christopher Fauletf7346382019-07-17 22:02:08 +020024#include <proto/http_htx.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010025#include <proto/http_rules.h>
26#include <proto/listener.h>
27#include <proto/protocol.h>
28#include <proto/proxy.h>
29#include <proto/server.h>
Frédéric Lécailled456aa42019-03-08 14:47:00 +010030#include <proto/stick_table.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010031
32/* Report a warning if a rule is placed after a 'tcp-request session' rule.
33 * Return 1 if the warning has been emitted, otherwise 0.
34 */
35int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
36{
37 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
38 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
39 file, line, arg);
40 return 1;
41 }
42 return 0;
43}
44
45/* Report a warning if a rule is placed after a 'tcp-request content' rule.
46 * Return 1 if the warning has been emitted, otherwise 0.
47 */
48int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
49{
50 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
51 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
52 file, line, arg);
53 return 1;
54 }
55 return 0;
56}
57
58/* Report a warning if a rule is placed after a 'monitor fail' rule.
59 * Return 1 if the warning has been emitted, otherwise 0.
60 */
61int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
62{
63 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
64 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
65 file, line, arg);
66 return 1;
67 }
68 return 0;
69}
70
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010071/* Report a warning if a rule is placed after an 'http_request' rule.
72 * Return 1 if the warning has been emitted, otherwise 0.
73 */
74int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
75{
76 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
77 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
78 file, line, arg);
79 return 1;
80 }
81 return 0;
82}
83
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010084/* Report a warning if a rule is placed after a redirect rule.
85 * Return 1 if the warning has been emitted, otherwise 0.
86 */
87int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
88{
89 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
90 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
91 file, line, arg);
92 return 1;
93 }
94 return 0;
95}
96
97/* Report a warning if a rule is placed after a 'use_backend' rule.
98 * Return 1 if the warning has been emitted, otherwise 0.
99 */
100int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
101{
102 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
103 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
104 file, line, arg);
105 return 1;
106 }
107 return 0;
108}
109
110/* Report a warning if a rule is placed after a 'use-server' rule.
111 * Return 1 if the warning has been emitted, otherwise 0.
112 */
113int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
114{
115 if (!LIST_ISEMPTY(&proxy->server_rules)) {
116 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
117 file, line, arg);
118 return 1;
119 }
120 return 0;
121}
122
123/* report a warning if a redirect rule is dangerously placed */
124int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
125{
126 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
127 warnif_rule_after_use_server(proxy, file, line, arg);
128}
129
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100130/* report a warning if an http-request rule is dangerously placed */
131int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
132{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200133 return warnif_rule_after_redirect(proxy, file, line, arg) ||
134 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100135}
136
137/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200138int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100139{
140 return warnif_rule_after_http_req(proxy, file, line, arg) ||
141 warnif_misplaced_http_req(proxy, file, line, arg);
142}
143
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100144/* report a warning if a "tcp request content" rule is dangerously placed */
145int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
146{
147 return warnif_rule_after_monitor(proxy, file, line, arg) ||
148 warnif_misplaced_monitor(proxy, file, line, arg);
149}
150
151/* report a warning if a "tcp request session" rule is dangerously placed */
152int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
153{
154 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
155 warnif_misplaced_tcp_cont(proxy, file, line, arg);
156}
157
158/* report a warning if a "tcp request connection" rule is dangerously placed */
159int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
160{
161 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
162 warnif_misplaced_tcp_sess(proxy, file, line, arg);
163}
164
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100165int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
166{
167 static struct proxy *curproxy = NULL;
168 const char *err;
169 char *error;
170 int rc;
171 unsigned val;
172 int err_code = 0;
173 struct acl_cond *cond = NULL;
174 struct logsrv *tmplogsrv;
175 char *errmsg = NULL;
176 struct bind_conf *bind_conf;
177
178 if (!strcmp(args[0], "listen"))
179 rc = PR_CAP_LISTEN;
180 else if (!strcmp(args[0], "frontend"))
181 rc = PR_CAP_FE;
182 else if (!strcmp(args[0], "backend"))
183 rc = PR_CAP_BE;
184 else
185 rc = PR_CAP_NONE;
186
187 if (rc != PR_CAP_NONE) { /* new proxy */
188 if (!*args[1]) {
189 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
190 " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
191 file, linenum, args[0]);
192 err_code |= ERR_ALERT | ERR_ABORT;
193 goto out;
194 }
195
196 err = invalid_char(args[1]);
197 if (err) {
198 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
199 file, linenum, *err, args[0], args[1]);
200 err_code |= ERR_ALERT | ERR_FATAL;
201 }
202
203 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
204 if (curproxy) {
205 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
206 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
207 curproxy->id, curproxy->conf.file, curproxy->conf.line);
208 err_code |= ERR_ALERT | ERR_FATAL;
209 }
210
211 if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
212 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
213 err_code |= ERR_ALERT | ERR_ABORT;
214 goto out;
215 }
216
217 init_new_proxy(curproxy);
218 curproxy->next = proxies_list;
219 proxies_list = curproxy;
220 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
221 curproxy->conf.args.line = curproxy->conf.line = linenum;
222 curproxy->last_change = now.tv_sec;
223 curproxy->id = strdup(args[1]);
224 curproxy->cap = rc;
225 proxy_store_name(curproxy);
226
227 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
228 if (curproxy->cap & PR_CAP_FE)
229 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
230 goto out;
231 }
232
233 /* set default values */
234 memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv));
235 curproxy->defsrv.id = "default-server";
236
237 curproxy->state = defproxy.state;
238 curproxy->options = defproxy.options;
239 curproxy->options2 = defproxy.options2;
240 curproxy->no_options = defproxy.no_options;
241 curproxy->no_options2 = defproxy.no_options2;
242 curproxy->bind_proc = defproxy.bind_proc;
243 curproxy->except_net = defproxy.except_net;
244 curproxy->except_mask = defproxy.except_mask;
245 curproxy->except_to = defproxy.except_to;
246 curproxy->except_mask_to = defproxy.except_mask_to;
Olivier Houcharda254a372019-04-05 15:30:12 +0200247 curproxy->retry_type = defproxy.retry_type;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100248
249 if (defproxy.fwdfor_hdr_len) {
250 curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len;
251 curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name);
252 }
253
254 if (defproxy.orgto_hdr_len) {
255 curproxy->orgto_hdr_len = defproxy.orgto_hdr_len;
256 curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name);
257 }
258
259 if (defproxy.server_id_hdr_len) {
260 curproxy->server_id_hdr_len = defproxy.server_id_hdr_len;
261 curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name);
262 }
263
264 /* initialize error relocations */
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100265 if (!proxy_dup_default_conf_errors(curproxy, &defproxy, &errmsg)) {
266 ha_alert("parsing [%s:%d] : proxy '%s' : %s\n", file, linenum, curproxy->id, errmsg);
267 err_code |= ERR_ALERT | ERR_FATAL;
268 goto out;
269 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100270
271 if (curproxy->cap & PR_CAP_FE) {
272 curproxy->maxconn = defproxy.maxconn;
273 curproxy->backlog = defproxy.backlog;
274 curproxy->fe_sps_lim = defproxy.fe_sps_lim;
275
276 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100277 curproxy->max_out_conns = defproxy.max_out_conns;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100278 }
279
280 if (curproxy->cap & PR_CAP_BE) {
281 curproxy->lbprm.algo = defproxy.lbprm.algo;
Willy Tarreau76e84f52019-01-14 16:50:58 +0100282 curproxy->lbprm.hash_balance_factor = defproxy.lbprm.hash_balance_factor;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100283 curproxy->fullconn = defproxy.fullconn;
284 curproxy->conn_retries = defproxy.conn_retries;
285 curproxy->redispatch_after = defproxy.redispatch_after;
286 curproxy->max_ka_queue = defproxy.max_ka_queue;
287
288 if (defproxy.check_req) {
289 curproxy->check_req = calloc(1, defproxy.check_len);
290 memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len);
291 }
292 curproxy->check_len = defproxy.check_len;
293
Christopher Faulet8acb1282020-04-09 08:44:06 +0200294 if (defproxy.check_hdrs) {
295 curproxy->check_hdrs = calloc(1, defproxy.check_hdrs_len);
296 memcpy(curproxy->check_hdrs, defproxy.check_hdrs, defproxy.check_hdrs_len);
297 }
298 curproxy->check_hdrs_len = defproxy.check_hdrs_len;
299
300 if (defproxy.check_body) {
301 curproxy->check_body = calloc(1, defproxy.check_body_len);
302 memcpy(curproxy->check_body, defproxy.check_body, defproxy.check_body_len);
303 }
304 curproxy->check_body_len = defproxy.check_body_len;
305
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200306 curproxy->tcpcheck_rules.flags = (defproxy.tcpcheck_rules.flags | TCPCHK_RULES_DEF);
307 curproxy->tcpcheck_rules.list = defproxy.tcpcheck_rules.list;
Christopher Faulet7a1e2e12020-04-02 18:05:11 +0200308 if (!LIST_ISEMPTY(&defproxy.tcpcheck_rules.preset_vars)) {
309 if (!dup_tcpcheck_vars(&curproxy->tcpcheck_rules.preset_vars,
310 &defproxy.tcpcheck_rules.preset_vars)) {
311 ha_alert("parsing [%s:%d] : failed to duplicate tcpcheck preset-vars\n",
312 file, linenum);
313 err_code |= ERR_ALERT | ERR_FATAL;
314 goto out;
315 }
316 }
Gaetan Rivet04578db2020-02-07 15:37:17 +0100317
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100318 if (defproxy.expect_str) {
319 curproxy->expect_str = strdup(defproxy.expect_str);
320 if (defproxy.expect_regex) {
321 /* note: this regex is known to be valid */
Dragan Dosen26743032019-04-30 15:54:36 +0200322 error = NULL;
323 if (!(curproxy->expect_regex = regex_comp(defproxy.expect_str, 1, 1, &error))) {
324 ha_alert("parsing [%s:%d] : regular expression '%s' : %s\n", file, linenum,
325 defproxy.expect_str, error);
326 free(error);
327 err_code |= ERR_ALERT | ERR_FATAL;
328 goto out;
329 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100330 }
331 }
332
333 curproxy->ck_opts = defproxy.ck_opts;
334 if (defproxy.cookie_name)
335 curproxy->cookie_name = strdup(defproxy.cookie_name);
336 curproxy->cookie_len = defproxy.cookie_len;
337
338 if (defproxy.dyncookie_key)
339 curproxy->dyncookie_key = strdup(defproxy.dyncookie_key);
340 if (defproxy.cookie_domain)
341 curproxy->cookie_domain = strdup(defproxy.cookie_domain);
342
343 if (defproxy.cookie_maxidle)
344 curproxy->cookie_maxidle = defproxy.cookie_maxidle;
345
346 if (defproxy.cookie_maxlife)
347 curproxy->cookie_maxlife = defproxy.cookie_maxlife;
348
349 if (defproxy.rdp_cookie_name)
350 curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name);
351 curproxy->rdp_cookie_len = defproxy.rdp_cookie_len;
352
Christopher Faulet2f533902020-01-21 11:06:48 +0100353 if (defproxy.cookie_attrs)
354 curproxy->cookie_attrs = strdup(defproxy.cookie_attrs);
Willy Tarreau20e68372019-01-14 16:04:01 +0100355
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100356 if (defproxy.lbprm.arg_str)
357 curproxy->lbprm.arg_str = strdup(defproxy.lbprm.arg_str);
358 curproxy->lbprm.arg_len = defproxy.lbprm.arg_len;
Willy Tarreau20e68372019-01-14 16:04:01 +0100359 curproxy->lbprm.arg_opt1 = defproxy.lbprm.arg_opt1;
360 curproxy->lbprm.arg_opt2 = defproxy.lbprm.arg_opt2;
361 curproxy->lbprm.arg_opt3 = defproxy.lbprm.arg_opt3;
362
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100363 if (defproxy.conn_src.iface_name)
364 curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name);
365 curproxy->conn_src.iface_len = defproxy.conn_src.iface_len;
366 curproxy->conn_src.opts = defproxy.conn_src.opts;
367#if defined(CONFIG_HAP_TRANSPARENT)
368 curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr;
369#endif
370 curproxy->load_server_state_from_file = defproxy.load_server_state_from_file;
371 }
372
373 if (curproxy->cap & PR_CAP_FE) {
374 if (defproxy.capture_name)
375 curproxy->capture_name = strdup(defproxy.capture_name);
376 curproxy->capture_namelen = defproxy.capture_namelen;
377 curproxy->capture_len = defproxy.capture_len;
378 }
379
380 if (curproxy->cap & PR_CAP_FE) {
381 curproxy->timeout.client = defproxy.timeout.client;
382 curproxy->timeout.clientfin = defproxy.timeout.clientfin;
383 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
384 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
385 curproxy->timeout.httpka = defproxy.timeout.httpka;
386 curproxy->mon_net = defproxy.mon_net;
387 curproxy->mon_mask = defproxy.mon_mask;
388 if (defproxy.monitor_uri)
389 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
390 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
391 if (defproxy.defbe.name)
392 curproxy->defbe.name = strdup(defproxy.defbe.name);
393
394 /* get either a pointer to the logformat string or a copy of it */
395 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
396 if (curproxy->conf.logformat_string &&
397 curproxy->conf.logformat_string != default_http_log_format &&
398 curproxy->conf.logformat_string != default_tcp_log_format &&
399 curproxy->conf.logformat_string != clf_http_log_format)
400 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
401
402 if (defproxy.conf.lfs_file) {
403 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
404 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
405 }
406
407 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
408 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
409 if (curproxy->conf.logformat_sd_string &&
410 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
411 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
412
413 if (defproxy.conf.lfsd_file) {
414 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
415 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
416 }
417 }
418
419 if (curproxy->cap & PR_CAP_BE) {
420 curproxy->timeout.connect = defproxy.timeout.connect;
421 curproxy->timeout.server = defproxy.timeout.server;
422 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
423 curproxy->timeout.check = defproxy.timeout.check;
424 curproxy->timeout.queue = defproxy.timeout.queue;
425 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
426 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
427 curproxy->timeout.httpka = defproxy.timeout.httpka;
428 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
429 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
430 }
431
432 curproxy->mode = defproxy.mode;
433 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
434
435 /* copy default logsrvs to curproxy */
436 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
437 struct logsrv *node = malloc(sizeof(*node));
438 memcpy(node, tmplogsrv, sizeof(struct logsrv));
439 node->ref = tmplogsrv->ref;
440 LIST_INIT(&node->list);
441 LIST_ADDQ(&curproxy->logsrvs, &node->list);
442 }
443
444 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
445 if (curproxy->conf.uniqueid_format_string)
446 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
447
448 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
449
450 if (defproxy.conf.uif_file) {
451 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
452 curproxy->conf.uif_line = defproxy.conf.uif_line;
453 }
454
455 /* copy default header unique id */
Tim Duesterhus0643b0e2020-03-05 17:56:35 +0100456 if (isttest(defproxy.header_unique_id)) {
457 const struct ist copy = istdup(defproxy.header_unique_id);
458 if (!isttest(copy)) {
459 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
460 err_code |= ERR_ALERT | ERR_FATAL;
461 goto out;
462 }
463 curproxy->header_unique_id = copy;
464 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100465
466 /* default compression options */
467 if (defproxy.comp != NULL) {
468 curproxy->comp = calloc(1, sizeof(struct comp));
469 curproxy->comp->algos = defproxy.comp->algos;
470 curproxy->comp->types = defproxy.comp->types;
471 }
472
473 curproxy->grace = defproxy.grace;
474 curproxy->conf.used_listener_id = EB_ROOT;
475 curproxy->conf.used_server_id = EB_ROOT;
476
477 if (defproxy.check_path)
478 curproxy->check_path = strdup(defproxy.check_path);
479 if (defproxy.check_command)
480 curproxy->check_command = strdup(defproxy.check_command);
481
482 if (defproxy.email_alert.mailers.name)
483 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
484 if (defproxy.email_alert.from)
485 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
486 if (defproxy.email_alert.to)
487 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
488 if (defproxy.email_alert.myhostname)
489 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
490 curproxy->email_alert.level = defproxy.email_alert.level;
491 curproxy->email_alert.set = defproxy.email_alert.set;
492
493 goto out;
494 }
495 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
496 /* some variables may have already been initialized earlier */
497 /* FIXME-20070101: we should do this too at the end of the
498 * config parsing to free all default values.
499 */
500 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
501 err_code |= ERR_ABORT;
502 goto out;
503 }
504
505 free(defproxy.check_req);
506 free(defproxy.check_command);
507 free(defproxy.check_path);
508 free(defproxy.cookie_name);
509 free(defproxy.rdp_cookie_name);
510 free(defproxy.dyncookie_key);
511 free(defproxy.cookie_domain);
Christopher Faulet2f533902020-01-21 11:06:48 +0100512 free(defproxy.cookie_attrs);
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100513 free(defproxy.lbprm.arg_str);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100514 free(defproxy.capture_name);
515 free(defproxy.monitor_uri);
516 free(defproxy.defbe.name);
517 free(defproxy.conn_src.iface_name);
518 free(defproxy.fwdfor_hdr_name);
519 defproxy.fwdfor_hdr_len = 0;
520 free(defproxy.orgto_hdr_name);
521 defproxy.orgto_hdr_len = 0;
522 free(defproxy.server_id_hdr_name);
523 defproxy.server_id_hdr_len = 0;
524 free(defproxy.expect_str);
Dragan Dosen26743032019-04-30 15:54:36 +0200525 regex_free(defproxy.expect_regex);
526 defproxy.expect_regex = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100527
528 if (defproxy.conf.logformat_string != default_http_log_format &&
529 defproxy.conf.logformat_string != default_tcp_log_format &&
530 defproxy.conf.logformat_string != clf_http_log_format)
531 free(defproxy.conf.logformat_string);
532
533 free(defproxy.conf.uniqueid_format_string);
534 free(defproxy.conf.lfs_file);
535 free(defproxy.conf.uif_file);
536 chunk_destroy(&defproxy.log_tag);
537 free_email_alert(&defproxy);
538
539 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
540 free(defproxy.conf.logformat_sd_string);
541 free(defproxy.conf.lfsd_file);
542
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100543 proxy_release_conf_errors(&defproxy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100544
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200545 deinit_proxy_tcpcheck(&defproxy);
546
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100547 /* we cannot free uri_auth because it might already be used */
548 init_default_instance();
549 curproxy = &defproxy;
550 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
551 curproxy->conf.args.line = curproxy->conf.line = linenum;
552 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
553 goto out;
554 }
555 else if (curproxy == NULL) {
556 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
557 err_code |= ERR_ALERT | ERR_FATAL;
558 goto out;
559 }
560
561 /* update the current file and line being parsed */
562 curproxy->conf.args.file = curproxy->conf.file;
563 curproxy->conf.args.line = linenum;
564
565 /* Now let's parse the proxy-specific keywords */
566 if (!strcmp(args[0], "server") ||
567 !strcmp(args[0], "default-server") ||
568 !strcmp(args[0], "server-template")) {
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200569 err_code |= parse_server(file, linenum, args, curproxy, &defproxy, 1, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100570 if (err_code & ERR_FATAL)
571 goto out;
572 }
573 else if (!strcmp(args[0], "bind")) { /* new listen addresses */
574 struct listener *l;
575 int cur_arg;
576
577 if (curproxy == &defproxy) {
578 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
579 err_code |= ERR_ALERT | ERR_FATAL;
580 goto out;
581 }
582 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
583 err_code |= ERR_WARN;
584
585 if (!*(args[1])) {
586 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
587 file, linenum, args[0]);
588 err_code |= ERR_ALERT | ERR_FATAL;
589 goto out;
590 }
591
592 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
593
594 /* use default settings for unix sockets */
595 bind_conf->ux.uid = global.unix_bind.ux.uid;
596 bind_conf->ux.gid = global.unix_bind.ux.gid;
597 bind_conf->ux.mode = global.unix_bind.ux.mode;
598
599 /* NOTE: the following line might create several listeners if there
600 * are comma-separated IPs or port ranges. So all further processing
601 * will have to be applied to all listeners created after last_listen.
602 */
603 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
604 if (errmsg && *errmsg) {
605 indent_msg(&errmsg, 2);
606 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
607 }
608 else
609 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
610 file, linenum, args[0], args[1]);
611 err_code |= ERR_ALERT | ERR_FATAL;
612 goto out;
613 }
614
615 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
616 /* Set default global rights and owner for unix bind */
617 global.maxsock++;
618 }
619
620 cur_arg = 2;
621 while (*(args[cur_arg])) {
622 static int bind_dumped;
623 struct bind_kw *kw;
624 char *err;
625
626 kw = bind_find_kw(args[cur_arg]);
627 if (kw) {
628 char *err = NULL;
629 int code;
630
631 if (!kw->parse) {
632 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
633 file, linenum, args[0], args[1], args[cur_arg]);
634 cur_arg += 1 + kw->skip ;
635 err_code |= ERR_ALERT | ERR_FATAL;
636 goto out;
637 }
638
639 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
640 err_code |= code;
641
642 if (code) {
643 if (err && *err) {
644 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200645 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
646 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
647 else
648 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100649 }
650 else
651 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
652 file, linenum, args[0], args[1], args[cur_arg]);
653 if (code & ERR_FATAL) {
654 free(err);
655 cur_arg += 1 + kw->skip;
656 goto out;
657 }
658 }
659 free(err);
660 cur_arg += 1 + kw->skip;
661 continue;
662 }
663
664 err = NULL;
665 if (!bind_dumped) {
666 bind_dump_kws(&err);
667 indent_msg(&err, 4);
668 bind_dumped = 1;
669 }
670
671 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
672 file, linenum, args[0], args[1], args[cur_arg],
673 err ? " Registered keywords :" : "", err ? err : "");
674 free(err);
675
676 err_code |= ERR_ALERT | ERR_FATAL;
677 goto out;
678 }
679 goto out;
680 }
681 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
682 if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) {
683 ha_alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
684 file, linenum, args[0]);
685 err_code |= ERR_ALERT | ERR_FATAL;
686 goto out;
687 }
688 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
689 err_code |= ERR_WARN;
690
691 /* flush useless bits */
692 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
693 goto out;
694 }
695 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
696 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
697 err_code |= ERR_WARN;
698
699 if (alertif_too_many_args(1, file, linenum, args, &err_code))
700 goto out;
701
702 if (!*args[1]) {
703 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
704 file, linenum, args[0]);
705 err_code |= ERR_ALERT | ERR_FATAL;
706 goto out;
707 }
708
709 free(curproxy->monitor_uri);
710 curproxy->monitor_uri_len = strlen(args[1]);
711 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
712 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
713 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
714
715 goto out;
716 }
717 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
718 if (alertif_too_many_args(1, file, linenum, args, &err_code))
719 goto out;
720
721 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
722 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
723 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
724 else {
725 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
726 err_code |= ERR_ALERT | ERR_FATAL;
727 goto out;
728 }
729 }
730 else if (!strcmp(args[0], "id")) {
731 struct eb32_node *node;
732
733 if (curproxy == &defproxy) {
734 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
735 file, linenum, args[0]);
736 err_code |= ERR_ALERT | ERR_FATAL;
737 goto out;
738 }
739
740 if (alertif_too_many_args(1, file, linenum, args, &err_code))
741 goto out;
742
743 if (!*args[1]) {
744 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
745 file, linenum, args[0]);
746 err_code |= ERR_ALERT | ERR_FATAL;
747 goto out;
748 }
749
750 curproxy->uuid = atol(args[1]);
751 curproxy->conf.id.key = curproxy->uuid;
752 curproxy->options |= PR_O_FORCED_ID;
753
754 if (curproxy->uuid <= 0) {
755 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
756 file, linenum);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760
761 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
762 if (node) {
763 struct proxy *target = container_of(node, struct proxy, conf.id);
764 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
765 file, linenum, proxy_type_str(curproxy), curproxy->id,
766 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
767 err_code |= ERR_ALERT | ERR_FATAL;
768 goto out;
769 }
770 eb32_insert(&used_proxy_id, &curproxy->conf.id);
771 }
772 else if (!strcmp(args[0], "description")) {
773 int i, len=0;
774 char *d;
775
776 if (curproxy == &defproxy) {
777 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
778 file, linenum, args[0]);
779 err_code |= ERR_ALERT | ERR_FATAL;
780 goto out;
781 }
782
783 if (!*args[1]) {
784 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
785 file, linenum, args[0]);
786 return -1;
787 }
788
789 for (i = 1; *args[i]; i++)
790 len += strlen(args[i]) + 1;
791
792 d = calloc(1, len);
793 curproxy->desc = d;
794
795 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
796 for (i = 2; *args[i]; i++)
797 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
798
799 }
800 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
801 if (alertif_too_many_args(0, file, linenum, args, &err_code))
802 goto out;
803 curproxy->state = PR_STSTOPPED;
804 }
805 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
806 if (alertif_too_many_args(0, file, linenum, args, &err_code))
807 goto out;
808 curproxy->state = PR_STNEW;
809 }
810 else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */
811 int cur_arg = 1;
812 unsigned long set = 0;
813
814 while (*args[cur_arg]) {
815 if (strcmp(args[cur_arg], "all") == 0) {
816 set = 0;
817 break;
818 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100819 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100820 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
821 err_code |= ERR_ALERT | ERR_FATAL;
822 goto out;
823 }
824 cur_arg++;
825 }
826 curproxy->bind_proc = set;
827 }
828 else if (!strcmp(args[0], "acl")) { /* add an ACL */
829 if (curproxy == &defproxy) {
830 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
831 err_code |= ERR_ALERT | ERR_FATAL;
832 goto out;
833 }
834
835 err = invalid_char(args[1]);
836 if (err) {
837 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
838 file, linenum, *err, args[1]);
839 err_code |= ERR_ALERT | ERR_FATAL;
840 goto out;
841 }
842
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100843 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100844 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100845 "logical disjunction within a condition.\n",
846 file, linenum, args[1]);
847 err_code |= ERR_ALERT | ERR_FATAL;
848 goto out;
849 }
850
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100851 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
852 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
853 file, linenum, args[1], errmsg);
854 err_code |= ERR_ALERT | ERR_FATAL;
855 goto out;
856 }
857 }
858 else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */
859
860 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
861 err_code |= ERR_WARN;
862
863 if (*(args[1]) == 0) {
864 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
865 file, linenum, args[0]);
866 err_code |= ERR_ALERT | ERR_FATAL;
867 goto out;
868 }
869 free(curproxy->dyncookie_key);
870 curproxy->dyncookie_key = strdup(args[1]);
871 }
872 else if (!strcmp(args[0], "cookie")) { /* cookie name */
873 int cur_arg;
874
875 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
876 err_code |= ERR_WARN;
877
878 if (*(args[1]) == 0) {
879 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
880 file, linenum, args[0]);
881 err_code |= ERR_ALERT | ERR_FATAL;
882 goto out;
883 }
884
885 curproxy->ck_opts = 0;
886 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
887 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
888 free(curproxy->cookie_name);
889 curproxy->cookie_name = strdup(args[1]);
890 curproxy->cookie_len = strlen(curproxy->cookie_name);
891
892 cur_arg = 2;
893 while (*(args[cur_arg])) {
894 if (!strcmp(args[cur_arg], "rewrite")) {
895 curproxy->ck_opts |= PR_CK_RW;
896 }
897 else if (!strcmp(args[cur_arg], "indirect")) {
898 curproxy->ck_opts |= PR_CK_IND;
899 }
900 else if (!strcmp(args[cur_arg], "insert")) {
901 curproxy->ck_opts |= PR_CK_INS;
902 }
903 else if (!strcmp(args[cur_arg], "nocache")) {
904 curproxy->ck_opts |= PR_CK_NOC;
905 }
906 else if (!strcmp(args[cur_arg], "postonly")) {
907 curproxy->ck_opts |= PR_CK_POST;
908 }
909 else if (!strcmp(args[cur_arg], "preserve")) {
910 curproxy->ck_opts |= PR_CK_PSV;
911 }
912 else if (!strcmp(args[cur_arg], "prefix")) {
913 curproxy->ck_opts |= PR_CK_PFX;
914 }
915 else if (!strcmp(args[cur_arg], "httponly")) {
916 curproxy->ck_opts |= PR_CK_HTTPONLY;
917 }
918 else if (!strcmp(args[cur_arg], "secure")) {
919 curproxy->ck_opts |= PR_CK_SECURE;
920 }
921 else if (!strcmp(args[cur_arg], "domain")) {
922 if (!*args[cur_arg + 1]) {
923 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
924 file, linenum, args[cur_arg]);
925 err_code |= ERR_ALERT | ERR_FATAL;
926 goto out;
927 }
928
Joao Moraise1583752019-10-30 21:04:00 -0300929 if (!strchr(args[cur_arg + 1], '.')) {
930 /* rfc6265, 5.2.3 The Domain Attribute */
931 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
932 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100933 file, linenum, args[cur_arg + 1]);
934 err_code |= ERR_WARN;
935 }
936
937 err = invalid_domainchar(args[cur_arg + 1]);
938 if (err) {
939 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
940 file, linenum, *err, args[cur_arg + 1]);
941 err_code |= ERR_ALERT | ERR_FATAL;
942 goto out;
943 }
944
945 if (!curproxy->cookie_domain) {
946 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
947 } else {
948 /* one domain was already specified, add another one by
949 * building the string which will be returned along with
950 * the cookie.
951 */
952 char *new_ptr;
953 int new_len = strlen(curproxy->cookie_domain) +
954 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
955 new_ptr = malloc(new_len);
956 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
957 free(curproxy->cookie_domain);
958 curproxy->cookie_domain = new_ptr;
959 }
960 cur_arg++;
961 }
962 else if (!strcmp(args[cur_arg], "maxidle")) {
963 unsigned int maxidle;
964 const char *res;
965
966 if (!*args[cur_arg + 1]) {
967 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
968 file, linenum, args[cur_arg]);
969 err_code |= ERR_ALERT | ERR_FATAL;
970 goto out;
971 }
972
973 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200974 if (res == PARSE_TIME_OVER) {
975 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
976 file, linenum, args[cur_arg+1], args[cur_arg]);
977 err_code |= ERR_ALERT | ERR_FATAL;
978 goto out;
979 }
980 else if (res == PARSE_TIME_UNDER) {
981 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
982 file, linenum, args[cur_arg+1], args[cur_arg]);
983 err_code |= ERR_ALERT | ERR_FATAL;
984 goto out;
985 }
986 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100987 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
988 file, linenum, *res, args[cur_arg]);
989 err_code |= ERR_ALERT | ERR_FATAL;
990 goto out;
991 }
992 curproxy->cookie_maxidle = maxidle;
993 cur_arg++;
994 }
995 else if (!strcmp(args[cur_arg], "maxlife")) {
996 unsigned int maxlife;
997 const char *res;
998
999 if (!*args[cur_arg + 1]) {
1000 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
1001 file, linenum, args[cur_arg]);
1002 err_code |= ERR_ALERT | ERR_FATAL;
1003 goto out;
1004 }
1005
Willy Tarreau9faebe32019-06-07 19:00:37 +02001006
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001007 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001008 if (res == PARSE_TIME_OVER) {
1009 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
1010 file, linenum, args[cur_arg+1], args[cur_arg]);
1011 err_code |= ERR_ALERT | ERR_FATAL;
1012 goto out;
1013 }
1014 else if (res == PARSE_TIME_UNDER) {
1015 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
1016 file, linenum, args[cur_arg+1], args[cur_arg]);
1017 err_code |= ERR_ALERT | ERR_FATAL;
1018 goto out;
1019 }
1020 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001021 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
1022 file, linenum, *res, args[cur_arg]);
1023 err_code |= ERR_ALERT | ERR_FATAL;
1024 goto out;
1025 }
1026 curproxy->cookie_maxlife = maxlife;
1027 cur_arg++;
1028 }
1029 else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */
1030
1031 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
1032 err_code |= ERR_WARN;
1033 curproxy->ck_opts |= PR_CK_DYNAMIC;
1034 }
Christopher Faulet2f533902020-01-21 11:06:48 +01001035 else if (!strcmp(args[cur_arg], "attr")) {
1036 char *val;
1037 if (!*args[cur_arg + 1]) {
1038 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
1039 file, linenum, args[cur_arg]);
1040 err_code |= ERR_ALERT | ERR_FATAL;
1041 goto out;
1042 }
1043 val = args[cur_arg + 1];
1044 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +01001045 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +01001046 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
1047 file, linenum, *val);
1048 err_code |= ERR_ALERT | ERR_FATAL;
1049 goto out;
1050 }
1051 val++;
1052 }
1053 /* don't add ';' for the first attribute */
1054 if (!curproxy->cookie_attrs)
1055 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
1056 else
1057 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
1058 cur_arg++;
1059 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001060
1061 else {
Christopher Faulet2f533902020-01-21 11:06:48 +01001062 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 +01001063 file, linenum, args[0]);
1064 err_code |= ERR_ALERT | ERR_FATAL;
1065 goto out;
1066 }
1067 cur_arg++;
1068 }
1069 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
1070 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
1071 file, linenum);
1072 err_code |= ERR_ALERT | ERR_FATAL;
1073 }
1074
1075 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
1076 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
1077 file, linenum);
1078 err_code |= ERR_ALERT | ERR_FATAL;
1079 }
1080
1081 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
1082 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
1083 file, linenum);
1084 err_code |= ERR_ALERT | ERR_FATAL;
1085 }
1086 }/* end else if (!strcmp(args[0], "cookie")) */
1087 else if (!strcmp(args[0], "email-alert")) {
1088 if (*(args[1]) == 0) {
1089 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1090 file, linenum, args[0]);
1091 err_code |= ERR_ALERT | ERR_FATAL;
1092 goto out;
1093 }
1094
1095 if (!strcmp(args[1], "from")) {
1096 if (*(args[1]) == 0) {
1097 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1098 file, linenum, args[1]);
1099 err_code |= ERR_ALERT | ERR_FATAL;
1100 goto out;
1101 }
1102 free(curproxy->email_alert.from);
1103 curproxy->email_alert.from = strdup(args[2]);
1104 }
1105 else if (!strcmp(args[1], "mailers")) {
1106 if (*(args[1]) == 0) {
1107 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1108 file, linenum, args[1]);
1109 err_code |= ERR_ALERT | ERR_FATAL;
1110 goto out;
1111 }
1112 free(curproxy->email_alert.mailers.name);
1113 curproxy->email_alert.mailers.name = strdup(args[2]);
1114 }
1115 else if (!strcmp(args[1], "myhostname")) {
1116 if (*(args[1]) == 0) {
1117 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1118 file, linenum, args[1]);
1119 err_code |= ERR_ALERT | ERR_FATAL;
1120 goto out;
1121 }
1122 free(curproxy->email_alert.myhostname);
1123 curproxy->email_alert.myhostname = strdup(args[2]);
1124 }
1125 else if (!strcmp(args[1], "level")) {
1126 curproxy->email_alert.level = get_log_level(args[2]);
1127 if (curproxy->email_alert.level < 0) {
1128 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1129 file, linenum, args[1], args[2]);
1130 err_code |= ERR_ALERT | ERR_FATAL;
1131 goto out;
1132 }
1133 }
1134 else if (!strcmp(args[1], "to")) {
1135 if (*(args[1]) == 0) {
1136 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1137 file, linenum, args[1]);
1138 err_code |= ERR_ALERT | ERR_FATAL;
1139 goto out;
1140 }
1141 free(curproxy->email_alert.to);
1142 curproxy->email_alert.to = strdup(args[2]);
1143 }
1144 else {
1145 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1146 file, linenum, args[1]);
1147 err_code |= ERR_ALERT | ERR_FATAL;
1148 goto out;
1149 }
1150 /* Indicate that the email_alert is at least partially configured */
1151 curproxy->email_alert.set = 1;
1152 }/* end else if (!strcmp(args[0], "email-alert")) */
1153 else if (!strcmp(args[0], "external-check")) {
1154 if (*(args[1]) == 0) {
1155 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1156 file, linenum, args[0]);
1157 err_code |= ERR_ALERT | ERR_FATAL;
1158 goto out;
1159 }
1160
1161 if (!strcmp(args[1], "command")) {
1162 if (alertif_too_many_args(2, file, linenum, args, &err_code))
1163 goto out;
1164 if (*(args[2]) == 0) {
1165 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1166 file, linenum, args[1]);
1167 err_code |= ERR_ALERT | ERR_FATAL;
1168 goto out;
1169 }
1170 free(curproxy->check_command);
1171 curproxy->check_command = strdup(args[2]);
1172 }
1173 else if (!strcmp(args[1], "path")) {
1174 if (alertif_too_many_args(2, file, linenum, args, &err_code))
1175 goto out;
1176 if (*(args[2]) == 0) {
1177 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1178 file, linenum, args[1]);
1179 err_code |= ERR_ALERT | ERR_FATAL;
1180 goto out;
1181 }
1182 free(curproxy->check_path);
1183 curproxy->check_path = strdup(args[2]);
1184 }
1185 else {
1186 ha_alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n",
1187 file, linenum, args[1]);
1188 err_code |= ERR_ALERT | ERR_FATAL;
1189 goto out;
1190 }
1191 }/* end else if (!strcmp(args[0], "external-check")) */
1192 else if (!strcmp(args[0], "persist")) { /* persist */
1193 if (*(args[1]) == 0) {
1194 ha_alert("parsing [%s:%d] : missing persist method.\n",
1195 file, linenum);
1196 err_code |= ERR_ALERT | ERR_FATAL;
1197 goto out;
1198 }
1199
1200 if (!strncmp(args[1], "rdp-cookie", 10)) {
1201 curproxy->options2 |= PR_O2_RDPC_PRST;
1202
1203 if (*(args[1] + 10) == '(') { /* cookie name */
1204 const char *beg, *end;
1205
1206 beg = args[1] + 11;
1207 end = strchr(beg, ')');
1208
1209 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1210 goto out;
1211
1212 if (!end || end == beg) {
1213 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1214 file, linenum);
1215 err_code |= ERR_ALERT | ERR_FATAL;
1216 goto out;
1217 }
1218
1219 free(curproxy->rdp_cookie_name);
1220 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
1221 curproxy->rdp_cookie_len = end-beg;
1222 }
1223 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1224 free(curproxy->rdp_cookie_name);
1225 curproxy->rdp_cookie_name = strdup("msts");
1226 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1227 }
1228 else { /* syntax */
1229 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1230 file, linenum);
1231 err_code |= ERR_ALERT | ERR_FATAL;
1232 goto out;
1233 }
1234 }
1235 else {
1236 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1237 file, linenum);
1238 err_code |= ERR_ALERT | ERR_FATAL;
1239 goto out;
1240 }
1241 }
1242 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001243 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 +01001244 err_code |= ERR_ALERT | ERR_FATAL;
1245 goto out;
1246 }
1247 else if (!strcmp(args[0], "load-server-state-from-file")) {
1248 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1249 err_code |= ERR_WARN;
1250 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
1251 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1252 }
1253 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
1254 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1255 }
1256 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
1257 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1258 }
1259 else {
1260 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1261 file, linenum, args[0], args[1]);
1262 err_code |= ERR_ALERT | ERR_FATAL;
1263 goto out;
1264 }
1265 }
1266 else if (!strcmp(args[0], "server-state-file-name")) {
1267 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1268 err_code |= ERR_WARN;
1269 if (*(args[1]) == 0) {
1270 ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
1271 file, linenum, args[0]);
1272 err_code |= ERR_ALERT | ERR_FATAL;
1273 goto out;
1274 }
1275 else if (!strcmp(args[1], "use-backend-name"))
1276 curproxy->server_state_file_name = strdup(curproxy->id);
1277 else
1278 curproxy->server_state_file_name = strdup(args[1]);
1279 }
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001280 else if (!strcmp(args[0], "max-session-srv-conns")) {
1281 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1282 err_code |= ERR_WARN;
1283 if (*(args[1]) == 0) {
1284 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1285 file, linenum, args[0]);
1286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
1289 curproxy->max_out_conns = atoi(args[1]);
1290 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001291 else if (!strcmp(args[0], "capture")) {
1292 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1293 err_code |= ERR_WARN;
1294
1295 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
1296 if (curproxy == &defproxy) {
1297 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1298 err_code |= ERR_ALERT | ERR_FATAL;
1299 goto out;
1300 }
1301
1302 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1303 goto out;
1304
1305 if (*(args[4]) == 0) {
1306 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1307 file, linenum, args[0]);
1308 err_code |= ERR_ALERT | ERR_FATAL;
1309 goto out;
1310 }
1311 free(curproxy->capture_name);
1312 curproxy->capture_name = strdup(args[2]);
1313 curproxy->capture_namelen = strlen(curproxy->capture_name);
1314 curproxy->capture_len = atol(args[4]);
1315 curproxy->to_log |= LW_COOKIE;
1316 }
1317 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
1318 struct cap_hdr *hdr;
1319
1320 if (curproxy == &defproxy) {
1321 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325
1326 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1327 goto out;
1328
1329 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1330 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1331 file, linenum, args[0], args[1]);
1332 err_code |= ERR_ALERT | ERR_FATAL;
1333 goto out;
1334 }
1335
1336 hdr = calloc(1, sizeof(*hdr));
1337 hdr->next = curproxy->req_cap;
1338 hdr->name = strdup(args[3]);
1339 hdr->namelen = strlen(args[3]);
1340 hdr->len = atol(args[5]);
1341 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1342 hdr->index = curproxy->nb_req_cap++;
1343 curproxy->req_cap = hdr;
1344 curproxy->to_log |= LW_REQHDR;
1345 }
1346 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
1347 struct cap_hdr *hdr;
1348
1349 if (curproxy == &defproxy) {
1350 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1351 err_code |= ERR_ALERT | ERR_FATAL;
1352 goto out;
1353 }
1354
1355 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1356 goto out;
1357
1358 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1359 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1360 file, linenum, args[0], args[1]);
1361 err_code |= ERR_ALERT | ERR_FATAL;
1362 goto out;
1363 }
1364 hdr = calloc(1, sizeof(*hdr));
1365 hdr->next = curproxy->rsp_cap;
1366 hdr->name = strdup(args[3]);
1367 hdr->namelen = strlen(args[3]);
1368 hdr->len = atol(args[5]);
1369 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1370 hdr->index = curproxy->nb_rsp_cap++;
1371 curproxy->rsp_cap = hdr;
1372 curproxy->to_log |= LW_RSPHDR;
1373 }
1374 else {
1375 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1376 file, linenum, args[0]);
1377 err_code |= ERR_ALERT | ERR_FATAL;
1378 goto out;
1379 }
1380 }
1381 else if (!strcmp(args[0], "retries")) { /* connection retries */
1382 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1383 err_code |= ERR_WARN;
1384
1385 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1386 goto out;
1387
1388 if (*(args[1]) == 0) {
1389 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1390 file, linenum, args[0]);
1391 err_code |= ERR_ALERT | ERR_FATAL;
1392 goto out;
1393 }
1394 curproxy->conn_retries = atol(args[1]);
1395 }
1396 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
1397 struct act_rule *rule;
1398
1399 if (curproxy == &defproxy) {
1400 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1401 err_code |= ERR_ALERT | ERR_FATAL;
1402 goto out;
1403 }
1404
1405 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1406 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001407 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001408 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1409 file, linenum, args[0]);
1410 err_code |= ERR_WARN;
1411 }
1412
1413 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1414
1415 if (!rule) {
1416 err_code |= ERR_ALERT | ERR_ABORT;
1417 goto out;
1418 }
1419
1420 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1421 err_code |= warnif_cond_conflicts(rule->cond,
1422 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1423 file, linenum);
1424
1425 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1426 }
1427 else if (!strcmp(args[0], "http-response")) { /* response access control */
1428 struct act_rule *rule;
1429
1430 if (curproxy == &defproxy) {
1431 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1432 err_code |= ERR_ALERT | ERR_FATAL;
1433 goto out;
1434 }
1435
1436 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1437 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001438 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001439 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1440 file, linenum, args[0]);
1441 err_code |= ERR_WARN;
1442 }
1443
1444 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1445
1446 if (!rule) {
1447 err_code |= ERR_ALERT | ERR_ABORT;
1448 goto out;
1449 }
1450
1451 err_code |= warnif_cond_conflicts(rule->cond,
1452 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1453 file, linenum);
1454
1455 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1456 }
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001457 else if (!strcmp(args[0], "http-after-response")) {
1458 struct act_rule *rule;
1459
1460 if (curproxy == &defproxy) {
1461 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1462 err_code |= ERR_ALERT | ERR_FATAL;
1463 goto out;
1464 }
1465
1466 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1467 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1468 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1469 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1470 file, linenum, args[0]);
1471 err_code |= ERR_WARN;
1472 }
1473
1474 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1475
1476 if (!rule) {
1477 err_code |= ERR_ALERT | ERR_ABORT;
1478 goto out;
1479 }
1480
1481 err_code |= warnif_cond_conflicts(rule->cond,
1482 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1483 file, linenum);
1484
1485 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1486 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001487 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
1488 /* set the header name and length into the proxy structure */
1489 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1490 err_code |= ERR_WARN;
1491
1492 if (!*args[1]) {
1493 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1494 file, linenum, args[0]);
1495 err_code |= ERR_ALERT | ERR_FATAL;
1496 goto out;
1497 }
1498
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001499 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001500 free(curproxy->server_id_hdr_name);
1501 curproxy->server_id_hdr_name = strdup(args[1]);
1502 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001503 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 +01001504 }
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001505 else if (!strcmp(args[0], "block")) {
1506 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 +01001507
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001508 err_code |= ERR_ALERT | ERR_FATAL;
1509 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001510 }
1511 else if (!strcmp(args[0], "redirect")) {
1512 struct redirect_rule *rule;
1513
1514 if (curproxy == &defproxy) {
1515 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1516 err_code |= ERR_ALERT | ERR_FATAL;
1517 goto out;
1518 }
1519
1520 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1521 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1522 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1523 err_code |= ERR_ALERT | ERR_FATAL;
1524 goto out;
1525 }
1526
1527 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1528 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1529 err_code |= warnif_cond_conflicts(rule->cond,
1530 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1531 file, linenum);
1532 }
1533 else if (!strcmp(args[0], "use_backend")) {
1534 struct switching_rule *rule;
1535
1536 if (curproxy == &defproxy) {
1537 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1538 err_code |= ERR_ALERT | ERR_FATAL;
1539 goto out;
1540 }
1541
1542 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1543 err_code |= ERR_WARN;
1544
1545 if (*(args[1]) == 0) {
1546 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1547 err_code |= ERR_ALERT | ERR_FATAL;
1548 goto out;
1549 }
1550
1551 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1552 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1553 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1554 file, linenum, errmsg);
1555 err_code |= ERR_ALERT | ERR_FATAL;
1556 goto out;
1557 }
1558
1559 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1560 }
1561 else if (*args[2]) {
1562 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1563 file, linenum, args[2]);
1564 err_code |= ERR_ALERT | ERR_FATAL;
1565 goto out;
1566 }
1567
1568 rule = calloc(1, sizeof(*rule));
1569 if (!rule) {
1570 ha_alert("Out of memory error.\n");
1571 goto out;
1572 }
1573 rule->cond = cond;
1574 rule->be.name = strdup(args[1]);
1575 rule->line = linenum;
1576 rule->file = strdup(file);
1577 if (!rule->file) {
1578 ha_alert("Out of memory error.\n");
1579 goto out;
1580 }
1581 LIST_INIT(&rule->list);
1582 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1583 }
1584 else if (strcmp(args[0], "use-server") == 0) {
1585 struct server_rule *rule;
1586
1587 if (curproxy == &defproxy) {
1588 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1589 err_code |= ERR_ALERT | ERR_FATAL;
1590 goto out;
1591 }
1592
1593 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1594 err_code |= ERR_WARN;
1595
1596 if (*(args[1]) == 0) {
1597 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1598 err_code |= ERR_ALERT | ERR_FATAL;
1599 goto out;
1600 }
1601
1602 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1603 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1604 file, linenum, args[0]);
1605 err_code |= ERR_ALERT | ERR_FATAL;
1606 goto out;
1607 }
1608
1609 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1610 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1611 file, linenum, errmsg);
1612 err_code |= ERR_ALERT | ERR_FATAL;
1613 goto out;
1614 }
1615
1616 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1617
1618 rule = calloc(1, sizeof(*rule));
1619 rule->cond = cond;
1620 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001621 rule->line = linenum;
1622 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001623 LIST_INIT(&rule->list);
1624 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1625 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1626 }
1627 else if ((!strcmp(args[0], "force-persist")) ||
1628 (!strcmp(args[0], "ignore-persist"))) {
1629 struct persist_rule *rule;
1630
1631 if (curproxy == &defproxy) {
1632 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1633 err_code |= ERR_ALERT | ERR_FATAL;
1634 goto out;
1635 }
1636
1637 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1638 err_code |= ERR_WARN;
1639
1640 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1641 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1642 file, linenum, args[0]);
1643 err_code |= ERR_ALERT | ERR_FATAL;
1644 goto out;
1645 }
1646
1647 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1648 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1649 file, linenum, args[0], errmsg);
1650 err_code |= ERR_ALERT | ERR_FATAL;
1651 goto out;
1652 }
1653
1654 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1655 * where force-persist is applied.
1656 */
1657 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1658
1659 rule = calloc(1, sizeof(*rule));
1660 rule->cond = cond;
1661 if (!strcmp(args[0], "force-persist")) {
1662 rule->type = PERSIST_TYPE_FORCE;
1663 } else {
1664 rule->type = PERSIST_TYPE_IGNORE;
1665 }
1666 LIST_INIT(&rule->list);
1667 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1668 }
1669 else if (!strcmp(args[0], "stick-table")) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001670 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001671
1672 if (curproxy == &defproxy) {
1673 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1674 file, linenum);
1675 err_code |= ERR_ALERT | ERR_FATAL;
1676 goto out;
1677 }
1678
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001679 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001680 if (other) {
1681 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 +01001682 file, linenum, curproxy->id,
1683 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1684 other->proxy ? other->id : other->peers.p->id,
1685 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001686 err_code |= ERR_ALERT | ERR_FATAL;
1687 goto out;
1688 }
1689
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001690 curproxy->table = calloc(1, sizeof *curproxy->table);
1691 if (!curproxy->table) {
1692 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1693 file, linenum, args[0], args[1]);
1694 err_code |= ERR_ALERT | ERR_FATAL;
1695 goto out;
1696 }
1697
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001698 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1699 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001700 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001701 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001702
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001703 /* Store the proxy in the stick-table. */
1704 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001705
1706 stktable_store_name(curproxy->table);
1707 curproxy->table->next = stktables_list;
1708 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001709
1710 /* Add this proxy to the list of proxies which refer to its stick-table. */
1711 if (curproxy->table->proxies_list != curproxy) {
1712 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1713 curproxy->table->proxies_list = curproxy;
1714 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001715 }
1716 else if (!strcmp(args[0], "stick")) {
1717 struct sticking_rule *rule;
1718 struct sample_expr *expr;
1719 int myidx = 0;
1720 const char *name = NULL;
1721 int flags;
1722
1723 if (curproxy == &defproxy) {
1724 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1725 err_code |= ERR_ALERT | ERR_FATAL;
1726 goto out;
1727 }
1728
1729 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1730 err_code |= ERR_WARN;
1731 goto out;
1732 }
1733
1734 myidx++;
1735 if ((strcmp(args[myidx], "store") == 0) ||
1736 (strcmp(args[myidx], "store-request") == 0)) {
1737 myidx++;
1738 flags = STK_IS_STORE;
1739 }
1740 else if (strcmp(args[myidx], "store-response") == 0) {
1741 myidx++;
1742 flags = STK_IS_STORE | STK_ON_RSP;
1743 }
1744 else if (strcmp(args[myidx], "match") == 0) {
1745 myidx++;
1746 flags = STK_IS_MATCH;
1747 }
1748 else if (strcmp(args[myidx], "on") == 0) {
1749 myidx++;
1750 flags = STK_IS_MATCH | STK_IS_STORE;
1751 }
1752 else {
1753 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1754 err_code |= ERR_ALERT | ERR_FATAL;
1755 goto out;
1756 }
1757
1758 if (*(args[myidx]) == 0) {
1759 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1760 err_code |= ERR_ALERT | ERR_FATAL;
1761 goto out;
1762 }
1763
1764 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001765 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001766 if (!expr) {
1767 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1768 err_code |= ERR_ALERT | ERR_FATAL;
1769 goto out;
1770 }
1771
1772 if (flags & STK_ON_RSP) {
1773 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1774 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1775 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1776 err_code |= ERR_ALERT | ERR_FATAL;
1777 free(expr);
1778 goto out;
1779 }
1780 } else {
1781 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1782 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1783 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1784 err_code |= ERR_ALERT | ERR_FATAL;
1785 free(expr);
1786 goto out;
1787 }
1788 }
1789
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001790 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001791 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1792
1793 if (strcmp(args[myidx], "table") == 0) {
1794 myidx++;
1795 name = args[myidx++];
1796 }
1797
1798 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1799 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1800 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1801 file, linenum, args[0], errmsg);
1802 err_code |= ERR_ALERT | ERR_FATAL;
1803 free(expr);
1804 goto out;
1805 }
1806 }
1807 else if (*(args[myidx])) {
1808 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1809 file, linenum, args[0], args[myidx]);
1810 err_code |= ERR_ALERT | ERR_FATAL;
1811 free(expr);
1812 goto out;
1813 }
1814 if (flags & STK_ON_RSP)
1815 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1816 else
1817 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1818
1819 rule = calloc(1, sizeof(*rule));
1820 rule->cond = cond;
1821 rule->expr = expr;
1822 rule->flags = flags;
1823 rule->table.name = name ? strdup(name) : NULL;
1824 LIST_INIT(&rule->list);
1825 if (flags & STK_ON_RSP)
1826 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1827 else
1828 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1829 }
1830 else if (!strcmp(args[0], "stats")) {
1831 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
1832 curproxy->uri_auth = NULL; /* we must detach from the default config */
1833
1834 if (!*args[1]) {
1835 goto stats_error_parsing;
1836 } else if (!strcmp(args[1], "admin")) {
1837 struct stats_admin_rule *rule;
1838
1839 if (curproxy == &defproxy) {
1840 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1841 err_code |= ERR_ALERT | ERR_FATAL;
1842 goto out;
1843 }
1844
1845 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1846 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1847 err_code |= ERR_ALERT | ERR_ABORT;
1848 goto out;
1849 }
1850
1851 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1852 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1853 file, linenum, args[0], args[1]);
1854 err_code |= ERR_ALERT | ERR_FATAL;
1855 goto out;
1856 }
1857 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1858 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1859 file, linenum, args[0], args[1], errmsg);
1860 err_code |= ERR_ALERT | ERR_FATAL;
1861 goto out;
1862 }
1863
1864 err_code |= warnif_cond_conflicts(cond,
1865 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1866 file, linenum);
1867
1868 rule = calloc(1, sizeof(*rule));
1869 rule->cond = cond;
1870 LIST_INIT(&rule->list);
1871 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
1872 } else if (!strcmp(args[1], "uri")) {
1873 if (*(args[2]) == 0) {
1874 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1875 err_code |= ERR_ALERT | ERR_FATAL;
1876 goto out;
1877 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1878 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1879 err_code |= ERR_ALERT | ERR_ABORT;
1880 goto out;
1881 }
1882 } else if (!strcmp(args[1], "realm")) {
1883 if (*(args[2]) == 0) {
1884 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1885 err_code |= ERR_ALERT | ERR_FATAL;
1886 goto out;
1887 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1888 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1889 err_code |= ERR_ALERT | ERR_ABORT;
1890 goto out;
1891 }
1892 } else if (!strcmp(args[1], "refresh")) {
1893 unsigned interval;
1894
1895 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001896 if (err == PARSE_TIME_OVER) {
1897 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1898 file, linenum, args[2]);
1899 err_code |= ERR_ALERT | ERR_FATAL;
1900 goto out;
1901 }
1902 else if (err == PARSE_TIME_UNDER) {
1903 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1904 file, linenum, args[2]);
1905 err_code |= ERR_ALERT | ERR_FATAL;
1906 goto out;
1907 }
1908 else if (err) {
1909 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001910 file, linenum, *err);
1911 err_code |= ERR_ALERT | ERR_FATAL;
1912 goto out;
1913 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1914 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1915 err_code |= ERR_ALERT | ERR_ABORT;
1916 goto out;
1917 }
1918 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
1919 struct act_rule *rule;
1920
1921 if (curproxy == &defproxy) {
1922 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1923 err_code |= ERR_ALERT | ERR_FATAL;
1924 goto out;
1925 }
1926
1927 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1928 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1929 err_code |= ERR_ALERT | ERR_ABORT;
1930 goto out;
1931 }
1932
1933 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1934 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1935 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1936 file, linenum, args[0]);
1937 err_code |= ERR_WARN;
1938 }
1939
1940 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1941
1942 if (!rule) {
1943 err_code |= ERR_ALERT | ERR_ABORT;
1944 goto out;
1945 }
1946
1947 err_code |= warnif_cond_conflicts(rule->cond,
1948 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1949 file, linenum);
1950 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1951
1952 } else if (!strcmp(args[1], "auth")) {
1953 if (*(args[2]) == 0) {
1954 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1955 err_code |= ERR_ALERT | ERR_FATAL;
1956 goto out;
1957 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1958 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1959 err_code |= ERR_ALERT | ERR_ABORT;
1960 goto out;
1961 }
1962 } else if (!strcmp(args[1], "scope")) {
1963 if (*(args[2]) == 0) {
1964 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1965 err_code |= ERR_ALERT | ERR_FATAL;
1966 goto out;
1967 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1968 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1969 err_code |= ERR_ALERT | ERR_ABORT;
1970 goto out;
1971 }
1972 } else if (!strcmp(args[1], "enable")) {
1973 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1974 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1975 err_code |= ERR_ALERT | ERR_ABORT;
1976 goto out;
1977 }
1978 } else if (!strcmp(args[1], "hide-version")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001979 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001980 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1981 err_code |= ERR_ALERT | ERR_ABORT;
1982 goto out;
1983 }
1984 } else if (!strcmp(args[1], "show-legends")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001985 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001986 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1987 err_code |= ERR_ALERT | ERR_ABORT;
1988 goto out;
1989 }
1990 } else if (!strcmp(args[1], "show-node")) {
1991
1992 if (*args[2]) {
1993 int i;
1994 char c;
1995
1996 for (i=0; args[2][i]; i++) {
1997 c = args[2][i];
1998 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1999 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
2000 break;
2001 }
2002
2003 if (!i || args[2][i]) {
2004 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
2005 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
2006 file, linenum, args[0], args[1]);
2007 err_code |= ERR_ALERT | ERR_FATAL;
2008 goto out;
2009 }
2010 }
2011
2012 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
2013 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
2014 err_code |= ERR_ALERT | ERR_ABORT;
2015 goto out;
2016 }
2017 } else if (!strcmp(args[1], "show-desc")) {
2018 char *desc = NULL;
2019
2020 if (*args[2]) {
2021 int i, len=0;
2022 char *d;
2023
2024 for (i = 2; *args[i]; i++)
2025 len += strlen(args[i]) + 1;
2026
2027 desc = d = calloc(1, len);
2028
2029 d += snprintf(d, desc + len - d, "%s", args[2]);
2030 for (i = 3; *args[i]; i++)
2031 d += snprintf(d, desc + len - d, " %s", args[i]);
2032 }
2033
2034 if (!*args[2] && !global.desc)
2035 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
2036 file, linenum, args[1]);
2037 else {
2038 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
2039 free(desc);
2040 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
2041 err_code |= ERR_ALERT | ERR_ABORT;
2042 goto out;
2043 }
2044 free(desc);
2045 }
2046 } else {
2047stats_error_parsing:
2048 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
2049 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
2050 err_code |= ERR_ALERT | ERR_FATAL;
2051 goto out;
2052 }
2053 }
2054 else if (!strcmp(args[0], "option")) {
2055 int optnum;
2056
2057 if (*(args[1]) == '\0') {
2058 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
2059 file, linenum, args[0]);
2060 err_code |= ERR_ALERT | ERR_FATAL;
2061 goto out;
2062 }
2063
2064 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
2065 if (!strcmp(args[1], cfg_opts[optnum].name)) {
2066 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
2067 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2068 file, linenum, cfg_opts[optnum].name);
2069 err_code |= ERR_ALERT | ERR_FATAL;
2070 goto out;
2071 }
2072 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2073 goto out;
2074
2075 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
2076 err_code |= ERR_WARN;
2077 goto out;
2078 }
2079
2080 curproxy->no_options &= ~cfg_opts[optnum].val;
2081 curproxy->options &= ~cfg_opts[optnum].val;
2082
2083 switch (kwm) {
2084 case KWM_STD:
2085 curproxy->options |= cfg_opts[optnum].val;
2086 break;
2087 case KWM_NO:
2088 curproxy->no_options |= cfg_opts[optnum].val;
2089 break;
2090 case KWM_DEF: /* already cleared */
2091 break;
2092 }
2093
2094 goto out;
2095 }
2096 }
2097
2098 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
2099 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
2100 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2101 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2102 file, linenum, cfg_opts2[optnum].name);
2103 err_code |= ERR_ALERT | ERR_FATAL;
2104 goto out;
2105 }
2106 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2107 goto out;
2108 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2109 err_code |= ERR_WARN;
2110 goto out;
2111 }
2112
Christopher Faulet31930372019-07-15 10:16:58 +02002113 /* "[no] option http-use-htx" is deprecated */
2114 if (!strcmp(cfg_opts2[optnum].name, "http-use-htx")) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02002115 if (kwm ==KWM_NO) {
2116 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
2117 " The HTX mode is now the only supported mode.\n",
2118 file, linenum, cfg_opts2[optnum].name);
2119 err_code |= ERR_WARN;
2120 }
Christopher Faulet31930372019-07-15 10:16:58 +02002121 goto out;
2122 }
2123
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002124 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2125 curproxy->options2 &= ~cfg_opts2[optnum].val;
2126
2127 switch (kwm) {
2128 case KWM_STD:
2129 curproxy->options2 |= cfg_opts2[optnum].val;
2130 break;
2131 case KWM_NO:
2132 curproxy->no_options2 |= cfg_opts2[optnum].val;
2133 break;
2134 case KWM_DEF: /* already cleared */
2135 break;
2136 }
2137 goto out;
2138 }
2139 }
2140
2141 /* HTTP options override each other. They can be cancelled using
2142 * "no option xxx" which only switches to default mode if the mode
2143 * was this one (useful for cancelling options set in defaults
2144 * sections).
2145 */
2146 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02002147 if (strcmp(args[1], "forceclose") == 0) {
2148 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
2149 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
2150 file, linenum, args[1]);
2151 err_code |= ERR_WARN;
2152 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002153 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2154 goto out;
2155 if (kwm == KWM_STD) {
2156 curproxy->options &= ~PR_O_HTTP_MODE;
2157 curproxy->options |= PR_O_HTTP_CLO;
2158 goto out;
2159 }
2160 else if (kwm == KWM_NO) {
2161 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2162 curproxy->options &= ~PR_O_HTTP_MODE;
2163 goto out;
2164 }
2165 }
2166 else if (strcmp(args[1], "http-server-close") == 0) {
2167 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2168 goto out;
2169 if (kwm == KWM_STD) {
2170 curproxy->options &= ~PR_O_HTTP_MODE;
2171 curproxy->options |= PR_O_HTTP_SCL;
2172 goto out;
2173 }
2174 else if (kwm == KWM_NO) {
2175 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2176 curproxy->options &= ~PR_O_HTTP_MODE;
2177 goto out;
2178 }
2179 }
2180 else if (strcmp(args[1], "http-keep-alive") == 0) {
2181 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2182 goto out;
2183 if (kwm == KWM_STD) {
2184 curproxy->options &= ~PR_O_HTTP_MODE;
2185 curproxy->options |= PR_O_HTTP_KAL;
2186 goto out;
2187 }
2188 else if (kwm == KWM_NO) {
2189 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2190 curproxy->options &= ~PR_O_HTTP_MODE;
2191 goto out;
2192 }
2193 }
2194 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002195 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2196 file, linenum, args[1]);
2197 err_code |= ERR_WARN;
2198 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002199 }
2200
2201 /* Redispatch can take an integer argument that control when the
2202 * resispatch occurs. All values are relative to the retries option.
2203 * This can be cancelled using "no option xxx".
2204 */
2205 if (strcmp(args[1], "redispatch") == 0) {
2206 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2207 err_code |= ERR_WARN;
2208 goto out;
2209 }
2210
2211 curproxy->no_options &= ~PR_O_REDISP;
2212 curproxy->options &= ~PR_O_REDISP;
2213
2214 switch (kwm) {
2215 case KWM_STD:
2216 curproxy->options |= PR_O_REDISP;
2217 curproxy->redispatch_after = -1;
2218 if(*args[2]) {
2219 curproxy->redispatch_after = atol(args[2]);
2220 }
2221 break;
2222 case KWM_NO:
2223 curproxy->no_options |= PR_O_REDISP;
2224 curproxy->redispatch_after = 0;
2225 break;
2226 case KWM_DEF: /* already cleared */
2227 break;
2228 }
2229 goto out;
2230 }
2231
2232 if (kwm != KWM_STD) {
2233 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2234 file, linenum, args[1]);
2235 err_code |= ERR_ALERT | ERR_FATAL;
2236 goto out;
2237 }
2238
2239 if (!strcmp(args[1], "httplog")) {
2240 char *logformat;
2241 /* generate a complete HTTP log */
2242 logformat = default_http_log_format;
2243 if (*(args[2]) != '\0') {
2244 if (!strcmp(args[2], "clf")) {
2245 curproxy->options2 |= PR_O2_CLFLOG;
2246 logformat = clf_http_log_format;
2247 } else {
2248 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2249 err_code |= ERR_ALERT | ERR_FATAL;
2250 goto out;
2251 }
2252 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2253 goto out;
2254 }
2255 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2256 char *oldlogformat = "log-format";
2257 char *clflogformat = "";
2258
2259 if (curproxy->conf.logformat_string == default_http_log_format)
2260 oldlogformat = "option httplog";
2261 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2262 oldlogformat = "option tcplog";
2263 else if (curproxy->conf.logformat_string == clf_http_log_format)
2264 oldlogformat = "option httplog clf";
2265 if (logformat == clf_http_log_format)
2266 clflogformat = " clf";
2267 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2268 file, linenum, clflogformat, oldlogformat);
2269 }
2270 if (curproxy->conf.logformat_string != default_http_log_format &&
2271 curproxy->conf.logformat_string != default_tcp_log_format &&
2272 curproxy->conf.logformat_string != clf_http_log_format)
2273 free(curproxy->conf.logformat_string);
2274 curproxy->conf.logformat_string = logformat;
2275
2276 free(curproxy->conf.lfs_file);
2277 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2278 curproxy->conf.lfs_line = curproxy->conf.args.line;
2279
2280 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2281 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2282 file, linenum, curproxy->id);
2283 err_code |= ERR_WARN;
2284 }
2285 }
2286 else if (!strcmp(args[1], "tcplog")) {
2287 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2288 char *oldlogformat = "log-format";
2289
2290 if (curproxy->conf.logformat_string == default_http_log_format)
2291 oldlogformat = "option httplog";
2292 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2293 oldlogformat = "option tcplog";
2294 else if (curproxy->conf.logformat_string == clf_http_log_format)
2295 oldlogformat = "option httplog clf";
2296 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2297 file, linenum, oldlogformat);
2298 }
2299 /* generate a detailed TCP log */
2300 if (curproxy->conf.logformat_string != default_http_log_format &&
2301 curproxy->conf.logformat_string != default_tcp_log_format &&
2302 curproxy->conf.logformat_string != clf_http_log_format)
2303 free(curproxy->conf.logformat_string);
2304 curproxy->conf.logformat_string = default_tcp_log_format;
2305
2306 free(curproxy->conf.lfs_file);
2307 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2308 curproxy->conf.lfs_line = curproxy->conf.args.line;
2309
2310 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2311 goto out;
2312
2313 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2314 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2315 file, linenum, curproxy->id);
2316 err_code |= ERR_WARN;
2317 }
2318 }
2319 else if (!strcmp(args[1], "tcpka")) {
2320 /* enable TCP keep-alives on client and server streams */
2321 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2322 err_code |= ERR_WARN;
2323
2324 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2325 goto out;
2326
2327 if (curproxy->cap & PR_CAP_FE)
2328 curproxy->options |= PR_O_TCP_CLI_KA;
2329 if (curproxy->cap & PR_CAP_BE)
2330 curproxy->options |= PR_O_TCP_SRV_KA;
2331 }
2332 else if (!strcmp(args[1], "httpchk")) {
2333 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
2334 err_code |= ERR_WARN;
2335
2336 /* use HTTP request to check servers' health */
2337 free(curproxy->check_req);
Christopher Faulet8acb1282020-04-09 08:44:06 +02002338 free(curproxy->check_hdrs);
2339 free(curproxy->check_body);
2340 curproxy->check_req = curproxy->check_hdrs = curproxy->check_body = NULL;
2341 curproxy->check_len = curproxy->check_hdrs_len = curproxy->check_body_len = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002342 curproxy->options2 &= ~PR_O2_CHK_ANY;
2343 curproxy->options2 |= PR_O2_HTTP_CHK;
2344 if (!*args[2]) { /* no argument */
2345 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
2346 curproxy->check_len = strlen(DEF_CHECK_REQ);
2347 } else if (!*args[3]) { /* one argument : URI */
2348 int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1;
2349 curproxy->check_req = malloc(reqlen);
2350 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
2351 "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */
Christopher Faulet8acb1282020-04-09 08:44:06 +02002352 } else if (!*args[4]) { /* two arguments : METHOD URI */
2353 int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" HTTP/1.0\r\n") + 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002354
2355 curproxy->check_req = malloc(reqlen);
2356 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Christopher Faulet8acb1282020-04-09 08:44:06 +02002357 "%s %s HTTP/1.0\r\n", args[2], args[3]);
2358 } else { /* 3 arguments : METHOD URI HTTP_VER */
2359 char *vsn = args[4];
2360 char *hdrs = strstr(vsn, "\r\n");
2361 char *body = strstr(vsn, "\r\n\r\n");
2362
2363 if (hdrs || body) {
2364 ha_warning("parsing [%s:%d]: '%s %s' : hiding headers or body at the end of the version string is deprecated."
2365 " Please, consider to use 'http-check send' directive instead.\n",
2366 file, linenum, args[0], args[1]);
2367 err_code |= ERR_WARN;
2368 }
2369
2370 if (hdrs == body)
2371 hdrs = NULL;
2372 if (hdrs) {
2373 *hdrs = '\0';
2374 hdrs += 2;
2375 }
2376 if (body) {
2377 *body = '\0';
2378 body += 4;
2379 }
2380
2381 curproxy->check_len = strlen(args[2]) + strlen(args[3]) + strlen(vsn) + 4;
2382 curproxy->check_req = malloc(curproxy->check_len+1);
2383 snprintf(curproxy->check_req, curproxy->check_len+1, "%s %s %s\r\n", args[2], args[3], vsn);
2384
2385 if (hdrs) {
2386 curproxy->check_hdrs_len = strlen(hdrs) + 2;
2387 curproxy->check_hdrs = malloc(curproxy->check_hdrs_len+1);
2388 snprintf(curproxy->check_hdrs, curproxy->check_hdrs_len+1, "%s\r\n", hdrs);
2389 }
2390
2391 if (body) {
2392 curproxy->check_body_len = strlen(body);
2393 curproxy->check_body = strdup(body);
2394 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002395 }
2396 if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code))
2397 goto out;
2398 }
2399 else if (!strcmp(args[1], "ssl-hello-chk")) {
Christopher Faulet811f78c2020-04-01 11:10:27 +02002400 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum);
2401 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002402 goto out;
2403 }
2404 else if (!strcmp(args[1], "smtpchk")) {
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002405 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2406 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002407 goto out;
2408 }
2409 else if (!strcmp(args[1], "pgsql-check")) {
Christopher Fauletce355072020-04-02 11:44:39 +02002410 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2411 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002412 goto out;
2413 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002414 else if (!strcmp(args[1], "redis-check")) {
Christopher Faulet33f05df2020-04-01 11:08:50 +02002415 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2416 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002417 goto out;
2418 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002419 else if (!strcmp(args[1], "mysql-check")) {
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002420 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2421 if (err_code & ERR_FATAL)
2422 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002423 }
2424 else if (!strcmp(args[1], "ldap-check")) {
Christopher Faulet1997eca2020-04-03 23:13:50 +02002425 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2426 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002427 goto out;
2428 }
2429 else if (!strcmp(args[1], "spop-check")) {
Christopher Faulet267b01b2020-04-04 10:27:09 +02002430 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2431 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002432 goto out;
2433 }
2434 else if (!strcmp(args[1], "tcp-check")) {
Christopher Faulet5d503fc2020-03-30 20:34:34 +02002435 struct tcpcheck_rules *rules = &curproxy->tcpcheck_rules;
2436
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002437 /* use raw TCPCHK send/expect to check servers' health */
2438 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
2439 err_code |= ERR_WARN;
2440
Christopher Faulet5d503fc2020-03-30 20:34:34 +02002441 if (rules->flags & TCPCHK_RULES_DEF) {
2442 /* Only shared ruleset can be inherited from the default section */
2443 rules->flags = 0;
2444 rules->list = NULL;
2445 }
2446 else if (rules->list && (rules->flags & TCPCHK_RULES_SHARED)) {
2447 ha_alert("parsing [%s:%d] : A shared tcp-check ruleset alreayd configured.\n", file, linenum);
2448 err_code |= ERR_ALERT | ERR_FATAL;
2449 goto out;
2450 }
2451
2452 if (curproxy != &defproxy && !rules->list) {
2453 rules->list = calloc(1, sizeof(*rules->list));
2454 if (!rules->list) {
Gaetan Rivet04578db2020-02-07 15:37:17 +01002455 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2456 err_code |= ERR_ALERT | ERR_FATAL;
2457 goto out;
2458 }
Christopher Faulet5d503fc2020-03-30 20:34:34 +02002459 LIST_INIT(rules->list);
Gaetan Rivet04578db2020-02-07 15:37:17 +01002460 }
2461
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002462 free(curproxy->check_req);
2463 curproxy->check_req = NULL;
2464 curproxy->options2 &= ~PR_O2_CHK_ANY;
2465 curproxy->options2 |= PR_O2_TCPCHK_CHK;
2466 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2467 goto out;
2468 }
2469 else if (!strcmp(args[1], "external-check")) {
2470 /* excute an external command to check servers' health */
2471 free(curproxy->check_req);
2472 curproxy->check_req = NULL;
2473 curproxy->options2 &= ~PR_O2_CHK_ANY;
2474 curproxy->options2 |= PR_O2_EXT_CHK;
2475 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2476 goto out;
2477 }
2478 else if (!strcmp(args[1], "forwardfor")) {
2479 int cur_arg;
2480
2481 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002482 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002483 */
2484
2485 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2486
2487 free(curproxy->fwdfor_hdr_name);
2488 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2489 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2490
2491 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2492 cur_arg = 2;
2493 while (*(args[cur_arg])) {
2494 if (!strcmp(args[cur_arg], "except")) {
2495 /* suboption except - needs additional argument for it */
2496 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2497 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2498 file, linenum, args[0], args[1], args[cur_arg]);
2499 err_code |= ERR_ALERT | ERR_FATAL;
2500 goto out;
2501 }
2502 /* flush useless bits */
2503 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2504 cur_arg += 2;
2505 } else if (!strcmp(args[cur_arg], "header")) {
2506 /* suboption header - needs additional argument for it */
2507 if (*(args[cur_arg+1]) == 0) {
2508 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2509 file, linenum, args[0], args[1], args[cur_arg]);
2510 err_code |= ERR_ALERT | ERR_FATAL;
2511 goto out;
2512 }
2513 free(curproxy->fwdfor_hdr_name);
2514 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2515 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2516 cur_arg += 2;
2517 } else if (!strcmp(args[cur_arg], "if-none")) {
2518 curproxy->options &= ~PR_O_FF_ALWAYS;
2519 cur_arg += 1;
2520 } else {
2521 /* unknown suboption - catchall */
2522 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2523 file, linenum, args[0], args[1]);
2524 err_code |= ERR_ALERT | ERR_FATAL;
2525 goto out;
2526 }
2527 } /* end while loop */
2528 }
2529 else if (!strcmp(args[1], "originalto")) {
2530 int cur_arg;
2531
2532 /* insert x-original-to field, but not for the IP address listed as an except.
2533 * set default options (ie: bitfield, header name, etc)
2534 */
2535
2536 curproxy->options |= PR_O_ORGTO;
2537
2538 free(curproxy->orgto_hdr_name);
2539 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2540 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2541
2542 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2543 cur_arg = 2;
2544 while (*(args[cur_arg])) {
2545 if (!strcmp(args[cur_arg], "except")) {
2546 /* suboption except - needs additional argument for it */
2547 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2548 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2549 file, linenum, args[0], args[1], args[cur_arg]);
2550 err_code |= ERR_ALERT | ERR_FATAL;
2551 goto out;
2552 }
2553 /* flush useless bits */
2554 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2555 cur_arg += 2;
2556 } else if (!strcmp(args[cur_arg], "header")) {
2557 /* suboption header - needs additional argument for it */
2558 if (*(args[cur_arg+1]) == 0) {
2559 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2560 file, linenum, args[0], args[1], args[cur_arg]);
2561 err_code |= ERR_ALERT | ERR_FATAL;
2562 goto out;
2563 }
2564 free(curproxy->orgto_hdr_name);
2565 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2566 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2567 cur_arg += 2;
2568 } else {
2569 /* unknown suboption - catchall */
2570 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2571 file, linenum, args[0], args[1]);
2572 err_code |= ERR_ALERT | ERR_FATAL;
2573 goto out;
2574 }
2575 } /* end while loop */
2576 }
2577 else {
2578 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2579 err_code |= ERR_ALERT | ERR_FATAL;
2580 goto out;
2581 }
2582 goto out;
2583 }
2584 else if (!strcmp(args[0], "default_backend")) {
2585 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2586 err_code |= ERR_WARN;
2587
2588 if (*(args[1]) == 0) {
2589 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2590 err_code |= ERR_ALERT | ERR_FATAL;
2591 goto out;
2592 }
2593 free(curproxy->defbe.name);
2594 curproxy->defbe.name = strdup(args[1]);
2595
2596 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2597 goto out;
2598 }
2599 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002600 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 +01002601
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002602 err_code |= ERR_ALERT | ERR_FATAL;
2603 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604 }
2605 else if (!strcmp(args[0], "http-reuse")) {
2606 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2607 err_code |= ERR_WARN;
2608
2609 if (strcmp(args[1], "never") == 0) {
2610 /* enable a graceful server shutdown on an HTTP 404 response */
2611 curproxy->options &= ~PR_O_REUSE_MASK;
2612 curproxy->options |= PR_O_REUSE_NEVR;
2613 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2614 goto out;
2615 }
2616 else if (strcmp(args[1], "safe") == 0) {
2617 /* enable a graceful server shutdown on an HTTP 404 response */
2618 curproxy->options &= ~PR_O_REUSE_MASK;
2619 curproxy->options |= PR_O_REUSE_SAFE;
2620 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2621 goto out;
2622 }
2623 else if (strcmp(args[1], "aggressive") == 0) {
2624 curproxy->options &= ~PR_O_REUSE_MASK;
2625 curproxy->options |= PR_O_REUSE_AGGR;
2626 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2627 goto out;
2628 }
2629 else if (strcmp(args[1], "always") == 0) {
2630 /* enable a graceful server shutdown on an HTTP 404 response */
2631 curproxy->options &= ~PR_O_REUSE_MASK;
2632 curproxy->options |= PR_O_REUSE_ALWS;
2633 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2634 goto out;
2635 }
2636 else {
2637 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2638 err_code |= ERR_ALERT | ERR_FATAL;
2639 goto out;
2640 }
2641 }
2642 else if (!strcmp(args[0], "http-check")) {
2643 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2644 err_code |= ERR_WARN;
2645
2646 if (strcmp(args[1], "disable-on-404") == 0) {
2647 /* enable a graceful server shutdown on an HTTP 404 response */
2648 curproxy->options |= PR_O_DISABLE404;
2649 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2650 goto out;
2651 }
2652 else if (strcmp(args[1], "send-state") == 0) {
2653 /* enable emission of the apparent state of a server in HTTP checks */
2654 curproxy->options2 |= PR_O2_CHK_SNDST;
2655 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2656 goto out;
2657 }
Christopher Faulet8acb1282020-04-09 08:44:06 +02002658 else if (strcmp(args[1], "send") == 0) {
2659 int cur_arg = 2;
2660
2661 free(curproxy->check_hdrs);
2662 free(curproxy->check_body);
2663 curproxy->check_hdrs = curproxy->check_body = NULL;
2664 curproxy->check_hdrs_len = curproxy->check_body_len = 0;
2665 while (*(args[cur_arg])) {
2666 if (strcmp(args[cur_arg], "hdr") == 0) {
2667 int hdr_len;
2668 if (!*(args[cur_arg+1]) || !*(args[cur_arg+2])) {
2669 ha_alert("parsing [%s:%d] : '%s %s' : %s expects a name and a value as parameter.\n",
2670 file, linenum, args[0], args[1], args[cur_arg]);
2671 err_code |= ERR_ALERT | ERR_FATAL;
2672 goto out;
2673 }
2674
2675 cur_arg++;
2676 hdr_len = strlen(args[cur_arg]) + strlen(args[cur_arg+1]) + 4;
2677 curproxy->check_hdrs = my_realloc2(curproxy->check_hdrs, curproxy->check_hdrs_len+hdr_len+1);
2678 if (curproxy->check_hdrs == NULL) {
2679 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2680 err_code |= ERR_ALERT | ERR_FATAL;
2681 goto out;
2682 }
2683 snprintf(curproxy->check_hdrs + curproxy->check_hdrs_len, hdr_len+1, "%s: %s\r\n", args[cur_arg], args[cur_arg+1]);
2684 curproxy->check_hdrs_len += hdr_len;
2685
2686 cur_arg++;
2687 }
2688 else if (strcmp(args[cur_arg], "body") == 0) {
2689 if (!*(args[cur_arg+1])) {
2690 ha_alert("parsing [%s:%d] : '%s %s' : %s expects a string as parameter.\n",
2691 file, linenum, args[0], args[1], args[cur_arg]);
2692 err_code |= ERR_ALERT | ERR_FATAL;
2693 goto out;
2694 }
2695 cur_arg++;
2696 free(curproxy->check_body);
2697 curproxy->check_body = strdup(args[cur_arg]);
2698 curproxy->check_body_len = strlen(args[cur_arg]);
2699 if (curproxy->check_body == NULL) {
2700 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2701 err_code |= ERR_ALERT | ERR_FATAL;
2702 goto out;
2703 }
2704 }
2705 else {
2706 ha_alert("parsing [%s:%d] : '%s %s' only supports 'hdr' and 'body', found '%s'.\n",
2707 file, linenum, args[0], args[1], args[cur_arg]);
2708 err_code |= ERR_ALERT | ERR_FATAL;
2709 goto out;
2710 }
2711 cur_arg++;
2712 }
2713
2714 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002715 else if (strcmp(args[1], "expect") == 0) {
2716 const char *ptr_arg;
2717 int cur_arg;
2718
2719 if (curproxy->options2 & PR_O2_EXP_TYPE) {
2720 ha_alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
2721 err_code |= ERR_ALERT | ERR_FATAL;
2722 goto out;
2723 }
2724
2725 cur_arg = 2;
2726 /* consider exclamation marks, sole or at the beginning of a word */
2727 while (*(ptr_arg = args[cur_arg])) {
2728 while (*ptr_arg == '!') {
2729 curproxy->options2 ^= PR_O2_EXP_INV;
2730 ptr_arg++;
2731 }
2732 if (*ptr_arg)
2733 break;
2734 cur_arg++;
2735 }
2736 /* now ptr_arg points to the beginning of a word past any possible
2737 * exclamation mark, and cur_arg is the argument which holds this word.
2738 */
2739 if (strcmp(ptr_arg, "status") == 0) {
2740 if (!*(args[cur_arg + 1])) {
2741 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
2742 file, linenum, args[0], args[1], ptr_arg);
2743 err_code |= ERR_ALERT | ERR_FATAL;
2744 goto out;
2745 }
2746 curproxy->options2 |= PR_O2_EXP_STS;
2747 free(curproxy->expect_str);
2748 curproxy->expect_str = strdup(args[cur_arg + 1]);
2749 }
2750 else if (strcmp(ptr_arg, "string") == 0) {
2751 if (!*(args[cur_arg + 1])) {
2752 ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
2753 file, linenum, args[0], args[1], ptr_arg);
2754 err_code |= ERR_ALERT | ERR_FATAL;
2755 goto out;
2756 }
2757 curproxy->options2 |= PR_O2_EXP_STR;
2758 free(curproxy->expect_str);
2759 curproxy->expect_str = strdup(args[cur_arg + 1]);
2760 }
2761 else if (strcmp(ptr_arg, "rstatus") == 0) {
2762 if (!*(args[cur_arg + 1])) {
2763 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
2764 file, linenum, args[0], args[1], ptr_arg);
2765 err_code |= ERR_ALERT | ERR_FATAL;
2766 goto out;
2767 }
2768 curproxy->options2 |= PR_O2_EXP_RSTS;
2769 free(curproxy->expect_str);
Dragan Dosen26743032019-04-30 15:54:36 +02002770 regex_free(curproxy->expect_regex);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002771 curproxy->expect_str = strdup(args[cur_arg + 1]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002772 error = NULL;
Dragan Dosen26743032019-04-30 15:54:36 +02002773 if (!(curproxy->expect_regex = regex_comp(args[cur_arg + 1], 1, 1, &error))) {
2774 ha_alert("parsing [%s:%d] : '%s %s %s' : regular expression '%s': %s.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002775 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
2776 free(error);
2777 err_code |= ERR_ALERT | ERR_FATAL;
2778 goto out;
2779 }
2780 }
2781 else if (strcmp(ptr_arg, "rstring") == 0) {
2782 if (!*(args[cur_arg + 1])) {
2783 ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
2784 file, linenum, args[0], args[1], ptr_arg);
2785 err_code |= ERR_ALERT | ERR_FATAL;
2786 goto out;
2787 }
2788 curproxy->options2 |= PR_O2_EXP_RSTR;
2789 free(curproxy->expect_str);
Dragan Dosen26743032019-04-30 15:54:36 +02002790 regex_free(curproxy->expect_regex);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002791 curproxy->expect_str = strdup(args[cur_arg + 1]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002792 error = NULL;
Dragan Dosen26743032019-04-30 15:54:36 +02002793 if (!(curproxy->expect_regex = regex_comp(args[cur_arg + 1], 1, 1, &error))) {
2794 ha_alert("parsing [%s:%d] : '%s %s %s' : regular expression '%s': %s.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002795 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
2796 free(error);
2797 err_code |= ERR_ALERT | ERR_FATAL;
2798 goto out;
2799 }
2800 }
2801 else {
2802 ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n",
2803 file, linenum, args[0], args[1], ptr_arg);
2804 err_code |= ERR_ALERT | ERR_FATAL;
2805 goto out;
2806 }
2807 }
2808 else {
2809 ha_alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'send-state', 'expect'.\n", file, linenum, args[0]);
2810 err_code |= ERR_ALERT | ERR_FATAL;
2811 goto out;
2812 }
2813 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002814 else if (!strcmp(args[0], "monitor")) {
2815 if (curproxy == &defproxy) {
2816 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2817 err_code |= ERR_ALERT | ERR_FATAL;
2818 goto out;
2819 }
2820
2821 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2822 err_code |= ERR_WARN;
2823
2824 if (strcmp(args[1], "fail") == 0) {
2825 /* add a condition to fail monitor requests */
2826 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2827 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2828 file, linenum, args[0], args[1]);
2829 err_code |= ERR_ALERT | ERR_FATAL;
2830 goto out;
2831 }
2832
2833 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2834 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2835 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2836 file, linenum, args[0], args[1], errmsg);
2837 err_code |= ERR_ALERT | ERR_FATAL;
2838 goto out;
2839 }
2840 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2841 }
2842 else {
2843 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2844 err_code |= ERR_ALERT | ERR_FATAL;
2845 goto out;
2846 }
2847 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002848#ifdef USE_TPROXY
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002849 else if (!strcmp(args[0], "transparent")) {
2850 /* enable transparent proxy connections */
2851 curproxy->options |= PR_O_TRANSP;
2852 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2853 goto out;
2854 }
2855#endif
2856 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
2857 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2858 err_code |= ERR_WARN;
2859
2860 if (*(args[1]) == 0) {
2861 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2862 err_code |= ERR_ALERT | ERR_FATAL;
2863 goto out;
2864 }
2865 curproxy->maxconn = atol(args[1]);
2866 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2867 goto out;
2868 }
2869 else if (!strcmp(args[0], "backlog")) { /* backlog */
2870 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2871 err_code |= ERR_WARN;
2872
2873 if (*(args[1]) == 0) {
2874 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2875 err_code |= ERR_ALERT | ERR_FATAL;
2876 goto out;
2877 }
2878 curproxy->backlog = atol(args[1]);
2879 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2880 goto out;
2881 }
2882 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
2883 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2884 err_code |= ERR_WARN;
2885
2886 if (*(args[1]) == 0) {
2887 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2888 err_code |= ERR_ALERT | ERR_FATAL;
2889 goto out;
2890 }
2891 curproxy->fullconn = atol(args[1]);
2892 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2893 goto out;
2894 }
2895 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
2896 if (*(args[1]) == 0) {
2897 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2898 err_code |= ERR_ALERT | ERR_FATAL;
2899 goto out;
2900 }
2901 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002902 if (err == PARSE_TIME_OVER) {
2903 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2904 file, linenum, args[1]);
2905 err_code |= ERR_ALERT | ERR_FATAL;
2906 goto out;
2907 }
2908 else if (err == PARSE_TIME_UNDER) {
2909 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2910 file, linenum, args[1]);
2911 err_code |= ERR_ALERT | ERR_FATAL;
2912 goto out;
2913 }
2914 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002915 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2916 file, linenum, *err);
2917 err_code |= ERR_ALERT | ERR_FATAL;
2918 goto out;
2919 }
2920 curproxy->grace = val;
2921 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2922 goto out;
2923 }
2924 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
2925 struct sockaddr_storage *sk;
2926 int port1, port2;
2927 struct protocol *proto;
2928
2929 if (curproxy == &defproxy) {
2930 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2931 err_code |= ERR_ALERT | ERR_FATAL;
2932 goto out;
2933 }
2934 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2935 err_code |= ERR_WARN;
2936
2937 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2938 if (!sk) {
2939 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2940 err_code |= ERR_ALERT | ERR_FATAL;
2941 goto out;
2942 }
2943
2944 proto = protocol_by_family(sk->ss_family);
2945 if (!proto || !proto->connect) {
2946 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2947 file, linenum, args[0], args[1]);
2948 err_code |= ERR_ALERT | ERR_FATAL;
2949 goto out;
2950 }
2951
2952 if (port1 != port2) {
2953 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
2954 file, linenum, args[0], args[1]);
2955 err_code |= ERR_ALERT | ERR_FATAL;
2956 goto out;
2957 }
2958
2959 if (!port1) {
2960 ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
2961 file, linenum, args[0], args[1]);
2962 err_code |= ERR_ALERT | ERR_FATAL;
2963 goto out;
2964 }
2965
2966 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2967 goto out;
2968
2969 curproxy->dispatch_addr = *sk;
2970 curproxy->options |= PR_O_DISPATCH;
2971 }
2972 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
2973 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2974 err_code |= ERR_WARN;
2975
2976 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2977 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2978 err_code |= ERR_ALERT | ERR_FATAL;
2979 goto out;
2980 }
2981 }
2982 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
2983 /**
2984 * The syntax for hash-type config element is
2985 * hash-type {map-based|consistent} [[<algo>] avalanche]
2986 *
2987 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2988 */
2989 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2990
2991 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2992 err_code |= ERR_WARN;
2993
2994 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2995 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2996 }
2997 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2998 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2999 }
3000 else if (strcmp(args[1], "avalanche") == 0) {
3001 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]);
3002 err_code |= ERR_ALERT | ERR_FATAL;
3003 goto out;
3004 }
3005 else {
3006 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
3007 err_code |= ERR_ALERT | ERR_FATAL;
3008 goto out;
3009 }
3010
3011 /* set the hash function to use */
3012 if (!*args[2]) {
3013 /* the default algo is sdbm */
3014 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
3015
3016 /* if consistent with no argument, then avalanche modifier is also applied */
3017 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
3018 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
3019 } else {
3020 /* set the hash function */
3021 if (!strcmp(args[2], "sdbm")) {
3022 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
3023 }
3024 else if (!strcmp(args[2], "djb2")) {
3025 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
3026 }
3027 else if (!strcmp(args[2], "wt6")) {
3028 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
3029 }
3030 else if (!strcmp(args[2], "crc32")) {
3031 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
3032 }
3033 else {
3034 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
3035 err_code |= ERR_ALERT | ERR_FATAL;
3036 goto out;
3037 }
3038
3039 /* set the hash modifier */
3040 if (!strcmp(args[3], "avalanche")) {
3041 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
3042 }
3043 else if (*args[3]) {
3044 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
3045 err_code |= ERR_ALERT | ERR_FATAL;
3046 goto out;
3047 }
3048 }
3049 }
3050 else if (strcmp(args[0], "hash-balance-factor") == 0) {
3051 if (*(args[1]) == 0) {
3052 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
3053 err_code |= ERR_ALERT | ERR_FATAL;
3054 goto out;
3055 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01003056 curproxy->lbprm.hash_balance_factor = atol(args[1]);
3057 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003058 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
3059 err_code |= ERR_ALERT | ERR_FATAL;
3060 goto out;
3061 }
3062 }
3063 else if (strcmp(args[0], "unique-id-format") == 0) {
3064 if (!*(args[1])) {
3065 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
3066 err_code |= ERR_ALERT | ERR_FATAL;
3067 goto out;
3068 }
3069 if (*(args[2])) {
3070 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
3071 err_code |= ERR_ALERT | ERR_FATAL;
3072 goto out;
3073 }
3074 free(curproxy->conf.uniqueid_format_string);
3075 curproxy->conf.uniqueid_format_string = strdup(args[1]);
3076
3077 free(curproxy->conf.uif_file);
3078 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
3079 curproxy->conf.uif_line = curproxy->conf.args.line;
3080 }
3081
3082 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01003083 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003084 if (!*(args[1])) {
3085 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
3086 err_code |= ERR_ALERT | ERR_FATAL;
3087 goto out;
3088 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01003089 copy = strdup(args[1]);
3090 if (copy == NULL) {
3091 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
3092 err_code |= ERR_ALERT | ERR_FATAL;
3093 goto out;
3094 }
3095
3096 istfree(&curproxy->header_unique_id);
3097 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003098 }
3099
3100 else if (strcmp(args[0], "log-format") == 0) {
3101 if (!*(args[1])) {
3102 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
3105 }
3106 if (*(args[2])) {
3107 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
3108 err_code |= ERR_ALERT | ERR_FATAL;
3109 goto out;
3110 }
3111 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
3112 char *oldlogformat = "log-format";
3113
3114 if (curproxy->conf.logformat_string == default_http_log_format)
3115 oldlogformat = "option httplog";
3116 else if (curproxy->conf.logformat_string == default_tcp_log_format)
3117 oldlogformat = "option tcplog";
3118 else if (curproxy->conf.logformat_string == clf_http_log_format)
3119 oldlogformat = "option httplog clf";
3120 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
3121 file, linenum, oldlogformat);
3122 }
3123 if (curproxy->conf.logformat_string != default_http_log_format &&
3124 curproxy->conf.logformat_string != default_tcp_log_format &&
3125 curproxy->conf.logformat_string != clf_http_log_format)
3126 free(curproxy->conf.logformat_string);
3127 curproxy->conf.logformat_string = strdup(args[1]);
3128
3129 free(curproxy->conf.lfs_file);
3130 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
3131 curproxy->conf.lfs_line = curproxy->conf.args.line;
3132
3133 /* get a chance to improve log-format error reporting by
3134 * reporting the correct line-number when possible.
3135 */
3136 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
3137 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
3138 file, linenum, curproxy->id);
3139 err_code |= ERR_WARN;
3140 }
3141 }
3142 else if (!strcmp(args[0], "log-format-sd")) {
3143 if (!*(args[1])) {
3144 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
3145 err_code |= ERR_ALERT | ERR_FATAL;
3146 goto out;
3147 }
3148 if (*(args[2])) {
3149 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
3150 err_code |= ERR_ALERT | ERR_FATAL;
3151 goto out;
3152 }
3153
3154 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
3155 free(curproxy->conf.logformat_sd_string);
3156 curproxy->conf.logformat_sd_string = strdup(args[1]);
3157
3158 free(curproxy->conf.lfsd_file);
3159 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
3160 curproxy->conf.lfsd_line = curproxy->conf.args.line;
3161
3162 /* get a chance to improve log-format-sd error reporting by
3163 * reporting the correct line-number when possible.
3164 */
3165 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
3166 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
3167 file, linenum, curproxy->id);
3168 err_code |= ERR_WARN;
3169 }
3170 }
3171 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
3172 if (*(args[1]) == 0) {
3173 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
3174 err_code |= ERR_ALERT | ERR_FATAL;
3175 goto out;
3176 }
3177 chunk_destroy(&curproxy->log_tag);
3178 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
3179 }
3180 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
3181 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
3182 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
3183 err_code |= ERR_ALERT | ERR_FATAL;
3184 goto out;
3185 }
3186 }
3187 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
3188 int cur_arg;
3189 int port1, port2;
3190 struct sockaddr_storage *sk;
3191 struct protocol *proto;
3192
3193 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3194 err_code |= ERR_WARN;
3195
3196 if (!*args[1]) {
3197 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
3198 file, linenum, "source", "usesrc", "interface");
3199 err_code |= ERR_ALERT | ERR_FATAL;
3200 goto out;
3201 }
3202
Christopher Faulet31930372019-07-15 10:16:58 +02003203 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003204 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
3205 free(curproxy->conn_src.iface_name);
3206 curproxy->conn_src.iface_name = NULL;
3207 curproxy->conn_src.iface_len = 0;
3208
3209 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
3210 if (!sk) {
3211 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
3212 file, linenum, args[0], args[1], errmsg);
3213 err_code |= ERR_ALERT | ERR_FATAL;
3214 goto out;
3215 }
3216
3217 proto = protocol_by_family(sk->ss_family);
3218 if (!proto || !proto->connect) {
3219 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
3220 file, linenum, args[0], args[1]);
3221 err_code |= ERR_ALERT | ERR_FATAL;
3222 goto out;
3223 }
3224
3225 if (port1 != port2) {
3226 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
3227 file, linenum, args[0], args[1]);
3228 err_code |= ERR_ALERT | ERR_FATAL;
3229 goto out;
3230 }
3231
3232 curproxy->conn_src.source_addr = *sk;
3233 curproxy->conn_src.opts |= CO_SRC_BIND;
3234
3235 cur_arg = 2;
3236 while (*(args[cur_arg])) {
3237 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
3238#if defined(CONFIG_HAP_TRANSPARENT)
3239 if (!*args[cur_arg + 1]) {
3240 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
3241 file, linenum, "usesrc");
3242 err_code |= ERR_ALERT | ERR_FATAL;
3243 goto out;
3244 }
3245
3246 if (!strcmp(args[cur_arg + 1], "client")) {
3247 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
3248 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
3249 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
3250 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
3251 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
3252 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
3253 char *name, *end;
3254
3255 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01003256 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003257 name++;
3258
3259 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01003260 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003261 end++;
3262
3263 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
3264 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
3265 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
3266 curproxy->conn_src.bind_hdr_len = end - name;
3267 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
3268 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
3269 curproxy->conn_src.bind_hdr_occ = -1;
3270
3271 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01003272 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003273 end++;
3274 if (*end == ',') {
3275 end++;
3276 name = end;
3277 if (*end == '-')
3278 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01003279 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003280 end++;
3281 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
3282 }
3283
3284 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
3285 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
3286 " occurrences values smaller than %d.\n",
3287 file, linenum, MAX_HDR_HISTORY);
3288 err_code |= ERR_ALERT | ERR_FATAL;
3289 goto out;
3290 }
3291 } else {
3292 struct sockaddr_storage *sk;
3293
3294 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
3295 if (!sk) {
3296 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
3297 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
3298 err_code |= ERR_ALERT | ERR_FATAL;
3299 goto out;
3300 }
3301
3302 proto = protocol_by_family(sk->ss_family);
3303 if (!proto || !proto->connect) {
3304 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
3305 file, linenum, args[cur_arg], args[cur_arg+1]);
3306 err_code |= ERR_ALERT | ERR_FATAL;
3307 goto out;
3308 }
3309
3310 if (port1 != port2) {
3311 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
3312 file, linenum, args[cur_arg], args[cur_arg + 1]);
3313 err_code |= ERR_ALERT | ERR_FATAL;
3314 goto out;
3315 }
3316 curproxy->conn_src.tproxy_addr = *sk;
3317 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3318 }
3319 global.last_checks |= LSTCHK_NETADM;
3320#else /* no TPROXY support */
3321 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3322 file, linenum, "usesrc");
3323 err_code |= ERR_ALERT | ERR_FATAL;
3324 goto out;
3325#endif
3326 cur_arg += 2;
3327 continue;
3328 }
3329
3330 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
3331#ifdef SO_BINDTODEVICE
3332 if (!*args[cur_arg + 1]) {
3333 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3334 file, linenum, args[0]);
3335 err_code |= ERR_ALERT | ERR_FATAL;
3336 goto out;
3337 }
3338 free(curproxy->conn_src.iface_name);
3339 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
3340 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3341 global.last_checks |= LSTCHK_NETADM;
3342#else
3343 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3344 file, linenum, args[0], args[cur_arg]);
3345 err_code |= ERR_ALERT | ERR_FATAL;
3346 goto out;
3347#endif
3348 cur_arg += 2;
3349 continue;
3350 }
3351 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3352 file, linenum, args[0], "interface", "usesrc");
3353 err_code |= ERR_ALERT | ERR_FATAL;
3354 goto out;
3355 }
3356 }
3357 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
3358 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3359 file, linenum, "usesrc", "source");
3360 err_code |= ERR_ALERT | ERR_FATAL;
3361 goto out;
3362 }
3363 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003364 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003365 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003366 file, linenum, args[0]);
3367 err_code |= ERR_ALERT | ERR_FATAL;
3368 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003369 }
3370 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003371 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3372 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3373 err_code |= ERR_ALERT | ERR_FATAL;
3374 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003375 }
3376 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003377 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3378 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3379 err_code |= ERR_ALERT | ERR_FATAL;
3380 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003381 }
3382 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003383 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3384 err_code |= ERR_ALERT | ERR_FATAL;
3385 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003386 }
3387 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003388 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3389 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3390 err_code |= ERR_ALERT | ERR_FATAL;
3391 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003392 }
3393 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003394 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3395 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3396 err_code |= ERR_ALERT | ERR_FATAL;
3397 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003398 }
3399 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003400 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3401 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3402 err_code |= ERR_ALERT | ERR_FATAL;
3403 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003404 }
3405 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003406 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3407 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3408 err_code |= ERR_ALERT | ERR_FATAL;
3409 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003410 }
3411 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003412 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3413 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3414 err_code |= ERR_ALERT | ERR_FATAL;
3415 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003416 }
3417 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003418 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3419 err_code |= ERR_ALERT | ERR_FATAL;
3420 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003421 }
3422 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003423 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3424 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3425 err_code |= ERR_ALERT | ERR_FATAL;
3426 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003427 }
3428 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003429 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3430 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3431 err_code |= ERR_ALERT | ERR_FATAL;
3432 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003433 }
3434 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003435 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3436 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3437 err_code |= ERR_ALERT | ERR_FATAL;
3438 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003439 }
3440 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003441 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3442 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3443 err_code |= ERR_ALERT | ERR_FATAL;
3444 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003445 }
3446 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003447 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3448 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3449 err_code |= ERR_ALERT | ERR_FATAL;
3450 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003451 }
3452 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003453 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3454 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3455 err_code |= ERR_ALERT | ERR_FATAL;
3456 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003457 }
3458 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303459 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003460 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3461 err_code |= ERR_ALERT | ERR_FATAL;
3462 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003463 }
3464 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003465 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3466 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3467 err_code |= ERR_ALERT | ERR_FATAL;
3468 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003469 }
3470 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003471 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3472 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3473 err_code |= ERR_ALERT | ERR_FATAL;
3474 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003475 }
3476 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003477 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3478 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3479 err_code |= ERR_ALERT | ERR_FATAL;
3480 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003481 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003482 else {
3483 struct cfg_kw_list *kwl;
3484 int index;
3485
3486 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3487 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3488 if (kwl->kw[index].section != CFG_LISTEN)
3489 continue;
3490 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3491 /* prepare error message just in case */
3492 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
3493 if (rc < 0) {
3494 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3495 err_code |= ERR_ALERT | ERR_FATAL;
3496 goto out;
3497 }
3498 else if (rc > 0) {
3499 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3500 err_code |= ERR_WARN;
3501 goto out;
3502 }
3503 goto out;
3504 }
3505 }
3506 }
3507
3508 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
3509 err_code |= ERR_ALERT | ERR_FATAL;
3510 goto out;
3511 }
3512 out:
3513 free(errmsg);
3514 return err_code;
3515}