blob: 7b33eb06f7445e64ab526b9d5dc9a6e406758d82 [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")) {
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002333 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2334 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002335 goto out;
2336 }
2337 else if (!strcmp(args[1], "ssl-hello-chk")) {
Christopher Faulet811f78c2020-04-01 11:10:27 +02002338 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum);
2339 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002340 goto out;
2341 }
2342 else if (!strcmp(args[1], "smtpchk")) {
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002343 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2344 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002345 goto out;
2346 }
2347 else if (!strcmp(args[1], "pgsql-check")) {
Christopher Fauletce355072020-04-02 11:44:39 +02002348 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2349 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002350 goto out;
2351 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002352 else if (!strcmp(args[1], "redis-check")) {
Christopher Faulet33f05df2020-04-01 11:08:50 +02002353 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2354 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002355 goto out;
2356 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002357 else if (!strcmp(args[1], "mysql-check")) {
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002358 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2359 if (err_code & ERR_FATAL)
2360 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002361 }
2362 else if (!strcmp(args[1], "ldap-check")) {
Christopher Faulet1997eca2020-04-03 23:13:50 +02002363 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2364 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002365 goto out;
2366 }
2367 else if (!strcmp(args[1], "spop-check")) {
Christopher Faulet267b01b2020-04-04 10:27:09 +02002368 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2369 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002370 goto out;
2371 }
2372 else if (!strcmp(args[1], "tcp-check")) {
Christopher Faulet430e4802020-04-09 15:28:16 +02002373 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2374 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002375 goto out;
2376 }
2377 else if (!strcmp(args[1], "external-check")) {
2378 /* excute an external command to check servers' health */
2379 free(curproxy->check_req);
2380 curproxy->check_req = NULL;
2381 curproxy->options2 &= ~PR_O2_CHK_ANY;
2382 curproxy->options2 |= PR_O2_EXT_CHK;
2383 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2384 goto out;
2385 }
2386 else if (!strcmp(args[1], "forwardfor")) {
2387 int cur_arg;
2388
2389 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002390 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002391 */
2392
2393 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2394
2395 free(curproxy->fwdfor_hdr_name);
2396 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2397 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2398
2399 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2400 cur_arg = 2;
2401 while (*(args[cur_arg])) {
2402 if (!strcmp(args[cur_arg], "except")) {
2403 /* suboption except - needs additional argument for it */
2404 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2405 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2406 file, linenum, args[0], args[1], args[cur_arg]);
2407 err_code |= ERR_ALERT | ERR_FATAL;
2408 goto out;
2409 }
2410 /* flush useless bits */
2411 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2412 cur_arg += 2;
2413 } else if (!strcmp(args[cur_arg], "header")) {
2414 /* suboption header - needs additional argument for it */
2415 if (*(args[cur_arg+1]) == 0) {
2416 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2417 file, linenum, args[0], args[1], args[cur_arg]);
2418 err_code |= ERR_ALERT | ERR_FATAL;
2419 goto out;
2420 }
2421 free(curproxy->fwdfor_hdr_name);
2422 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2423 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2424 cur_arg += 2;
2425 } else if (!strcmp(args[cur_arg], "if-none")) {
2426 curproxy->options &= ~PR_O_FF_ALWAYS;
2427 cur_arg += 1;
2428 } else {
2429 /* unknown suboption - catchall */
2430 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2431 file, linenum, args[0], args[1]);
2432 err_code |= ERR_ALERT | ERR_FATAL;
2433 goto out;
2434 }
2435 } /* end while loop */
2436 }
2437 else if (!strcmp(args[1], "originalto")) {
2438 int cur_arg;
2439
2440 /* insert x-original-to field, but not for the IP address listed as an except.
2441 * set default options (ie: bitfield, header name, etc)
2442 */
2443
2444 curproxy->options |= PR_O_ORGTO;
2445
2446 free(curproxy->orgto_hdr_name);
2447 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2448 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2449
2450 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2451 cur_arg = 2;
2452 while (*(args[cur_arg])) {
2453 if (!strcmp(args[cur_arg], "except")) {
2454 /* suboption except - needs additional argument for it */
2455 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2456 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2457 file, linenum, args[0], args[1], args[cur_arg]);
2458 err_code |= ERR_ALERT | ERR_FATAL;
2459 goto out;
2460 }
2461 /* flush useless bits */
2462 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2463 cur_arg += 2;
2464 } else if (!strcmp(args[cur_arg], "header")) {
2465 /* suboption header - needs additional argument for it */
2466 if (*(args[cur_arg+1]) == 0) {
2467 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2468 file, linenum, args[0], args[1], args[cur_arg]);
2469 err_code |= ERR_ALERT | ERR_FATAL;
2470 goto out;
2471 }
2472 free(curproxy->orgto_hdr_name);
2473 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2474 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2475 cur_arg += 2;
2476 } else {
2477 /* unknown suboption - catchall */
2478 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2479 file, linenum, args[0], args[1]);
2480 err_code |= ERR_ALERT | ERR_FATAL;
2481 goto out;
2482 }
2483 } /* end while loop */
2484 }
2485 else {
2486 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2487 err_code |= ERR_ALERT | ERR_FATAL;
2488 goto out;
2489 }
2490 goto out;
2491 }
2492 else if (!strcmp(args[0], "default_backend")) {
2493 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2494 err_code |= ERR_WARN;
2495
2496 if (*(args[1]) == 0) {
2497 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2498 err_code |= ERR_ALERT | ERR_FATAL;
2499 goto out;
2500 }
2501 free(curproxy->defbe.name);
2502 curproxy->defbe.name = strdup(args[1]);
2503
2504 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2505 goto out;
2506 }
2507 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002508 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 +01002509
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002510 err_code |= ERR_ALERT | ERR_FATAL;
2511 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002512 }
2513 else if (!strcmp(args[0], "http-reuse")) {
2514 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2515 err_code |= ERR_WARN;
2516
2517 if (strcmp(args[1], "never") == 0) {
2518 /* enable a graceful server shutdown on an HTTP 404 response */
2519 curproxy->options &= ~PR_O_REUSE_MASK;
2520 curproxy->options |= PR_O_REUSE_NEVR;
2521 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2522 goto out;
2523 }
2524 else if (strcmp(args[1], "safe") == 0) {
2525 /* enable a graceful server shutdown on an HTTP 404 response */
2526 curproxy->options &= ~PR_O_REUSE_MASK;
2527 curproxy->options |= PR_O_REUSE_SAFE;
2528 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2529 goto out;
2530 }
2531 else if (strcmp(args[1], "aggressive") == 0) {
2532 curproxy->options &= ~PR_O_REUSE_MASK;
2533 curproxy->options |= PR_O_REUSE_AGGR;
2534 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2535 goto out;
2536 }
2537 else if (strcmp(args[1], "always") == 0) {
2538 /* enable a graceful server shutdown on an HTTP 404 response */
2539 curproxy->options &= ~PR_O_REUSE_MASK;
2540 curproxy->options |= PR_O_REUSE_ALWS;
2541 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2542 goto out;
2543 }
2544 else {
2545 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2546 err_code |= ERR_ALERT | ERR_FATAL;
2547 goto out;
2548 }
2549 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002550 else if (!strcmp(args[0], "monitor")) {
2551 if (curproxy == &defproxy) {
2552 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2553 err_code |= ERR_ALERT | ERR_FATAL;
2554 goto out;
2555 }
2556
2557 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2558 err_code |= ERR_WARN;
2559
2560 if (strcmp(args[1], "fail") == 0) {
2561 /* add a condition to fail monitor requests */
2562 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2563 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2564 file, linenum, args[0], args[1]);
2565 err_code |= ERR_ALERT | ERR_FATAL;
2566 goto out;
2567 }
2568
2569 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2570 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2571 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2572 file, linenum, args[0], args[1], errmsg);
2573 err_code |= ERR_ALERT | ERR_FATAL;
2574 goto out;
2575 }
2576 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2577 }
2578 else {
2579 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2580 err_code |= ERR_ALERT | ERR_FATAL;
2581 goto out;
2582 }
2583 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002584#ifdef USE_TPROXY
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002585 else if (!strcmp(args[0], "transparent")) {
2586 /* enable transparent proxy connections */
2587 curproxy->options |= PR_O_TRANSP;
2588 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2589 goto out;
2590 }
2591#endif
2592 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
2593 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2594 err_code |= ERR_WARN;
2595
2596 if (*(args[1]) == 0) {
2597 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2598 err_code |= ERR_ALERT | ERR_FATAL;
2599 goto out;
2600 }
2601 curproxy->maxconn = atol(args[1]);
2602 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2603 goto out;
2604 }
2605 else if (!strcmp(args[0], "backlog")) { /* backlog */
2606 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2607 err_code |= ERR_WARN;
2608
2609 if (*(args[1]) == 0) {
2610 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2611 err_code |= ERR_ALERT | ERR_FATAL;
2612 goto out;
2613 }
2614 curproxy->backlog = atol(args[1]);
2615 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2616 goto out;
2617 }
2618 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
2619 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2620 err_code |= ERR_WARN;
2621
2622 if (*(args[1]) == 0) {
2623 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2624 err_code |= ERR_ALERT | ERR_FATAL;
2625 goto out;
2626 }
2627 curproxy->fullconn = atol(args[1]);
2628 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2629 goto out;
2630 }
2631 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
2632 if (*(args[1]) == 0) {
2633 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2634 err_code |= ERR_ALERT | ERR_FATAL;
2635 goto out;
2636 }
2637 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002638 if (err == PARSE_TIME_OVER) {
2639 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2640 file, linenum, args[1]);
2641 err_code |= ERR_ALERT | ERR_FATAL;
2642 goto out;
2643 }
2644 else if (err == PARSE_TIME_UNDER) {
2645 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2646 file, linenum, args[1]);
2647 err_code |= ERR_ALERT | ERR_FATAL;
2648 goto out;
2649 }
2650 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002651 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2652 file, linenum, *err);
2653 err_code |= ERR_ALERT | ERR_FATAL;
2654 goto out;
2655 }
2656 curproxy->grace = val;
2657 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2658 goto out;
2659 }
2660 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
2661 struct sockaddr_storage *sk;
2662 int port1, port2;
2663 struct protocol *proto;
2664
2665 if (curproxy == &defproxy) {
2666 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2667 err_code |= ERR_ALERT | ERR_FATAL;
2668 goto out;
2669 }
2670 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2671 err_code |= ERR_WARN;
2672
2673 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2674 if (!sk) {
2675 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2676 err_code |= ERR_ALERT | ERR_FATAL;
2677 goto out;
2678 }
2679
2680 proto = protocol_by_family(sk->ss_family);
2681 if (!proto || !proto->connect) {
2682 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2683 file, linenum, args[0], args[1]);
2684 err_code |= ERR_ALERT | ERR_FATAL;
2685 goto out;
2686 }
2687
2688 if (port1 != port2) {
2689 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
2690 file, linenum, args[0], args[1]);
2691 err_code |= ERR_ALERT | ERR_FATAL;
2692 goto out;
2693 }
2694
2695 if (!port1) {
2696 ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
2697 file, linenum, args[0], args[1]);
2698 err_code |= ERR_ALERT | ERR_FATAL;
2699 goto out;
2700 }
2701
2702 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2703 goto out;
2704
2705 curproxy->dispatch_addr = *sk;
2706 curproxy->options |= PR_O_DISPATCH;
2707 }
2708 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
2709 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2710 err_code |= ERR_WARN;
2711
2712 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2713 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2714 err_code |= ERR_ALERT | ERR_FATAL;
2715 goto out;
2716 }
2717 }
2718 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
2719 /**
2720 * The syntax for hash-type config element is
2721 * hash-type {map-based|consistent} [[<algo>] avalanche]
2722 *
2723 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2724 */
2725 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2726
2727 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2728 err_code |= ERR_WARN;
2729
2730 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2731 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2732 }
2733 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2734 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2735 }
2736 else if (strcmp(args[1], "avalanche") == 0) {
2737 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]);
2738 err_code |= ERR_ALERT | ERR_FATAL;
2739 goto out;
2740 }
2741 else {
2742 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2743 err_code |= ERR_ALERT | ERR_FATAL;
2744 goto out;
2745 }
2746
2747 /* set the hash function to use */
2748 if (!*args[2]) {
2749 /* the default algo is sdbm */
2750 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2751
2752 /* if consistent with no argument, then avalanche modifier is also applied */
2753 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2754 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2755 } else {
2756 /* set the hash function */
2757 if (!strcmp(args[2], "sdbm")) {
2758 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2759 }
2760 else if (!strcmp(args[2], "djb2")) {
2761 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2762 }
2763 else if (!strcmp(args[2], "wt6")) {
2764 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2765 }
2766 else if (!strcmp(args[2], "crc32")) {
2767 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2768 }
2769 else {
2770 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2771 err_code |= ERR_ALERT | ERR_FATAL;
2772 goto out;
2773 }
2774
2775 /* set the hash modifier */
2776 if (!strcmp(args[3], "avalanche")) {
2777 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2778 }
2779 else if (*args[3]) {
2780 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2781 err_code |= ERR_ALERT | ERR_FATAL;
2782 goto out;
2783 }
2784 }
2785 }
2786 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2787 if (*(args[1]) == 0) {
2788 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2789 err_code |= ERR_ALERT | ERR_FATAL;
2790 goto out;
2791 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002792 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2793 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002794 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2795 err_code |= ERR_ALERT | ERR_FATAL;
2796 goto out;
2797 }
2798 }
2799 else if (strcmp(args[0], "unique-id-format") == 0) {
2800 if (!*(args[1])) {
2801 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2802 err_code |= ERR_ALERT | ERR_FATAL;
2803 goto out;
2804 }
2805 if (*(args[2])) {
2806 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2807 err_code |= ERR_ALERT | ERR_FATAL;
2808 goto out;
2809 }
2810 free(curproxy->conf.uniqueid_format_string);
2811 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2812
2813 free(curproxy->conf.uif_file);
2814 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2815 curproxy->conf.uif_line = curproxy->conf.args.line;
2816 }
2817
2818 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002819 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002820 if (!*(args[1])) {
2821 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2822 err_code |= ERR_ALERT | ERR_FATAL;
2823 goto out;
2824 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002825 copy = strdup(args[1]);
2826 if (copy == NULL) {
2827 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2828 err_code |= ERR_ALERT | ERR_FATAL;
2829 goto out;
2830 }
2831
2832 istfree(&curproxy->header_unique_id);
2833 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002834 }
2835
2836 else if (strcmp(args[0], "log-format") == 0) {
2837 if (!*(args[1])) {
2838 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2839 err_code |= ERR_ALERT | ERR_FATAL;
2840 goto out;
2841 }
2842 if (*(args[2])) {
2843 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2844 err_code |= ERR_ALERT | ERR_FATAL;
2845 goto out;
2846 }
2847 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2848 char *oldlogformat = "log-format";
2849
2850 if (curproxy->conf.logformat_string == default_http_log_format)
2851 oldlogformat = "option httplog";
2852 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2853 oldlogformat = "option tcplog";
2854 else if (curproxy->conf.logformat_string == clf_http_log_format)
2855 oldlogformat = "option httplog clf";
2856 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2857 file, linenum, oldlogformat);
2858 }
2859 if (curproxy->conf.logformat_string != default_http_log_format &&
2860 curproxy->conf.logformat_string != default_tcp_log_format &&
2861 curproxy->conf.logformat_string != clf_http_log_format)
2862 free(curproxy->conf.logformat_string);
2863 curproxy->conf.logformat_string = strdup(args[1]);
2864
2865 free(curproxy->conf.lfs_file);
2866 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2867 curproxy->conf.lfs_line = curproxy->conf.args.line;
2868
2869 /* get a chance to improve log-format error reporting by
2870 * reporting the correct line-number when possible.
2871 */
2872 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2873 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2874 file, linenum, curproxy->id);
2875 err_code |= ERR_WARN;
2876 }
2877 }
2878 else if (!strcmp(args[0], "log-format-sd")) {
2879 if (!*(args[1])) {
2880 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2881 err_code |= ERR_ALERT | ERR_FATAL;
2882 goto out;
2883 }
2884 if (*(args[2])) {
2885 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2886 err_code |= ERR_ALERT | ERR_FATAL;
2887 goto out;
2888 }
2889
2890 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2891 free(curproxy->conf.logformat_sd_string);
2892 curproxy->conf.logformat_sd_string = strdup(args[1]);
2893
2894 free(curproxy->conf.lfsd_file);
2895 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2896 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2897
2898 /* get a chance to improve log-format-sd error reporting by
2899 * reporting the correct line-number when possible.
2900 */
2901 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2902 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2903 file, linenum, curproxy->id);
2904 err_code |= ERR_WARN;
2905 }
2906 }
2907 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
2908 if (*(args[1]) == 0) {
2909 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2910 err_code |= ERR_ALERT | ERR_FATAL;
2911 goto out;
2912 }
2913 chunk_destroy(&curproxy->log_tag);
2914 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
2915 }
2916 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
2917 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2918 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2919 err_code |= ERR_ALERT | ERR_FATAL;
2920 goto out;
2921 }
2922 }
2923 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
2924 int cur_arg;
2925 int port1, port2;
2926 struct sockaddr_storage *sk;
2927 struct protocol *proto;
2928
2929 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2930 err_code |= ERR_WARN;
2931
2932 if (!*args[1]) {
2933 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2934 file, linenum, "source", "usesrc", "interface");
2935 err_code |= ERR_ALERT | ERR_FATAL;
2936 goto out;
2937 }
2938
Christopher Faulet31930372019-07-15 10:16:58 +02002939 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002940 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2941 free(curproxy->conn_src.iface_name);
2942 curproxy->conn_src.iface_name = NULL;
2943 curproxy->conn_src.iface_len = 0;
2944
2945 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2946 if (!sk) {
2947 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2948 file, linenum, args[0], args[1], errmsg);
2949 err_code |= ERR_ALERT | ERR_FATAL;
2950 goto out;
2951 }
2952
2953 proto = protocol_by_family(sk->ss_family);
2954 if (!proto || !proto->connect) {
2955 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2956 file, linenum, args[0], args[1]);
2957 err_code |= ERR_ALERT | ERR_FATAL;
2958 goto out;
2959 }
2960
2961 if (port1 != port2) {
2962 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
2963 file, linenum, args[0], args[1]);
2964 err_code |= ERR_ALERT | ERR_FATAL;
2965 goto out;
2966 }
2967
2968 curproxy->conn_src.source_addr = *sk;
2969 curproxy->conn_src.opts |= CO_SRC_BIND;
2970
2971 cur_arg = 2;
2972 while (*(args[cur_arg])) {
2973 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
2974#if defined(CONFIG_HAP_TRANSPARENT)
2975 if (!*args[cur_arg + 1]) {
2976 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2977 file, linenum, "usesrc");
2978 err_code |= ERR_ALERT | ERR_FATAL;
2979 goto out;
2980 }
2981
2982 if (!strcmp(args[cur_arg + 1], "client")) {
2983 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2984 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
2985 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
2986 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2987 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2988 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2989 char *name, *end;
2990
2991 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002992 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002993 name++;
2994
2995 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002996 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002997 end++;
2998
2999 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
3000 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
3001 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
3002 curproxy->conn_src.bind_hdr_len = end - name;
3003 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
3004 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
3005 curproxy->conn_src.bind_hdr_occ = -1;
3006
3007 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01003008 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003009 end++;
3010 if (*end == ',') {
3011 end++;
3012 name = end;
3013 if (*end == '-')
3014 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01003015 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003016 end++;
3017 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
3018 }
3019
3020 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
3021 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
3022 " occurrences values smaller than %d.\n",
3023 file, linenum, MAX_HDR_HISTORY);
3024 err_code |= ERR_ALERT | ERR_FATAL;
3025 goto out;
3026 }
3027 } else {
3028 struct sockaddr_storage *sk;
3029
3030 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
3031 if (!sk) {
3032 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
3033 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
3034 err_code |= ERR_ALERT | ERR_FATAL;
3035 goto out;
3036 }
3037
3038 proto = protocol_by_family(sk->ss_family);
3039 if (!proto || !proto->connect) {
3040 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
3041 file, linenum, args[cur_arg], args[cur_arg+1]);
3042 err_code |= ERR_ALERT | ERR_FATAL;
3043 goto out;
3044 }
3045
3046 if (port1 != port2) {
3047 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
3048 file, linenum, args[cur_arg], args[cur_arg + 1]);
3049 err_code |= ERR_ALERT | ERR_FATAL;
3050 goto out;
3051 }
3052 curproxy->conn_src.tproxy_addr = *sk;
3053 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3054 }
3055 global.last_checks |= LSTCHK_NETADM;
3056#else /* no TPROXY support */
3057 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3058 file, linenum, "usesrc");
3059 err_code |= ERR_ALERT | ERR_FATAL;
3060 goto out;
3061#endif
3062 cur_arg += 2;
3063 continue;
3064 }
3065
3066 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
3067#ifdef SO_BINDTODEVICE
3068 if (!*args[cur_arg + 1]) {
3069 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3070 file, linenum, args[0]);
3071 err_code |= ERR_ALERT | ERR_FATAL;
3072 goto out;
3073 }
3074 free(curproxy->conn_src.iface_name);
3075 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
3076 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3077 global.last_checks |= LSTCHK_NETADM;
3078#else
3079 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3080 file, linenum, args[0], args[cur_arg]);
3081 err_code |= ERR_ALERT | ERR_FATAL;
3082 goto out;
3083#endif
3084 cur_arg += 2;
3085 continue;
3086 }
3087 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3088 file, linenum, args[0], "interface", "usesrc");
3089 err_code |= ERR_ALERT | ERR_FATAL;
3090 goto out;
3091 }
3092 }
3093 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
3094 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3095 file, linenum, "usesrc", "source");
3096 err_code |= ERR_ALERT | ERR_FATAL;
3097 goto out;
3098 }
3099 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003100 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003101 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003102 file, linenum, args[0]);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003105 }
3106 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003107 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3108 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3109 err_code |= ERR_ALERT | ERR_FATAL;
3110 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003111 }
3112 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003113 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3114 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3115 err_code |= ERR_ALERT | ERR_FATAL;
3116 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003117 }
3118 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003119 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3120 err_code |= ERR_ALERT | ERR_FATAL;
3121 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003122 }
3123 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003124 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3125 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3126 err_code |= ERR_ALERT | ERR_FATAL;
3127 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003128 }
3129 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003130 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3131 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3132 err_code |= ERR_ALERT | ERR_FATAL;
3133 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003134 }
3135 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003136 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3137 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3138 err_code |= ERR_ALERT | ERR_FATAL;
3139 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003140 }
3141 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003142 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3143 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3144 err_code |= ERR_ALERT | ERR_FATAL;
3145 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003146 }
3147 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003148 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3149 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3150 err_code |= ERR_ALERT | ERR_FATAL;
3151 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003152 }
3153 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003154 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3155 err_code |= ERR_ALERT | ERR_FATAL;
3156 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003157 }
3158 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003159 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3160 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3161 err_code |= ERR_ALERT | ERR_FATAL;
3162 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003163 }
3164 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003165 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3166 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3167 err_code |= ERR_ALERT | ERR_FATAL;
3168 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003169 }
3170 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003171 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3172 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3173 err_code |= ERR_ALERT | ERR_FATAL;
3174 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003175 }
3176 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003177 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3178 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3179 err_code |= ERR_ALERT | ERR_FATAL;
3180 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003181 }
3182 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003183 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3184 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3185 err_code |= ERR_ALERT | ERR_FATAL;
3186 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003187 }
3188 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003189 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3190 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3191 err_code |= ERR_ALERT | ERR_FATAL;
3192 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003193 }
3194 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303195 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003196 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3197 err_code |= ERR_ALERT | ERR_FATAL;
3198 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003199 }
3200 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003201 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3202 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3203 err_code |= ERR_ALERT | ERR_FATAL;
3204 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003205 }
3206 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003207 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3208 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3209 err_code |= ERR_ALERT | ERR_FATAL;
3210 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003211 }
3212 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003213 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3214 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3215 err_code |= ERR_ALERT | ERR_FATAL;
3216 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003217 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003218 else {
3219 struct cfg_kw_list *kwl;
3220 int index;
3221
3222 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3223 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3224 if (kwl->kw[index].section != CFG_LISTEN)
3225 continue;
3226 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3227 /* prepare error message just in case */
3228 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
3229 if (rc < 0) {
3230 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3231 err_code |= ERR_ALERT | ERR_FATAL;
3232 goto out;
3233 }
3234 else if (rc > 0) {
3235 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3236 err_code |= ERR_WARN;
3237 goto out;
3238 }
3239 goto out;
3240 }
3241 }
3242 }
3243
3244 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
3245 err_code |= ERR_ALERT | ERR_FATAL;
3246 goto out;
3247 }
3248 out:
3249 free(errmsg);
3250 return err_code;
3251}