blob: 3a7050e45573f4c46e3e77af34ac2b950d40d31f [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 Faulet404f9192020-04-09 23:13:54 +0200306 curproxy->tcpcheck_rules.flags = (defproxy.tcpcheck_rules.flags & ~TCPCHK_RULES_UNUSED_TCP_RS);
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200307 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")) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001153 else if (!strcmp(args[0], "persist")) { /* persist */
1154 if (*(args[1]) == 0) {
1155 ha_alert("parsing [%s:%d] : missing persist method.\n",
1156 file, linenum);
1157 err_code |= ERR_ALERT | ERR_FATAL;
1158 goto out;
1159 }
1160
1161 if (!strncmp(args[1], "rdp-cookie", 10)) {
1162 curproxy->options2 |= PR_O2_RDPC_PRST;
1163
1164 if (*(args[1] + 10) == '(') { /* cookie name */
1165 const char *beg, *end;
1166
1167 beg = args[1] + 11;
1168 end = strchr(beg, ')');
1169
1170 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1171 goto out;
1172
1173 if (!end || end == beg) {
1174 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1175 file, linenum);
1176 err_code |= ERR_ALERT | ERR_FATAL;
1177 goto out;
1178 }
1179
1180 free(curproxy->rdp_cookie_name);
1181 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
1182 curproxy->rdp_cookie_len = end-beg;
1183 }
1184 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1185 free(curproxy->rdp_cookie_name);
1186 curproxy->rdp_cookie_name = strdup("msts");
1187 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1188 }
1189 else { /* syntax */
1190 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1191 file, linenum);
1192 err_code |= ERR_ALERT | ERR_FATAL;
1193 goto out;
1194 }
1195 }
1196 else {
1197 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1198 file, linenum);
1199 err_code |= ERR_ALERT | ERR_FATAL;
1200 goto out;
1201 }
1202 }
1203 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001204 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 +01001205 err_code |= ERR_ALERT | ERR_FATAL;
1206 goto out;
1207 }
1208 else if (!strcmp(args[0], "load-server-state-from-file")) {
1209 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1210 err_code |= ERR_WARN;
1211 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
1212 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1213 }
1214 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
1215 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1216 }
1217 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
1218 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1219 }
1220 else {
1221 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1222 file, linenum, args[0], args[1]);
1223 err_code |= ERR_ALERT | ERR_FATAL;
1224 goto out;
1225 }
1226 }
1227 else if (!strcmp(args[0], "server-state-file-name")) {
1228 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1229 err_code |= ERR_WARN;
1230 if (*(args[1]) == 0) {
1231 ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
1232 file, linenum, args[0]);
1233 err_code |= ERR_ALERT | ERR_FATAL;
1234 goto out;
1235 }
1236 else if (!strcmp(args[1], "use-backend-name"))
1237 curproxy->server_state_file_name = strdup(curproxy->id);
1238 else
1239 curproxy->server_state_file_name = strdup(args[1]);
1240 }
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001241 else if (!strcmp(args[0], "max-session-srv-conns")) {
1242 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1243 err_code |= ERR_WARN;
1244 if (*(args[1]) == 0) {
1245 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1246 file, linenum, args[0]);
1247 err_code |= ERR_ALERT | ERR_FATAL;
1248 goto out;
1249 }
1250 curproxy->max_out_conns = atoi(args[1]);
1251 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001252 else if (!strcmp(args[0], "capture")) {
1253 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1254 err_code |= ERR_WARN;
1255
1256 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
1257 if (curproxy == &defproxy) {
1258 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1259 err_code |= ERR_ALERT | ERR_FATAL;
1260 goto out;
1261 }
1262
1263 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1264 goto out;
1265
1266 if (*(args[4]) == 0) {
1267 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1268 file, linenum, args[0]);
1269 err_code |= ERR_ALERT | ERR_FATAL;
1270 goto out;
1271 }
1272 free(curproxy->capture_name);
1273 curproxy->capture_name = strdup(args[2]);
1274 curproxy->capture_namelen = strlen(curproxy->capture_name);
1275 curproxy->capture_len = atol(args[4]);
1276 curproxy->to_log |= LW_COOKIE;
1277 }
1278 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
1279 struct cap_hdr *hdr;
1280
1281 if (curproxy == &defproxy) {
1282 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1283 err_code |= ERR_ALERT | ERR_FATAL;
1284 goto out;
1285 }
1286
1287 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1288 goto out;
1289
1290 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1291 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1292 file, linenum, args[0], args[1]);
1293 err_code |= ERR_ALERT | ERR_FATAL;
1294 goto out;
1295 }
1296
1297 hdr = calloc(1, sizeof(*hdr));
1298 hdr->next = curproxy->req_cap;
1299 hdr->name = strdup(args[3]);
1300 hdr->namelen = strlen(args[3]);
1301 hdr->len = atol(args[5]);
1302 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1303 hdr->index = curproxy->nb_req_cap++;
1304 curproxy->req_cap = hdr;
1305 curproxy->to_log |= LW_REQHDR;
1306 }
1307 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
1308 struct cap_hdr *hdr;
1309
1310 if (curproxy == &defproxy) {
1311 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1312 err_code |= ERR_ALERT | ERR_FATAL;
1313 goto out;
1314 }
1315
1316 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1317 goto out;
1318
1319 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1320 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1321 file, linenum, args[0], args[1]);
1322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325 hdr = calloc(1, sizeof(*hdr));
1326 hdr->next = curproxy->rsp_cap;
1327 hdr->name = strdup(args[3]);
1328 hdr->namelen = strlen(args[3]);
1329 hdr->len = atol(args[5]);
1330 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1331 hdr->index = curproxy->nb_rsp_cap++;
1332 curproxy->rsp_cap = hdr;
1333 curproxy->to_log |= LW_RSPHDR;
1334 }
1335 else {
1336 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1337 file, linenum, args[0]);
1338 err_code |= ERR_ALERT | ERR_FATAL;
1339 goto out;
1340 }
1341 }
1342 else if (!strcmp(args[0], "retries")) { /* connection retries */
1343 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1344 err_code |= ERR_WARN;
1345
1346 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1347 goto out;
1348
1349 if (*(args[1]) == 0) {
1350 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1351 file, linenum, args[0]);
1352 err_code |= ERR_ALERT | ERR_FATAL;
1353 goto out;
1354 }
1355 curproxy->conn_retries = atol(args[1]);
1356 }
1357 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
1358 struct act_rule *rule;
1359
1360 if (curproxy == &defproxy) {
1361 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1362 err_code |= ERR_ALERT | ERR_FATAL;
1363 goto out;
1364 }
1365
1366 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1367 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001368 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001369 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1370 file, linenum, args[0]);
1371 err_code |= ERR_WARN;
1372 }
1373
1374 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1375
1376 if (!rule) {
1377 err_code |= ERR_ALERT | ERR_ABORT;
1378 goto out;
1379 }
1380
1381 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1382 err_code |= warnif_cond_conflicts(rule->cond,
1383 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1384 file, linenum);
1385
1386 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1387 }
1388 else if (!strcmp(args[0], "http-response")) { /* response access control */
1389 struct act_rule *rule;
1390
1391 if (curproxy == &defproxy) {
1392 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1393 err_code |= ERR_ALERT | ERR_FATAL;
1394 goto out;
1395 }
1396
1397 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1398 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001399 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001400 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1401 file, linenum, args[0]);
1402 err_code |= ERR_WARN;
1403 }
1404
1405 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1406
1407 if (!rule) {
1408 err_code |= ERR_ALERT | ERR_ABORT;
1409 goto out;
1410 }
1411
1412 err_code |= warnif_cond_conflicts(rule->cond,
1413 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1414 file, linenum);
1415
1416 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1417 }
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001418 else if (!strcmp(args[0], "http-after-response")) {
1419 struct act_rule *rule;
1420
1421 if (curproxy == &defproxy) {
1422 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1423 err_code |= ERR_ALERT | ERR_FATAL;
1424 goto out;
1425 }
1426
1427 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1428 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1429 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1430 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1431 file, linenum, args[0]);
1432 err_code |= ERR_WARN;
1433 }
1434
1435 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1436
1437 if (!rule) {
1438 err_code |= ERR_ALERT | ERR_ABORT;
1439 goto out;
1440 }
1441
1442 err_code |= warnif_cond_conflicts(rule->cond,
1443 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1444 file, linenum);
1445
1446 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1447 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
1449 /* set the header name and length into the proxy structure */
1450 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1451 err_code |= ERR_WARN;
1452
1453 if (!*args[1]) {
1454 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1455 file, linenum, args[0]);
1456 err_code |= ERR_ALERT | ERR_FATAL;
1457 goto out;
1458 }
1459
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001460 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001461 free(curproxy->server_id_hdr_name);
1462 curproxy->server_id_hdr_name = strdup(args[1]);
1463 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001464 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 +01001465 }
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001466 else if (!strcmp(args[0], "block")) {
1467 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 +01001468
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001469 err_code |= ERR_ALERT | ERR_FATAL;
1470 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001471 }
1472 else if (!strcmp(args[0], "redirect")) {
1473 struct redirect_rule *rule;
1474
1475 if (curproxy == &defproxy) {
1476 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1477 err_code |= ERR_ALERT | ERR_FATAL;
1478 goto out;
1479 }
1480
1481 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1482 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1483 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1484 err_code |= ERR_ALERT | ERR_FATAL;
1485 goto out;
1486 }
1487
1488 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1489 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1490 err_code |= warnif_cond_conflicts(rule->cond,
1491 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1492 file, linenum);
1493 }
1494 else if (!strcmp(args[0], "use_backend")) {
1495 struct switching_rule *rule;
1496
1497 if (curproxy == &defproxy) {
1498 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1499 err_code |= ERR_ALERT | ERR_FATAL;
1500 goto out;
1501 }
1502
1503 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1504 err_code |= ERR_WARN;
1505
1506 if (*(args[1]) == 0) {
1507 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1508 err_code |= ERR_ALERT | ERR_FATAL;
1509 goto out;
1510 }
1511
1512 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1513 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1514 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1515 file, linenum, errmsg);
1516 err_code |= ERR_ALERT | ERR_FATAL;
1517 goto out;
1518 }
1519
1520 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1521 }
1522 else if (*args[2]) {
1523 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1524 file, linenum, args[2]);
1525 err_code |= ERR_ALERT | ERR_FATAL;
1526 goto out;
1527 }
1528
1529 rule = calloc(1, sizeof(*rule));
1530 if (!rule) {
1531 ha_alert("Out of memory error.\n");
1532 goto out;
1533 }
1534 rule->cond = cond;
1535 rule->be.name = strdup(args[1]);
1536 rule->line = linenum;
1537 rule->file = strdup(file);
1538 if (!rule->file) {
1539 ha_alert("Out of memory error.\n");
1540 goto out;
1541 }
1542 LIST_INIT(&rule->list);
1543 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1544 }
1545 else if (strcmp(args[0], "use-server") == 0) {
1546 struct server_rule *rule;
1547
1548 if (curproxy == &defproxy) {
1549 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1550 err_code |= ERR_ALERT | ERR_FATAL;
1551 goto out;
1552 }
1553
1554 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1555 err_code |= ERR_WARN;
1556
1557 if (*(args[1]) == 0) {
1558 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1559 err_code |= ERR_ALERT | ERR_FATAL;
1560 goto out;
1561 }
1562
1563 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1564 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1565 file, linenum, args[0]);
1566 err_code |= ERR_ALERT | ERR_FATAL;
1567 goto out;
1568 }
1569
1570 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1571 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1572 file, linenum, errmsg);
1573 err_code |= ERR_ALERT | ERR_FATAL;
1574 goto out;
1575 }
1576
1577 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1578
1579 rule = calloc(1, sizeof(*rule));
1580 rule->cond = cond;
1581 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001582 rule->line = linenum;
1583 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001584 LIST_INIT(&rule->list);
1585 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1586 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1587 }
1588 else if ((!strcmp(args[0], "force-persist")) ||
1589 (!strcmp(args[0], "ignore-persist"))) {
1590 struct persist_rule *rule;
1591
1592 if (curproxy == &defproxy) {
1593 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1594 err_code |= ERR_ALERT | ERR_FATAL;
1595 goto out;
1596 }
1597
1598 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1599 err_code |= ERR_WARN;
1600
1601 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1602 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1603 file, linenum, args[0]);
1604 err_code |= ERR_ALERT | ERR_FATAL;
1605 goto out;
1606 }
1607
1608 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1609 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1610 file, linenum, args[0], errmsg);
1611 err_code |= ERR_ALERT | ERR_FATAL;
1612 goto out;
1613 }
1614
1615 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1616 * where force-persist is applied.
1617 */
1618 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1619
1620 rule = calloc(1, sizeof(*rule));
1621 rule->cond = cond;
1622 if (!strcmp(args[0], "force-persist")) {
1623 rule->type = PERSIST_TYPE_FORCE;
1624 } else {
1625 rule->type = PERSIST_TYPE_IGNORE;
1626 }
1627 LIST_INIT(&rule->list);
1628 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1629 }
1630 else if (!strcmp(args[0], "stick-table")) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001631 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001632
1633 if (curproxy == &defproxy) {
1634 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1635 file, linenum);
1636 err_code |= ERR_ALERT | ERR_FATAL;
1637 goto out;
1638 }
1639
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001640 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001641 if (other) {
1642 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 +01001643 file, linenum, curproxy->id,
1644 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1645 other->proxy ? other->id : other->peers.p->id,
1646 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001647 err_code |= ERR_ALERT | ERR_FATAL;
1648 goto out;
1649 }
1650
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001651 curproxy->table = calloc(1, sizeof *curproxy->table);
1652 if (!curproxy->table) {
1653 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1654 file, linenum, args[0], args[1]);
1655 err_code |= ERR_ALERT | ERR_FATAL;
1656 goto out;
1657 }
1658
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001659 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1660 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001661 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001662 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001663
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001664 /* Store the proxy in the stick-table. */
1665 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001666
1667 stktable_store_name(curproxy->table);
1668 curproxy->table->next = stktables_list;
1669 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001670
1671 /* Add this proxy to the list of proxies which refer to its stick-table. */
1672 if (curproxy->table->proxies_list != curproxy) {
1673 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1674 curproxy->table->proxies_list = curproxy;
1675 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001676 }
1677 else if (!strcmp(args[0], "stick")) {
1678 struct sticking_rule *rule;
1679 struct sample_expr *expr;
1680 int myidx = 0;
1681 const char *name = NULL;
1682 int flags;
1683
1684 if (curproxy == &defproxy) {
1685 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1686 err_code |= ERR_ALERT | ERR_FATAL;
1687 goto out;
1688 }
1689
1690 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1691 err_code |= ERR_WARN;
1692 goto out;
1693 }
1694
1695 myidx++;
1696 if ((strcmp(args[myidx], "store") == 0) ||
1697 (strcmp(args[myidx], "store-request") == 0)) {
1698 myidx++;
1699 flags = STK_IS_STORE;
1700 }
1701 else if (strcmp(args[myidx], "store-response") == 0) {
1702 myidx++;
1703 flags = STK_IS_STORE | STK_ON_RSP;
1704 }
1705 else if (strcmp(args[myidx], "match") == 0) {
1706 myidx++;
1707 flags = STK_IS_MATCH;
1708 }
1709 else if (strcmp(args[myidx], "on") == 0) {
1710 myidx++;
1711 flags = STK_IS_MATCH | STK_IS_STORE;
1712 }
1713 else {
1714 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1715 err_code |= ERR_ALERT | ERR_FATAL;
1716 goto out;
1717 }
1718
1719 if (*(args[myidx]) == 0) {
1720 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1721 err_code |= ERR_ALERT | ERR_FATAL;
1722 goto out;
1723 }
1724
1725 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001726 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001727 if (!expr) {
1728 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1729 err_code |= ERR_ALERT | ERR_FATAL;
1730 goto out;
1731 }
1732
1733 if (flags & STK_ON_RSP) {
1734 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1735 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1736 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1737 err_code |= ERR_ALERT | ERR_FATAL;
1738 free(expr);
1739 goto out;
1740 }
1741 } else {
1742 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1743 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1744 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1745 err_code |= ERR_ALERT | ERR_FATAL;
1746 free(expr);
1747 goto out;
1748 }
1749 }
1750
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001751 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001752 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1753
1754 if (strcmp(args[myidx], "table") == 0) {
1755 myidx++;
1756 name = args[myidx++];
1757 }
1758
1759 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1760 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1761 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1762 file, linenum, args[0], errmsg);
1763 err_code |= ERR_ALERT | ERR_FATAL;
1764 free(expr);
1765 goto out;
1766 }
1767 }
1768 else if (*(args[myidx])) {
1769 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1770 file, linenum, args[0], args[myidx]);
1771 err_code |= ERR_ALERT | ERR_FATAL;
1772 free(expr);
1773 goto out;
1774 }
1775 if (flags & STK_ON_RSP)
1776 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1777 else
1778 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1779
1780 rule = calloc(1, sizeof(*rule));
1781 rule->cond = cond;
1782 rule->expr = expr;
1783 rule->flags = flags;
1784 rule->table.name = name ? strdup(name) : NULL;
1785 LIST_INIT(&rule->list);
1786 if (flags & STK_ON_RSP)
1787 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1788 else
1789 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1790 }
1791 else if (!strcmp(args[0], "stats")) {
1792 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
1793 curproxy->uri_auth = NULL; /* we must detach from the default config */
1794
1795 if (!*args[1]) {
1796 goto stats_error_parsing;
1797 } else if (!strcmp(args[1], "admin")) {
1798 struct stats_admin_rule *rule;
1799
1800 if (curproxy == &defproxy) {
1801 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1802 err_code |= ERR_ALERT | ERR_FATAL;
1803 goto out;
1804 }
1805
1806 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1807 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1808 err_code |= ERR_ALERT | ERR_ABORT;
1809 goto out;
1810 }
1811
1812 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1813 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1814 file, linenum, args[0], args[1]);
1815 err_code |= ERR_ALERT | ERR_FATAL;
1816 goto out;
1817 }
1818 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1819 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1820 file, linenum, args[0], args[1], errmsg);
1821 err_code |= ERR_ALERT | ERR_FATAL;
1822 goto out;
1823 }
1824
1825 err_code |= warnif_cond_conflicts(cond,
1826 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1827 file, linenum);
1828
1829 rule = calloc(1, sizeof(*rule));
1830 rule->cond = cond;
1831 LIST_INIT(&rule->list);
1832 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
1833 } else if (!strcmp(args[1], "uri")) {
1834 if (*(args[2]) == 0) {
1835 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1836 err_code |= ERR_ALERT | ERR_FATAL;
1837 goto out;
1838 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1839 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1840 err_code |= ERR_ALERT | ERR_ABORT;
1841 goto out;
1842 }
1843 } else if (!strcmp(args[1], "realm")) {
1844 if (*(args[2]) == 0) {
1845 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1846 err_code |= ERR_ALERT | ERR_FATAL;
1847 goto out;
1848 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1849 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1850 err_code |= ERR_ALERT | ERR_ABORT;
1851 goto out;
1852 }
1853 } else if (!strcmp(args[1], "refresh")) {
1854 unsigned interval;
1855
1856 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001857 if (err == PARSE_TIME_OVER) {
1858 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1859 file, linenum, args[2]);
1860 err_code |= ERR_ALERT | ERR_FATAL;
1861 goto out;
1862 }
1863 else if (err == PARSE_TIME_UNDER) {
1864 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1865 file, linenum, args[2]);
1866 err_code |= ERR_ALERT | ERR_FATAL;
1867 goto out;
1868 }
1869 else if (err) {
1870 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001871 file, linenum, *err);
1872 err_code |= ERR_ALERT | ERR_FATAL;
1873 goto out;
1874 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1875 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1876 err_code |= ERR_ALERT | ERR_ABORT;
1877 goto out;
1878 }
1879 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
1880 struct act_rule *rule;
1881
1882 if (curproxy == &defproxy) {
1883 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1884 err_code |= ERR_ALERT | ERR_FATAL;
1885 goto out;
1886 }
1887
1888 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1889 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1890 err_code |= ERR_ALERT | ERR_ABORT;
1891 goto out;
1892 }
1893
1894 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1895 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1896 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1897 file, linenum, args[0]);
1898 err_code |= ERR_WARN;
1899 }
1900
1901 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1902
1903 if (!rule) {
1904 err_code |= ERR_ALERT | ERR_ABORT;
1905 goto out;
1906 }
1907
1908 err_code |= warnif_cond_conflicts(rule->cond,
1909 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1910 file, linenum);
1911 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1912
1913 } else if (!strcmp(args[1], "auth")) {
1914 if (*(args[2]) == 0) {
1915 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1916 err_code |= ERR_ALERT | ERR_FATAL;
1917 goto out;
1918 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1919 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1920 err_code |= ERR_ALERT | ERR_ABORT;
1921 goto out;
1922 }
1923 } else if (!strcmp(args[1], "scope")) {
1924 if (*(args[2]) == 0) {
1925 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1926 err_code |= ERR_ALERT | ERR_FATAL;
1927 goto out;
1928 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1929 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1930 err_code |= ERR_ALERT | ERR_ABORT;
1931 goto out;
1932 }
1933 } else if (!strcmp(args[1], "enable")) {
1934 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1935 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1936 err_code |= ERR_ALERT | ERR_ABORT;
1937 goto out;
1938 }
1939 } else if (!strcmp(args[1], "hide-version")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001940 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001941 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1942 err_code |= ERR_ALERT | ERR_ABORT;
1943 goto out;
1944 }
1945 } else if (!strcmp(args[1], "show-legends")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001946 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001947 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1948 err_code |= ERR_ALERT | ERR_ABORT;
1949 goto out;
1950 }
1951 } else if (!strcmp(args[1], "show-node")) {
1952
1953 if (*args[2]) {
1954 int i;
1955 char c;
1956
1957 for (i=0; args[2][i]; i++) {
1958 c = args[2][i];
1959 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1960 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1961 break;
1962 }
1963
1964 if (!i || args[2][i]) {
1965 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1966 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1967 file, linenum, args[0], args[1]);
1968 err_code |= ERR_ALERT | ERR_FATAL;
1969 goto out;
1970 }
1971 }
1972
1973 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
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], "show-desc")) {
1979 char *desc = NULL;
1980
1981 if (*args[2]) {
1982 int i, len=0;
1983 char *d;
1984
1985 for (i = 2; *args[i]; i++)
1986 len += strlen(args[i]) + 1;
1987
1988 desc = d = calloc(1, len);
1989
1990 d += snprintf(d, desc + len - d, "%s", args[2]);
1991 for (i = 3; *args[i]; i++)
1992 d += snprintf(d, desc + len - d, " %s", args[i]);
1993 }
1994
1995 if (!*args[2] && !global.desc)
1996 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1997 file, linenum, args[1]);
1998 else {
1999 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
2000 free(desc);
2001 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
2002 err_code |= ERR_ALERT | ERR_ABORT;
2003 goto out;
2004 }
2005 free(desc);
2006 }
2007 } else {
2008stats_error_parsing:
2009 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
2010 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
2011 err_code |= ERR_ALERT | ERR_FATAL;
2012 goto out;
2013 }
2014 }
2015 else if (!strcmp(args[0], "option")) {
2016 int optnum;
2017
2018 if (*(args[1]) == '\0') {
2019 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
2020 file, linenum, args[0]);
2021 err_code |= ERR_ALERT | ERR_FATAL;
2022 goto out;
2023 }
2024
2025 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
2026 if (!strcmp(args[1], cfg_opts[optnum].name)) {
2027 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
2028 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2029 file, linenum, cfg_opts[optnum].name);
2030 err_code |= ERR_ALERT | ERR_FATAL;
2031 goto out;
2032 }
2033 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2034 goto out;
2035
2036 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
2037 err_code |= ERR_WARN;
2038 goto out;
2039 }
2040
2041 curproxy->no_options &= ~cfg_opts[optnum].val;
2042 curproxy->options &= ~cfg_opts[optnum].val;
2043
2044 switch (kwm) {
2045 case KWM_STD:
2046 curproxy->options |= cfg_opts[optnum].val;
2047 break;
2048 case KWM_NO:
2049 curproxy->no_options |= cfg_opts[optnum].val;
2050 break;
2051 case KWM_DEF: /* already cleared */
2052 break;
2053 }
2054
2055 goto out;
2056 }
2057 }
2058
2059 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
2060 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
2061 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2062 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2063 file, linenum, cfg_opts2[optnum].name);
2064 err_code |= ERR_ALERT | ERR_FATAL;
2065 goto out;
2066 }
2067 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2068 goto out;
2069 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2070 err_code |= ERR_WARN;
2071 goto out;
2072 }
2073
Christopher Faulet31930372019-07-15 10:16:58 +02002074 /* "[no] option http-use-htx" is deprecated */
2075 if (!strcmp(cfg_opts2[optnum].name, "http-use-htx")) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02002076 if (kwm ==KWM_NO) {
2077 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
2078 " The HTX mode is now the only supported mode.\n",
2079 file, linenum, cfg_opts2[optnum].name);
2080 err_code |= ERR_WARN;
2081 }
Christopher Faulet31930372019-07-15 10:16:58 +02002082 goto out;
2083 }
2084
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002085 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2086 curproxy->options2 &= ~cfg_opts2[optnum].val;
2087
2088 switch (kwm) {
2089 case KWM_STD:
2090 curproxy->options2 |= cfg_opts2[optnum].val;
2091 break;
2092 case KWM_NO:
2093 curproxy->no_options2 |= cfg_opts2[optnum].val;
2094 break;
2095 case KWM_DEF: /* already cleared */
2096 break;
2097 }
2098 goto out;
2099 }
2100 }
2101
2102 /* HTTP options override each other. They can be cancelled using
2103 * "no option xxx" which only switches to default mode if the mode
2104 * was this one (useful for cancelling options set in defaults
2105 * sections).
2106 */
2107 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02002108 if (strcmp(args[1], "forceclose") == 0) {
2109 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
2110 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
2111 file, linenum, args[1]);
2112 err_code |= ERR_WARN;
2113 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002114 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2115 goto out;
2116 if (kwm == KWM_STD) {
2117 curproxy->options &= ~PR_O_HTTP_MODE;
2118 curproxy->options |= PR_O_HTTP_CLO;
2119 goto out;
2120 }
2121 else if (kwm == KWM_NO) {
2122 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2123 curproxy->options &= ~PR_O_HTTP_MODE;
2124 goto out;
2125 }
2126 }
2127 else if (strcmp(args[1], "http-server-close") == 0) {
2128 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2129 goto out;
2130 if (kwm == KWM_STD) {
2131 curproxy->options &= ~PR_O_HTTP_MODE;
2132 curproxy->options |= PR_O_HTTP_SCL;
2133 goto out;
2134 }
2135 else if (kwm == KWM_NO) {
2136 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2137 curproxy->options &= ~PR_O_HTTP_MODE;
2138 goto out;
2139 }
2140 }
2141 else if (strcmp(args[1], "http-keep-alive") == 0) {
2142 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2143 goto out;
2144 if (kwm == KWM_STD) {
2145 curproxy->options &= ~PR_O_HTTP_MODE;
2146 curproxy->options |= PR_O_HTTP_KAL;
2147 goto out;
2148 }
2149 else if (kwm == KWM_NO) {
2150 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2151 curproxy->options &= ~PR_O_HTTP_MODE;
2152 goto out;
2153 }
2154 }
2155 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002156 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2157 file, linenum, args[1]);
2158 err_code |= ERR_WARN;
2159 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002160 }
2161
2162 /* Redispatch can take an integer argument that control when the
2163 * resispatch occurs. All values are relative to the retries option.
2164 * This can be cancelled using "no option xxx".
2165 */
2166 if (strcmp(args[1], "redispatch") == 0) {
2167 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2168 err_code |= ERR_WARN;
2169 goto out;
2170 }
2171
2172 curproxy->no_options &= ~PR_O_REDISP;
2173 curproxy->options &= ~PR_O_REDISP;
2174
2175 switch (kwm) {
2176 case KWM_STD:
2177 curproxy->options |= PR_O_REDISP;
2178 curproxy->redispatch_after = -1;
2179 if(*args[2]) {
2180 curproxy->redispatch_after = atol(args[2]);
2181 }
2182 break;
2183 case KWM_NO:
2184 curproxy->no_options |= PR_O_REDISP;
2185 curproxy->redispatch_after = 0;
2186 break;
2187 case KWM_DEF: /* already cleared */
2188 break;
2189 }
2190 goto out;
2191 }
2192
2193 if (kwm != KWM_STD) {
2194 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2195 file, linenum, args[1]);
2196 err_code |= ERR_ALERT | ERR_FATAL;
2197 goto out;
2198 }
2199
2200 if (!strcmp(args[1], "httplog")) {
2201 char *logformat;
2202 /* generate a complete HTTP log */
2203 logformat = default_http_log_format;
2204 if (*(args[2]) != '\0') {
2205 if (!strcmp(args[2], "clf")) {
2206 curproxy->options2 |= PR_O2_CLFLOG;
2207 logformat = clf_http_log_format;
2208 } else {
2209 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2210 err_code |= ERR_ALERT | ERR_FATAL;
2211 goto out;
2212 }
2213 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2214 goto out;
2215 }
2216 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2217 char *oldlogformat = "log-format";
2218 char *clflogformat = "";
2219
2220 if (curproxy->conf.logformat_string == default_http_log_format)
2221 oldlogformat = "option httplog";
2222 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2223 oldlogformat = "option tcplog";
2224 else if (curproxy->conf.logformat_string == clf_http_log_format)
2225 oldlogformat = "option httplog clf";
2226 if (logformat == clf_http_log_format)
2227 clflogformat = " clf";
2228 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2229 file, linenum, clflogformat, oldlogformat);
2230 }
2231 if (curproxy->conf.logformat_string != default_http_log_format &&
2232 curproxy->conf.logformat_string != default_tcp_log_format &&
2233 curproxy->conf.logformat_string != clf_http_log_format)
2234 free(curproxy->conf.logformat_string);
2235 curproxy->conf.logformat_string = logformat;
2236
2237 free(curproxy->conf.lfs_file);
2238 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2239 curproxy->conf.lfs_line = curproxy->conf.args.line;
2240
2241 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2242 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2243 file, linenum, curproxy->id);
2244 err_code |= ERR_WARN;
2245 }
2246 }
2247 else if (!strcmp(args[1], "tcplog")) {
2248 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2249 char *oldlogformat = "log-format";
2250
2251 if (curproxy->conf.logformat_string == default_http_log_format)
2252 oldlogformat = "option httplog";
2253 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2254 oldlogformat = "option tcplog";
2255 else if (curproxy->conf.logformat_string == clf_http_log_format)
2256 oldlogformat = "option httplog clf";
2257 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2258 file, linenum, oldlogformat);
2259 }
2260 /* generate a detailed TCP log */
2261 if (curproxy->conf.logformat_string != default_http_log_format &&
2262 curproxy->conf.logformat_string != default_tcp_log_format &&
2263 curproxy->conf.logformat_string != clf_http_log_format)
2264 free(curproxy->conf.logformat_string);
2265 curproxy->conf.logformat_string = default_tcp_log_format;
2266
2267 free(curproxy->conf.lfs_file);
2268 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2269 curproxy->conf.lfs_line = curproxy->conf.args.line;
2270
2271 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2272 goto out;
2273
2274 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2275 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2276 file, linenum, curproxy->id);
2277 err_code |= ERR_WARN;
2278 }
2279 }
2280 else if (!strcmp(args[1], "tcpka")) {
2281 /* enable TCP keep-alives on client and server streams */
2282 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2283 err_code |= ERR_WARN;
2284
2285 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2286 goto out;
2287
2288 if (curproxy->cap & PR_CAP_FE)
2289 curproxy->options |= PR_O_TCP_CLI_KA;
2290 if (curproxy->cap & PR_CAP_BE)
2291 curproxy->options |= PR_O_TCP_SRV_KA;
2292 }
2293 else if (!strcmp(args[1], "httpchk")) {
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002294 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2295 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002296 goto out;
2297 }
2298 else if (!strcmp(args[1], "ssl-hello-chk")) {
Christopher Faulet811f78c2020-04-01 11:10:27 +02002299 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum);
2300 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002301 goto out;
2302 }
2303 else if (!strcmp(args[1], "smtpchk")) {
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002304 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2305 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002306 goto out;
2307 }
2308 else if (!strcmp(args[1], "pgsql-check")) {
Christopher Fauletce355072020-04-02 11:44:39 +02002309 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2310 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002311 goto out;
2312 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002313 else if (!strcmp(args[1], "redis-check")) {
Christopher Faulet33f05df2020-04-01 11:08:50 +02002314 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2315 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002316 goto out;
2317 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002318 else if (!strcmp(args[1], "mysql-check")) {
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002319 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2320 if (err_code & ERR_FATAL)
2321 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002322 }
2323 else if (!strcmp(args[1], "ldap-check")) {
Christopher Faulet1997eca2020-04-03 23:13:50 +02002324 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2325 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002326 goto out;
2327 }
2328 else if (!strcmp(args[1], "spop-check")) {
Christopher Faulet267b01b2020-04-04 10:27:09 +02002329 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2330 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002331 goto out;
2332 }
2333 else if (!strcmp(args[1], "tcp-check")) {
Christopher Faulet430e4802020-04-09 15:28:16 +02002334 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2335 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002336 goto out;
2337 }
2338 else if (!strcmp(args[1], "external-check")) {
Christopher Faulet6f557912020-04-09 15:58:50 +02002339 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2340 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002341 goto out;
2342 }
2343 else if (!strcmp(args[1], "forwardfor")) {
2344 int cur_arg;
2345
2346 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002347 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002348 */
2349
2350 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2351
2352 free(curproxy->fwdfor_hdr_name);
2353 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2354 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2355
2356 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2357 cur_arg = 2;
2358 while (*(args[cur_arg])) {
2359 if (!strcmp(args[cur_arg], "except")) {
2360 /* suboption except - needs additional argument for it */
2361 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2362 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2363 file, linenum, args[0], args[1], args[cur_arg]);
2364 err_code |= ERR_ALERT | ERR_FATAL;
2365 goto out;
2366 }
2367 /* flush useless bits */
2368 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2369 cur_arg += 2;
2370 } else if (!strcmp(args[cur_arg], "header")) {
2371 /* suboption header - needs additional argument for it */
2372 if (*(args[cur_arg+1]) == 0) {
2373 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2374 file, linenum, args[0], args[1], args[cur_arg]);
2375 err_code |= ERR_ALERT | ERR_FATAL;
2376 goto out;
2377 }
2378 free(curproxy->fwdfor_hdr_name);
2379 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2380 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2381 cur_arg += 2;
2382 } else if (!strcmp(args[cur_arg], "if-none")) {
2383 curproxy->options &= ~PR_O_FF_ALWAYS;
2384 cur_arg += 1;
2385 } else {
2386 /* unknown suboption - catchall */
2387 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2388 file, linenum, args[0], args[1]);
2389 err_code |= ERR_ALERT | ERR_FATAL;
2390 goto out;
2391 }
2392 } /* end while loop */
2393 }
2394 else if (!strcmp(args[1], "originalto")) {
2395 int cur_arg;
2396
2397 /* insert x-original-to field, but not for the IP address listed as an except.
2398 * set default options (ie: bitfield, header name, etc)
2399 */
2400
2401 curproxy->options |= PR_O_ORGTO;
2402
2403 free(curproxy->orgto_hdr_name);
2404 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2405 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2406
2407 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2408 cur_arg = 2;
2409 while (*(args[cur_arg])) {
2410 if (!strcmp(args[cur_arg], "except")) {
2411 /* suboption except - needs additional argument for it */
2412 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2413 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2414 file, linenum, args[0], args[1], args[cur_arg]);
2415 err_code |= ERR_ALERT | ERR_FATAL;
2416 goto out;
2417 }
2418 /* flush useless bits */
2419 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2420 cur_arg += 2;
2421 } else if (!strcmp(args[cur_arg], "header")) {
2422 /* suboption header - needs additional argument for it */
2423 if (*(args[cur_arg+1]) == 0) {
2424 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2425 file, linenum, args[0], args[1], args[cur_arg]);
2426 err_code |= ERR_ALERT | ERR_FATAL;
2427 goto out;
2428 }
2429 free(curproxy->orgto_hdr_name);
2430 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2431 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2432 cur_arg += 2;
2433 } else {
2434 /* unknown suboption - catchall */
2435 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2436 file, linenum, args[0], args[1]);
2437 err_code |= ERR_ALERT | ERR_FATAL;
2438 goto out;
2439 }
2440 } /* end while loop */
2441 }
2442 else {
2443 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2444 err_code |= ERR_ALERT | ERR_FATAL;
2445 goto out;
2446 }
2447 goto out;
2448 }
2449 else if (!strcmp(args[0], "default_backend")) {
2450 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2451 err_code |= ERR_WARN;
2452
2453 if (*(args[1]) == 0) {
2454 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2455 err_code |= ERR_ALERT | ERR_FATAL;
2456 goto out;
2457 }
2458 free(curproxy->defbe.name);
2459 curproxy->defbe.name = strdup(args[1]);
2460
2461 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2462 goto out;
2463 }
2464 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002465 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 +01002466
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002467 err_code |= ERR_ALERT | ERR_FATAL;
2468 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002469 }
2470 else if (!strcmp(args[0], "http-reuse")) {
2471 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2472 err_code |= ERR_WARN;
2473
2474 if (strcmp(args[1], "never") == 0) {
2475 /* enable a graceful server shutdown on an HTTP 404 response */
2476 curproxy->options &= ~PR_O_REUSE_MASK;
2477 curproxy->options |= PR_O_REUSE_NEVR;
2478 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2479 goto out;
2480 }
2481 else if (strcmp(args[1], "safe") == 0) {
2482 /* enable a graceful server shutdown on an HTTP 404 response */
2483 curproxy->options &= ~PR_O_REUSE_MASK;
2484 curproxy->options |= PR_O_REUSE_SAFE;
2485 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2486 goto out;
2487 }
2488 else if (strcmp(args[1], "aggressive") == 0) {
2489 curproxy->options &= ~PR_O_REUSE_MASK;
2490 curproxy->options |= PR_O_REUSE_AGGR;
2491 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2492 goto out;
2493 }
2494 else if (strcmp(args[1], "always") == 0) {
2495 /* enable a graceful server shutdown on an HTTP 404 response */
2496 curproxy->options &= ~PR_O_REUSE_MASK;
2497 curproxy->options |= PR_O_REUSE_ALWS;
2498 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2499 goto out;
2500 }
2501 else {
2502 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2503 err_code |= ERR_ALERT | ERR_FATAL;
2504 goto out;
2505 }
2506 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002507 else if (!strcmp(args[0], "monitor")) {
2508 if (curproxy == &defproxy) {
2509 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2510 err_code |= ERR_ALERT | ERR_FATAL;
2511 goto out;
2512 }
2513
2514 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2515 err_code |= ERR_WARN;
2516
2517 if (strcmp(args[1], "fail") == 0) {
2518 /* add a condition to fail monitor requests */
2519 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2520 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2521 file, linenum, args[0], args[1]);
2522 err_code |= ERR_ALERT | ERR_FATAL;
2523 goto out;
2524 }
2525
2526 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2527 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2528 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2529 file, linenum, args[0], args[1], errmsg);
2530 err_code |= ERR_ALERT | ERR_FATAL;
2531 goto out;
2532 }
2533 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2534 }
2535 else {
2536 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2537 err_code |= ERR_ALERT | ERR_FATAL;
2538 goto out;
2539 }
2540 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002541#ifdef USE_TPROXY
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002542 else if (!strcmp(args[0], "transparent")) {
2543 /* enable transparent proxy connections */
2544 curproxy->options |= PR_O_TRANSP;
2545 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2546 goto out;
2547 }
2548#endif
2549 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
2550 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2551 err_code |= ERR_WARN;
2552
2553 if (*(args[1]) == 0) {
2554 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2555 err_code |= ERR_ALERT | ERR_FATAL;
2556 goto out;
2557 }
2558 curproxy->maxconn = atol(args[1]);
2559 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2560 goto out;
2561 }
2562 else if (!strcmp(args[0], "backlog")) { /* backlog */
2563 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2564 err_code |= ERR_WARN;
2565
2566 if (*(args[1]) == 0) {
2567 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2568 err_code |= ERR_ALERT | ERR_FATAL;
2569 goto out;
2570 }
2571 curproxy->backlog = atol(args[1]);
2572 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2573 goto out;
2574 }
2575 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
2576 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2577 err_code |= ERR_WARN;
2578
2579 if (*(args[1]) == 0) {
2580 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2581 err_code |= ERR_ALERT | ERR_FATAL;
2582 goto out;
2583 }
2584 curproxy->fullconn = atol(args[1]);
2585 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2586 goto out;
2587 }
2588 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
2589 if (*(args[1]) == 0) {
2590 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2591 err_code |= ERR_ALERT | ERR_FATAL;
2592 goto out;
2593 }
2594 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002595 if (err == PARSE_TIME_OVER) {
2596 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2597 file, linenum, args[1]);
2598 err_code |= ERR_ALERT | ERR_FATAL;
2599 goto out;
2600 }
2601 else if (err == PARSE_TIME_UNDER) {
2602 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2603 file, linenum, args[1]);
2604 err_code |= ERR_ALERT | ERR_FATAL;
2605 goto out;
2606 }
2607 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002608 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2609 file, linenum, *err);
2610 err_code |= ERR_ALERT | ERR_FATAL;
2611 goto out;
2612 }
2613 curproxy->grace = val;
2614 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2615 goto out;
2616 }
2617 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
2618 struct sockaddr_storage *sk;
2619 int port1, port2;
2620 struct protocol *proto;
2621
2622 if (curproxy == &defproxy) {
2623 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2624 err_code |= ERR_ALERT | ERR_FATAL;
2625 goto out;
2626 }
2627 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2628 err_code |= ERR_WARN;
2629
2630 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2631 if (!sk) {
2632 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2633 err_code |= ERR_ALERT | ERR_FATAL;
2634 goto out;
2635 }
2636
2637 proto = protocol_by_family(sk->ss_family);
2638 if (!proto || !proto->connect) {
2639 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2640 file, linenum, args[0], args[1]);
2641 err_code |= ERR_ALERT | ERR_FATAL;
2642 goto out;
2643 }
2644
2645 if (port1 != port2) {
2646 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
2647 file, linenum, args[0], args[1]);
2648 err_code |= ERR_ALERT | ERR_FATAL;
2649 goto out;
2650 }
2651
2652 if (!port1) {
2653 ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
2654 file, linenum, args[0], args[1]);
2655 err_code |= ERR_ALERT | ERR_FATAL;
2656 goto out;
2657 }
2658
2659 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2660 goto out;
2661
2662 curproxy->dispatch_addr = *sk;
2663 curproxy->options |= PR_O_DISPATCH;
2664 }
2665 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
2666 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2667 err_code |= ERR_WARN;
2668
2669 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2670 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2671 err_code |= ERR_ALERT | ERR_FATAL;
2672 goto out;
2673 }
2674 }
2675 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
2676 /**
2677 * The syntax for hash-type config element is
2678 * hash-type {map-based|consistent} [[<algo>] avalanche]
2679 *
2680 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2681 */
2682 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2683
2684 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2685 err_code |= ERR_WARN;
2686
2687 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2688 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2689 }
2690 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2691 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2692 }
2693 else if (strcmp(args[1], "avalanche") == 0) {
2694 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]);
2695 err_code |= ERR_ALERT | ERR_FATAL;
2696 goto out;
2697 }
2698 else {
2699 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2700 err_code |= ERR_ALERT | ERR_FATAL;
2701 goto out;
2702 }
2703
2704 /* set the hash function to use */
2705 if (!*args[2]) {
2706 /* the default algo is sdbm */
2707 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2708
2709 /* if consistent with no argument, then avalanche modifier is also applied */
2710 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2711 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2712 } else {
2713 /* set the hash function */
2714 if (!strcmp(args[2], "sdbm")) {
2715 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2716 }
2717 else if (!strcmp(args[2], "djb2")) {
2718 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2719 }
2720 else if (!strcmp(args[2], "wt6")) {
2721 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2722 }
2723 else if (!strcmp(args[2], "crc32")) {
2724 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2725 }
2726 else {
2727 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2728 err_code |= ERR_ALERT | ERR_FATAL;
2729 goto out;
2730 }
2731
2732 /* set the hash modifier */
2733 if (!strcmp(args[3], "avalanche")) {
2734 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2735 }
2736 else if (*args[3]) {
2737 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2738 err_code |= ERR_ALERT | ERR_FATAL;
2739 goto out;
2740 }
2741 }
2742 }
2743 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2744 if (*(args[1]) == 0) {
2745 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2746 err_code |= ERR_ALERT | ERR_FATAL;
2747 goto out;
2748 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002749 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2750 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002751 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2752 err_code |= ERR_ALERT | ERR_FATAL;
2753 goto out;
2754 }
2755 }
2756 else if (strcmp(args[0], "unique-id-format") == 0) {
2757 if (!*(args[1])) {
2758 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2759 err_code |= ERR_ALERT | ERR_FATAL;
2760 goto out;
2761 }
2762 if (*(args[2])) {
2763 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2764 err_code |= ERR_ALERT | ERR_FATAL;
2765 goto out;
2766 }
2767 free(curproxy->conf.uniqueid_format_string);
2768 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2769
2770 free(curproxy->conf.uif_file);
2771 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2772 curproxy->conf.uif_line = curproxy->conf.args.line;
2773 }
2774
2775 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002776 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002777 if (!*(args[1])) {
2778 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2779 err_code |= ERR_ALERT | ERR_FATAL;
2780 goto out;
2781 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002782 copy = strdup(args[1]);
2783 if (copy == NULL) {
2784 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2785 err_code |= ERR_ALERT | ERR_FATAL;
2786 goto out;
2787 }
2788
2789 istfree(&curproxy->header_unique_id);
2790 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002791 }
2792
2793 else if (strcmp(args[0], "log-format") == 0) {
2794 if (!*(args[1])) {
2795 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2796 err_code |= ERR_ALERT | ERR_FATAL;
2797 goto out;
2798 }
2799 if (*(args[2])) {
2800 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2801 err_code |= ERR_ALERT | ERR_FATAL;
2802 goto out;
2803 }
2804 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2805 char *oldlogformat = "log-format";
2806
2807 if (curproxy->conf.logformat_string == default_http_log_format)
2808 oldlogformat = "option httplog";
2809 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2810 oldlogformat = "option tcplog";
2811 else if (curproxy->conf.logformat_string == clf_http_log_format)
2812 oldlogformat = "option httplog clf";
2813 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2814 file, linenum, oldlogformat);
2815 }
2816 if (curproxy->conf.logformat_string != default_http_log_format &&
2817 curproxy->conf.logformat_string != default_tcp_log_format &&
2818 curproxy->conf.logformat_string != clf_http_log_format)
2819 free(curproxy->conf.logformat_string);
2820 curproxy->conf.logformat_string = strdup(args[1]);
2821
2822 free(curproxy->conf.lfs_file);
2823 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2824 curproxy->conf.lfs_line = curproxy->conf.args.line;
2825
2826 /* get a chance to improve log-format error reporting by
2827 * reporting the correct line-number when possible.
2828 */
2829 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2830 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2831 file, linenum, curproxy->id);
2832 err_code |= ERR_WARN;
2833 }
2834 }
2835 else if (!strcmp(args[0], "log-format-sd")) {
2836 if (!*(args[1])) {
2837 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2838 err_code |= ERR_ALERT | ERR_FATAL;
2839 goto out;
2840 }
2841 if (*(args[2])) {
2842 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2843 err_code |= ERR_ALERT | ERR_FATAL;
2844 goto out;
2845 }
2846
2847 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2848 free(curproxy->conf.logformat_sd_string);
2849 curproxy->conf.logformat_sd_string = strdup(args[1]);
2850
2851 free(curproxy->conf.lfsd_file);
2852 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2853 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2854
2855 /* get a chance to improve log-format-sd error reporting by
2856 * reporting the correct line-number when possible.
2857 */
2858 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2859 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2860 file, linenum, curproxy->id);
2861 err_code |= ERR_WARN;
2862 }
2863 }
2864 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
2865 if (*(args[1]) == 0) {
2866 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2867 err_code |= ERR_ALERT | ERR_FATAL;
2868 goto out;
2869 }
2870 chunk_destroy(&curproxy->log_tag);
2871 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
2872 }
2873 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
2874 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2875 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2876 err_code |= ERR_ALERT | ERR_FATAL;
2877 goto out;
2878 }
2879 }
2880 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
2881 int cur_arg;
2882 int port1, port2;
2883 struct sockaddr_storage *sk;
2884 struct protocol *proto;
2885
2886 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2887 err_code |= ERR_WARN;
2888
2889 if (!*args[1]) {
2890 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2891 file, linenum, "source", "usesrc", "interface");
2892 err_code |= ERR_ALERT | ERR_FATAL;
2893 goto out;
2894 }
2895
Christopher Faulet31930372019-07-15 10:16:58 +02002896 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002897 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2898 free(curproxy->conn_src.iface_name);
2899 curproxy->conn_src.iface_name = NULL;
2900 curproxy->conn_src.iface_len = 0;
2901
2902 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2903 if (!sk) {
2904 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2905 file, linenum, args[0], args[1], errmsg);
2906 err_code |= ERR_ALERT | ERR_FATAL;
2907 goto out;
2908 }
2909
2910 proto = protocol_by_family(sk->ss_family);
2911 if (!proto || !proto->connect) {
2912 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2913 file, linenum, args[0], args[1]);
2914 err_code |= ERR_ALERT | ERR_FATAL;
2915 goto out;
2916 }
2917
2918 if (port1 != port2) {
2919 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
2920 file, linenum, args[0], args[1]);
2921 err_code |= ERR_ALERT | ERR_FATAL;
2922 goto out;
2923 }
2924
2925 curproxy->conn_src.source_addr = *sk;
2926 curproxy->conn_src.opts |= CO_SRC_BIND;
2927
2928 cur_arg = 2;
2929 while (*(args[cur_arg])) {
2930 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
2931#if defined(CONFIG_HAP_TRANSPARENT)
2932 if (!*args[cur_arg + 1]) {
2933 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2934 file, linenum, "usesrc");
2935 err_code |= ERR_ALERT | ERR_FATAL;
2936 goto out;
2937 }
2938
2939 if (!strcmp(args[cur_arg + 1], "client")) {
2940 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2941 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
2942 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
2943 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2944 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2945 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2946 char *name, *end;
2947
2948 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002949 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002950 name++;
2951
2952 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002953 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002954 end++;
2955
2956 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2957 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
2958 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2959 curproxy->conn_src.bind_hdr_len = end - name;
2960 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2961 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2962 curproxy->conn_src.bind_hdr_occ = -1;
2963
2964 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002965 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002966 end++;
2967 if (*end == ',') {
2968 end++;
2969 name = end;
2970 if (*end == '-')
2971 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002972 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002973 end++;
2974 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2975 }
2976
2977 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2978 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2979 " occurrences values smaller than %d.\n",
2980 file, linenum, MAX_HDR_HISTORY);
2981 err_code |= ERR_ALERT | ERR_FATAL;
2982 goto out;
2983 }
2984 } else {
2985 struct sockaddr_storage *sk;
2986
2987 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2988 if (!sk) {
2989 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2990 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2991 err_code |= ERR_ALERT | ERR_FATAL;
2992 goto out;
2993 }
2994
2995 proto = protocol_by_family(sk->ss_family);
2996 if (!proto || !proto->connect) {
2997 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2998 file, linenum, args[cur_arg], args[cur_arg+1]);
2999 err_code |= ERR_ALERT | ERR_FATAL;
3000 goto out;
3001 }
3002
3003 if (port1 != port2) {
3004 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
3005 file, linenum, args[cur_arg], args[cur_arg + 1]);
3006 err_code |= ERR_ALERT | ERR_FATAL;
3007 goto out;
3008 }
3009 curproxy->conn_src.tproxy_addr = *sk;
3010 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
3011 }
3012 global.last_checks |= LSTCHK_NETADM;
3013#else /* no TPROXY support */
3014 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
3015 file, linenum, "usesrc");
3016 err_code |= ERR_ALERT | ERR_FATAL;
3017 goto out;
3018#endif
3019 cur_arg += 2;
3020 continue;
3021 }
3022
3023 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
3024#ifdef SO_BINDTODEVICE
3025 if (!*args[cur_arg + 1]) {
3026 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
3027 file, linenum, args[0]);
3028 err_code |= ERR_ALERT | ERR_FATAL;
3029 goto out;
3030 }
3031 free(curproxy->conn_src.iface_name);
3032 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
3033 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
3034 global.last_checks |= LSTCHK_NETADM;
3035#else
3036 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3037 file, linenum, args[0], args[cur_arg]);
3038 err_code |= ERR_ALERT | ERR_FATAL;
3039 goto out;
3040#endif
3041 cur_arg += 2;
3042 continue;
3043 }
3044 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3045 file, linenum, args[0], "interface", "usesrc");
3046 err_code |= ERR_ALERT | ERR_FATAL;
3047 goto out;
3048 }
3049 }
3050 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
3051 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3052 file, linenum, "usesrc", "source");
3053 err_code |= ERR_ALERT | ERR_FATAL;
3054 goto out;
3055 }
3056 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003057 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003058 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003059 file, linenum, args[0]);
3060 err_code |= ERR_ALERT | ERR_FATAL;
3061 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003062 }
3063 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003064 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3065 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3066 err_code |= ERR_ALERT | ERR_FATAL;
3067 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003068 }
3069 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003070 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3071 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3072 err_code |= ERR_ALERT | ERR_FATAL;
3073 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003074 }
3075 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003076 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3077 err_code |= ERR_ALERT | ERR_FATAL;
3078 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003079 }
3080 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003081 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3082 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3083 err_code |= ERR_ALERT | ERR_FATAL;
3084 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003085 }
3086 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003087 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3088 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3089 err_code |= ERR_ALERT | ERR_FATAL;
3090 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003091 }
3092 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003093 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3094 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3095 err_code |= ERR_ALERT | ERR_FATAL;
3096 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003097 }
3098 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003099 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3100 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3101 err_code |= ERR_ALERT | ERR_FATAL;
3102 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003103 }
3104 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003105 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3106 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3107 err_code |= ERR_ALERT | ERR_FATAL;
3108 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003109 }
3110 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003111 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3112 err_code |= ERR_ALERT | ERR_FATAL;
3113 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003114 }
3115 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003116 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3117 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3118 err_code |= ERR_ALERT | ERR_FATAL;
3119 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003120 }
3121 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003122 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3123 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3124 err_code |= ERR_ALERT | ERR_FATAL;
3125 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003126 }
3127 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003128 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3129 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3130 err_code |= ERR_ALERT | ERR_FATAL;
3131 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003132 }
3133 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003134 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3135 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3136 err_code |= ERR_ALERT | ERR_FATAL;
3137 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003138 }
3139 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003140 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3141 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3142 err_code |= ERR_ALERT | ERR_FATAL;
3143 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003144 }
3145 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003146 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3147 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3148 err_code |= ERR_ALERT | ERR_FATAL;
3149 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003150 }
3151 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303152 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003153 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3154 err_code |= ERR_ALERT | ERR_FATAL;
3155 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003156 }
3157 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003158 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3159 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3160 err_code |= ERR_ALERT | ERR_FATAL;
3161 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003162 }
3163 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003164 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3165 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3166 err_code |= ERR_ALERT | ERR_FATAL;
3167 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003168 }
3169 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003170 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3171 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3172 err_code |= ERR_ALERT | ERR_FATAL;
3173 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003174 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003175 else {
3176 struct cfg_kw_list *kwl;
3177 int index;
3178
3179 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3180 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3181 if (kwl->kw[index].section != CFG_LISTEN)
3182 continue;
3183 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3184 /* prepare error message just in case */
3185 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
3186 if (rc < 0) {
3187 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3188 err_code |= ERR_ALERT | ERR_FATAL;
3189 goto out;
3190 }
3191 else if (rc > 0) {
3192 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3193 err_code |= ERR_WARN;
3194 goto out;
3195 }
3196 goto out;
3197 }
3198 }
3199 }
3200
3201 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
3202 err_code |= ERR_ALERT | ERR_FATAL;
3203 goto out;
3204 }
3205 out:
3206 free(errmsg);
3207 return err_code;
3208}