blob: d5359ffa2fea5944819f19ff2143828c153f8537 [file] [log] [blame]
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13
Willy Tarreaudcc048a2020-06-04 19:11:43 +020014#include <haproxy/acl.h>
Eric Salama7cea6062020-10-02 11:58:19 +020015#include <haproxy/buf.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020016#include <haproxy/capture-t.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020017#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020018#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020019#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020020#include <haproxy/connection.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020021#include <haproxy/extcheck.h>
Willy Tarreau87735332020-06-04 09:08:41 +020022#include <haproxy/http_htx.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020023#include <haproxy/http_rules.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020024#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020025#include <haproxy/log.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020026#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020027#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020028#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020029#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020030#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020031#include <haproxy/stats-t.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020032#include <haproxy/stick_table.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/tcpcheck.h>
34#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010035
36/* Report a warning if a rule is placed after a 'tcp-request session' rule.
37 * Return 1 if the warning has been emitted, otherwise 0.
38 */
39int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
40{
41 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
42 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
43 file, line, arg);
44 return 1;
45 }
46 return 0;
47}
48
49/* Report a warning if a rule is placed after a 'tcp-request content' rule.
50 * Return 1 if the warning has been emitted, otherwise 0.
51 */
52int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
53{
54 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
55 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
56 file, line, arg);
57 return 1;
58 }
59 return 0;
60}
61
62/* Report a warning if a rule is placed after a 'monitor fail' rule.
63 * Return 1 if the warning has been emitted, otherwise 0.
64 */
65int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
66{
67 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
68 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
69 file, line, arg);
70 return 1;
71 }
72 return 0;
73}
74
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010075/* Report a warning if a rule is placed after an 'http_request' rule.
76 * Return 1 if the warning has been emitted, otherwise 0.
77 */
78int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
79{
80 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
81 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
82 file, line, arg);
83 return 1;
84 }
85 return 0;
86}
87
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010088/* Report a warning if a rule is placed after a redirect rule.
89 * Return 1 if the warning has been emitted, otherwise 0.
90 */
91int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
92{
93 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
94 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
95 file, line, arg);
96 return 1;
97 }
98 return 0;
99}
100
101/* Report a warning if a rule is placed after a 'use_backend' rule.
102 * Return 1 if the warning has been emitted, otherwise 0.
103 */
104int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
105{
106 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
107 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
108 file, line, arg);
109 return 1;
110 }
111 return 0;
112}
113
114/* Report a warning if a rule is placed after a 'use-server' rule.
115 * Return 1 if the warning has been emitted, otherwise 0.
116 */
117int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
118{
119 if (!LIST_ISEMPTY(&proxy->server_rules)) {
120 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
121 file, line, arg);
122 return 1;
123 }
124 return 0;
125}
126
127/* report a warning if a redirect rule is dangerously placed */
128int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
129{
130 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
131 warnif_rule_after_use_server(proxy, file, line, arg);
132}
133
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100134/* report a warning if an http-request rule is dangerously placed */
135int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
136{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200137 return warnif_rule_after_redirect(proxy, file, line, arg) ||
138 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100139}
140
141/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200142int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100143{
144 return warnif_rule_after_http_req(proxy, file, line, arg) ||
145 warnif_misplaced_http_req(proxy, file, line, arg);
146}
147
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100148/* report a warning if a "tcp request content" rule is dangerously placed */
149int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
150{
151 return warnif_rule_after_monitor(proxy, file, line, arg) ||
152 warnif_misplaced_monitor(proxy, file, line, arg);
153}
154
155/* report a warning if a "tcp request session" rule is dangerously placed */
156int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
157{
158 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
159 warnif_misplaced_tcp_cont(proxy, file, line, arg);
160}
161
162/* report a warning if a "tcp request connection" rule is dangerously placed */
163int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
164{
165 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
166 warnif_misplaced_tcp_sess(proxy, file, line, arg);
167}
168
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100169int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
170{
171 static struct proxy *curproxy = NULL;
172 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100173 int rc;
174 unsigned val;
175 int err_code = 0;
176 struct acl_cond *cond = NULL;
177 struct logsrv *tmplogsrv;
178 char *errmsg = NULL;
179 struct bind_conf *bind_conf;
180
181 if (!strcmp(args[0], "listen"))
182 rc = PR_CAP_LISTEN;
183 else if (!strcmp(args[0], "frontend"))
184 rc = PR_CAP_FE;
185 else if (!strcmp(args[0], "backend"))
186 rc = PR_CAP_BE;
187 else
188 rc = PR_CAP_NONE;
189
190 if (rc != PR_CAP_NONE) { /* new proxy */
191 if (!*args[1]) {
Willy Tarreaua3201bc2021-02-12 13:28:22 +0100192 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100193 file, linenum, args[0]);
194 err_code |= ERR_ALERT | ERR_ABORT;
195 goto out;
196 }
197
198 err = invalid_char(args[1]);
199 if (err) {
200 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
201 file, linenum, *err, args[0], args[1]);
202 err_code |= ERR_ALERT | ERR_FATAL;
203 }
204
205 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
206 if (curproxy) {
207 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
208 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
209 curproxy->id, curproxy->conf.file, curproxy->conf.line);
210 err_code |= ERR_ALERT | ERR_FATAL;
211 }
212
Emeric Brunb0c331f2020-10-07 17:05:59 +0200213 curproxy = log_forward_by_name(args[1]);
214 if (curproxy) {
215 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
216 file, linenum, proxy_cap_str(rc), args[1],
217 curproxy->id, curproxy->conf.file, curproxy->conf.line);
218 err_code |= ERR_ALERT | ERR_FATAL;
219 }
220
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100221 if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
222 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
223 err_code |= ERR_ALERT | ERR_ABORT;
224 goto out;
225 }
226
227 init_new_proxy(curproxy);
228 curproxy->next = proxies_list;
229 proxies_list = curproxy;
230 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
231 curproxy->conf.args.line = curproxy->conf.line = linenum;
232 curproxy->last_change = now.tv_sec;
233 curproxy->id = strdup(args[1]);
234 curproxy->cap = rc;
235 proxy_store_name(curproxy);
236
237 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
238 if (curproxy->cap & PR_CAP_FE)
239 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
240 goto out;
241 }
242
243 /* set default values */
244 memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv));
245 curproxy->defsrv.id = "default-server";
246
Willy Tarreauc3914d42020-09-24 08:39:22 +0200247 curproxy->disabled = defproxy.disabled;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100248 curproxy->options = defproxy.options;
249 curproxy->options2 = defproxy.options2;
250 curproxy->no_options = defproxy.no_options;
251 curproxy->no_options2 = defproxy.no_options2;
252 curproxy->bind_proc = defproxy.bind_proc;
253 curproxy->except_net = defproxy.except_net;
254 curproxy->except_mask = defproxy.except_mask;
255 curproxy->except_to = defproxy.except_to;
256 curproxy->except_mask_to = defproxy.except_mask_to;
Olivier Houcharda254a372019-04-05 15:30:12 +0200257 curproxy->retry_type = defproxy.retry_type;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100258
259 if (defproxy.fwdfor_hdr_len) {
260 curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len;
261 curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name);
262 }
263
264 if (defproxy.orgto_hdr_len) {
265 curproxy->orgto_hdr_len = defproxy.orgto_hdr_len;
266 curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name);
267 }
268
269 if (defproxy.server_id_hdr_len) {
270 curproxy->server_id_hdr_len = defproxy.server_id_hdr_len;
271 curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name);
272 }
273
274 /* initialize error relocations */
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100275 if (!proxy_dup_default_conf_errors(curproxy, &defproxy, &errmsg)) {
276 ha_alert("parsing [%s:%d] : proxy '%s' : %s\n", file, linenum, curproxy->id, errmsg);
277 err_code |= ERR_ALERT | ERR_FATAL;
278 goto out;
279 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100280
281 if (curproxy->cap & PR_CAP_FE) {
282 curproxy->maxconn = defproxy.maxconn;
283 curproxy->backlog = defproxy.backlog;
284 curproxy->fe_sps_lim = defproxy.fe_sps_lim;
285
286 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100287 curproxy->max_out_conns = defproxy.max_out_conns;
MIZUTA Takeshib24bc0d2020-07-09 11:13:20 +0900288
289 curproxy->clitcpka_cnt = defproxy.clitcpka_cnt;
290 curproxy->clitcpka_idle = defproxy.clitcpka_idle;
291 curproxy->clitcpka_intvl = defproxy.clitcpka_intvl;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100292 }
293
294 if (curproxy->cap & PR_CAP_BE) {
295 curproxy->lbprm.algo = defproxy.lbprm.algo;
Willy Tarreau76e84f52019-01-14 16:50:58 +0100296 curproxy->lbprm.hash_balance_factor = defproxy.lbprm.hash_balance_factor;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100297 curproxy->fullconn = defproxy.fullconn;
298 curproxy->conn_retries = defproxy.conn_retries;
299 curproxy->redispatch_after = defproxy.redispatch_after;
300 curproxy->max_ka_queue = defproxy.max_ka_queue;
301
Christopher Faulete5870d82020-04-15 11:32:03 +0200302 curproxy->tcpcheck_rules.flags = (defproxy.tcpcheck_rules.flags & ~TCPCHK_RULES_UNUSED_RS);
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200303 curproxy->tcpcheck_rules.list = defproxy.tcpcheck_rules.list;
Christopher Faulet7a1e2e12020-04-02 18:05:11 +0200304 if (!LIST_ISEMPTY(&defproxy.tcpcheck_rules.preset_vars)) {
305 if (!dup_tcpcheck_vars(&curproxy->tcpcheck_rules.preset_vars,
306 &defproxy.tcpcheck_rules.preset_vars)) {
307 ha_alert("parsing [%s:%d] : failed to duplicate tcpcheck preset-vars\n",
308 file, linenum);
309 err_code |= ERR_ALERT | ERR_FATAL;
310 goto out;
311 }
312 }
Gaetan Rivet04578db2020-02-07 15:37:17 +0100313
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100314 curproxy->ck_opts = defproxy.ck_opts;
315 if (defproxy.cookie_name)
316 curproxy->cookie_name = strdup(defproxy.cookie_name);
317 curproxy->cookie_len = defproxy.cookie_len;
318
319 if (defproxy.dyncookie_key)
320 curproxy->dyncookie_key = strdup(defproxy.dyncookie_key);
321 if (defproxy.cookie_domain)
322 curproxy->cookie_domain = strdup(defproxy.cookie_domain);
323
324 if (defproxy.cookie_maxidle)
325 curproxy->cookie_maxidle = defproxy.cookie_maxidle;
326
327 if (defproxy.cookie_maxlife)
328 curproxy->cookie_maxlife = defproxy.cookie_maxlife;
329
330 if (defproxy.rdp_cookie_name)
331 curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name);
332 curproxy->rdp_cookie_len = defproxy.rdp_cookie_len;
333
Christopher Faulet2f533902020-01-21 11:06:48 +0100334 if (defproxy.cookie_attrs)
335 curproxy->cookie_attrs = strdup(defproxy.cookie_attrs);
Willy Tarreau20e68372019-01-14 16:04:01 +0100336
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100337 if (defproxy.lbprm.arg_str)
338 curproxy->lbprm.arg_str = strdup(defproxy.lbprm.arg_str);
339 curproxy->lbprm.arg_len = defproxy.lbprm.arg_len;
Willy Tarreau20e68372019-01-14 16:04:01 +0100340 curproxy->lbprm.arg_opt1 = defproxy.lbprm.arg_opt1;
341 curproxy->lbprm.arg_opt2 = defproxy.lbprm.arg_opt2;
342 curproxy->lbprm.arg_opt3 = defproxy.lbprm.arg_opt3;
343
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100344 if (defproxy.conn_src.iface_name)
345 curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name);
346 curproxy->conn_src.iface_len = defproxy.conn_src.iface_len;
347 curproxy->conn_src.opts = defproxy.conn_src.opts;
348#if defined(CONFIG_HAP_TRANSPARENT)
349 curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr;
350#endif
351 curproxy->load_server_state_from_file = defproxy.load_server_state_from_file;
MIZUTA Takeshib24bc0d2020-07-09 11:13:20 +0900352
353 curproxy->srvtcpka_cnt = defproxy.srvtcpka_cnt;
354 curproxy->srvtcpka_idle = defproxy.srvtcpka_idle;
355 curproxy->srvtcpka_intvl = defproxy.srvtcpka_intvl;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100356 }
357
358 if (curproxy->cap & PR_CAP_FE) {
359 if (defproxy.capture_name)
360 curproxy->capture_name = strdup(defproxy.capture_name);
361 curproxy->capture_namelen = defproxy.capture_namelen;
362 curproxy->capture_len = defproxy.capture_len;
363 }
364
365 if (curproxy->cap & PR_CAP_FE) {
366 curproxy->timeout.client = defproxy.timeout.client;
367 curproxy->timeout.clientfin = defproxy.timeout.clientfin;
368 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
369 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
370 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100371 if (defproxy.monitor_uri)
372 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
373 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
374 if (defproxy.defbe.name)
375 curproxy->defbe.name = strdup(defproxy.defbe.name);
376
377 /* get either a pointer to the logformat string or a copy of it */
378 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
379 if (curproxy->conf.logformat_string &&
380 curproxy->conf.logformat_string != default_http_log_format &&
381 curproxy->conf.logformat_string != default_tcp_log_format &&
382 curproxy->conf.logformat_string != clf_http_log_format)
383 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
384
385 if (defproxy.conf.lfs_file) {
386 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
387 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
388 }
389
390 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
391 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
392 if (curproxy->conf.logformat_sd_string &&
393 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
394 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
395
396 if (defproxy.conf.lfsd_file) {
397 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
398 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
399 }
400 }
401
402 if (curproxy->cap & PR_CAP_BE) {
403 curproxy->timeout.connect = defproxy.timeout.connect;
404 curproxy->timeout.server = defproxy.timeout.server;
405 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
406 curproxy->timeout.check = defproxy.timeout.check;
407 curproxy->timeout.queue = defproxy.timeout.queue;
408 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
409 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
410 curproxy->timeout.httpka = defproxy.timeout.httpka;
411 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
412 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
413 }
414
415 curproxy->mode = defproxy.mode;
416 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
417
418 /* copy default logsrvs to curproxy */
419 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
420 struct logsrv *node = malloc(sizeof(*node));
421 memcpy(node, tmplogsrv, sizeof(struct logsrv));
422 node->ref = tmplogsrv->ref;
423 LIST_INIT(&node->list);
424 LIST_ADDQ(&curproxy->logsrvs, &node->list);
425 }
426
427 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
428 if (curproxy->conf.uniqueid_format_string)
429 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
430
431 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
432
433 if (defproxy.conf.uif_file) {
434 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
435 curproxy->conf.uif_line = defproxy.conf.uif_line;
436 }
437
438 /* copy default header unique id */
Tim Duesterhus0643b0e2020-03-05 17:56:35 +0100439 if (isttest(defproxy.header_unique_id)) {
440 const struct ist copy = istdup(defproxy.header_unique_id);
441 if (!isttest(copy)) {
442 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
443 err_code |= ERR_ALERT | ERR_FATAL;
444 goto out;
445 }
446 curproxy->header_unique_id = copy;
447 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100448
449 /* default compression options */
450 if (defproxy.comp != NULL) {
Tim Duesterhuse52b6e52020-09-12 20:26:43 +0200451 curproxy->comp = calloc(1, sizeof(*curproxy->comp));
Remi Tricot-Le Breton1c3a2022021-05-12 18:07:27 +0200452 if (!curproxy->comp) {
453 ha_alert("parsing [%s:%d] : out of memory for default compression options", file, linenum);
454 err_code |= ERR_ALERT | ERR_ABORT;
455 goto out;
456 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100457 curproxy->comp->algos = defproxy.comp->algos;
458 curproxy->comp->types = defproxy.comp->types;
459 }
460
461 curproxy->grace = defproxy.grace;
462 curproxy->conf.used_listener_id = EB_ROOT;
463 curproxy->conf.used_server_id = EB_ROOT;
464
465 if (defproxy.check_path)
466 curproxy->check_path = strdup(defproxy.check_path);
467 if (defproxy.check_command)
468 curproxy->check_command = strdup(defproxy.check_command);
469
470 if (defproxy.email_alert.mailers.name)
471 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
472 if (defproxy.email_alert.from)
473 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
474 if (defproxy.email_alert.to)
475 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
476 if (defproxy.email_alert.myhostname)
477 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
478 curproxy->email_alert.level = defproxy.email_alert.level;
479 curproxy->email_alert.set = defproxy.email_alert.set;
480
481 goto out;
482 }
483 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
484 /* some variables may have already been initialized earlier */
485 /* FIXME-20070101: we should do this too at the end of the
486 * config parsing to free all default values.
487 */
488 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
489 err_code |= ERR_ABORT;
490 goto out;
491 }
492
Amaury Denoyelle36b53662020-09-18 15:59:39 +0200493 free(defproxy.conf.file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100494 free(defproxy.check_command);
495 free(defproxy.check_path);
496 free(defproxy.cookie_name);
497 free(defproxy.rdp_cookie_name);
498 free(defproxy.dyncookie_key);
499 free(defproxy.cookie_domain);
Christopher Faulet2f533902020-01-21 11:06:48 +0100500 free(defproxy.cookie_attrs);
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100501 free(defproxy.lbprm.arg_str);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100502 free(defproxy.capture_name);
503 free(defproxy.monitor_uri);
504 free(defproxy.defbe.name);
505 free(defproxy.conn_src.iface_name);
506 free(defproxy.fwdfor_hdr_name);
507 defproxy.fwdfor_hdr_len = 0;
508 free(defproxy.orgto_hdr_name);
509 defproxy.orgto_hdr_len = 0;
510 free(defproxy.server_id_hdr_name);
511 defproxy.server_id_hdr_len = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100512
513 if (defproxy.conf.logformat_string != default_http_log_format &&
514 defproxy.conf.logformat_string != default_tcp_log_format &&
515 defproxy.conf.logformat_string != clf_http_log_format)
516 free(defproxy.conf.logformat_string);
517
518 free(defproxy.conf.uniqueid_format_string);
519 free(defproxy.conf.lfs_file);
520 free(defproxy.conf.uif_file);
521 chunk_destroy(&defproxy.log_tag);
522 free_email_alert(&defproxy);
523
524 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
525 free(defproxy.conf.logformat_sd_string);
526 free(defproxy.conf.lfsd_file);
527
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100528 proxy_release_conf_errors(&defproxy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100529
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200530 deinit_proxy_tcpcheck(&defproxy);
531
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100532 /* we cannot free uri_auth because it might already be used */
533 init_default_instance();
534 curproxy = &defproxy;
535 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
536 curproxy->conf.args.line = curproxy->conf.line = linenum;
537 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
538 goto out;
539 }
540 else if (curproxy == NULL) {
541 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
542 err_code |= ERR_ALERT | ERR_FATAL;
543 goto out;
544 }
545
546 /* update the current file and line being parsed */
547 curproxy->conf.args.file = curproxy->conf.file;
548 curproxy->conf.args.line = linenum;
549
550 /* Now let's parse the proxy-specific keywords */
551 if (!strcmp(args[0], "server") ||
552 !strcmp(args[0], "default-server") ||
553 !strcmp(args[0], "server-template")) {
Emeric Brund3db3842020-07-21 16:54:36 +0200554 err_code |= parse_server(file, linenum, args, curproxy, &defproxy, 1, 0, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100555 if (err_code & ERR_FATAL)
556 goto out;
557 }
558 else if (!strcmp(args[0], "bind")) { /* new listen addresses */
559 struct listener *l;
560 int cur_arg;
561
562 if (curproxy == &defproxy) {
563 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
564 err_code |= ERR_ALERT | ERR_FATAL;
565 goto out;
566 }
567 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
568 err_code |= ERR_WARN;
569
570 if (!*(args[1])) {
571 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
572 file, linenum, args[0]);
573 err_code |= ERR_ALERT | ERR_FATAL;
574 goto out;
575 }
576
577 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
578
579 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200580 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
581 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
582 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100583
584 /* NOTE: the following line might create several listeners if there
585 * are comma-separated IPs or port ranges. So all further processing
586 * will have to be applied to all listeners created after last_listen.
587 */
588 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
589 if (errmsg && *errmsg) {
590 indent_msg(&errmsg, 2);
591 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
592 }
593 else
594 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
595 file, linenum, args[0], args[1]);
596 err_code |= ERR_ALERT | ERR_FATAL;
597 goto out;
598 }
599
600 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
601 /* Set default global rights and owner for unix bind */
602 global.maxsock++;
603 }
604
605 cur_arg = 2;
606 while (*(args[cur_arg])) {
607 static int bind_dumped;
608 struct bind_kw *kw;
609 char *err;
610
611 kw = bind_find_kw(args[cur_arg]);
612 if (kw) {
613 char *err = NULL;
614 int code;
615
616 if (!kw->parse) {
617 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
618 file, linenum, args[0], args[1], args[cur_arg]);
619 cur_arg += 1 + kw->skip ;
620 err_code |= ERR_ALERT | ERR_FATAL;
621 goto out;
622 }
623
624 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
625 err_code |= code;
626
627 if (code) {
628 if (err && *err) {
629 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200630 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
631 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
632 else
633 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100634 }
635 else
636 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
637 file, linenum, args[0], args[1], args[cur_arg]);
638 if (code & ERR_FATAL) {
639 free(err);
640 cur_arg += 1 + kw->skip;
641 goto out;
642 }
643 }
644 free(err);
645 cur_arg += 1 + kw->skip;
646 continue;
647 }
648
649 err = NULL;
650 if (!bind_dumped) {
651 bind_dump_kws(&err);
652 indent_msg(&err, 4);
653 bind_dumped = 1;
654 }
655
656 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
657 file, linenum, args[0], args[1], args[cur_arg],
658 err ? " Registered keywords :" : "", err ? err : "");
659 free(err);
660
661 err_code |= ERR_ALERT | ERR_FATAL;
662 goto out;
663 }
664 goto out;
665 }
666 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200667 ha_alert("parsing [%s:%d] : 'monitor-net' doesn't exist anymore. Please use 'http-request return status 200 if { src %s }' instead.\n", file, linenum, args[1]);
668 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100669 goto out;
670 }
671 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
672 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
673 err_code |= ERR_WARN;
674
675 if (alertif_too_many_args(1, file, linenum, args, &err_code))
676 goto out;
677
678 if (!*args[1]) {
679 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
680 file, linenum, args[0]);
681 err_code |= ERR_ALERT | ERR_FATAL;
682 goto out;
683 }
684
685 free(curproxy->monitor_uri);
686 curproxy->monitor_uri_len = strlen(args[1]);
687 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
688 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
689 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
690
691 goto out;
692 }
693 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
694 if (alertif_too_many_args(1, file, linenum, args, &err_code))
695 goto out;
696
697 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
698 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200699 else if (!strcmp(args[1], "health")) {
700 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
701 err_code |= ERR_ALERT | ERR_FATAL;
702 goto out;
703 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100704 else {
705 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
706 err_code |= ERR_ALERT | ERR_FATAL;
707 goto out;
708 }
709 }
710 else if (!strcmp(args[0], "id")) {
711 struct eb32_node *node;
712
713 if (curproxy == &defproxy) {
714 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
715 file, linenum, args[0]);
716 err_code |= ERR_ALERT | ERR_FATAL;
717 goto out;
718 }
719
720 if (alertif_too_many_args(1, file, linenum, args, &err_code))
721 goto out;
722
723 if (!*args[1]) {
724 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
725 file, linenum, args[0]);
726 err_code |= ERR_ALERT | ERR_FATAL;
727 goto out;
728 }
729
730 curproxy->uuid = atol(args[1]);
731 curproxy->conf.id.key = curproxy->uuid;
732 curproxy->options |= PR_O_FORCED_ID;
733
734 if (curproxy->uuid <= 0) {
735 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
736 file, linenum);
737 err_code |= ERR_ALERT | ERR_FATAL;
738 goto out;
739 }
740
741 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
742 if (node) {
743 struct proxy *target = container_of(node, struct proxy, conf.id);
744 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
745 file, linenum, proxy_type_str(curproxy), curproxy->id,
746 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
747 err_code |= ERR_ALERT | ERR_FATAL;
748 goto out;
749 }
750 eb32_insert(&used_proxy_id, &curproxy->conf.id);
751 }
752 else if (!strcmp(args[0], "description")) {
753 int i, len=0;
754 char *d;
755
756 if (curproxy == &defproxy) {
757 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
758 file, linenum, args[0]);
759 err_code |= ERR_ALERT | ERR_FATAL;
760 goto out;
761 }
762
763 if (!*args[1]) {
764 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
765 file, linenum, args[0]);
766 return -1;
767 }
768
769 for (i = 1; *args[i]; i++)
770 len += strlen(args[i]) + 1;
771
772 d = calloc(1, len);
773 curproxy->desc = d;
774
775 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
776 for (i = 2; *args[i]; i++)
777 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
778
779 }
780 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
781 if (alertif_too_many_args(0, file, linenum, args, &err_code))
782 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200783 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100784 }
785 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
786 if (alertif_too_many_args(0, file, linenum, args, &err_code))
787 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200788 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100789 }
790 else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */
791 int cur_arg = 1;
792 unsigned long set = 0;
793
794 while (*args[cur_arg]) {
795 if (strcmp(args[cur_arg], "all") == 0) {
796 set = 0;
797 break;
798 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100799 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100800 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
801 err_code |= ERR_ALERT | ERR_FATAL;
802 goto out;
803 }
804 cur_arg++;
805 }
806 curproxy->bind_proc = set;
807 }
808 else if (!strcmp(args[0], "acl")) { /* add an ACL */
809 if (curproxy == &defproxy) {
810 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
811 err_code |= ERR_ALERT | ERR_FATAL;
812 goto out;
813 }
814
815 err = invalid_char(args[1]);
816 if (err) {
817 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
818 file, linenum, *err, args[1]);
819 err_code |= ERR_ALERT | ERR_FATAL;
820 goto out;
821 }
822
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100823 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100824 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100825 "logical disjunction within a condition.\n",
826 file, linenum, args[1]);
827 err_code |= ERR_ALERT | ERR_FATAL;
828 goto out;
829 }
830
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100831 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
832 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
833 file, linenum, args[1], errmsg);
834 err_code |= ERR_ALERT | ERR_FATAL;
835 goto out;
836 }
837 }
838 else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */
839
840 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
841 err_code |= ERR_WARN;
842
843 if (*(args[1]) == 0) {
844 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
845 file, linenum, args[0]);
846 err_code |= ERR_ALERT | ERR_FATAL;
847 goto out;
848 }
849 free(curproxy->dyncookie_key);
850 curproxy->dyncookie_key = strdup(args[1]);
851 }
852 else if (!strcmp(args[0], "cookie")) { /* cookie name */
853 int cur_arg;
854
855 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
856 err_code |= ERR_WARN;
857
858 if (*(args[1]) == 0) {
859 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
860 file, linenum, args[0]);
861 err_code |= ERR_ALERT | ERR_FATAL;
862 goto out;
863 }
864
865 curproxy->ck_opts = 0;
866 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
867 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
868 free(curproxy->cookie_name);
869 curproxy->cookie_name = strdup(args[1]);
870 curproxy->cookie_len = strlen(curproxy->cookie_name);
871
872 cur_arg = 2;
873 while (*(args[cur_arg])) {
874 if (!strcmp(args[cur_arg], "rewrite")) {
875 curproxy->ck_opts |= PR_CK_RW;
876 }
877 else if (!strcmp(args[cur_arg], "indirect")) {
878 curproxy->ck_opts |= PR_CK_IND;
879 }
880 else if (!strcmp(args[cur_arg], "insert")) {
881 curproxy->ck_opts |= PR_CK_INS;
882 }
883 else if (!strcmp(args[cur_arg], "nocache")) {
884 curproxy->ck_opts |= PR_CK_NOC;
885 }
886 else if (!strcmp(args[cur_arg], "postonly")) {
887 curproxy->ck_opts |= PR_CK_POST;
888 }
889 else if (!strcmp(args[cur_arg], "preserve")) {
890 curproxy->ck_opts |= PR_CK_PSV;
891 }
892 else if (!strcmp(args[cur_arg], "prefix")) {
893 curproxy->ck_opts |= PR_CK_PFX;
894 }
895 else if (!strcmp(args[cur_arg], "httponly")) {
896 curproxy->ck_opts |= PR_CK_HTTPONLY;
897 }
898 else if (!strcmp(args[cur_arg], "secure")) {
899 curproxy->ck_opts |= PR_CK_SECURE;
900 }
901 else if (!strcmp(args[cur_arg], "domain")) {
902 if (!*args[cur_arg + 1]) {
903 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
904 file, linenum, args[cur_arg]);
905 err_code |= ERR_ALERT | ERR_FATAL;
906 goto out;
907 }
908
Joao Moraise1583752019-10-30 21:04:00 -0300909 if (!strchr(args[cur_arg + 1], '.')) {
910 /* rfc6265, 5.2.3 The Domain Attribute */
911 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
912 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100913 file, linenum, args[cur_arg + 1]);
914 err_code |= ERR_WARN;
915 }
916
917 err = invalid_domainchar(args[cur_arg + 1]);
918 if (err) {
919 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
920 file, linenum, *err, args[cur_arg + 1]);
921 err_code |= ERR_ALERT | ERR_FATAL;
922 goto out;
923 }
924
925 if (!curproxy->cookie_domain) {
926 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
927 } else {
928 /* one domain was already specified, add another one by
929 * building the string which will be returned along with
930 * the cookie.
931 */
932 char *new_ptr;
933 int new_len = strlen(curproxy->cookie_domain) +
934 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
935 new_ptr = malloc(new_len);
936 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
937 free(curproxy->cookie_domain);
938 curproxy->cookie_domain = new_ptr;
939 }
940 cur_arg++;
941 }
942 else if (!strcmp(args[cur_arg], "maxidle")) {
943 unsigned int maxidle;
944 const char *res;
945
946 if (!*args[cur_arg + 1]) {
947 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
948 file, linenum, args[cur_arg]);
949 err_code |= ERR_ALERT | ERR_FATAL;
950 goto out;
951 }
952
953 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200954 if (res == PARSE_TIME_OVER) {
955 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
956 file, linenum, args[cur_arg+1], args[cur_arg]);
957 err_code |= ERR_ALERT | ERR_FATAL;
958 goto out;
959 }
960 else if (res == PARSE_TIME_UNDER) {
961 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
962 file, linenum, args[cur_arg+1], args[cur_arg]);
963 err_code |= ERR_ALERT | ERR_FATAL;
964 goto out;
965 }
966 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100967 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
968 file, linenum, *res, args[cur_arg]);
969 err_code |= ERR_ALERT | ERR_FATAL;
970 goto out;
971 }
972 curproxy->cookie_maxidle = maxidle;
973 cur_arg++;
974 }
975 else if (!strcmp(args[cur_arg], "maxlife")) {
976 unsigned int maxlife;
977 const char *res;
978
979 if (!*args[cur_arg + 1]) {
980 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
981 file, linenum, args[cur_arg]);
982 err_code |= ERR_ALERT | ERR_FATAL;
983 goto out;
984 }
985
Willy Tarreau9faebe32019-06-07 19:00:37 +0200986
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100987 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200988 if (res == PARSE_TIME_OVER) {
989 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
990 file, linenum, args[cur_arg+1], args[cur_arg]);
991 err_code |= ERR_ALERT | ERR_FATAL;
992 goto out;
993 }
994 else if (res == PARSE_TIME_UNDER) {
995 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
996 file, linenum, args[cur_arg+1], args[cur_arg]);
997 err_code |= ERR_ALERT | ERR_FATAL;
998 goto out;
999 }
1000 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001001 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
1002 file, linenum, *res, args[cur_arg]);
1003 err_code |= ERR_ALERT | ERR_FATAL;
1004 goto out;
1005 }
1006 curproxy->cookie_maxlife = maxlife;
1007 cur_arg++;
1008 }
1009 else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */
1010
1011 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
1012 err_code |= ERR_WARN;
1013 curproxy->ck_opts |= PR_CK_DYNAMIC;
1014 }
Christopher Faulet2f533902020-01-21 11:06:48 +01001015 else if (!strcmp(args[cur_arg], "attr")) {
1016 char *val;
1017 if (!*args[cur_arg + 1]) {
1018 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
1019 file, linenum, args[cur_arg]);
1020 err_code |= ERR_ALERT | ERR_FATAL;
1021 goto out;
1022 }
1023 val = args[cur_arg + 1];
1024 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +01001025 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +01001026 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
1027 file, linenum, *val);
1028 err_code |= ERR_ALERT | ERR_FATAL;
1029 goto out;
1030 }
1031 val++;
1032 }
1033 /* don't add ';' for the first attribute */
1034 if (!curproxy->cookie_attrs)
1035 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
1036 else
1037 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
1038 cur_arg++;
1039 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001040
1041 else {
Christopher Faulet2f533902020-01-21 11:06:48 +01001042 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 +01001043 file, linenum, args[0]);
1044 err_code |= ERR_ALERT | ERR_FATAL;
1045 goto out;
1046 }
1047 cur_arg++;
1048 }
1049 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
1050 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
1051 file, linenum);
1052 err_code |= ERR_ALERT | ERR_FATAL;
1053 }
1054
1055 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
1056 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
1057 file, linenum);
1058 err_code |= ERR_ALERT | ERR_FATAL;
1059 }
1060
1061 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
1062 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
1063 file, linenum);
1064 err_code |= ERR_ALERT | ERR_FATAL;
1065 }
1066 }/* end else if (!strcmp(args[0], "cookie")) */
1067 else if (!strcmp(args[0], "email-alert")) {
1068 if (*(args[1]) == 0) {
1069 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1070 file, linenum, args[0]);
1071 err_code |= ERR_ALERT | ERR_FATAL;
1072 goto out;
1073 }
1074
1075 if (!strcmp(args[1], "from")) {
1076 if (*(args[1]) == 0) {
1077 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1078 file, linenum, args[1]);
1079 err_code |= ERR_ALERT | ERR_FATAL;
1080 goto out;
1081 }
1082 free(curproxy->email_alert.from);
1083 curproxy->email_alert.from = strdup(args[2]);
1084 }
1085 else if (!strcmp(args[1], "mailers")) {
1086 if (*(args[1]) == 0) {
1087 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1088 file, linenum, args[1]);
1089 err_code |= ERR_ALERT | ERR_FATAL;
1090 goto out;
1091 }
1092 free(curproxy->email_alert.mailers.name);
1093 curproxy->email_alert.mailers.name = strdup(args[2]);
1094 }
1095 else if (!strcmp(args[1], "myhostname")) {
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.myhostname);
1103 curproxy->email_alert.myhostname = strdup(args[2]);
1104 }
1105 else if (!strcmp(args[1], "level")) {
1106 curproxy->email_alert.level = get_log_level(args[2]);
1107 if (curproxy->email_alert.level < 0) {
1108 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1109 file, linenum, args[1], args[2]);
1110 err_code |= ERR_ALERT | ERR_FATAL;
1111 goto out;
1112 }
1113 }
1114 else if (!strcmp(args[1], "to")) {
1115 if (*(args[1]) == 0) {
1116 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1117 file, linenum, args[1]);
1118 err_code |= ERR_ALERT | ERR_FATAL;
1119 goto out;
1120 }
1121 free(curproxy->email_alert.to);
1122 curproxy->email_alert.to = strdup(args[2]);
1123 }
1124 else {
1125 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1126 file, linenum, args[1]);
1127 err_code |= ERR_ALERT | ERR_FATAL;
1128 goto out;
1129 }
1130 /* Indicate that the email_alert is at least partially configured */
1131 curproxy->email_alert.set = 1;
1132 }/* end else if (!strcmp(args[0], "email-alert")) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001133 else if (!strcmp(args[0], "persist")) { /* persist */
1134 if (*(args[1]) == 0) {
1135 ha_alert("parsing [%s:%d] : missing persist method.\n",
1136 file, linenum);
1137 err_code |= ERR_ALERT | ERR_FATAL;
1138 goto out;
1139 }
1140
1141 if (!strncmp(args[1], "rdp-cookie", 10)) {
1142 curproxy->options2 |= PR_O2_RDPC_PRST;
1143
1144 if (*(args[1] + 10) == '(') { /* cookie name */
1145 const char *beg, *end;
1146
1147 beg = args[1] + 11;
1148 end = strchr(beg, ')');
1149
1150 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1151 goto out;
1152
1153 if (!end || end == beg) {
1154 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1155 file, linenum);
1156 err_code |= ERR_ALERT | ERR_FATAL;
1157 goto out;
1158 }
1159
1160 free(curproxy->rdp_cookie_name);
1161 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
1162 curproxy->rdp_cookie_len = end-beg;
1163 }
1164 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1165 free(curproxy->rdp_cookie_name);
1166 curproxy->rdp_cookie_name = strdup("msts");
1167 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1168 }
1169 else { /* syntax */
1170 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1171 file, linenum);
1172 err_code |= ERR_ALERT | ERR_FATAL;
1173 goto out;
1174 }
1175 }
1176 else {
1177 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1178 file, linenum);
1179 err_code |= ERR_ALERT | ERR_FATAL;
1180 goto out;
1181 }
1182 }
1183 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001184 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 +01001185 err_code |= ERR_ALERT | ERR_FATAL;
1186 goto out;
1187 }
1188 else if (!strcmp(args[0], "load-server-state-from-file")) {
1189 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1190 err_code |= ERR_WARN;
1191 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
1192 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1193 }
1194 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
1195 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1196 }
1197 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
1198 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1199 }
1200 else {
1201 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1202 file, linenum, args[0], args[1]);
1203 err_code |= ERR_ALERT | ERR_FATAL;
1204 goto out;
1205 }
1206 }
1207 else if (!strcmp(args[0], "server-state-file-name")) {
1208 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1209 err_code |= ERR_WARN;
Christopher Faulet05df94b2021-02-12 09:27:10 +01001210 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001211 goto out;
Christopher Faulet05df94b2021-02-12 09:27:10 +01001212
1213 free(curproxy->server_state_file_name);
1214 curproxy->server_state_file_name = NULL;
1215
1216 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001217 curproxy->server_state_file_name = strdup(curproxy->id);
1218 else
1219 curproxy->server_state_file_name = strdup(args[1]);
1220 }
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001221 else if (!strcmp(args[0], "max-session-srv-conns")) {
1222 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1223 err_code |= ERR_WARN;
1224 if (*(args[1]) == 0) {
1225 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1226 file, linenum, args[0]);
1227 err_code |= ERR_ALERT | ERR_FATAL;
1228 goto out;
1229 }
1230 curproxy->max_out_conns = atoi(args[1]);
1231 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001232 else if (!strcmp(args[0], "capture")) {
1233 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1234 err_code |= ERR_WARN;
1235
1236 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
1237 if (curproxy == &defproxy) {
1238 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1239 err_code |= ERR_ALERT | ERR_FATAL;
1240 goto out;
1241 }
1242
1243 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1244 goto out;
1245
1246 if (*(args[4]) == 0) {
1247 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1248 file, linenum, args[0]);
1249 err_code |= ERR_ALERT | ERR_FATAL;
1250 goto out;
1251 }
1252 free(curproxy->capture_name);
1253 curproxy->capture_name = strdup(args[2]);
1254 curproxy->capture_namelen = strlen(curproxy->capture_name);
1255 curproxy->capture_len = atol(args[4]);
1256 curproxy->to_log |= LW_COOKIE;
1257 }
1258 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
1259 struct cap_hdr *hdr;
1260
1261 if (curproxy == &defproxy) {
1262 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1263 err_code |= ERR_ALERT | ERR_FATAL;
1264 goto out;
1265 }
1266
1267 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1268 goto out;
1269
1270 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1271 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1272 file, linenum, args[0], args[1]);
1273 err_code |= ERR_ALERT | ERR_FATAL;
1274 goto out;
1275 }
1276
1277 hdr = calloc(1, sizeof(*hdr));
1278 hdr->next = curproxy->req_cap;
1279 hdr->name = strdup(args[3]);
1280 hdr->namelen = strlen(args[3]);
1281 hdr->len = atol(args[5]);
1282 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1283 hdr->index = curproxy->nb_req_cap++;
1284 curproxy->req_cap = hdr;
1285 curproxy->to_log |= LW_REQHDR;
1286 }
1287 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
1288 struct cap_hdr *hdr;
1289
1290 if (curproxy == &defproxy) {
1291 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1292 err_code |= ERR_ALERT | ERR_FATAL;
1293 goto out;
1294 }
1295
1296 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1297 goto out;
1298
1299 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1300 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1301 file, linenum, args[0], args[1]);
1302 err_code |= ERR_ALERT | ERR_FATAL;
1303 goto out;
1304 }
1305 hdr = calloc(1, sizeof(*hdr));
1306 hdr->next = curproxy->rsp_cap;
1307 hdr->name = strdup(args[3]);
1308 hdr->namelen = strlen(args[3]);
1309 hdr->len = atol(args[5]);
1310 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1311 hdr->index = curproxy->nb_rsp_cap++;
1312 curproxy->rsp_cap = hdr;
1313 curproxy->to_log |= LW_RSPHDR;
1314 }
1315 else {
1316 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1317 file, linenum, args[0]);
1318 err_code |= ERR_ALERT | ERR_FATAL;
1319 goto out;
1320 }
1321 }
1322 else if (!strcmp(args[0], "retries")) { /* connection retries */
1323 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1324 err_code |= ERR_WARN;
1325
1326 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1327 goto out;
1328
1329 if (*(args[1]) == 0) {
1330 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1331 file, linenum, args[0]);
1332 err_code |= ERR_ALERT | ERR_FATAL;
1333 goto out;
1334 }
1335 curproxy->conn_retries = atol(args[1]);
1336 }
1337 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
1338 struct act_rule *rule;
1339
1340 if (curproxy == &defproxy) {
1341 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1342 err_code |= ERR_ALERT | ERR_FATAL;
1343 goto out;
1344 }
1345
1346 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1347 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001348 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001349 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1350 file, linenum, args[0]);
1351 err_code |= ERR_WARN;
1352 }
1353
1354 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1355
1356 if (!rule) {
1357 err_code |= ERR_ALERT | ERR_ABORT;
1358 goto out;
1359 }
1360
1361 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1362 err_code |= warnif_cond_conflicts(rule->cond,
1363 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1364 file, linenum);
1365
1366 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1367 }
1368 else if (!strcmp(args[0], "http-response")) { /* response access control */
1369 struct act_rule *rule;
1370
1371 if (curproxy == &defproxy) {
1372 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1373 err_code |= ERR_ALERT | ERR_FATAL;
1374 goto out;
1375 }
1376
1377 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1378 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001379 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001380 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1381 file, linenum, args[0]);
1382 err_code |= ERR_WARN;
1383 }
1384
1385 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1386
1387 if (!rule) {
1388 err_code |= ERR_ALERT | ERR_ABORT;
1389 goto out;
1390 }
1391
1392 err_code |= warnif_cond_conflicts(rule->cond,
1393 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1394 file, linenum);
1395
1396 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1397 }
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001398 else if (!strcmp(args[0], "http-after-response")) {
1399 struct act_rule *rule;
1400
1401 if (curproxy == &defproxy) {
1402 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1403 err_code |= ERR_ALERT | ERR_FATAL;
1404 goto out;
1405 }
1406
1407 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1408 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1409 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1410 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1411 file, linenum, args[0]);
1412 err_code |= ERR_WARN;
1413 }
1414
1415 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1416
1417 if (!rule) {
1418 err_code |= ERR_ALERT | ERR_ABORT;
1419 goto out;
1420 }
1421
1422 err_code |= warnif_cond_conflicts(rule->cond,
1423 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1424 file, linenum);
1425
1426 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1427 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001428 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
1429 /* set the header name and length into the proxy structure */
1430 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1431 err_code |= ERR_WARN;
1432
1433 if (!*args[1]) {
1434 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1435 file, linenum, args[0]);
1436 err_code |= ERR_ALERT | ERR_FATAL;
1437 goto out;
1438 }
1439
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001440 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001441 free(curproxy->server_id_hdr_name);
1442 curproxy->server_id_hdr_name = strdup(args[1]);
1443 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001444 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 +01001445 }
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001446 else if (!strcmp(args[0], "block")) {
1447 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 +01001448
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001449 err_code |= ERR_ALERT | ERR_FATAL;
1450 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001451 }
1452 else if (!strcmp(args[0], "redirect")) {
1453 struct redirect_rule *rule;
1454
1455 if (curproxy == &defproxy) {
1456 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1457 err_code |= ERR_ALERT | ERR_FATAL;
1458 goto out;
1459 }
1460
1461 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1462 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1463 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1464 err_code |= ERR_ALERT | ERR_FATAL;
1465 goto out;
1466 }
1467
1468 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1469 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1470 err_code |= warnif_cond_conflicts(rule->cond,
1471 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1472 file, linenum);
1473 }
1474 else if (!strcmp(args[0], "use_backend")) {
1475 struct switching_rule *rule;
1476
1477 if (curproxy == &defproxy) {
1478 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1479 err_code |= ERR_ALERT | ERR_FATAL;
1480 goto out;
1481 }
1482
1483 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1484 err_code |= ERR_WARN;
1485
1486 if (*(args[1]) == 0) {
1487 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1488 err_code |= ERR_ALERT | ERR_FATAL;
1489 goto out;
1490 }
1491
1492 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1493 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1494 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1495 file, linenum, errmsg);
1496 err_code |= ERR_ALERT | ERR_FATAL;
1497 goto out;
1498 }
1499
1500 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1501 }
1502 else if (*args[2]) {
1503 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1504 file, linenum, args[2]);
1505 err_code |= ERR_ALERT | ERR_FATAL;
1506 goto out;
1507 }
1508
1509 rule = calloc(1, sizeof(*rule));
1510 if (!rule) {
1511 ha_alert("Out of memory error.\n");
1512 goto out;
1513 }
1514 rule->cond = cond;
1515 rule->be.name = strdup(args[1]);
Tim Duesterhusf46d9cd2021-01-03 22:54:43 +01001516 if (!rule->be.name) {
1517 ha_alert("Out of memory error.\n");
1518 goto out;
1519 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001520 rule->line = linenum;
1521 rule->file = strdup(file);
1522 if (!rule->file) {
1523 ha_alert("Out of memory error.\n");
1524 goto out;
1525 }
1526 LIST_INIT(&rule->list);
1527 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1528 }
1529 else if (strcmp(args[0], "use-server") == 0) {
1530 struct server_rule *rule;
1531
1532 if (curproxy == &defproxy) {
1533 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1534 err_code |= ERR_ALERT | ERR_FATAL;
1535 goto out;
1536 }
1537
1538 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1539 err_code |= ERR_WARN;
1540
1541 if (*(args[1]) == 0) {
1542 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1543 err_code |= ERR_ALERT | ERR_FATAL;
1544 goto out;
1545 }
1546
1547 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1548 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1549 file, linenum, args[0]);
1550 err_code |= ERR_ALERT | ERR_FATAL;
1551 goto out;
1552 }
1553
1554 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1555 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1556 file, linenum, errmsg);
1557 err_code |= ERR_ALERT | ERR_FATAL;
1558 goto out;
1559 }
1560
1561 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1562
1563 rule = calloc(1, sizeof(*rule));
1564 rule->cond = cond;
1565 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001566 rule->line = linenum;
1567 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001568 LIST_INIT(&rule->list);
1569 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1570 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1571 }
1572 else if ((!strcmp(args[0], "force-persist")) ||
1573 (!strcmp(args[0], "ignore-persist"))) {
1574 struct persist_rule *rule;
1575
1576 if (curproxy == &defproxy) {
1577 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1578 err_code |= ERR_ALERT | ERR_FATAL;
1579 goto out;
1580 }
1581
1582 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1583 err_code |= ERR_WARN;
1584
1585 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1586 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1587 file, linenum, args[0]);
1588 err_code |= ERR_ALERT | ERR_FATAL;
1589 goto out;
1590 }
1591
1592 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1593 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1594 file, linenum, args[0], errmsg);
1595 err_code |= ERR_ALERT | ERR_FATAL;
1596 goto out;
1597 }
1598
1599 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1600 * where force-persist is applied.
1601 */
1602 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1603
1604 rule = calloc(1, sizeof(*rule));
1605 rule->cond = cond;
1606 if (!strcmp(args[0], "force-persist")) {
1607 rule->type = PERSIST_TYPE_FORCE;
1608 } else {
1609 rule->type = PERSIST_TYPE_IGNORE;
1610 }
1611 LIST_INIT(&rule->list);
1612 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1613 }
1614 else if (!strcmp(args[0], "stick-table")) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001615 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001616
1617 if (curproxy == &defproxy) {
1618 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1619 file, linenum);
1620 err_code |= ERR_ALERT | ERR_FATAL;
1621 goto out;
1622 }
1623
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001624 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001625 if (other) {
1626 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 +01001627 file, linenum, curproxy->id,
1628 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1629 other->proxy ? other->id : other->peers.p->id,
1630 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001631 err_code |= ERR_ALERT | ERR_FATAL;
1632 goto out;
1633 }
1634
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001635 curproxy->table = calloc(1, sizeof *curproxy->table);
1636 if (!curproxy->table) {
1637 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1638 file, linenum, args[0], args[1]);
1639 err_code |= ERR_ALERT | ERR_FATAL;
1640 goto out;
1641 }
1642
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001643 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1644 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001645 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001646 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001647
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001648 /* Store the proxy in the stick-table. */
1649 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001650
1651 stktable_store_name(curproxy->table);
1652 curproxy->table->next = stktables_list;
1653 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001654
1655 /* Add this proxy to the list of proxies which refer to its stick-table. */
1656 if (curproxy->table->proxies_list != curproxy) {
1657 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1658 curproxy->table->proxies_list = curproxy;
1659 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001660 }
1661 else if (!strcmp(args[0], "stick")) {
1662 struct sticking_rule *rule;
1663 struct sample_expr *expr;
1664 int myidx = 0;
1665 const char *name = NULL;
1666 int flags;
1667
1668 if (curproxy == &defproxy) {
1669 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1670 err_code |= ERR_ALERT | ERR_FATAL;
1671 goto out;
1672 }
1673
1674 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1675 err_code |= ERR_WARN;
1676 goto out;
1677 }
1678
1679 myidx++;
1680 if ((strcmp(args[myidx], "store") == 0) ||
1681 (strcmp(args[myidx], "store-request") == 0)) {
1682 myidx++;
1683 flags = STK_IS_STORE;
1684 }
1685 else if (strcmp(args[myidx], "store-response") == 0) {
1686 myidx++;
1687 flags = STK_IS_STORE | STK_ON_RSP;
1688 }
1689 else if (strcmp(args[myidx], "match") == 0) {
1690 myidx++;
1691 flags = STK_IS_MATCH;
1692 }
1693 else if (strcmp(args[myidx], "on") == 0) {
1694 myidx++;
1695 flags = STK_IS_MATCH | STK_IS_STORE;
1696 }
1697 else {
1698 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1699 err_code |= ERR_ALERT | ERR_FATAL;
1700 goto out;
1701 }
1702
1703 if (*(args[myidx]) == 0) {
1704 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1705 err_code |= ERR_ALERT | ERR_FATAL;
1706 goto out;
1707 }
1708
1709 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001710 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001711 if (!expr) {
1712 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1713 err_code |= ERR_ALERT | ERR_FATAL;
1714 goto out;
1715 }
1716
1717 if (flags & STK_ON_RSP) {
1718 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1719 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1720 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1721 err_code |= ERR_ALERT | ERR_FATAL;
1722 free(expr);
1723 goto out;
1724 }
1725 } else {
1726 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1727 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1728 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1729 err_code |= ERR_ALERT | ERR_FATAL;
1730 free(expr);
1731 goto out;
1732 }
1733 }
1734
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001735 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001736 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1737
1738 if (strcmp(args[myidx], "table") == 0) {
1739 myidx++;
1740 name = args[myidx++];
1741 }
1742
1743 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1744 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1745 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1746 file, linenum, args[0], errmsg);
1747 err_code |= ERR_ALERT | ERR_FATAL;
1748 free(expr);
1749 goto out;
1750 }
1751 }
1752 else if (*(args[myidx])) {
1753 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1754 file, linenum, args[0], args[myidx]);
1755 err_code |= ERR_ALERT | ERR_FATAL;
1756 free(expr);
1757 goto out;
1758 }
1759 if (flags & STK_ON_RSP)
1760 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1761 else
1762 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1763
1764 rule = calloc(1, sizeof(*rule));
1765 rule->cond = cond;
1766 rule->expr = expr;
1767 rule->flags = flags;
1768 rule->table.name = name ? strdup(name) : NULL;
1769 LIST_INIT(&rule->list);
1770 if (flags & STK_ON_RSP)
1771 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1772 else
1773 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1774 }
1775 else if (!strcmp(args[0], "stats")) {
1776 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
1777 curproxy->uri_auth = NULL; /* we must detach from the default config */
1778
1779 if (!*args[1]) {
1780 goto stats_error_parsing;
1781 } else if (!strcmp(args[1], "admin")) {
1782 struct stats_admin_rule *rule;
1783
1784 if (curproxy == &defproxy) {
1785 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1786 err_code |= ERR_ALERT | ERR_FATAL;
1787 goto out;
1788 }
1789
1790 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1791 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1792 err_code |= ERR_ALERT | ERR_ABORT;
1793 goto out;
1794 }
1795
1796 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1797 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1798 file, linenum, args[0], args[1]);
1799 err_code |= ERR_ALERT | ERR_FATAL;
1800 goto out;
1801 }
1802 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1803 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1804 file, linenum, args[0], args[1], errmsg);
1805 err_code |= ERR_ALERT | ERR_FATAL;
1806 goto out;
1807 }
1808
1809 err_code |= warnif_cond_conflicts(cond,
1810 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1811 file, linenum);
1812
1813 rule = calloc(1, sizeof(*rule));
1814 rule->cond = cond;
1815 LIST_INIT(&rule->list);
1816 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
1817 } else if (!strcmp(args[1], "uri")) {
1818 if (*(args[2]) == 0) {
1819 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1820 err_code |= ERR_ALERT | ERR_FATAL;
1821 goto out;
1822 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1823 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1824 err_code |= ERR_ALERT | ERR_ABORT;
1825 goto out;
1826 }
1827 } else if (!strcmp(args[1], "realm")) {
1828 if (*(args[2]) == 0) {
1829 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1830 err_code |= ERR_ALERT | ERR_FATAL;
1831 goto out;
1832 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1833 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1834 err_code |= ERR_ALERT | ERR_ABORT;
1835 goto out;
1836 }
1837 } else if (!strcmp(args[1], "refresh")) {
1838 unsigned interval;
1839
1840 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001841 if (err == PARSE_TIME_OVER) {
1842 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1843 file, linenum, args[2]);
1844 err_code |= ERR_ALERT | ERR_FATAL;
1845 goto out;
1846 }
1847 else if (err == PARSE_TIME_UNDER) {
1848 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1849 file, linenum, args[2]);
1850 err_code |= ERR_ALERT | ERR_FATAL;
1851 goto out;
1852 }
1853 else if (err) {
1854 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001855 file, linenum, *err);
1856 err_code |= ERR_ALERT | ERR_FATAL;
1857 goto out;
1858 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1859 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1860 err_code |= ERR_ALERT | ERR_ABORT;
1861 goto out;
1862 }
1863 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
1864 struct act_rule *rule;
1865
1866 if (curproxy == &defproxy) {
1867 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1868 err_code |= ERR_ALERT | ERR_FATAL;
1869 goto out;
1870 }
1871
1872 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1873 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1874 err_code |= ERR_ALERT | ERR_ABORT;
1875 goto out;
1876 }
1877
1878 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1879 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1880 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1881 file, linenum, args[0]);
1882 err_code |= ERR_WARN;
1883 }
1884
1885 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1886
1887 if (!rule) {
1888 err_code |= ERR_ALERT | ERR_ABORT;
1889 goto out;
1890 }
1891
1892 err_code |= warnif_cond_conflicts(rule->cond,
1893 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1894 file, linenum);
1895 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1896
1897 } else if (!strcmp(args[1], "auth")) {
1898 if (*(args[2]) == 0) {
1899 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1900 err_code |= ERR_ALERT | ERR_FATAL;
1901 goto out;
1902 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1903 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1904 err_code |= ERR_ALERT | ERR_ABORT;
1905 goto out;
1906 }
1907 } else if (!strcmp(args[1], "scope")) {
1908 if (*(args[2]) == 0) {
1909 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1910 err_code |= ERR_ALERT | ERR_FATAL;
1911 goto out;
1912 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1913 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1914 err_code |= ERR_ALERT | ERR_ABORT;
1915 goto out;
1916 }
1917 } else if (!strcmp(args[1], "enable")) {
1918 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
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], "hide-version")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001924 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001925 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1926 err_code |= ERR_ALERT | ERR_ABORT;
1927 goto out;
1928 }
1929 } else if (!strcmp(args[1], "show-legends")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001930 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001931 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1932 err_code |= ERR_ALERT | ERR_ABORT;
1933 goto out;
1934 }
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001935 } else if (!strcmp(args[1], "show-modules")) {
1936 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1937 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1938 err_code |= ERR_ALERT | ERR_ABORT;
1939 goto out;
1940 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001941 } else if (!strcmp(args[1], "show-node")) {
1942
1943 if (*args[2]) {
1944 int i;
1945 char c;
1946
1947 for (i=0; args[2][i]; i++) {
1948 c = args[2][i];
1949 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1950 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1951 break;
1952 }
1953
1954 if (!i || args[2][i]) {
1955 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1956 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1957 file, linenum, args[0], args[1]);
1958 err_code |= ERR_ALERT | ERR_FATAL;
1959 goto out;
1960 }
1961 }
1962
1963 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1964 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1965 err_code |= ERR_ALERT | ERR_ABORT;
1966 goto out;
1967 }
1968 } else if (!strcmp(args[1], "show-desc")) {
1969 char *desc = NULL;
1970
1971 if (*args[2]) {
1972 int i, len=0;
1973 char *d;
1974
1975 for (i = 2; *args[i]; i++)
1976 len += strlen(args[i]) + 1;
1977
1978 desc = d = calloc(1, len);
1979
1980 d += snprintf(d, desc + len - d, "%s", args[2]);
1981 for (i = 3; *args[i]; i++)
1982 d += snprintf(d, desc + len - d, " %s", args[i]);
1983 }
1984
1985 if (!*args[2] && !global.desc)
1986 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1987 file, linenum, args[1]);
1988 else {
1989 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1990 free(desc);
1991 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1992 err_code |= ERR_ALERT | ERR_ABORT;
1993 goto out;
1994 }
1995 free(desc);
1996 }
1997 } else {
1998stats_error_parsing:
1999 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
2000 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
2001 err_code |= ERR_ALERT | ERR_FATAL;
2002 goto out;
2003 }
2004 }
2005 else if (!strcmp(args[0], "option")) {
2006 int optnum;
2007
2008 if (*(args[1]) == '\0') {
2009 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
2010 file, linenum, args[0]);
2011 err_code |= ERR_ALERT | ERR_FATAL;
2012 goto out;
2013 }
2014
2015 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
2016 if (!strcmp(args[1], cfg_opts[optnum].name)) {
2017 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
2018 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2019 file, linenum, cfg_opts[optnum].name);
2020 err_code |= ERR_ALERT | ERR_FATAL;
2021 goto out;
2022 }
2023 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2024 goto out;
2025
2026 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
2027 err_code |= ERR_WARN;
2028 goto out;
2029 }
2030
2031 curproxy->no_options &= ~cfg_opts[optnum].val;
2032 curproxy->options &= ~cfg_opts[optnum].val;
2033
2034 switch (kwm) {
2035 case KWM_STD:
2036 curproxy->options |= cfg_opts[optnum].val;
2037 break;
2038 case KWM_NO:
2039 curproxy->no_options |= cfg_opts[optnum].val;
2040 break;
2041 case KWM_DEF: /* already cleared */
2042 break;
2043 }
2044
2045 goto out;
2046 }
2047 }
2048
2049 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
2050 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
2051 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2052 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2053 file, linenum, cfg_opts2[optnum].name);
2054 err_code |= ERR_ALERT | ERR_FATAL;
2055 goto out;
2056 }
2057 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2058 goto out;
2059 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2060 err_code |= ERR_WARN;
2061 goto out;
2062 }
2063
Christopher Faulet31930372019-07-15 10:16:58 +02002064 /* "[no] option http-use-htx" is deprecated */
2065 if (!strcmp(cfg_opts2[optnum].name, "http-use-htx")) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02002066 if (kwm ==KWM_NO) {
2067 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
2068 " The HTX mode is now the only supported mode.\n",
2069 file, linenum, cfg_opts2[optnum].name);
2070 err_code |= ERR_WARN;
2071 }
Christopher Faulet31930372019-07-15 10:16:58 +02002072 goto out;
2073 }
2074
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002075 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2076 curproxy->options2 &= ~cfg_opts2[optnum].val;
2077
2078 switch (kwm) {
2079 case KWM_STD:
2080 curproxy->options2 |= cfg_opts2[optnum].val;
2081 break;
2082 case KWM_NO:
2083 curproxy->no_options2 |= cfg_opts2[optnum].val;
2084 break;
2085 case KWM_DEF: /* already cleared */
2086 break;
2087 }
2088 goto out;
2089 }
2090 }
2091
2092 /* HTTP options override each other. They can be cancelled using
2093 * "no option xxx" which only switches to default mode if the mode
2094 * was this one (useful for cancelling options set in defaults
2095 * sections).
2096 */
2097 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02002098 if (strcmp(args[1], "forceclose") == 0) {
2099 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
2100 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
2101 file, linenum, args[1]);
2102 err_code |= ERR_WARN;
2103 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002104 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2105 goto out;
2106 if (kwm == KWM_STD) {
2107 curproxy->options &= ~PR_O_HTTP_MODE;
2108 curproxy->options |= PR_O_HTTP_CLO;
2109 goto out;
2110 }
2111 else if (kwm == KWM_NO) {
2112 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2113 curproxy->options &= ~PR_O_HTTP_MODE;
2114 goto out;
2115 }
2116 }
2117 else if (strcmp(args[1], "http-server-close") == 0) {
2118 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2119 goto out;
2120 if (kwm == KWM_STD) {
2121 curproxy->options &= ~PR_O_HTTP_MODE;
2122 curproxy->options |= PR_O_HTTP_SCL;
2123 goto out;
2124 }
2125 else if (kwm == KWM_NO) {
2126 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2127 curproxy->options &= ~PR_O_HTTP_MODE;
2128 goto out;
2129 }
2130 }
2131 else if (strcmp(args[1], "http-keep-alive") == 0) {
2132 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2133 goto out;
2134 if (kwm == KWM_STD) {
2135 curproxy->options &= ~PR_O_HTTP_MODE;
2136 curproxy->options |= PR_O_HTTP_KAL;
2137 goto out;
2138 }
2139 else if (kwm == KWM_NO) {
2140 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2141 curproxy->options &= ~PR_O_HTTP_MODE;
2142 goto out;
2143 }
2144 }
2145 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002146 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2147 file, linenum, args[1]);
2148 err_code |= ERR_WARN;
2149 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002150 }
2151
2152 /* Redispatch can take an integer argument that control when the
2153 * resispatch occurs. All values are relative to the retries option.
2154 * This can be cancelled using "no option xxx".
2155 */
2156 if (strcmp(args[1], "redispatch") == 0) {
2157 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2158 err_code |= ERR_WARN;
2159 goto out;
2160 }
2161
2162 curproxy->no_options &= ~PR_O_REDISP;
2163 curproxy->options &= ~PR_O_REDISP;
2164
2165 switch (kwm) {
2166 case KWM_STD:
2167 curproxy->options |= PR_O_REDISP;
2168 curproxy->redispatch_after = -1;
2169 if(*args[2]) {
2170 curproxy->redispatch_after = atol(args[2]);
2171 }
2172 break;
2173 case KWM_NO:
2174 curproxy->no_options |= PR_O_REDISP;
2175 curproxy->redispatch_after = 0;
2176 break;
2177 case KWM_DEF: /* already cleared */
2178 break;
2179 }
2180 goto out;
2181 }
2182
2183 if (kwm != KWM_STD) {
2184 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2185 file, linenum, args[1]);
2186 err_code |= ERR_ALERT | ERR_FATAL;
2187 goto out;
2188 }
2189
2190 if (!strcmp(args[1], "httplog")) {
2191 char *logformat;
2192 /* generate a complete HTTP log */
2193 logformat = default_http_log_format;
2194 if (*(args[2]) != '\0') {
2195 if (!strcmp(args[2], "clf")) {
2196 curproxy->options2 |= PR_O2_CLFLOG;
2197 logformat = clf_http_log_format;
2198 } else {
2199 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2200 err_code |= ERR_ALERT | ERR_FATAL;
2201 goto out;
2202 }
2203 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2204 goto out;
2205 }
2206 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2207 char *oldlogformat = "log-format";
2208 char *clflogformat = "";
2209
2210 if (curproxy->conf.logformat_string == default_http_log_format)
2211 oldlogformat = "option httplog";
2212 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2213 oldlogformat = "option tcplog";
2214 else if (curproxy->conf.logformat_string == clf_http_log_format)
2215 oldlogformat = "option httplog clf";
2216 if (logformat == clf_http_log_format)
2217 clflogformat = " clf";
2218 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2219 file, linenum, clflogformat, oldlogformat);
2220 }
2221 if (curproxy->conf.logformat_string != default_http_log_format &&
2222 curproxy->conf.logformat_string != default_tcp_log_format &&
2223 curproxy->conf.logformat_string != clf_http_log_format)
2224 free(curproxy->conf.logformat_string);
2225 curproxy->conf.logformat_string = logformat;
2226
2227 free(curproxy->conf.lfs_file);
2228 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2229 curproxy->conf.lfs_line = curproxy->conf.args.line;
2230
2231 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2232 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2233 file, linenum, curproxy->id);
2234 err_code |= ERR_WARN;
2235 }
2236 }
2237 else if (!strcmp(args[1], "tcplog")) {
2238 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2239 char *oldlogformat = "log-format";
2240
2241 if (curproxy->conf.logformat_string == default_http_log_format)
2242 oldlogformat = "option httplog";
2243 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2244 oldlogformat = "option tcplog";
2245 else if (curproxy->conf.logformat_string == clf_http_log_format)
2246 oldlogformat = "option httplog clf";
2247 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2248 file, linenum, oldlogformat);
2249 }
2250 /* generate a detailed TCP log */
2251 if (curproxy->conf.logformat_string != default_http_log_format &&
2252 curproxy->conf.logformat_string != default_tcp_log_format &&
2253 curproxy->conf.logformat_string != clf_http_log_format)
2254 free(curproxy->conf.logformat_string);
2255 curproxy->conf.logformat_string = default_tcp_log_format;
2256
2257 free(curproxy->conf.lfs_file);
2258 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2259 curproxy->conf.lfs_line = curproxy->conf.args.line;
2260
2261 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2262 goto out;
2263
2264 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2265 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2266 file, linenum, curproxy->id);
2267 err_code |= ERR_WARN;
2268 }
2269 }
2270 else if (!strcmp(args[1], "tcpka")) {
2271 /* enable TCP keep-alives on client and server streams */
2272 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2273 err_code |= ERR_WARN;
2274
2275 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2276 goto out;
2277
2278 if (curproxy->cap & PR_CAP_FE)
2279 curproxy->options |= PR_O_TCP_CLI_KA;
2280 if (curproxy->cap & PR_CAP_BE)
2281 curproxy->options |= PR_O_TCP_SRV_KA;
2282 }
2283 else if (!strcmp(args[1], "httpchk")) {
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002284 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2285 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002286 goto out;
2287 }
2288 else if (!strcmp(args[1], "ssl-hello-chk")) {
Christopher Faulet811f78c2020-04-01 11:10:27 +02002289 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum);
2290 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002291 goto out;
2292 }
2293 else if (!strcmp(args[1], "smtpchk")) {
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002294 err_code |= proxy_parse_smtpchk_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], "pgsql-check")) {
Christopher Fauletce355072020-04-02 11:44:39 +02002299 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2300 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002301 goto out;
2302 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002303 else if (!strcmp(args[1], "redis-check")) {
Christopher Faulet33f05df2020-04-01 11:08:50 +02002304 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2305 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002306 goto out;
2307 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002308 else if (!strcmp(args[1], "mysql-check")) {
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002309 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2310 if (err_code & ERR_FATAL)
2311 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002312 }
2313 else if (!strcmp(args[1], "ldap-check")) {
Christopher Faulet1997eca2020-04-03 23:13:50 +02002314 err_code |= proxy_parse_ldap_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 }
2318 else if (!strcmp(args[1], "spop-check")) {
Christopher Faulet267b01b2020-04-04 10:27:09 +02002319 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2320 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002321 goto out;
2322 }
2323 else if (!strcmp(args[1], "tcp-check")) {
Christopher Faulet430e4802020-04-09 15:28:16 +02002324 err_code |= proxy_parse_tcp_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], "external-check")) {
Christopher Faulet6f557912020-04-09 15:58:50 +02002329 err_code |= proxy_parse_external_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], "forwardfor")) {
2334 int cur_arg;
2335
2336 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002337 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002338 */
2339
2340 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2341
2342 free(curproxy->fwdfor_hdr_name);
2343 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2344 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2345
2346 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2347 cur_arg = 2;
2348 while (*(args[cur_arg])) {
2349 if (!strcmp(args[cur_arg], "except")) {
2350 /* suboption except - needs additional argument for it */
2351 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2352 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2353 file, linenum, args[0], args[1], args[cur_arg]);
2354 err_code |= ERR_ALERT | ERR_FATAL;
2355 goto out;
2356 }
2357 /* flush useless bits */
2358 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2359 cur_arg += 2;
2360 } else if (!strcmp(args[cur_arg], "header")) {
2361 /* suboption header - needs additional argument for it */
2362 if (*(args[cur_arg+1]) == 0) {
2363 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2364 file, linenum, args[0], args[1], args[cur_arg]);
2365 err_code |= ERR_ALERT | ERR_FATAL;
2366 goto out;
2367 }
2368 free(curproxy->fwdfor_hdr_name);
2369 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2370 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2371 cur_arg += 2;
2372 } else if (!strcmp(args[cur_arg], "if-none")) {
2373 curproxy->options &= ~PR_O_FF_ALWAYS;
2374 cur_arg += 1;
2375 } else {
2376 /* unknown suboption - catchall */
2377 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2378 file, linenum, args[0], args[1]);
2379 err_code |= ERR_ALERT | ERR_FATAL;
2380 goto out;
2381 }
2382 } /* end while loop */
2383 }
2384 else if (!strcmp(args[1], "originalto")) {
2385 int cur_arg;
2386
2387 /* insert x-original-to field, but not for the IP address listed as an except.
2388 * set default options (ie: bitfield, header name, etc)
2389 */
2390
2391 curproxy->options |= PR_O_ORGTO;
2392
2393 free(curproxy->orgto_hdr_name);
2394 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2395 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2396
2397 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2398 cur_arg = 2;
2399 while (*(args[cur_arg])) {
2400 if (!strcmp(args[cur_arg], "except")) {
2401 /* suboption except - needs additional argument for it */
2402 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2403 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2404 file, linenum, args[0], args[1], args[cur_arg]);
2405 err_code |= ERR_ALERT | ERR_FATAL;
2406 goto out;
2407 }
2408 /* flush useless bits */
2409 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2410 cur_arg += 2;
2411 } else if (!strcmp(args[cur_arg], "header")) {
2412 /* suboption header - needs additional argument for it */
2413 if (*(args[cur_arg+1]) == 0) {
2414 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2415 file, linenum, args[0], args[1], args[cur_arg]);
2416 err_code |= ERR_ALERT | ERR_FATAL;
2417 goto out;
2418 }
2419 free(curproxy->orgto_hdr_name);
2420 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2421 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2422 cur_arg += 2;
2423 } else {
2424 /* unknown suboption - catchall */
2425 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2426 file, linenum, args[0], args[1]);
2427 err_code |= ERR_ALERT | ERR_FATAL;
2428 goto out;
2429 }
2430 } /* end while loop */
2431 }
2432 else {
2433 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2434 err_code |= ERR_ALERT | ERR_FATAL;
2435 goto out;
2436 }
2437 goto out;
2438 }
2439 else if (!strcmp(args[0], "default_backend")) {
2440 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2441 err_code |= ERR_WARN;
2442
2443 if (*(args[1]) == 0) {
2444 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2445 err_code |= ERR_ALERT | ERR_FATAL;
2446 goto out;
2447 }
2448 free(curproxy->defbe.name);
2449 curproxy->defbe.name = strdup(args[1]);
2450
2451 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2452 goto out;
2453 }
2454 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002455 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 +01002456
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002457 err_code |= ERR_ALERT | ERR_FATAL;
2458 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002459 }
2460 else if (!strcmp(args[0], "http-reuse")) {
2461 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2462 err_code |= ERR_WARN;
2463
2464 if (strcmp(args[1], "never") == 0) {
2465 /* enable a graceful server shutdown on an HTTP 404 response */
2466 curproxy->options &= ~PR_O_REUSE_MASK;
2467 curproxy->options |= PR_O_REUSE_NEVR;
2468 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2469 goto out;
2470 }
2471 else if (strcmp(args[1], "safe") == 0) {
2472 /* enable a graceful server shutdown on an HTTP 404 response */
2473 curproxy->options &= ~PR_O_REUSE_MASK;
2474 curproxy->options |= PR_O_REUSE_SAFE;
2475 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2476 goto out;
2477 }
2478 else if (strcmp(args[1], "aggressive") == 0) {
2479 curproxy->options &= ~PR_O_REUSE_MASK;
2480 curproxy->options |= PR_O_REUSE_AGGR;
2481 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2482 goto out;
2483 }
2484 else if (strcmp(args[1], "always") == 0) {
2485 /* enable a graceful server shutdown on an HTTP 404 response */
2486 curproxy->options &= ~PR_O_REUSE_MASK;
2487 curproxy->options |= PR_O_REUSE_ALWS;
2488 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2489 goto out;
2490 }
2491 else {
2492 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2493 err_code |= ERR_ALERT | ERR_FATAL;
2494 goto out;
2495 }
2496 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002497 else if (!strcmp(args[0], "monitor")) {
2498 if (curproxy == &defproxy) {
2499 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2500 err_code |= ERR_ALERT | ERR_FATAL;
2501 goto out;
2502 }
2503
2504 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2505 err_code |= ERR_WARN;
2506
2507 if (strcmp(args[1], "fail") == 0) {
2508 /* add a condition to fail monitor requests */
2509 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2510 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2511 file, linenum, args[0], args[1]);
2512 err_code |= ERR_ALERT | ERR_FATAL;
2513 goto out;
2514 }
2515
2516 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2517 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2518 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2519 file, linenum, args[0], args[1], errmsg);
2520 err_code |= ERR_ALERT | ERR_FATAL;
2521 goto out;
2522 }
2523 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2524 }
2525 else {
2526 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2527 err_code |= ERR_ALERT | ERR_FATAL;
2528 goto out;
2529 }
2530 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002531#ifdef USE_TPROXY
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002532 else if (!strcmp(args[0], "transparent")) {
2533 /* enable transparent proxy connections */
2534 curproxy->options |= PR_O_TRANSP;
2535 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2536 goto out;
2537 }
2538#endif
2539 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
2540 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2541 err_code |= ERR_WARN;
2542
2543 if (*(args[1]) == 0) {
2544 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2545 err_code |= ERR_ALERT | ERR_FATAL;
2546 goto out;
2547 }
2548 curproxy->maxconn = atol(args[1]);
2549 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2550 goto out;
2551 }
2552 else if (!strcmp(args[0], "backlog")) { /* backlog */
2553 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2554 err_code |= ERR_WARN;
2555
2556 if (*(args[1]) == 0) {
2557 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2558 err_code |= ERR_ALERT | ERR_FATAL;
2559 goto out;
2560 }
2561 curproxy->backlog = atol(args[1]);
2562 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2563 goto out;
2564 }
2565 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
2566 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2567 err_code |= ERR_WARN;
2568
2569 if (*(args[1]) == 0) {
2570 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2571 err_code |= ERR_ALERT | ERR_FATAL;
2572 goto out;
2573 }
2574 curproxy->fullconn = atol(args[1]);
2575 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2576 goto out;
2577 }
2578 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
2579 if (*(args[1]) == 0) {
2580 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2581 err_code |= ERR_ALERT | ERR_FATAL;
2582 goto out;
2583 }
2584 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002585 if (err == PARSE_TIME_OVER) {
2586 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2587 file, linenum, args[1]);
2588 err_code |= ERR_ALERT | ERR_FATAL;
2589 goto out;
2590 }
2591 else if (err == PARSE_TIME_UNDER) {
2592 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2593 file, linenum, args[1]);
2594 err_code |= ERR_ALERT | ERR_FATAL;
2595 goto out;
2596 }
2597 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002598 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2599 file, linenum, *err);
2600 err_code |= ERR_ALERT | ERR_FATAL;
2601 goto out;
2602 }
2603 curproxy->grace = val;
2604 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2605 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002606
2607 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2608 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002609 }
2610 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
2611 struct sockaddr_storage *sk;
2612 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002613
2614 if (curproxy == &defproxy) {
2615 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2616 err_code |= ERR_ALERT | ERR_FATAL;
2617 goto out;
2618 }
2619 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2620 err_code |= ERR_WARN;
2621
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002622 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2623 &errmsg, NULL, NULL,
2624 PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002625 if (!sk) {
2626 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2627 err_code |= ERR_ALERT | ERR_FATAL;
2628 goto out;
2629 }
2630
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002631 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2632 goto out;
2633
2634 curproxy->dispatch_addr = *sk;
2635 curproxy->options |= PR_O_DISPATCH;
2636 }
2637 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
2638 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2639 err_code |= ERR_WARN;
2640
2641 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2642 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2643 err_code |= ERR_ALERT | ERR_FATAL;
2644 goto out;
2645 }
2646 }
2647 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
2648 /**
2649 * The syntax for hash-type config element is
2650 * hash-type {map-based|consistent} [[<algo>] avalanche]
2651 *
2652 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2653 */
2654 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2655
2656 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2657 err_code |= ERR_WARN;
2658
2659 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2660 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2661 }
2662 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2663 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2664 }
2665 else if (strcmp(args[1], "avalanche") == 0) {
2666 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]);
2667 err_code |= ERR_ALERT | ERR_FATAL;
2668 goto out;
2669 }
2670 else {
2671 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2672 err_code |= ERR_ALERT | ERR_FATAL;
2673 goto out;
2674 }
2675
2676 /* set the hash function to use */
2677 if (!*args[2]) {
2678 /* the default algo is sdbm */
2679 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2680
2681 /* if consistent with no argument, then avalanche modifier is also applied */
2682 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2683 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2684 } else {
2685 /* set the hash function */
2686 if (!strcmp(args[2], "sdbm")) {
2687 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2688 }
2689 else if (!strcmp(args[2], "djb2")) {
2690 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2691 }
2692 else if (!strcmp(args[2], "wt6")) {
2693 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2694 }
2695 else if (!strcmp(args[2], "crc32")) {
2696 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2697 }
2698 else {
2699 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2700 err_code |= ERR_ALERT | ERR_FATAL;
2701 goto out;
2702 }
2703
2704 /* set the hash modifier */
2705 if (!strcmp(args[3], "avalanche")) {
2706 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2707 }
2708 else if (*args[3]) {
2709 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2710 err_code |= ERR_ALERT | ERR_FATAL;
2711 goto out;
2712 }
2713 }
2714 }
2715 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2716 if (*(args[1]) == 0) {
2717 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2718 err_code |= ERR_ALERT | ERR_FATAL;
2719 goto out;
2720 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002721 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2722 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002723 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2724 err_code |= ERR_ALERT | ERR_FATAL;
2725 goto out;
2726 }
2727 }
2728 else if (strcmp(args[0], "unique-id-format") == 0) {
2729 if (!*(args[1])) {
2730 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2731 err_code |= ERR_ALERT | ERR_FATAL;
2732 goto out;
2733 }
2734 if (*(args[2])) {
2735 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2736 err_code |= ERR_ALERT | ERR_FATAL;
2737 goto out;
2738 }
2739 free(curproxy->conf.uniqueid_format_string);
2740 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2741
2742 free(curproxy->conf.uif_file);
2743 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2744 curproxy->conf.uif_line = curproxy->conf.args.line;
2745 }
2746
2747 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002748 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002749 if (!*(args[1])) {
2750 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2751 err_code |= ERR_ALERT | ERR_FATAL;
2752 goto out;
2753 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002754 copy = strdup(args[1]);
2755 if (copy == NULL) {
2756 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2757 err_code |= ERR_ALERT | ERR_FATAL;
2758 goto out;
2759 }
2760
2761 istfree(&curproxy->header_unique_id);
2762 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002763 }
2764
2765 else if (strcmp(args[0], "log-format") == 0) {
2766 if (!*(args[1])) {
2767 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2768 err_code |= ERR_ALERT | ERR_FATAL;
2769 goto out;
2770 }
2771 if (*(args[2])) {
2772 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2773 err_code |= ERR_ALERT | ERR_FATAL;
2774 goto out;
2775 }
2776 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2777 char *oldlogformat = "log-format";
2778
2779 if (curproxy->conf.logformat_string == default_http_log_format)
2780 oldlogformat = "option httplog";
2781 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2782 oldlogformat = "option tcplog";
2783 else if (curproxy->conf.logformat_string == clf_http_log_format)
2784 oldlogformat = "option httplog clf";
2785 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2786 file, linenum, oldlogformat);
2787 }
2788 if (curproxy->conf.logformat_string != default_http_log_format &&
2789 curproxy->conf.logformat_string != default_tcp_log_format &&
2790 curproxy->conf.logformat_string != clf_http_log_format)
2791 free(curproxy->conf.logformat_string);
2792 curproxy->conf.logformat_string = strdup(args[1]);
2793
2794 free(curproxy->conf.lfs_file);
2795 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2796 curproxy->conf.lfs_line = curproxy->conf.args.line;
2797
2798 /* get a chance to improve log-format error reporting by
2799 * reporting the correct line-number when possible.
2800 */
2801 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2802 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2803 file, linenum, curproxy->id);
2804 err_code |= ERR_WARN;
2805 }
2806 }
2807 else if (!strcmp(args[0], "log-format-sd")) {
2808 if (!*(args[1])) {
2809 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2810 err_code |= ERR_ALERT | ERR_FATAL;
2811 goto out;
2812 }
2813 if (*(args[2])) {
2814 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2815 err_code |= ERR_ALERT | ERR_FATAL;
2816 goto out;
2817 }
2818
2819 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2820 free(curproxy->conf.logformat_sd_string);
2821 curproxy->conf.logformat_sd_string = strdup(args[1]);
2822
2823 free(curproxy->conf.lfsd_file);
2824 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2825 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2826
2827 /* get a chance to improve log-format-sd error reporting by
2828 * reporting the correct line-number when possible.
2829 */
2830 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2831 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2832 file, linenum, curproxy->id);
2833 err_code |= ERR_WARN;
2834 }
2835 }
2836 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
2837 if (*(args[1]) == 0) {
2838 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2839 err_code |= ERR_ALERT | ERR_FATAL;
2840 goto out;
2841 }
2842 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002843 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2844 if (b_orig(&curproxy->log_tag) == NULL) {
2845 chunk_destroy(&curproxy->log_tag);
2846 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2847 err_code |= ERR_ALERT | ERR_FATAL;
2848 goto out;
2849 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002850 }
2851 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
2852 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2853 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2854 err_code |= ERR_ALERT | ERR_FATAL;
2855 goto out;
2856 }
2857 }
2858 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
2859 int cur_arg;
2860 int port1, port2;
2861 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002862
2863 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2864 err_code |= ERR_WARN;
2865
2866 if (!*args[1]) {
2867 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2868 file, linenum, "source", "usesrc", "interface");
2869 err_code |= ERR_ALERT | ERR_FATAL;
2870 goto out;
2871 }
2872
Christopher Faulet31930372019-07-15 10:16:58 +02002873 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002874 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2875 free(curproxy->conn_src.iface_name);
2876 curproxy->conn_src.iface_name = NULL;
2877 curproxy->conn_src.iface_len = 0;
2878
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002879 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2880 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002881 if (!sk) {
2882 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2883 file, linenum, args[0], args[1], errmsg);
2884 err_code |= ERR_ALERT | ERR_FATAL;
2885 goto out;
2886 }
2887
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002888 curproxy->conn_src.source_addr = *sk;
2889 curproxy->conn_src.opts |= CO_SRC_BIND;
2890
2891 cur_arg = 2;
2892 while (*(args[cur_arg])) {
2893 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
2894#if defined(CONFIG_HAP_TRANSPARENT)
2895 if (!*args[cur_arg + 1]) {
2896 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2897 file, linenum, "usesrc");
2898 err_code |= ERR_ALERT | ERR_FATAL;
2899 goto out;
2900 }
2901
2902 if (!strcmp(args[cur_arg + 1], "client")) {
2903 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2904 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
2905 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
2906 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2907 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2908 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2909 char *name, *end;
2910
2911 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002912 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002913 name++;
2914
2915 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002916 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002917 end++;
2918
2919 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2920 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle7edf20e2021-01-26 14:35:22 +01002921 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002922 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2923 curproxy->conn_src.bind_hdr_len = end - name;
2924 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2925 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2926 curproxy->conn_src.bind_hdr_occ = -1;
2927
2928 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002929 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002930 end++;
2931 if (*end == ',') {
2932 end++;
2933 name = end;
2934 if (*end == '-')
2935 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002936 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002937 end++;
2938 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2939 }
2940
2941 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2942 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2943 " occurrences values smaller than %d.\n",
2944 file, linenum, MAX_HDR_HISTORY);
2945 err_code |= ERR_ALERT | ERR_FATAL;
2946 goto out;
2947 }
2948 } else {
2949 struct sockaddr_storage *sk;
2950
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002951 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2952 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002953 if (!sk) {
2954 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2955 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2956 err_code |= ERR_ALERT | ERR_FATAL;
2957 goto out;
2958 }
2959
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002960 curproxy->conn_src.tproxy_addr = *sk;
2961 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2962 }
2963 global.last_checks |= LSTCHK_NETADM;
2964#else /* no TPROXY support */
2965 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2966 file, linenum, "usesrc");
2967 err_code |= ERR_ALERT | ERR_FATAL;
2968 goto out;
2969#endif
2970 cur_arg += 2;
2971 continue;
2972 }
2973
2974 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
2975#ifdef SO_BINDTODEVICE
2976 if (!*args[cur_arg + 1]) {
2977 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2978 file, linenum, args[0]);
2979 err_code |= ERR_ALERT | ERR_FATAL;
2980 goto out;
2981 }
2982 free(curproxy->conn_src.iface_name);
2983 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2984 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2985 global.last_checks |= LSTCHK_NETADM;
2986#else
2987 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2988 file, linenum, args[0], args[cur_arg]);
2989 err_code |= ERR_ALERT | ERR_FATAL;
2990 goto out;
2991#endif
2992 cur_arg += 2;
2993 continue;
2994 }
2995 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2996 file, linenum, args[0], "interface", "usesrc");
2997 err_code |= ERR_ALERT | ERR_FATAL;
2998 goto out;
2999 }
3000 }
3001 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
3002 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3003 file, linenum, "usesrc", "source");
3004 err_code |= ERR_ALERT | ERR_FATAL;
3005 goto out;
3006 }
3007 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003008 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003009 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003010 file, linenum, args[0]);
3011 err_code |= ERR_ALERT | ERR_FATAL;
3012 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003013 }
3014 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003015 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3016 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3017 err_code |= ERR_ALERT | ERR_FATAL;
3018 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003019 }
3020 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003021 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3022 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3023 err_code |= ERR_ALERT | ERR_FATAL;
3024 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003025 }
3026 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003027 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3028 err_code |= ERR_ALERT | ERR_FATAL;
3029 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003030 }
3031 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003032 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3033 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3034 err_code |= ERR_ALERT | ERR_FATAL;
3035 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003036 }
3037 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003038 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3039 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3040 err_code |= ERR_ALERT | ERR_FATAL;
3041 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003042 }
3043 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003044 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3045 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3046 err_code |= ERR_ALERT | ERR_FATAL;
3047 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003048 }
3049 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003050 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3051 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3052 err_code |= ERR_ALERT | ERR_FATAL;
3053 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003054 }
3055 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003056 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3057 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3058 err_code |= ERR_ALERT | ERR_FATAL;
3059 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003060 }
3061 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003062 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3063 err_code |= ERR_ALERT | ERR_FATAL;
3064 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003065 }
3066 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003067 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3068 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3069 err_code |= ERR_ALERT | ERR_FATAL;
3070 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003071 }
3072 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003073 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3074 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3075 err_code |= ERR_ALERT | ERR_FATAL;
3076 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003077 }
3078 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003079 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3080 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3081 err_code |= ERR_ALERT | ERR_FATAL;
3082 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003083 }
3084 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003085 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3086 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3087 err_code |= ERR_ALERT | ERR_FATAL;
3088 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003089 }
3090 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003091 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3092 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3093 err_code |= ERR_ALERT | ERR_FATAL;
3094 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003095 }
3096 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003097 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3098 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3099 err_code |= ERR_ALERT | ERR_FATAL;
3100 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003101 }
3102 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303103 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003104 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3105 err_code |= ERR_ALERT | ERR_FATAL;
3106 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003107 }
3108 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003109 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3110 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3111 err_code |= ERR_ALERT | ERR_FATAL;
3112 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003113 }
3114 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003115 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3116 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3117 err_code |= ERR_ALERT | ERR_FATAL;
3118 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003119 }
3120 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003121 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3122 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3123 err_code |= ERR_ALERT | ERR_FATAL;
3124 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003125 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003126 else {
3127 struct cfg_kw_list *kwl;
3128 int index;
3129
3130 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3131 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3132 if (kwl->kw[index].section != CFG_LISTEN)
3133 continue;
3134 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3135 /* prepare error message just in case */
3136 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
3137 if (rc < 0) {
3138 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3139 err_code |= ERR_ALERT | ERR_FATAL;
3140 goto out;
3141 }
3142 else if (rc > 0) {
3143 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3144 err_code |= ERR_WARN;
3145 goto out;
3146 }
3147 goto out;
3148 }
3149 }
3150 }
3151
3152 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
3153 err_code |= ERR_ALERT | ERR_FATAL;
3154 goto out;
3155 }
3156 out:
3157 free(errmsg);
3158 return err_code;
3159}