blob: a493e741cd59816e81c320b56ba4caf815f758e9 [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]) {
192 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
193 " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
194 file, linenum, args[0]);
195 err_code |= ERR_ALERT | ERR_ABORT;
196 goto out;
197 }
198
199 err = invalid_char(args[1]);
200 if (err) {
201 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
202 file, linenum, *err, args[0], args[1]);
203 err_code |= ERR_ALERT | ERR_FATAL;
204 }
205
206 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
207 if (curproxy) {
208 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
209 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
210 curproxy->id, curproxy->conf.file, curproxy->conf.line);
211 err_code |= ERR_ALERT | ERR_FATAL;
212 }
213
Emeric Brunb0c331f2020-10-07 17:05:59 +0200214 curproxy = log_forward_by_name(args[1]);
215 if (curproxy) {
216 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
217 file, linenum, proxy_cap_str(rc), args[1],
218 curproxy->id, curproxy->conf.file, curproxy->conf.line);
219 err_code |= ERR_ALERT | ERR_FATAL;
220 }
221
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100222 if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
223 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
224 err_code |= ERR_ALERT | ERR_ABORT;
225 goto out;
226 }
227
228 init_new_proxy(curproxy);
229 curproxy->next = proxies_list;
230 proxies_list = curproxy;
231 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
232 curproxy->conf.args.line = curproxy->conf.line = linenum;
233 curproxy->last_change = now.tv_sec;
234 curproxy->id = strdup(args[1]);
235 curproxy->cap = rc;
236 proxy_store_name(curproxy);
237
238 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
239 if (curproxy->cap & PR_CAP_FE)
240 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
241 goto out;
242 }
243
244 /* set default values */
245 memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv));
246 curproxy->defsrv.id = "default-server";
247
Willy Tarreauc3914d42020-09-24 08:39:22 +0200248 curproxy->disabled = defproxy.disabled;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100249 curproxy->options = defproxy.options;
250 curproxy->options2 = defproxy.options2;
251 curproxy->no_options = defproxy.no_options;
252 curproxy->no_options2 = defproxy.no_options2;
253 curproxy->bind_proc = defproxy.bind_proc;
254 curproxy->except_net = defproxy.except_net;
255 curproxy->except_mask = defproxy.except_mask;
256 curproxy->except_to = defproxy.except_to;
257 curproxy->except_mask_to = defproxy.except_mask_to;
Olivier Houcharda254a372019-04-05 15:30:12 +0200258 curproxy->retry_type = defproxy.retry_type;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100259
260 if (defproxy.fwdfor_hdr_len) {
261 curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len;
262 curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name);
263 }
264
265 if (defproxy.orgto_hdr_len) {
266 curproxy->orgto_hdr_len = defproxy.orgto_hdr_len;
267 curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name);
268 }
269
270 if (defproxy.server_id_hdr_len) {
271 curproxy->server_id_hdr_len = defproxy.server_id_hdr_len;
272 curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name);
273 }
274
275 /* initialize error relocations */
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100276 if (!proxy_dup_default_conf_errors(curproxy, &defproxy, &errmsg)) {
277 ha_alert("parsing [%s:%d] : proxy '%s' : %s\n", file, linenum, curproxy->id, errmsg);
278 err_code |= ERR_ALERT | ERR_FATAL;
279 goto out;
280 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100281
282 if (curproxy->cap & PR_CAP_FE) {
283 curproxy->maxconn = defproxy.maxconn;
284 curproxy->backlog = defproxy.backlog;
285 curproxy->fe_sps_lim = defproxy.fe_sps_lim;
286
287 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100288 curproxy->max_out_conns = defproxy.max_out_conns;
MIZUTA Takeshib24bc0d2020-07-09 11:13:20 +0900289
290 curproxy->clitcpka_cnt = defproxy.clitcpka_cnt;
291 curproxy->clitcpka_idle = defproxy.clitcpka_idle;
292 curproxy->clitcpka_intvl = defproxy.clitcpka_intvl;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100293 }
294
295 if (curproxy->cap & PR_CAP_BE) {
296 curproxy->lbprm.algo = defproxy.lbprm.algo;
Willy Tarreau76e84f52019-01-14 16:50:58 +0100297 curproxy->lbprm.hash_balance_factor = defproxy.lbprm.hash_balance_factor;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100298 curproxy->fullconn = defproxy.fullconn;
299 curproxy->conn_retries = defproxy.conn_retries;
300 curproxy->redispatch_after = defproxy.redispatch_after;
301 curproxy->max_ka_queue = defproxy.max_ka_queue;
302
Christopher Faulete5870d82020-04-15 11:32:03 +0200303 curproxy->tcpcheck_rules.flags = (defproxy.tcpcheck_rules.flags & ~TCPCHK_RULES_UNUSED_RS);
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200304 curproxy->tcpcheck_rules.list = defproxy.tcpcheck_rules.list;
Christopher Faulet7a1e2e12020-04-02 18:05:11 +0200305 if (!LIST_ISEMPTY(&defproxy.tcpcheck_rules.preset_vars)) {
306 if (!dup_tcpcheck_vars(&curproxy->tcpcheck_rules.preset_vars,
307 &defproxy.tcpcheck_rules.preset_vars)) {
308 ha_alert("parsing [%s:%d] : failed to duplicate tcpcheck preset-vars\n",
309 file, linenum);
310 err_code |= ERR_ALERT | ERR_FATAL;
311 goto out;
312 }
313 }
Gaetan Rivet04578db2020-02-07 15:37:17 +0100314
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100315 curproxy->ck_opts = defproxy.ck_opts;
316 if (defproxy.cookie_name)
317 curproxy->cookie_name = strdup(defproxy.cookie_name);
318 curproxy->cookie_len = defproxy.cookie_len;
319
320 if (defproxy.dyncookie_key)
321 curproxy->dyncookie_key = strdup(defproxy.dyncookie_key);
322 if (defproxy.cookie_domain)
323 curproxy->cookie_domain = strdup(defproxy.cookie_domain);
324
325 if (defproxy.cookie_maxidle)
326 curproxy->cookie_maxidle = defproxy.cookie_maxidle;
327
328 if (defproxy.cookie_maxlife)
329 curproxy->cookie_maxlife = defproxy.cookie_maxlife;
330
331 if (defproxy.rdp_cookie_name)
332 curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name);
333 curproxy->rdp_cookie_len = defproxy.rdp_cookie_len;
334
Christopher Faulet2f533902020-01-21 11:06:48 +0100335 if (defproxy.cookie_attrs)
336 curproxy->cookie_attrs = strdup(defproxy.cookie_attrs);
Willy Tarreau20e68372019-01-14 16:04:01 +0100337
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100338 if (defproxy.lbprm.arg_str)
339 curproxy->lbprm.arg_str = strdup(defproxy.lbprm.arg_str);
340 curproxy->lbprm.arg_len = defproxy.lbprm.arg_len;
Willy Tarreau20e68372019-01-14 16:04:01 +0100341 curproxy->lbprm.arg_opt1 = defproxy.lbprm.arg_opt1;
342 curproxy->lbprm.arg_opt2 = defproxy.lbprm.arg_opt2;
343 curproxy->lbprm.arg_opt3 = defproxy.lbprm.arg_opt3;
344
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100345 if (defproxy.conn_src.iface_name)
346 curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name);
347 curproxy->conn_src.iface_len = defproxy.conn_src.iface_len;
348 curproxy->conn_src.opts = defproxy.conn_src.opts;
349#if defined(CONFIG_HAP_TRANSPARENT)
350 curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr;
351#endif
352 curproxy->load_server_state_from_file = defproxy.load_server_state_from_file;
MIZUTA Takeshib24bc0d2020-07-09 11:13:20 +0900353
354 curproxy->srvtcpka_cnt = defproxy.srvtcpka_cnt;
355 curproxy->srvtcpka_idle = defproxy.srvtcpka_idle;
356 curproxy->srvtcpka_intvl = defproxy.srvtcpka_intvl;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100357 }
358
359 if (curproxy->cap & PR_CAP_FE) {
360 if (defproxy.capture_name)
361 curproxy->capture_name = strdup(defproxy.capture_name);
362 curproxy->capture_namelen = defproxy.capture_namelen;
363 curproxy->capture_len = defproxy.capture_len;
364 }
365
366 if (curproxy->cap & PR_CAP_FE) {
367 curproxy->timeout.client = defproxy.timeout.client;
368 curproxy->timeout.clientfin = defproxy.timeout.clientfin;
369 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
370 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
371 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100372 if (defproxy.monitor_uri)
373 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
374 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
375 if (defproxy.defbe.name)
376 curproxy->defbe.name = strdup(defproxy.defbe.name);
377
378 /* get either a pointer to the logformat string or a copy of it */
379 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
380 if (curproxy->conf.logformat_string &&
381 curproxy->conf.logformat_string != default_http_log_format &&
382 curproxy->conf.logformat_string != default_tcp_log_format &&
383 curproxy->conf.logformat_string != clf_http_log_format)
384 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
385
386 if (defproxy.conf.lfs_file) {
387 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
388 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
389 }
390
391 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
392 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
393 if (curproxy->conf.logformat_sd_string &&
394 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
395 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
396
397 if (defproxy.conf.lfsd_file) {
398 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
399 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
400 }
401 }
402
403 if (curproxy->cap & PR_CAP_BE) {
404 curproxy->timeout.connect = defproxy.timeout.connect;
405 curproxy->timeout.server = defproxy.timeout.server;
406 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
407 curproxy->timeout.check = defproxy.timeout.check;
408 curproxy->timeout.queue = defproxy.timeout.queue;
409 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
410 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
411 curproxy->timeout.httpka = defproxy.timeout.httpka;
412 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
413 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
414 }
415
416 curproxy->mode = defproxy.mode;
417 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
418
419 /* copy default logsrvs to curproxy */
420 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
421 struct logsrv *node = malloc(sizeof(*node));
422 memcpy(node, tmplogsrv, sizeof(struct logsrv));
423 node->ref = tmplogsrv->ref;
424 LIST_INIT(&node->list);
425 LIST_ADDQ(&curproxy->logsrvs, &node->list);
426 }
427
428 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
429 if (curproxy->conf.uniqueid_format_string)
430 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
431
432 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
433
434 if (defproxy.conf.uif_file) {
435 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
436 curproxy->conf.uif_line = defproxy.conf.uif_line;
437 }
438
439 /* copy default header unique id */
Tim Duesterhus0643b0e2020-03-05 17:56:35 +0100440 if (isttest(defproxy.header_unique_id)) {
441 const struct ist copy = istdup(defproxy.header_unique_id);
442 if (!isttest(copy)) {
443 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
444 err_code |= ERR_ALERT | ERR_FATAL;
445 goto out;
446 }
447 curproxy->header_unique_id = copy;
448 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100449
450 /* default compression options */
451 if (defproxy.comp != NULL) {
Tim Duesterhuse52b6e52020-09-12 20:26:43 +0200452 curproxy->comp = calloc(1, sizeof(*curproxy->comp));
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100453 curproxy->comp->algos = defproxy.comp->algos;
454 curproxy->comp->types = defproxy.comp->types;
455 }
456
457 curproxy->grace = defproxy.grace;
458 curproxy->conf.used_listener_id = EB_ROOT;
459 curproxy->conf.used_server_id = EB_ROOT;
Thayne McCombs92149f92020-11-20 01:28:26 -0700460 curproxy->used_server_addr = EB_ROOT_UNIQUE;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100461
462 if (defproxy.check_path)
463 curproxy->check_path = strdup(defproxy.check_path);
464 if (defproxy.check_command)
465 curproxy->check_command = strdup(defproxy.check_command);
466
467 if (defproxy.email_alert.mailers.name)
468 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
469 if (defproxy.email_alert.from)
470 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
471 if (defproxy.email_alert.to)
472 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
473 if (defproxy.email_alert.myhostname)
474 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
475 curproxy->email_alert.level = defproxy.email_alert.level;
476 curproxy->email_alert.set = defproxy.email_alert.set;
477
478 goto out;
479 }
480 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
481 /* some variables may have already been initialized earlier */
482 /* FIXME-20070101: we should do this too at the end of the
483 * config parsing to free all default values.
484 */
485 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
486 err_code |= ERR_ABORT;
487 goto out;
488 }
489
Amaury Denoyelle36b53662020-09-18 15:59:39 +0200490 free(defproxy.conf.file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100491 free(defproxy.check_command);
492 free(defproxy.check_path);
493 free(defproxy.cookie_name);
494 free(defproxy.rdp_cookie_name);
495 free(defproxy.dyncookie_key);
496 free(defproxy.cookie_domain);
Christopher Faulet2f533902020-01-21 11:06:48 +0100497 free(defproxy.cookie_attrs);
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100498 free(defproxy.lbprm.arg_str);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100499 free(defproxy.capture_name);
500 free(defproxy.monitor_uri);
501 free(defproxy.defbe.name);
502 free(defproxy.conn_src.iface_name);
503 free(defproxy.fwdfor_hdr_name);
504 defproxy.fwdfor_hdr_len = 0;
505 free(defproxy.orgto_hdr_name);
506 defproxy.orgto_hdr_len = 0;
507 free(defproxy.server_id_hdr_name);
508 defproxy.server_id_hdr_len = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100509
510 if (defproxy.conf.logformat_string != default_http_log_format &&
511 defproxy.conf.logformat_string != default_tcp_log_format &&
512 defproxy.conf.logformat_string != clf_http_log_format)
513 free(defproxy.conf.logformat_string);
514
515 free(defproxy.conf.uniqueid_format_string);
516 free(defproxy.conf.lfs_file);
517 free(defproxy.conf.uif_file);
518 chunk_destroy(&defproxy.log_tag);
519 free_email_alert(&defproxy);
520
521 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
522 free(defproxy.conf.logformat_sd_string);
523 free(defproxy.conf.lfsd_file);
524
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100525 proxy_release_conf_errors(&defproxy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100526
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200527 deinit_proxy_tcpcheck(&defproxy);
528
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100529 /* we cannot free uri_auth because it might already be used */
530 init_default_instance();
531 curproxy = &defproxy;
532 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
533 curproxy->conf.args.line = curproxy->conf.line = linenum;
534 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
535 goto out;
536 }
537 else if (curproxy == NULL) {
538 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
539 err_code |= ERR_ALERT | ERR_FATAL;
540 goto out;
541 }
542
543 /* update the current file and line being parsed */
544 curproxy->conf.args.file = curproxy->conf.file;
545 curproxy->conf.args.line = linenum;
546
547 /* Now let's parse the proxy-specific keywords */
548 if (!strcmp(args[0], "server") ||
549 !strcmp(args[0], "default-server") ||
550 !strcmp(args[0], "server-template")) {
Emeric Brund3db3842020-07-21 16:54:36 +0200551 err_code |= parse_server(file, linenum, args, curproxy, &defproxy, 1, 0, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100552 if (err_code & ERR_FATAL)
553 goto out;
554 }
555 else if (!strcmp(args[0], "bind")) { /* new listen addresses */
556 struct listener *l;
557 int cur_arg;
558
559 if (curproxy == &defproxy) {
560 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
561 err_code |= ERR_ALERT | ERR_FATAL;
562 goto out;
563 }
564 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
565 err_code |= ERR_WARN;
566
567 if (!*(args[1])) {
568 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
569 file, linenum, args[0]);
570 err_code |= ERR_ALERT | ERR_FATAL;
571 goto out;
572 }
573
574 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
575
576 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200577 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
578 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
579 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100580
581 /* NOTE: the following line might create several listeners if there
582 * are comma-separated IPs or port ranges. So all further processing
583 * will have to be applied to all listeners created after last_listen.
584 */
585 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
586 if (errmsg && *errmsg) {
587 indent_msg(&errmsg, 2);
588 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
589 }
590 else
591 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
592 file, linenum, args[0], args[1]);
593 err_code |= ERR_ALERT | ERR_FATAL;
594 goto out;
595 }
596
597 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
598 /* Set default global rights and owner for unix bind */
599 global.maxsock++;
600 }
601
602 cur_arg = 2;
603 while (*(args[cur_arg])) {
604 static int bind_dumped;
605 struct bind_kw *kw;
606 char *err;
607
608 kw = bind_find_kw(args[cur_arg]);
609 if (kw) {
610 char *err = NULL;
611 int code;
612
613 if (!kw->parse) {
614 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
615 file, linenum, args[0], args[1], args[cur_arg]);
616 cur_arg += 1 + kw->skip ;
617 err_code |= ERR_ALERT | ERR_FATAL;
618 goto out;
619 }
620
621 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
622 err_code |= code;
623
624 if (code) {
625 if (err && *err) {
626 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200627 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
628 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
629 else
630 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100631 }
632 else
633 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
634 file, linenum, args[0], args[1], args[cur_arg]);
635 if (code & ERR_FATAL) {
636 free(err);
637 cur_arg += 1 + kw->skip;
638 goto out;
639 }
640 }
641 free(err);
642 cur_arg += 1 + kw->skip;
643 continue;
644 }
645
646 err = NULL;
647 if (!bind_dumped) {
648 bind_dump_kws(&err);
649 indent_msg(&err, 4);
650 bind_dumped = 1;
651 }
652
653 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
654 file, linenum, args[0], args[1], args[cur_arg],
655 err ? " Registered keywords :" : "", err ? err : "");
656 free(err);
657
658 err_code |= ERR_ALERT | ERR_FATAL;
659 goto out;
660 }
661 goto out;
662 }
663 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200664 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]);
665 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100666 goto out;
667 }
668 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
669 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
670 err_code |= ERR_WARN;
671
672 if (alertif_too_many_args(1, file, linenum, args, &err_code))
673 goto out;
674
675 if (!*args[1]) {
676 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
677 file, linenum, args[0]);
678 err_code |= ERR_ALERT | ERR_FATAL;
679 goto out;
680 }
681
682 free(curproxy->monitor_uri);
683 curproxy->monitor_uri_len = strlen(args[1]);
684 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
685 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
686 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
687
688 goto out;
689 }
690 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
691 if (alertif_too_many_args(1, file, linenum, args, &err_code))
692 goto out;
693
694 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
695 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200696 else if (!strcmp(args[1], "health")) {
697 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
698 err_code |= ERR_ALERT | ERR_FATAL;
699 goto out;
700 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100701 else {
702 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
703 err_code |= ERR_ALERT | ERR_FATAL;
704 goto out;
705 }
706 }
707 else if (!strcmp(args[0], "id")) {
708 struct eb32_node *node;
709
710 if (curproxy == &defproxy) {
711 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
712 file, linenum, args[0]);
713 err_code |= ERR_ALERT | ERR_FATAL;
714 goto out;
715 }
716
717 if (alertif_too_many_args(1, file, linenum, args, &err_code))
718 goto out;
719
720 if (!*args[1]) {
721 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
722 file, linenum, args[0]);
723 err_code |= ERR_ALERT | ERR_FATAL;
724 goto out;
725 }
726
727 curproxy->uuid = atol(args[1]);
728 curproxy->conf.id.key = curproxy->uuid;
729 curproxy->options |= PR_O_FORCED_ID;
730
731 if (curproxy->uuid <= 0) {
732 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
733 file, linenum);
734 err_code |= ERR_ALERT | ERR_FATAL;
735 goto out;
736 }
737
738 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
739 if (node) {
740 struct proxy *target = container_of(node, struct proxy, conf.id);
741 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
742 file, linenum, proxy_type_str(curproxy), curproxy->id,
743 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
744 err_code |= ERR_ALERT | ERR_FATAL;
745 goto out;
746 }
747 eb32_insert(&used_proxy_id, &curproxy->conf.id);
748 }
749 else if (!strcmp(args[0], "description")) {
750 int i, len=0;
751 char *d;
752
753 if (curproxy == &defproxy) {
754 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
755 file, linenum, args[0]);
756 err_code |= ERR_ALERT | ERR_FATAL;
757 goto out;
758 }
759
760 if (!*args[1]) {
761 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
762 file, linenum, args[0]);
763 return -1;
764 }
765
766 for (i = 1; *args[i]; i++)
767 len += strlen(args[i]) + 1;
768
769 d = calloc(1, len);
770 curproxy->desc = d;
771
772 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
773 for (i = 2; *args[i]; i++)
774 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
775
776 }
777 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
778 if (alertif_too_many_args(0, file, linenum, args, &err_code))
779 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200780 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100781 }
782 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
783 if (alertif_too_many_args(0, file, linenum, args, &err_code))
784 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200785 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100786 }
787 else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */
788 int cur_arg = 1;
789 unsigned long set = 0;
790
791 while (*args[cur_arg]) {
792 if (strcmp(args[cur_arg], "all") == 0) {
793 set = 0;
794 break;
795 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100796 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100797 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
798 err_code |= ERR_ALERT | ERR_FATAL;
799 goto out;
800 }
801 cur_arg++;
802 }
803 curproxy->bind_proc = set;
804 }
805 else if (!strcmp(args[0], "acl")) { /* add an ACL */
806 if (curproxy == &defproxy) {
807 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
808 err_code |= ERR_ALERT | ERR_FATAL;
809 goto out;
810 }
811
812 err = invalid_char(args[1]);
813 if (err) {
814 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
815 file, linenum, *err, args[1]);
816 err_code |= ERR_ALERT | ERR_FATAL;
817 goto out;
818 }
819
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100820 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100821 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100822 "logical disjunction within a condition.\n",
823 file, linenum, args[1]);
824 err_code |= ERR_ALERT | ERR_FATAL;
825 goto out;
826 }
827
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100828 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
829 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
830 file, linenum, args[1], errmsg);
831 err_code |= ERR_ALERT | ERR_FATAL;
832 goto out;
833 }
834 }
835 else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */
836
837 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
838 err_code |= ERR_WARN;
839
840 if (*(args[1]) == 0) {
841 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
842 file, linenum, args[0]);
843 err_code |= ERR_ALERT | ERR_FATAL;
844 goto out;
845 }
846 free(curproxy->dyncookie_key);
847 curproxy->dyncookie_key = strdup(args[1]);
848 }
849 else if (!strcmp(args[0], "cookie")) { /* cookie name */
850 int cur_arg;
851
852 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
853 err_code |= ERR_WARN;
854
855 if (*(args[1]) == 0) {
856 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
857 file, linenum, args[0]);
858 err_code |= ERR_ALERT | ERR_FATAL;
859 goto out;
860 }
861
862 curproxy->ck_opts = 0;
863 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
864 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
865 free(curproxy->cookie_name);
866 curproxy->cookie_name = strdup(args[1]);
867 curproxy->cookie_len = strlen(curproxy->cookie_name);
868
869 cur_arg = 2;
870 while (*(args[cur_arg])) {
871 if (!strcmp(args[cur_arg], "rewrite")) {
872 curproxy->ck_opts |= PR_CK_RW;
873 }
874 else if (!strcmp(args[cur_arg], "indirect")) {
875 curproxy->ck_opts |= PR_CK_IND;
876 }
877 else if (!strcmp(args[cur_arg], "insert")) {
878 curproxy->ck_opts |= PR_CK_INS;
879 }
880 else if (!strcmp(args[cur_arg], "nocache")) {
881 curproxy->ck_opts |= PR_CK_NOC;
882 }
883 else if (!strcmp(args[cur_arg], "postonly")) {
884 curproxy->ck_opts |= PR_CK_POST;
885 }
886 else if (!strcmp(args[cur_arg], "preserve")) {
887 curproxy->ck_opts |= PR_CK_PSV;
888 }
889 else if (!strcmp(args[cur_arg], "prefix")) {
890 curproxy->ck_opts |= PR_CK_PFX;
891 }
892 else if (!strcmp(args[cur_arg], "httponly")) {
893 curproxy->ck_opts |= PR_CK_HTTPONLY;
894 }
895 else if (!strcmp(args[cur_arg], "secure")) {
896 curproxy->ck_opts |= PR_CK_SECURE;
897 }
898 else if (!strcmp(args[cur_arg], "domain")) {
899 if (!*args[cur_arg + 1]) {
900 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
901 file, linenum, args[cur_arg]);
902 err_code |= ERR_ALERT | ERR_FATAL;
903 goto out;
904 }
905
Joao Moraise1583752019-10-30 21:04:00 -0300906 if (!strchr(args[cur_arg + 1], '.')) {
907 /* rfc6265, 5.2.3 The Domain Attribute */
908 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
909 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100910 file, linenum, args[cur_arg + 1]);
911 err_code |= ERR_WARN;
912 }
913
914 err = invalid_domainchar(args[cur_arg + 1]);
915 if (err) {
916 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
917 file, linenum, *err, args[cur_arg + 1]);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921
922 if (!curproxy->cookie_domain) {
923 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
924 } else {
925 /* one domain was already specified, add another one by
926 * building the string which will be returned along with
927 * the cookie.
928 */
929 char *new_ptr;
930 int new_len = strlen(curproxy->cookie_domain) +
931 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
932 new_ptr = malloc(new_len);
933 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
934 free(curproxy->cookie_domain);
935 curproxy->cookie_domain = new_ptr;
936 }
937 cur_arg++;
938 }
939 else if (!strcmp(args[cur_arg], "maxidle")) {
940 unsigned int maxidle;
941 const char *res;
942
943 if (!*args[cur_arg + 1]) {
944 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
945 file, linenum, args[cur_arg]);
946 err_code |= ERR_ALERT | ERR_FATAL;
947 goto out;
948 }
949
950 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200951 if (res == PARSE_TIME_OVER) {
952 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
953 file, linenum, args[cur_arg+1], args[cur_arg]);
954 err_code |= ERR_ALERT | ERR_FATAL;
955 goto out;
956 }
957 else if (res == PARSE_TIME_UNDER) {
958 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
959 file, linenum, args[cur_arg+1], args[cur_arg]);
960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
962 }
963 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100964 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
965 file, linenum, *res, args[cur_arg]);
966 err_code |= ERR_ALERT | ERR_FATAL;
967 goto out;
968 }
969 curproxy->cookie_maxidle = maxidle;
970 cur_arg++;
971 }
972 else if (!strcmp(args[cur_arg], "maxlife")) {
973 unsigned int maxlife;
974 const char *res;
975
976 if (!*args[cur_arg + 1]) {
977 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
978 file, linenum, args[cur_arg]);
979 err_code |= ERR_ALERT | ERR_FATAL;
980 goto out;
981 }
982
Willy Tarreau9faebe32019-06-07 19:00:37 +0200983
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100984 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200985 if (res == PARSE_TIME_OVER) {
986 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
987 file, linenum, args[cur_arg+1], args[cur_arg]);
988 err_code |= ERR_ALERT | ERR_FATAL;
989 goto out;
990 }
991 else if (res == PARSE_TIME_UNDER) {
992 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
993 file, linenum, args[cur_arg+1], args[cur_arg]);
994 err_code |= ERR_ALERT | ERR_FATAL;
995 goto out;
996 }
997 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100998 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
999 file, linenum, *res, args[cur_arg]);
1000 err_code |= ERR_ALERT | ERR_FATAL;
1001 goto out;
1002 }
1003 curproxy->cookie_maxlife = maxlife;
1004 cur_arg++;
1005 }
1006 else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */
1007
1008 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
1009 err_code |= ERR_WARN;
1010 curproxy->ck_opts |= PR_CK_DYNAMIC;
1011 }
Christopher Faulet2f533902020-01-21 11:06:48 +01001012 else if (!strcmp(args[cur_arg], "attr")) {
1013 char *val;
1014 if (!*args[cur_arg + 1]) {
1015 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
1016 file, linenum, args[cur_arg]);
1017 err_code |= ERR_ALERT | ERR_FATAL;
1018 goto out;
1019 }
1020 val = args[cur_arg + 1];
1021 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +01001022 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +01001023 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
1024 file, linenum, *val);
1025 err_code |= ERR_ALERT | ERR_FATAL;
1026 goto out;
1027 }
1028 val++;
1029 }
1030 /* don't add ';' for the first attribute */
1031 if (!curproxy->cookie_attrs)
1032 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
1033 else
1034 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
1035 cur_arg++;
1036 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001037
1038 else {
Christopher Faulet2f533902020-01-21 11:06:48 +01001039 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 +01001040 file, linenum, args[0]);
1041 err_code |= ERR_ALERT | ERR_FATAL;
1042 goto out;
1043 }
1044 cur_arg++;
1045 }
1046 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
1047 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
1048 file, linenum);
1049 err_code |= ERR_ALERT | ERR_FATAL;
1050 }
1051
1052 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
1053 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
1054 file, linenum);
1055 err_code |= ERR_ALERT | ERR_FATAL;
1056 }
1057
1058 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
1059 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
1060 file, linenum);
1061 err_code |= ERR_ALERT | ERR_FATAL;
1062 }
1063 }/* end else if (!strcmp(args[0], "cookie")) */
1064 else if (!strcmp(args[0], "email-alert")) {
1065 if (*(args[1]) == 0) {
1066 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1067 file, linenum, args[0]);
1068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071
1072 if (!strcmp(args[1], "from")) {
1073 if (*(args[1]) == 0) {
1074 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1075 file, linenum, args[1]);
1076 err_code |= ERR_ALERT | ERR_FATAL;
1077 goto out;
1078 }
1079 free(curproxy->email_alert.from);
1080 curproxy->email_alert.from = strdup(args[2]);
1081 }
1082 else if (!strcmp(args[1], "mailers")) {
1083 if (*(args[1]) == 0) {
1084 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1085 file, linenum, args[1]);
1086 err_code |= ERR_ALERT | ERR_FATAL;
1087 goto out;
1088 }
1089 free(curproxy->email_alert.mailers.name);
1090 curproxy->email_alert.mailers.name = strdup(args[2]);
1091 }
1092 else if (!strcmp(args[1], "myhostname")) {
1093 if (*(args[1]) == 0) {
1094 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1095 file, linenum, args[1]);
1096 err_code |= ERR_ALERT | ERR_FATAL;
1097 goto out;
1098 }
1099 free(curproxy->email_alert.myhostname);
1100 curproxy->email_alert.myhostname = strdup(args[2]);
1101 }
1102 else if (!strcmp(args[1], "level")) {
1103 curproxy->email_alert.level = get_log_level(args[2]);
1104 if (curproxy->email_alert.level < 0) {
1105 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1106 file, linenum, args[1], args[2]);
1107 err_code |= ERR_ALERT | ERR_FATAL;
1108 goto out;
1109 }
1110 }
1111 else if (!strcmp(args[1], "to")) {
1112 if (*(args[1]) == 0) {
1113 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1114 file, linenum, args[1]);
1115 err_code |= ERR_ALERT | ERR_FATAL;
1116 goto out;
1117 }
1118 free(curproxy->email_alert.to);
1119 curproxy->email_alert.to = strdup(args[2]);
1120 }
1121 else {
1122 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1123 file, linenum, args[1]);
1124 err_code |= ERR_ALERT | ERR_FATAL;
1125 goto out;
1126 }
1127 /* Indicate that the email_alert is at least partially configured */
1128 curproxy->email_alert.set = 1;
1129 }/* end else if (!strcmp(args[0], "email-alert")) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001130 else if (!strcmp(args[0], "persist")) { /* persist */
1131 if (*(args[1]) == 0) {
1132 ha_alert("parsing [%s:%d] : missing persist method.\n",
1133 file, linenum);
1134 err_code |= ERR_ALERT | ERR_FATAL;
1135 goto out;
1136 }
1137
1138 if (!strncmp(args[1], "rdp-cookie", 10)) {
1139 curproxy->options2 |= PR_O2_RDPC_PRST;
1140
1141 if (*(args[1] + 10) == '(') { /* cookie name */
1142 const char *beg, *end;
1143
1144 beg = args[1] + 11;
1145 end = strchr(beg, ')');
1146
1147 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1148 goto out;
1149
1150 if (!end || end == beg) {
1151 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1152 file, linenum);
1153 err_code |= ERR_ALERT | ERR_FATAL;
1154 goto out;
1155 }
1156
1157 free(curproxy->rdp_cookie_name);
1158 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
1159 curproxy->rdp_cookie_len = end-beg;
1160 }
1161 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1162 free(curproxy->rdp_cookie_name);
1163 curproxy->rdp_cookie_name = strdup("msts");
1164 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1165 }
1166 else { /* syntax */
1167 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1168 file, linenum);
1169 err_code |= ERR_ALERT | ERR_FATAL;
1170 goto out;
1171 }
1172 }
1173 else {
1174 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1175 file, linenum);
1176 err_code |= ERR_ALERT | ERR_FATAL;
1177 goto out;
1178 }
1179 }
1180 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001181 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 +01001182 err_code |= ERR_ALERT | ERR_FATAL;
1183 goto out;
1184 }
1185 else if (!strcmp(args[0], "load-server-state-from-file")) {
1186 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1187 err_code |= ERR_WARN;
1188 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
1189 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1190 }
1191 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
1192 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1193 }
1194 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
1195 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1196 }
1197 else {
1198 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1199 file, linenum, args[0], args[1]);
1200 err_code |= ERR_ALERT | ERR_FATAL;
1201 goto out;
1202 }
1203 }
1204 else if (!strcmp(args[0], "server-state-file-name")) {
1205 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1206 err_code |= ERR_WARN;
1207 if (*(args[1]) == 0) {
1208 ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
1209 file, linenum, args[0]);
1210 err_code |= ERR_ALERT | ERR_FATAL;
1211 goto out;
1212 }
1213 else if (!strcmp(args[1], "use-backend-name"))
1214 curproxy->server_state_file_name = strdup(curproxy->id);
1215 else
1216 curproxy->server_state_file_name = strdup(args[1]);
1217 }
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001218 else if (!strcmp(args[0], "max-session-srv-conns")) {
1219 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1220 err_code |= ERR_WARN;
1221 if (*(args[1]) == 0) {
1222 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1223 file, linenum, args[0]);
1224 err_code |= ERR_ALERT | ERR_FATAL;
1225 goto out;
1226 }
1227 curproxy->max_out_conns = atoi(args[1]);
1228 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001229 else if (!strcmp(args[0], "capture")) {
1230 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1231 err_code |= ERR_WARN;
1232
1233 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
1234 if (curproxy == &defproxy) {
1235 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1236 err_code |= ERR_ALERT | ERR_FATAL;
1237 goto out;
1238 }
1239
1240 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1241 goto out;
1242
1243 if (*(args[4]) == 0) {
1244 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1245 file, linenum, args[0]);
1246 err_code |= ERR_ALERT | ERR_FATAL;
1247 goto out;
1248 }
1249 free(curproxy->capture_name);
1250 curproxy->capture_name = strdup(args[2]);
1251 curproxy->capture_namelen = strlen(curproxy->capture_name);
1252 curproxy->capture_len = atol(args[4]);
1253 curproxy->to_log |= LW_COOKIE;
1254 }
1255 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
1256 struct cap_hdr *hdr;
1257
1258 if (curproxy == &defproxy) {
1259 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1260 err_code |= ERR_ALERT | ERR_FATAL;
1261 goto out;
1262 }
1263
1264 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1265 goto out;
1266
1267 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1268 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1269 file, linenum, args[0], args[1]);
1270 err_code |= ERR_ALERT | ERR_FATAL;
1271 goto out;
1272 }
1273
1274 hdr = calloc(1, sizeof(*hdr));
1275 hdr->next = curproxy->req_cap;
1276 hdr->name = strdup(args[3]);
1277 hdr->namelen = strlen(args[3]);
1278 hdr->len = atol(args[5]);
1279 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1280 hdr->index = curproxy->nb_req_cap++;
1281 curproxy->req_cap = hdr;
1282 curproxy->to_log |= LW_REQHDR;
1283 }
1284 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
1285 struct cap_hdr *hdr;
1286
1287 if (curproxy == &defproxy) {
1288 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1289 err_code |= ERR_ALERT | ERR_FATAL;
1290 goto out;
1291 }
1292
1293 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1294 goto out;
1295
1296 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1297 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1298 file, linenum, args[0], args[1]);
1299 err_code |= ERR_ALERT | ERR_FATAL;
1300 goto out;
1301 }
1302 hdr = calloc(1, sizeof(*hdr));
1303 hdr->next = curproxy->rsp_cap;
1304 hdr->name = strdup(args[3]);
1305 hdr->namelen = strlen(args[3]);
1306 hdr->len = atol(args[5]);
1307 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1308 hdr->index = curproxy->nb_rsp_cap++;
1309 curproxy->rsp_cap = hdr;
1310 curproxy->to_log |= LW_RSPHDR;
1311 }
1312 else {
1313 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1314 file, linenum, args[0]);
1315 err_code |= ERR_ALERT | ERR_FATAL;
1316 goto out;
1317 }
1318 }
1319 else if (!strcmp(args[0], "retries")) { /* connection retries */
1320 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1321 err_code |= ERR_WARN;
1322
1323 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1324 goto out;
1325
1326 if (*(args[1]) == 0) {
1327 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1328 file, linenum, args[0]);
1329 err_code |= ERR_ALERT | ERR_FATAL;
1330 goto out;
1331 }
1332 curproxy->conn_retries = atol(args[1]);
1333 }
1334 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
1335 struct act_rule *rule;
1336
1337 if (curproxy == &defproxy) {
1338 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1339 err_code |= ERR_ALERT | ERR_FATAL;
1340 goto out;
1341 }
1342
1343 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1344 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001345 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001346 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1347 file, linenum, args[0]);
1348 err_code |= ERR_WARN;
1349 }
1350
1351 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1352
1353 if (!rule) {
1354 err_code |= ERR_ALERT | ERR_ABORT;
1355 goto out;
1356 }
1357
1358 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1359 err_code |= warnif_cond_conflicts(rule->cond,
1360 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1361 file, linenum);
1362
1363 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1364 }
1365 else if (!strcmp(args[0], "http-response")) { /* response access control */
1366 struct act_rule *rule;
1367
1368 if (curproxy == &defproxy) {
1369 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1370 err_code |= ERR_ALERT | ERR_FATAL;
1371 goto out;
1372 }
1373
1374 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1375 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001376 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001377 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1378 file, linenum, args[0]);
1379 err_code |= ERR_WARN;
1380 }
1381
1382 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1383
1384 if (!rule) {
1385 err_code |= ERR_ALERT | ERR_ABORT;
1386 goto out;
1387 }
1388
1389 err_code |= warnif_cond_conflicts(rule->cond,
1390 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1391 file, linenum);
1392
1393 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1394 }
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001395 else if (!strcmp(args[0], "http-after-response")) {
1396 struct act_rule *rule;
1397
1398 if (curproxy == &defproxy) {
1399 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1400 err_code |= ERR_ALERT | ERR_FATAL;
1401 goto out;
1402 }
1403
1404 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1405 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1406 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1407 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1408 file, linenum, args[0]);
1409 err_code |= ERR_WARN;
1410 }
1411
1412 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1413
1414 if (!rule) {
1415 err_code |= ERR_ALERT | ERR_ABORT;
1416 goto out;
1417 }
1418
1419 err_code |= warnif_cond_conflicts(rule->cond,
1420 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1421 file, linenum);
1422
1423 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1424 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001425 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
1426 /* set the header name and length into the proxy structure */
1427 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1428 err_code |= ERR_WARN;
1429
1430 if (!*args[1]) {
1431 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1432 file, linenum, args[0]);
1433 err_code |= ERR_ALERT | ERR_FATAL;
1434 goto out;
1435 }
1436
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001437 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001438 free(curproxy->server_id_hdr_name);
1439 curproxy->server_id_hdr_name = strdup(args[1]);
1440 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001441 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 +01001442 }
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001443 else if (!strcmp(args[0], "block")) {
1444 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 +01001445
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001446 err_code |= ERR_ALERT | ERR_FATAL;
1447 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 }
1449 else if (!strcmp(args[0], "redirect")) {
1450 struct redirect_rule *rule;
1451
1452 if (curproxy == &defproxy) {
1453 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1454 err_code |= ERR_ALERT | ERR_FATAL;
1455 goto out;
1456 }
1457
1458 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1459 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1460 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1461 err_code |= ERR_ALERT | ERR_FATAL;
1462 goto out;
1463 }
1464
1465 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1466 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1467 err_code |= warnif_cond_conflicts(rule->cond,
1468 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1469 file, linenum);
1470 }
1471 else if (!strcmp(args[0], "use_backend")) {
1472 struct switching_rule *rule;
1473
1474 if (curproxy == &defproxy) {
1475 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1476 err_code |= ERR_ALERT | ERR_FATAL;
1477 goto out;
1478 }
1479
1480 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1481 err_code |= ERR_WARN;
1482
1483 if (*(args[1]) == 0) {
1484 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1485 err_code |= ERR_ALERT | ERR_FATAL;
1486 goto out;
1487 }
1488
1489 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1490 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1491 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1492 file, linenum, errmsg);
1493 err_code |= ERR_ALERT | ERR_FATAL;
1494 goto out;
1495 }
1496
1497 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1498 }
1499 else if (*args[2]) {
1500 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1501 file, linenum, args[2]);
1502 err_code |= ERR_ALERT | ERR_FATAL;
1503 goto out;
1504 }
1505
1506 rule = calloc(1, sizeof(*rule));
1507 if (!rule) {
1508 ha_alert("Out of memory error.\n");
1509 goto out;
1510 }
1511 rule->cond = cond;
1512 rule->be.name = strdup(args[1]);
1513 rule->line = linenum;
1514 rule->file = strdup(file);
1515 if (!rule->file) {
1516 ha_alert("Out of memory error.\n");
1517 goto out;
1518 }
1519 LIST_INIT(&rule->list);
1520 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1521 }
1522 else if (strcmp(args[0], "use-server") == 0) {
1523 struct server_rule *rule;
1524
1525 if (curproxy == &defproxy) {
1526 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1527 err_code |= ERR_ALERT | ERR_FATAL;
1528 goto out;
1529 }
1530
1531 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1532 err_code |= ERR_WARN;
1533
1534 if (*(args[1]) == 0) {
1535 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1536 err_code |= ERR_ALERT | ERR_FATAL;
1537 goto out;
1538 }
1539
1540 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1541 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1542 file, linenum, args[0]);
1543 err_code |= ERR_ALERT | ERR_FATAL;
1544 goto out;
1545 }
1546
1547 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1548 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1549 file, linenum, errmsg);
1550 err_code |= ERR_ALERT | ERR_FATAL;
1551 goto out;
1552 }
1553
1554 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1555
1556 rule = calloc(1, sizeof(*rule));
1557 rule->cond = cond;
1558 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001559 rule->line = linenum;
1560 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001561 LIST_INIT(&rule->list);
1562 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1563 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1564 }
1565 else if ((!strcmp(args[0], "force-persist")) ||
1566 (!strcmp(args[0], "ignore-persist"))) {
1567 struct persist_rule *rule;
1568
1569 if (curproxy == &defproxy) {
1570 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1571 err_code |= ERR_ALERT | ERR_FATAL;
1572 goto out;
1573 }
1574
1575 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1576 err_code |= ERR_WARN;
1577
1578 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1579 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1580 file, linenum, args[0]);
1581 err_code |= ERR_ALERT | ERR_FATAL;
1582 goto out;
1583 }
1584
1585 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1586 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1587 file, linenum, args[0], errmsg);
1588 err_code |= ERR_ALERT | ERR_FATAL;
1589 goto out;
1590 }
1591
1592 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1593 * where force-persist is applied.
1594 */
1595 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1596
1597 rule = calloc(1, sizeof(*rule));
1598 rule->cond = cond;
1599 if (!strcmp(args[0], "force-persist")) {
1600 rule->type = PERSIST_TYPE_FORCE;
1601 } else {
1602 rule->type = PERSIST_TYPE_IGNORE;
1603 }
1604 LIST_INIT(&rule->list);
1605 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1606 }
1607 else if (!strcmp(args[0], "stick-table")) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001608 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001609
1610 if (curproxy == &defproxy) {
1611 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1612 file, linenum);
1613 err_code |= ERR_ALERT | ERR_FATAL;
1614 goto out;
1615 }
1616
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001617 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001618 if (other) {
1619 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 +01001620 file, linenum, curproxy->id,
1621 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1622 other->proxy ? other->id : other->peers.p->id,
1623 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001624 err_code |= ERR_ALERT | ERR_FATAL;
1625 goto out;
1626 }
1627
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001628 curproxy->table = calloc(1, sizeof *curproxy->table);
1629 if (!curproxy->table) {
1630 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1631 file, linenum, args[0], args[1]);
1632 err_code |= ERR_ALERT | ERR_FATAL;
1633 goto out;
1634 }
1635
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001636 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1637 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001638 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001639 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001640
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001641 /* Store the proxy in the stick-table. */
1642 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001643
1644 stktable_store_name(curproxy->table);
1645 curproxy->table->next = stktables_list;
1646 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001647
1648 /* Add this proxy to the list of proxies which refer to its stick-table. */
1649 if (curproxy->table->proxies_list != curproxy) {
1650 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1651 curproxy->table->proxies_list = curproxy;
1652 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001653 }
1654 else if (!strcmp(args[0], "stick")) {
1655 struct sticking_rule *rule;
1656 struct sample_expr *expr;
1657 int myidx = 0;
1658 const char *name = NULL;
1659 int flags;
1660
1661 if (curproxy == &defproxy) {
1662 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1663 err_code |= ERR_ALERT | ERR_FATAL;
1664 goto out;
1665 }
1666
1667 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1668 err_code |= ERR_WARN;
1669 goto out;
1670 }
1671
1672 myidx++;
1673 if ((strcmp(args[myidx], "store") == 0) ||
1674 (strcmp(args[myidx], "store-request") == 0)) {
1675 myidx++;
1676 flags = STK_IS_STORE;
1677 }
1678 else if (strcmp(args[myidx], "store-response") == 0) {
1679 myidx++;
1680 flags = STK_IS_STORE | STK_ON_RSP;
1681 }
1682 else if (strcmp(args[myidx], "match") == 0) {
1683 myidx++;
1684 flags = STK_IS_MATCH;
1685 }
1686 else if (strcmp(args[myidx], "on") == 0) {
1687 myidx++;
1688 flags = STK_IS_MATCH | STK_IS_STORE;
1689 }
1690 else {
1691 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1692 err_code |= ERR_ALERT | ERR_FATAL;
1693 goto out;
1694 }
1695
1696 if (*(args[myidx]) == 0) {
1697 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1698 err_code |= ERR_ALERT | ERR_FATAL;
1699 goto out;
1700 }
1701
1702 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001703 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001704 if (!expr) {
1705 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1706 err_code |= ERR_ALERT | ERR_FATAL;
1707 goto out;
1708 }
1709
1710 if (flags & STK_ON_RSP) {
1711 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1712 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1713 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1714 err_code |= ERR_ALERT | ERR_FATAL;
1715 free(expr);
1716 goto out;
1717 }
1718 } else {
1719 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1720 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1721 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1722 err_code |= ERR_ALERT | ERR_FATAL;
1723 free(expr);
1724 goto out;
1725 }
1726 }
1727
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001728 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001729 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1730
1731 if (strcmp(args[myidx], "table") == 0) {
1732 myidx++;
1733 name = args[myidx++];
1734 }
1735
1736 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1737 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1738 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1739 file, linenum, args[0], errmsg);
1740 err_code |= ERR_ALERT | ERR_FATAL;
1741 free(expr);
1742 goto out;
1743 }
1744 }
1745 else if (*(args[myidx])) {
1746 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1747 file, linenum, args[0], args[myidx]);
1748 err_code |= ERR_ALERT | ERR_FATAL;
1749 free(expr);
1750 goto out;
1751 }
1752 if (flags & STK_ON_RSP)
1753 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1754 else
1755 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1756
1757 rule = calloc(1, sizeof(*rule));
1758 rule->cond = cond;
1759 rule->expr = expr;
1760 rule->flags = flags;
1761 rule->table.name = name ? strdup(name) : NULL;
1762 LIST_INIT(&rule->list);
1763 if (flags & STK_ON_RSP)
1764 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1765 else
1766 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1767 }
1768 else if (!strcmp(args[0], "stats")) {
1769 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
1770 curproxy->uri_auth = NULL; /* we must detach from the default config */
1771
1772 if (!*args[1]) {
1773 goto stats_error_parsing;
1774 } else if (!strcmp(args[1], "admin")) {
1775 struct stats_admin_rule *rule;
1776
1777 if (curproxy == &defproxy) {
1778 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1779 err_code |= ERR_ALERT | ERR_FATAL;
1780 goto out;
1781 }
1782
1783 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1784 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1785 err_code |= ERR_ALERT | ERR_ABORT;
1786 goto out;
1787 }
1788
1789 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1790 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1791 file, linenum, args[0], args[1]);
1792 err_code |= ERR_ALERT | ERR_FATAL;
1793 goto out;
1794 }
1795 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1796 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1797 file, linenum, args[0], args[1], errmsg);
1798 err_code |= ERR_ALERT | ERR_FATAL;
1799 goto out;
1800 }
1801
1802 err_code |= warnif_cond_conflicts(cond,
1803 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1804 file, linenum);
1805
1806 rule = calloc(1, sizeof(*rule));
1807 rule->cond = cond;
1808 LIST_INIT(&rule->list);
1809 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
1810 } else if (!strcmp(args[1], "uri")) {
1811 if (*(args[2]) == 0) {
1812 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1813 err_code |= ERR_ALERT | ERR_FATAL;
1814 goto out;
1815 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1816 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1817 err_code |= ERR_ALERT | ERR_ABORT;
1818 goto out;
1819 }
1820 } else if (!strcmp(args[1], "realm")) {
1821 if (*(args[2]) == 0) {
1822 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1823 err_code |= ERR_ALERT | ERR_FATAL;
1824 goto out;
1825 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1826 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1827 err_code |= ERR_ALERT | ERR_ABORT;
1828 goto out;
1829 }
1830 } else if (!strcmp(args[1], "refresh")) {
1831 unsigned interval;
1832
1833 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001834 if (err == PARSE_TIME_OVER) {
1835 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1836 file, linenum, args[2]);
1837 err_code |= ERR_ALERT | ERR_FATAL;
1838 goto out;
1839 }
1840 else if (err == PARSE_TIME_UNDER) {
1841 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1842 file, linenum, args[2]);
1843 err_code |= ERR_ALERT | ERR_FATAL;
1844 goto out;
1845 }
1846 else if (err) {
1847 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001848 file, linenum, *err);
1849 err_code |= ERR_ALERT | ERR_FATAL;
1850 goto out;
1851 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1852 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1853 err_code |= ERR_ALERT | ERR_ABORT;
1854 goto out;
1855 }
1856 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
1857 struct act_rule *rule;
1858
1859 if (curproxy == &defproxy) {
1860 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1861 err_code |= ERR_ALERT | ERR_FATAL;
1862 goto out;
1863 }
1864
1865 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1866 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1867 err_code |= ERR_ALERT | ERR_ABORT;
1868 goto out;
1869 }
1870
1871 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1872 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1873 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1874 file, linenum, args[0]);
1875 err_code |= ERR_WARN;
1876 }
1877
1878 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1879
1880 if (!rule) {
1881 err_code |= ERR_ALERT | ERR_ABORT;
1882 goto out;
1883 }
1884
1885 err_code |= warnif_cond_conflicts(rule->cond,
1886 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1887 file, linenum);
1888 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1889
1890 } else if (!strcmp(args[1], "auth")) {
1891 if (*(args[2]) == 0) {
1892 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1893 err_code |= ERR_ALERT | ERR_FATAL;
1894 goto out;
1895 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1896 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1897 err_code |= ERR_ALERT | ERR_ABORT;
1898 goto out;
1899 }
1900 } else if (!strcmp(args[1], "scope")) {
1901 if (*(args[2]) == 0) {
1902 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1903 err_code |= ERR_ALERT | ERR_FATAL;
1904 goto out;
1905 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1906 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1907 err_code |= ERR_ALERT | ERR_ABORT;
1908 goto out;
1909 }
1910 } else if (!strcmp(args[1], "enable")) {
1911 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1912 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1913 err_code |= ERR_ALERT | ERR_ABORT;
1914 goto out;
1915 }
1916 } else if (!strcmp(args[1], "hide-version")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001917 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001918 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1919 err_code |= ERR_ALERT | ERR_ABORT;
1920 goto out;
1921 }
1922 } else if (!strcmp(args[1], "show-legends")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001923 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001924 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1925 err_code |= ERR_ALERT | ERR_ABORT;
1926 goto out;
1927 }
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001928 } else if (!strcmp(args[1], "show-modules")) {
1929 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1930 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1931 err_code |= ERR_ALERT | ERR_ABORT;
1932 goto out;
1933 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001934 } else if (!strcmp(args[1], "show-node")) {
1935
1936 if (*args[2]) {
1937 int i;
1938 char c;
1939
1940 for (i=0; args[2][i]; i++) {
1941 c = args[2][i];
1942 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1943 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1944 break;
1945 }
1946
1947 if (!i || args[2][i]) {
1948 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1949 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1950 file, linenum, args[0], args[1]);
1951 err_code |= ERR_ALERT | ERR_FATAL;
1952 goto out;
1953 }
1954 }
1955
1956 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1957 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1958 err_code |= ERR_ALERT | ERR_ABORT;
1959 goto out;
1960 }
1961 } else if (!strcmp(args[1], "show-desc")) {
1962 char *desc = NULL;
1963
1964 if (*args[2]) {
1965 int i, len=0;
1966 char *d;
1967
1968 for (i = 2; *args[i]; i++)
1969 len += strlen(args[i]) + 1;
1970
1971 desc = d = calloc(1, len);
1972
1973 d += snprintf(d, desc + len - d, "%s", args[2]);
1974 for (i = 3; *args[i]; i++)
1975 d += snprintf(d, desc + len - d, " %s", args[i]);
1976 }
1977
1978 if (!*args[2] && !global.desc)
1979 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1980 file, linenum, args[1]);
1981 else {
1982 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1983 free(desc);
1984 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1985 err_code |= ERR_ALERT | ERR_ABORT;
1986 goto out;
1987 }
1988 free(desc);
1989 }
1990 } else {
1991stats_error_parsing:
1992 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1993 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1994 err_code |= ERR_ALERT | ERR_FATAL;
1995 goto out;
1996 }
1997 }
1998 else if (!strcmp(args[0], "option")) {
1999 int optnum;
2000
2001 if (*(args[1]) == '\0') {
2002 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
2003 file, linenum, args[0]);
2004 err_code |= ERR_ALERT | ERR_FATAL;
2005 goto out;
2006 }
2007
2008 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
2009 if (!strcmp(args[1], cfg_opts[optnum].name)) {
2010 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
2011 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2012 file, linenum, cfg_opts[optnum].name);
2013 err_code |= ERR_ALERT | ERR_FATAL;
2014 goto out;
2015 }
2016 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2017 goto out;
2018
2019 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
2020 err_code |= ERR_WARN;
2021 goto out;
2022 }
2023
2024 curproxy->no_options &= ~cfg_opts[optnum].val;
2025 curproxy->options &= ~cfg_opts[optnum].val;
2026
2027 switch (kwm) {
2028 case KWM_STD:
2029 curproxy->options |= cfg_opts[optnum].val;
2030 break;
2031 case KWM_NO:
2032 curproxy->no_options |= cfg_opts[optnum].val;
2033 break;
2034 case KWM_DEF: /* already cleared */
2035 break;
2036 }
2037
2038 goto out;
2039 }
2040 }
2041
2042 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
2043 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
2044 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2045 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2046 file, linenum, cfg_opts2[optnum].name);
2047 err_code |= ERR_ALERT | ERR_FATAL;
2048 goto out;
2049 }
2050 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2051 goto out;
2052 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2053 err_code |= ERR_WARN;
2054 goto out;
2055 }
2056
Christopher Faulet31930372019-07-15 10:16:58 +02002057 /* "[no] option http-use-htx" is deprecated */
2058 if (!strcmp(cfg_opts2[optnum].name, "http-use-htx")) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02002059 if (kwm ==KWM_NO) {
2060 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
2061 " The HTX mode is now the only supported mode.\n",
2062 file, linenum, cfg_opts2[optnum].name);
2063 err_code |= ERR_WARN;
2064 }
Christopher Faulet31930372019-07-15 10:16:58 +02002065 goto out;
2066 }
2067
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002068 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2069 curproxy->options2 &= ~cfg_opts2[optnum].val;
2070
2071 switch (kwm) {
2072 case KWM_STD:
2073 curproxy->options2 |= cfg_opts2[optnum].val;
2074 break;
2075 case KWM_NO:
2076 curproxy->no_options2 |= cfg_opts2[optnum].val;
2077 break;
2078 case KWM_DEF: /* already cleared */
2079 break;
2080 }
2081 goto out;
2082 }
2083 }
2084
2085 /* HTTP options override each other. They can be cancelled using
2086 * "no option xxx" which only switches to default mode if the mode
2087 * was this one (useful for cancelling options set in defaults
2088 * sections).
2089 */
2090 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02002091 if (strcmp(args[1], "forceclose") == 0) {
2092 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
2093 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
2094 file, linenum, args[1]);
2095 err_code |= ERR_WARN;
2096 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002097 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2098 goto out;
2099 if (kwm == KWM_STD) {
2100 curproxy->options &= ~PR_O_HTTP_MODE;
2101 curproxy->options |= PR_O_HTTP_CLO;
2102 goto out;
2103 }
2104 else if (kwm == KWM_NO) {
2105 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2106 curproxy->options &= ~PR_O_HTTP_MODE;
2107 goto out;
2108 }
2109 }
2110 else if (strcmp(args[1], "http-server-close") == 0) {
2111 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2112 goto out;
2113 if (kwm == KWM_STD) {
2114 curproxy->options &= ~PR_O_HTTP_MODE;
2115 curproxy->options |= PR_O_HTTP_SCL;
2116 goto out;
2117 }
2118 else if (kwm == KWM_NO) {
2119 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2120 curproxy->options &= ~PR_O_HTTP_MODE;
2121 goto out;
2122 }
2123 }
2124 else if (strcmp(args[1], "http-keep-alive") == 0) {
2125 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2126 goto out;
2127 if (kwm == KWM_STD) {
2128 curproxy->options &= ~PR_O_HTTP_MODE;
2129 curproxy->options |= PR_O_HTTP_KAL;
2130 goto out;
2131 }
2132 else if (kwm == KWM_NO) {
2133 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2134 curproxy->options &= ~PR_O_HTTP_MODE;
2135 goto out;
2136 }
2137 }
2138 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002139 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2140 file, linenum, args[1]);
2141 err_code |= ERR_WARN;
2142 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002143 }
2144
2145 /* Redispatch can take an integer argument that control when the
2146 * resispatch occurs. All values are relative to the retries option.
2147 * This can be cancelled using "no option xxx".
2148 */
2149 if (strcmp(args[1], "redispatch") == 0) {
2150 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2151 err_code |= ERR_WARN;
2152 goto out;
2153 }
2154
2155 curproxy->no_options &= ~PR_O_REDISP;
2156 curproxy->options &= ~PR_O_REDISP;
2157
2158 switch (kwm) {
2159 case KWM_STD:
2160 curproxy->options |= PR_O_REDISP;
2161 curproxy->redispatch_after = -1;
2162 if(*args[2]) {
2163 curproxy->redispatch_after = atol(args[2]);
2164 }
2165 break;
2166 case KWM_NO:
2167 curproxy->no_options |= PR_O_REDISP;
2168 curproxy->redispatch_after = 0;
2169 break;
2170 case KWM_DEF: /* already cleared */
2171 break;
2172 }
2173 goto out;
2174 }
2175
2176 if (kwm != KWM_STD) {
2177 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2178 file, linenum, args[1]);
2179 err_code |= ERR_ALERT | ERR_FATAL;
2180 goto out;
2181 }
2182
2183 if (!strcmp(args[1], "httplog")) {
2184 char *logformat;
2185 /* generate a complete HTTP log */
2186 logformat = default_http_log_format;
2187 if (*(args[2]) != '\0') {
2188 if (!strcmp(args[2], "clf")) {
2189 curproxy->options2 |= PR_O2_CLFLOG;
2190 logformat = clf_http_log_format;
2191 } else {
2192 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2193 err_code |= ERR_ALERT | ERR_FATAL;
2194 goto out;
2195 }
2196 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2197 goto out;
2198 }
2199 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2200 char *oldlogformat = "log-format";
2201 char *clflogformat = "";
2202
2203 if (curproxy->conf.logformat_string == default_http_log_format)
2204 oldlogformat = "option httplog";
2205 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2206 oldlogformat = "option tcplog";
2207 else if (curproxy->conf.logformat_string == clf_http_log_format)
2208 oldlogformat = "option httplog clf";
2209 if (logformat == clf_http_log_format)
2210 clflogformat = " clf";
2211 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2212 file, linenum, clflogformat, oldlogformat);
2213 }
2214 if (curproxy->conf.logformat_string != default_http_log_format &&
2215 curproxy->conf.logformat_string != default_tcp_log_format &&
2216 curproxy->conf.logformat_string != clf_http_log_format)
2217 free(curproxy->conf.logformat_string);
2218 curproxy->conf.logformat_string = logformat;
2219
2220 free(curproxy->conf.lfs_file);
2221 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2222 curproxy->conf.lfs_line = curproxy->conf.args.line;
2223
2224 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2225 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2226 file, linenum, curproxy->id);
2227 err_code |= ERR_WARN;
2228 }
2229 }
2230 else if (!strcmp(args[1], "tcplog")) {
2231 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2232 char *oldlogformat = "log-format";
2233
2234 if (curproxy->conf.logformat_string == default_http_log_format)
2235 oldlogformat = "option httplog";
2236 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2237 oldlogformat = "option tcplog";
2238 else if (curproxy->conf.logformat_string == clf_http_log_format)
2239 oldlogformat = "option httplog clf";
2240 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2241 file, linenum, oldlogformat);
2242 }
2243 /* generate a detailed TCP log */
2244 if (curproxy->conf.logformat_string != default_http_log_format &&
2245 curproxy->conf.logformat_string != default_tcp_log_format &&
2246 curproxy->conf.logformat_string != clf_http_log_format)
2247 free(curproxy->conf.logformat_string);
2248 curproxy->conf.logformat_string = default_tcp_log_format;
2249
2250 free(curproxy->conf.lfs_file);
2251 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2252 curproxy->conf.lfs_line = curproxy->conf.args.line;
2253
2254 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2255 goto out;
2256
2257 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2258 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2259 file, linenum, curproxy->id);
2260 err_code |= ERR_WARN;
2261 }
2262 }
2263 else if (!strcmp(args[1], "tcpka")) {
2264 /* enable TCP keep-alives on client and server streams */
2265 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2266 err_code |= ERR_WARN;
2267
2268 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2269 goto out;
2270
2271 if (curproxy->cap & PR_CAP_FE)
2272 curproxy->options |= PR_O_TCP_CLI_KA;
2273 if (curproxy->cap & PR_CAP_BE)
2274 curproxy->options |= PR_O_TCP_SRV_KA;
2275 }
2276 else if (!strcmp(args[1], "httpchk")) {
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002277 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2278 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002279 goto out;
2280 }
2281 else if (!strcmp(args[1], "ssl-hello-chk")) {
Christopher Faulet811f78c2020-04-01 11:10:27 +02002282 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum);
2283 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002284 goto out;
2285 }
2286 else if (!strcmp(args[1], "smtpchk")) {
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002287 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2288 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002289 goto out;
2290 }
2291 else if (!strcmp(args[1], "pgsql-check")) {
Christopher Fauletce355072020-04-02 11:44:39 +02002292 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2293 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002294 goto out;
2295 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002296 else if (!strcmp(args[1], "redis-check")) {
Christopher Faulet33f05df2020-04-01 11:08:50 +02002297 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2298 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002299 goto out;
2300 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002301 else if (!strcmp(args[1], "mysql-check")) {
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002302 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2303 if (err_code & ERR_FATAL)
2304 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002305 }
2306 else if (!strcmp(args[1], "ldap-check")) {
Christopher Faulet1997eca2020-04-03 23:13:50 +02002307 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2308 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002309 goto out;
2310 }
2311 else if (!strcmp(args[1], "spop-check")) {
Christopher Faulet267b01b2020-04-04 10:27:09 +02002312 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2313 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002314 goto out;
2315 }
2316 else if (!strcmp(args[1], "tcp-check")) {
Christopher Faulet430e4802020-04-09 15:28:16 +02002317 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2318 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002319 goto out;
2320 }
2321 else if (!strcmp(args[1], "external-check")) {
Christopher Faulet6f557912020-04-09 15:58:50 +02002322 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2323 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002324 goto out;
2325 }
2326 else if (!strcmp(args[1], "forwardfor")) {
2327 int cur_arg;
2328
2329 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002330 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002331 */
2332
2333 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2334
2335 free(curproxy->fwdfor_hdr_name);
2336 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2337 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2338
2339 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2340 cur_arg = 2;
2341 while (*(args[cur_arg])) {
2342 if (!strcmp(args[cur_arg], "except")) {
2343 /* suboption except - needs additional argument for it */
2344 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2345 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2346 file, linenum, args[0], args[1], args[cur_arg]);
2347 err_code |= ERR_ALERT | ERR_FATAL;
2348 goto out;
2349 }
2350 /* flush useless bits */
2351 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2352 cur_arg += 2;
2353 } else if (!strcmp(args[cur_arg], "header")) {
2354 /* suboption header - needs additional argument for it */
2355 if (*(args[cur_arg+1]) == 0) {
2356 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2357 file, linenum, args[0], args[1], args[cur_arg]);
2358 err_code |= ERR_ALERT | ERR_FATAL;
2359 goto out;
2360 }
2361 free(curproxy->fwdfor_hdr_name);
2362 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2363 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2364 cur_arg += 2;
2365 } else if (!strcmp(args[cur_arg], "if-none")) {
2366 curproxy->options &= ~PR_O_FF_ALWAYS;
2367 cur_arg += 1;
2368 } else {
2369 /* unknown suboption - catchall */
2370 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2371 file, linenum, args[0], args[1]);
2372 err_code |= ERR_ALERT | ERR_FATAL;
2373 goto out;
2374 }
2375 } /* end while loop */
2376 }
2377 else if (!strcmp(args[1], "originalto")) {
2378 int cur_arg;
2379
2380 /* insert x-original-to field, but not for the IP address listed as an except.
2381 * set default options (ie: bitfield, header name, etc)
2382 */
2383
2384 curproxy->options |= PR_O_ORGTO;
2385
2386 free(curproxy->orgto_hdr_name);
2387 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2388 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2389
2390 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2391 cur_arg = 2;
2392 while (*(args[cur_arg])) {
2393 if (!strcmp(args[cur_arg], "except")) {
2394 /* suboption except - needs additional argument for it */
2395 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2396 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2397 file, linenum, args[0], args[1], args[cur_arg]);
2398 err_code |= ERR_ALERT | ERR_FATAL;
2399 goto out;
2400 }
2401 /* flush useless bits */
2402 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2403 cur_arg += 2;
2404 } else if (!strcmp(args[cur_arg], "header")) {
2405 /* suboption header - needs additional argument for it */
2406 if (*(args[cur_arg+1]) == 0) {
2407 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2408 file, linenum, args[0], args[1], args[cur_arg]);
2409 err_code |= ERR_ALERT | ERR_FATAL;
2410 goto out;
2411 }
2412 free(curproxy->orgto_hdr_name);
2413 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2414 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2415 cur_arg += 2;
2416 } else {
2417 /* unknown suboption - catchall */
2418 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2419 file, linenum, args[0], args[1]);
2420 err_code |= ERR_ALERT | ERR_FATAL;
2421 goto out;
2422 }
2423 } /* end while loop */
2424 }
2425 else {
2426 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2427 err_code |= ERR_ALERT | ERR_FATAL;
2428 goto out;
2429 }
2430 goto out;
2431 }
2432 else if (!strcmp(args[0], "default_backend")) {
2433 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2434 err_code |= ERR_WARN;
2435
2436 if (*(args[1]) == 0) {
2437 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2438 err_code |= ERR_ALERT | ERR_FATAL;
2439 goto out;
2440 }
2441 free(curproxy->defbe.name);
2442 curproxy->defbe.name = strdup(args[1]);
2443
2444 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2445 goto out;
2446 }
2447 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002448 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 +01002449
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002450 err_code |= ERR_ALERT | ERR_FATAL;
2451 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002452 }
2453 else if (!strcmp(args[0], "http-reuse")) {
2454 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2455 err_code |= ERR_WARN;
2456
2457 if (strcmp(args[1], "never") == 0) {
2458 /* enable a graceful server shutdown on an HTTP 404 response */
2459 curproxy->options &= ~PR_O_REUSE_MASK;
2460 curproxy->options |= PR_O_REUSE_NEVR;
2461 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2462 goto out;
2463 }
2464 else if (strcmp(args[1], "safe") == 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_SAFE;
2468 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2469 goto out;
2470 }
2471 else if (strcmp(args[1], "aggressive") == 0) {
2472 curproxy->options &= ~PR_O_REUSE_MASK;
2473 curproxy->options |= PR_O_REUSE_AGGR;
2474 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2475 goto out;
2476 }
2477 else if (strcmp(args[1], "always") == 0) {
2478 /* enable a graceful server shutdown on an HTTP 404 response */
2479 curproxy->options &= ~PR_O_REUSE_MASK;
2480 curproxy->options |= PR_O_REUSE_ALWS;
2481 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2482 goto out;
2483 }
2484 else {
2485 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2486 err_code |= ERR_ALERT | ERR_FATAL;
2487 goto out;
2488 }
2489 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002490 else if (!strcmp(args[0], "monitor")) {
2491 if (curproxy == &defproxy) {
2492 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2493 err_code |= ERR_ALERT | ERR_FATAL;
2494 goto out;
2495 }
2496
2497 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2498 err_code |= ERR_WARN;
2499
2500 if (strcmp(args[1], "fail") == 0) {
2501 /* add a condition to fail monitor requests */
2502 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2503 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2504 file, linenum, args[0], args[1]);
2505 err_code |= ERR_ALERT | ERR_FATAL;
2506 goto out;
2507 }
2508
2509 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2510 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2511 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2512 file, linenum, args[0], args[1], errmsg);
2513 err_code |= ERR_ALERT | ERR_FATAL;
2514 goto out;
2515 }
2516 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2517 }
2518 else {
2519 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2520 err_code |= ERR_ALERT | ERR_FATAL;
2521 goto out;
2522 }
2523 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002524#ifdef USE_TPROXY
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002525 else if (!strcmp(args[0], "transparent")) {
2526 /* enable transparent proxy connections */
2527 curproxy->options |= PR_O_TRANSP;
2528 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2529 goto out;
2530 }
2531#endif
2532 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
2533 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2534 err_code |= ERR_WARN;
2535
2536 if (*(args[1]) == 0) {
2537 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2538 err_code |= ERR_ALERT | ERR_FATAL;
2539 goto out;
2540 }
2541 curproxy->maxconn = atol(args[1]);
2542 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2543 goto out;
2544 }
2545 else if (!strcmp(args[0], "backlog")) { /* backlog */
2546 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2547 err_code |= ERR_WARN;
2548
2549 if (*(args[1]) == 0) {
2550 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2551 err_code |= ERR_ALERT | ERR_FATAL;
2552 goto out;
2553 }
2554 curproxy->backlog = atol(args[1]);
2555 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2556 goto out;
2557 }
2558 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
2559 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2560 err_code |= ERR_WARN;
2561
2562 if (*(args[1]) == 0) {
2563 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2564 err_code |= ERR_ALERT | ERR_FATAL;
2565 goto out;
2566 }
2567 curproxy->fullconn = atol(args[1]);
2568 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2569 goto out;
2570 }
2571 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
2572 if (*(args[1]) == 0) {
2573 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2574 err_code |= ERR_ALERT | ERR_FATAL;
2575 goto out;
2576 }
2577 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002578 if (err == PARSE_TIME_OVER) {
2579 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2580 file, linenum, args[1]);
2581 err_code |= ERR_ALERT | ERR_FATAL;
2582 goto out;
2583 }
2584 else if (err == PARSE_TIME_UNDER) {
2585 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2586 file, linenum, args[1]);
2587 err_code |= ERR_ALERT | ERR_FATAL;
2588 goto out;
2589 }
2590 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002591 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2592 file, linenum, *err);
2593 err_code |= ERR_ALERT | ERR_FATAL;
2594 goto out;
2595 }
2596 curproxy->grace = val;
2597 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2598 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002599
2600 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2601 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002602 }
2603 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
2604 struct sockaddr_storage *sk;
2605 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002606
2607 if (curproxy == &defproxy) {
2608 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2609 err_code |= ERR_ALERT | ERR_FATAL;
2610 goto out;
2611 }
2612 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2613 err_code |= ERR_WARN;
2614
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002615 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2616 &errmsg, NULL, NULL,
2617 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 +01002618 if (!sk) {
2619 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2620 err_code |= ERR_ALERT | ERR_FATAL;
2621 goto out;
2622 }
2623
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002624 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2625 goto out;
2626
2627 curproxy->dispatch_addr = *sk;
2628 curproxy->options |= PR_O_DISPATCH;
2629 }
2630 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
2631 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2632 err_code |= ERR_WARN;
2633
2634 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2635 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2636 err_code |= ERR_ALERT | ERR_FATAL;
2637 goto out;
2638 }
2639 }
2640 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
2641 /**
2642 * The syntax for hash-type config element is
2643 * hash-type {map-based|consistent} [[<algo>] avalanche]
2644 *
2645 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2646 */
2647 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2648
2649 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2650 err_code |= ERR_WARN;
2651
2652 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2653 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2654 }
2655 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2656 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2657 }
2658 else if (strcmp(args[1], "avalanche") == 0) {
2659 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]);
2660 err_code |= ERR_ALERT | ERR_FATAL;
2661 goto out;
2662 }
2663 else {
2664 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2665 err_code |= ERR_ALERT | ERR_FATAL;
2666 goto out;
2667 }
2668
2669 /* set the hash function to use */
2670 if (!*args[2]) {
2671 /* the default algo is sdbm */
2672 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2673
2674 /* if consistent with no argument, then avalanche modifier is also applied */
2675 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2676 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2677 } else {
2678 /* set the hash function */
2679 if (!strcmp(args[2], "sdbm")) {
2680 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2681 }
2682 else if (!strcmp(args[2], "djb2")) {
2683 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2684 }
2685 else if (!strcmp(args[2], "wt6")) {
2686 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2687 }
2688 else if (!strcmp(args[2], "crc32")) {
2689 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2690 }
2691 else {
2692 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2693 err_code |= ERR_ALERT | ERR_FATAL;
2694 goto out;
2695 }
2696
2697 /* set the hash modifier */
2698 if (!strcmp(args[3], "avalanche")) {
2699 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2700 }
2701 else if (*args[3]) {
2702 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2703 err_code |= ERR_ALERT | ERR_FATAL;
2704 goto out;
2705 }
2706 }
2707 }
2708 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2709 if (*(args[1]) == 0) {
2710 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2711 err_code |= ERR_ALERT | ERR_FATAL;
2712 goto out;
2713 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002714 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2715 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002716 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2717 err_code |= ERR_ALERT | ERR_FATAL;
2718 goto out;
2719 }
2720 }
2721 else if (strcmp(args[0], "unique-id-format") == 0) {
2722 if (!*(args[1])) {
2723 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2724 err_code |= ERR_ALERT | ERR_FATAL;
2725 goto out;
2726 }
2727 if (*(args[2])) {
2728 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2729 err_code |= ERR_ALERT | ERR_FATAL;
2730 goto out;
2731 }
2732 free(curproxy->conf.uniqueid_format_string);
2733 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2734
2735 free(curproxy->conf.uif_file);
2736 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2737 curproxy->conf.uif_line = curproxy->conf.args.line;
2738 }
2739
2740 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002741 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002742 if (!*(args[1])) {
2743 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2744 err_code |= ERR_ALERT | ERR_FATAL;
2745 goto out;
2746 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002747 copy = strdup(args[1]);
2748 if (copy == NULL) {
2749 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2750 err_code |= ERR_ALERT | ERR_FATAL;
2751 goto out;
2752 }
2753
2754 istfree(&curproxy->header_unique_id);
2755 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002756 }
2757
2758 else if (strcmp(args[0], "log-format") == 0) {
2759 if (!*(args[1])) {
2760 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2761 err_code |= ERR_ALERT | ERR_FATAL;
2762 goto out;
2763 }
2764 if (*(args[2])) {
2765 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2766 err_code |= ERR_ALERT | ERR_FATAL;
2767 goto out;
2768 }
2769 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2770 char *oldlogformat = "log-format";
2771
2772 if (curproxy->conf.logformat_string == default_http_log_format)
2773 oldlogformat = "option httplog";
2774 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2775 oldlogformat = "option tcplog";
2776 else if (curproxy->conf.logformat_string == clf_http_log_format)
2777 oldlogformat = "option httplog clf";
2778 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2779 file, linenum, oldlogformat);
2780 }
2781 if (curproxy->conf.logformat_string != default_http_log_format &&
2782 curproxy->conf.logformat_string != default_tcp_log_format &&
2783 curproxy->conf.logformat_string != clf_http_log_format)
2784 free(curproxy->conf.logformat_string);
2785 curproxy->conf.logformat_string = strdup(args[1]);
2786
2787 free(curproxy->conf.lfs_file);
2788 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2789 curproxy->conf.lfs_line = curproxy->conf.args.line;
2790
2791 /* get a chance to improve log-format error reporting by
2792 * reporting the correct line-number when possible.
2793 */
2794 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2795 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2796 file, linenum, curproxy->id);
2797 err_code |= ERR_WARN;
2798 }
2799 }
2800 else if (!strcmp(args[0], "log-format-sd")) {
2801 if (!*(args[1])) {
2802 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2803 err_code |= ERR_ALERT | ERR_FATAL;
2804 goto out;
2805 }
2806 if (*(args[2])) {
2807 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2808 err_code |= ERR_ALERT | ERR_FATAL;
2809 goto out;
2810 }
2811
2812 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2813 free(curproxy->conf.logformat_sd_string);
2814 curproxy->conf.logformat_sd_string = strdup(args[1]);
2815
2816 free(curproxy->conf.lfsd_file);
2817 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2818 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2819
2820 /* get a chance to improve log-format-sd error reporting by
2821 * reporting the correct line-number when possible.
2822 */
2823 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2824 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2825 file, linenum, curproxy->id);
2826 err_code |= ERR_WARN;
2827 }
2828 }
2829 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
2830 if (*(args[1]) == 0) {
2831 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2832 err_code |= ERR_ALERT | ERR_FATAL;
2833 goto out;
2834 }
2835 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002836 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2837 if (b_orig(&curproxy->log_tag) == NULL) {
2838 chunk_destroy(&curproxy->log_tag);
2839 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2840 err_code |= ERR_ALERT | ERR_FATAL;
2841 goto out;
2842 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002843 }
2844 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
2845 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2846 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2847 err_code |= ERR_ALERT | ERR_FATAL;
2848 goto out;
2849 }
2850 }
2851 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
2852 int cur_arg;
2853 int port1, port2;
2854 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002855
2856 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2857 err_code |= ERR_WARN;
2858
2859 if (!*args[1]) {
2860 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2861 file, linenum, "source", "usesrc", "interface");
2862 err_code |= ERR_ALERT | ERR_FATAL;
2863 goto out;
2864 }
2865
Christopher Faulet31930372019-07-15 10:16:58 +02002866 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002867 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2868 free(curproxy->conn_src.iface_name);
2869 curproxy->conn_src.iface_name = NULL;
2870 curproxy->conn_src.iface_len = 0;
2871
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002872 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2873 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002874 if (!sk) {
2875 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2876 file, linenum, args[0], args[1], errmsg);
2877 err_code |= ERR_ALERT | ERR_FATAL;
2878 goto out;
2879 }
2880
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002881 curproxy->conn_src.source_addr = *sk;
2882 curproxy->conn_src.opts |= CO_SRC_BIND;
2883
2884 cur_arg = 2;
2885 while (*(args[cur_arg])) {
2886 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
2887#if defined(CONFIG_HAP_TRANSPARENT)
2888 if (!*args[cur_arg + 1]) {
2889 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2890 file, linenum, "usesrc");
2891 err_code |= ERR_ALERT | ERR_FATAL;
2892 goto out;
2893 }
2894
2895 if (!strcmp(args[cur_arg + 1], "client")) {
2896 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2897 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
2898 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
2899 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2900 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2901 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2902 char *name, *end;
2903
2904 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002905 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002906 name++;
2907
2908 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002909 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002910 end++;
2911
2912 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2913 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
2914 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2915 curproxy->conn_src.bind_hdr_len = end - name;
2916 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2917 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2918 curproxy->conn_src.bind_hdr_occ = -1;
2919
2920 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002921 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002922 end++;
2923 if (*end == ',') {
2924 end++;
2925 name = end;
2926 if (*end == '-')
2927 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002928 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002929 end++;
2930 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2931 }
2932
2933 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2934 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2935 " occurrences values smaller than %d.\n",
2936 file, linenum, MAX_HDR_HISTORY);
2937 err_code |= ERR_ALERT | ERR_FATAL;
2938 goto out;
2939 }
2940 } else {
2941 struct sockaddr_storage *sk;
2942
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002943 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2944 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002945 if (!sk) {
2946 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2947 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2948 err_code |= ERR_ALERT | ERR_FATAL;
2949 goto out;
2950 }
2951
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002952 curproxy->conn_src.tproxy_addr = *sk;
2953 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2954 }
2955 global.last_checks |= LSTCHK_NETADM;
2956#else /* no TPROXY support */
2957 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2958 file, linenum, "usesrc");
2959 err_code |= ERR_ALERT | ERR_FATAL;
2960 goto out;
2961#endif
2962 cur_arg += 2;
2963 continue;
2964 }
2965
2966 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
2967#ifdef SO_BINDTODEVICE
2968 if (!*args[cur_arg + 1]) {
2969 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2970 file, linenum, args[0]);
2971 err_code |= ERR_ALERT | ERR_FATAL;
2972 goto out;
2973 }
2974 free(curproxy->conn_src.iface_name);
2975 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2976 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2977 global.last_checks |= LSTCHK_NETADM;
2978#else
2979 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2980 file, linenum, args[0], args[cur_arg]);
2981 err_code |= ERR_ALERT | ERR_FATAL;
2982 goto out;
2983#endif
2984 cur_arg += 2;
2985 continue;
2986 }
2987 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2988 file, linenum, args[0], "interface", "usesrc");
2989 err_code |= ERR_ALERT | ERR_FATAL;
2990 goto out;
2991 }
2992 }
2993 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
2994 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2995 file, linenum, "usesrc", "source");
2996 err_code |= ERR_ALERT | ERR_FATAL;
2997 goto out;
2998 }
2999 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003000 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003001 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003002 file, linenum, args[0]);
3003 err_code |= ERR_ALERT | ERR_FATAL;
3004 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003005 }
3006 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003007 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3008 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3009 err_code |= ERR_ALERT | ERR_FATAL;
3010 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003011 }
3012 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003013 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3014 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3015 err_code |= ERR_ALERT | ERR_FATAL;
3016 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003017 }
3018 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003019 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3020 err_code |= ERR_ALERT | ERR_FATAL;
3021 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003022 }
3023 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003024 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3025 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3026 err_code |= ERR_ALERT | ERR_FATAL;
3027 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003028 }
3029 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003030 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3031 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3032 err_code |= ERR_ALERT | ERR_FATAL;
3033 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003034 }
3035 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003036 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3037 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3038 err_code |= ERR_ALERT | ERR_FATAL;
3039 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003040 }
3041 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003042 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3043 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3044 err_code |= ERR_ALERT | ERR_FATAL;
3045 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003046 }
3047 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003048 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3049 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3050 err_code |= ERR_ALERT | ERR_FATAL;
3051 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003052 }
3053 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003054 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3055 err_code |= ERR_ALERT | ERR_FATAL;
3056 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003057 }
3058 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003059 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3060 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3061 err_code |= ERR_ALERT | ERR_FATAL;
3062 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003063 }
3064 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003065 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3066 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3067 err_code |= ERR_ALERT | ERR_FATAL;
3068 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003069 }
3070 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003071 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3072 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3073 err_code |= ERR_ALERT | ERR_FATAL;
3074 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003075 }
3076 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003077 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3078 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3079 err_code |= ERR_ALERT | ERR_FATAL;
3080 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003081 }
3082 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003083 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3084 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3085 err_code |= ERR_ALERT | ERR_FATAL;
3086 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003087 }
3088 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003089 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3090 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3091 err_code |= ERR_ALERT | ERR_FATAL;
3092 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003093 }
3094 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303095 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003096 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3097 err_code |= ERR_ALERT | ERR_FATAL;
3098 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003099 }
3100 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003101 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3102 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3103 err_code |= ERR_ALERT | ERR_FATAL;
3104 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003105 }
3106 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003107 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3108 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3109 err_code |= ERR_ALERT | ERR_FATAL;
3110 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003111 }
3112 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003113 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3114 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3115 err_code |= ERR_ALERT | ERR_FATAL;
3116 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003117 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003118 else {
3119 struct cfg_kw_list *kwl;
3120 int index;
3121
3122 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3123 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3124 if (kwl->kw[index].section != CFG_LISTEN)
3125 continue;
3126 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3127 /* prepare error message just in case */
3128 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
3129 if (rc < 0) {
3130 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3131 err_code |= ERR_ALERT | ERR_FATAL;
3132 goto out;
3133 }
3134 else if (rc > 0) {
3135 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3136 err_code |= ERR_WARN;
3137 goto out;
3138 }
3139 goto out;
3140 }
3141 }
3142 }
3143
3144 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
3145 err_code |= ERR_ALERT | ERR_FATAL;
3146 goto out;
3147 }
3148 out:
3149 free(errmsg);
3150 return err_code;
3151}