blob: cdb68401a461fcacc577207d5231932d9da59253 [file] [log] [blame]
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13
14#include <common/cfgparse.h>
Willy Tarreau8c42b8a2020-06-04 19:27:34 +020015#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010016
Willy Tarreaudcc048a2020-06-04 19:11:43 +020017#include <haproxy/acl.h>
Willy Tarreau278161c2020-06-04 11:18:28 +020018#include <haproxy/capture-t.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020019#include <haproxy/check.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020020#include <haproxy/compression-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020021#include <haproxy/connection.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 Tarreau872f2ea2020-06-04 18:46:44 +020025#include <haproxy/peers.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020026#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020027#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020028#include <haproxy/server.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020029#include <haproxy/stats-t.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010030
Willy Tarreau2dd7c352020-06-03 15:26:55 +020031#include <haproxy/protocol.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020032#include <haproxy/stick_table.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010033
34/* Report a warning if a rule is placed after a 'tcp-request session' rule.
35 * Return 1 if the warning has been emitted, otherwise 0.
36 */
37int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
38{
39 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
40 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
41 file, line, arg);
42 return 1;
43 }
44 return 0;
45}
46
47/* Report a warning if a rule is placed after a 'tcp-request content' rule.
48 * Return 1 if the warning has been emitted, otherwise 0.
49 */
50int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
51{
52 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
53 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
54 file, line, arg);
55 return 1;
56 }
57 return 0;
58}
59
60/* Report a warning if a rule is placed after a 'monitor fail' rule.
61 * Return 1 if the warning has been emitted, otherwise 0.
62 */
63int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
64{
65 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
66 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
67 file, line, arg);
68 return 1;
69 }
70 return 0;
71}
72
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010073/* Report a warning if a rule is placed after an 'http_request' rule.
74 * Return 1 if the warning has been emitted, otherwise 0.
75 */
76int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
77{
78 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
79 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
80 file, line, arg);
81 return 1;
82 }
83 return 0;
84}
85
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010086/* Report a warning if a rule is placed after a redirect rule.
87 * Return 1 if the warning has been emitted, otherwise 0.
88 */
89int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
90{
91 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
92 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
93 file, line, arg);
94 return 1;
95 }
96 return 0;
97}
98
99/* Report a warning if a rule is placed after a 'use_backend' rule.
100 * Return 1 if the warning has been emitted, otherwise 0.
101 */
102int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
103{
104 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
105 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
106 file, line, arg);
107 return 1;
108 }
109 return 0;
110}
111
112/* Report a warning if a rule is placed after a 'use-server' rule.
113 * Return 1 if the warning has been emitted, otherwise 0.
114 */
115int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
116{
117 if (!LIST_ISEMPTY(&proxy->server_rules)) {
118 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
119 file, line, arg);
120 return 1;
121 }
122 return 0;
123}
124
125/* report a warning if a redirect rule is dangerously placed */
126int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
127{
128 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
129 warnif_rule_after_use_server(proxy, file, line, arg);
130}
131
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100132/* report a warning if an http-request rule is dangerously placed */
133int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
134{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200135 return warnif_rule_after_redirect(proxy, file, line, arg) ||
136 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100137}
138
139/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200140int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100141{
142 return warnif_rule_after_http_req(proxy, file, line, arg) ||
143 warnif_misplaced_http_req(proxy, file, line, arg);
144}
145
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100146/* report a warning if a "tcp request content" rule is dangerously placed */
147int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
148{
149 return warnif_rule_after_monitor(proxy, file, line, arg) ||
150 warnif_misplaced_monitor(proxy, file, line, arg);
151}
152
153/* report a warning if a "tcp request session" rule is dangerously placed */
154int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
155{
156 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
157 warnif_misplaced_tcp_cont(proxy, file, line, arg);
158}
159
160/* report a warning if a "tcp request connection" rule is dangerously placed */
161int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
162{
163 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
164 warnif_misplaced_tcp_sess(proxy, file, line, arg);
165}
166
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100167int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
168{
169 static struct proxy *curproxy = NULL;
170 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100171 int rc;
172 unsigned val;
173 int err_code = 0;
174 struct acl_cond *cond = NULL;
175 struct logsrv *tmplogsrv;
176 char *errmsg = NULL;
177 struct bind_conf *bind_conf;
178
179 if (!strcmp(args[0], "listen"))
180 rc = PR_CAP_LISTEN;
181 else if (!strcmp(args[0], "frontend"))
182 rc = PR_CAP_FE;
183 else if (!strcmp(args[0], "backend"))
184 rc = PR_CAP_BE;
185 else
186 rc = PR_CAP_NONE;
187
188 if (rc != PR_CAP_NONE) { /* new proxy */
189 if (!*args[1]) {
190 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
191 " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
192 file, linenum, args[0]);
193 err_code |= ERR_ALERT | ERR_ABORT;
194 goto out;
195 }
196
197 err = invalid_char(args[1]);
198 if (err) {
199 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
200 file, linenum, *err, args[0], args[1]);
201 err_code |= ERR_ALERT | ERR_FATAL;
202 }
203
204 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
205 if (curproxy) {
206 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
207 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
208 curproxy->id, curproxy->conf.file, curproxy->conf.line);
209 err_code |= ERR_ALERT | ERR_FATAL;
210 }
211
212 if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
213 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
214 err_code |= ERR_ALERT | ERR_ABORT;
215 goto out;
216 }
217
218 init_new_proxy(curproxy);
219 curproxy->next = proxies_list;
220 proxies_list = curproxy;
221 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
222 curproxy->conf.args.line = curproxy->conf.line = linenum;
223 curproxy->last_change = now.tv_sec;
224 curproxy->id = strdup(args[1]);
225 curproxy->cap = rc;
226 proxy_store_name(curproxy);
227
228 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
229 if (curproxy->cap & PR_CAP_FE)
230 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
231 goto out;
232 }
233
234 /* set default values */
235 memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv));
236 curproxy->defsrv.id = "default-server";
237
238 curproxy->state = defproxy.state;
239 curproxy->options = defproxy.options;
240 curproxy->options2 = defproxy.options2;
241 curproxy->no_options = defproxy.no_options;
242 curproxy->no_options2 = defproxy.no_options2;
243 curproxy->bind_proc = defproxy.bind_proc;
244 curproxy->except_net = defproxy.except_net;
245 curproxy->except_mask = defproxy.except_mask;
246 curproxy->except_to = defproxy.except_to;
247 curproxy->except_mask_to = defproxy.except_mask_to;
Olivier Houcharda254a372019-04-05 15:30:12 +0200248 curproxy->retry_type = defproxy.retry_type;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100249
250 if (defproxy.fwdfor_hdr_len) {
251 curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len;
252 curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name);
253 }
254
255 if (defproxy.orgto_hdr_len) {
256 curproxy->orgto_hdr_len = defproxy.orgto_hdr_len;
257 curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name);
258 }
259
260 if (defproxy.server_id_hdr_len) {
261 curproxy->server_id_hdr_len = defproxy.server_id_hdr_len;
262 curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name);
263 }
264
265 /* initialize error relocations */
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100266 if (!proxy_dup_default_conf_errors(curproxy, &defproxy, &errmsg)) {
267 ha_alert("parsing [%s:%d] : proxy '%s' : %s\n", file, linenum, curproxy->id, errmsg);
268 err_code |= ERR_ALERT | ERR_FATAL;
269 goto out;
270 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100271
272 if (curproxy->cap & PR_CAP_FE) {
273 curproxy->maxconn = defproxy.maxconn;
274 curproxy->backlog = defproxy.backlog;
275 curproxy->fe_sps_lim = defproxy.fe_sps_lim;
276
277 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +0100278 curproxy->max_out_conns = defproxy.max_out_conns;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100279 }
280
281 if (curproxy->cap & PR_CAP_BE) {
282 curproxy->lbprm.algo = defproxy.lbprm.algo;
Willy Tarreau76e84f52019-01-14 16:50:58 +0100283 curproxy->lbprm.hash_balance_factor = defproxy.lbprm.hash_balance_factor;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100284 curproxy->fullconn = defproxy.fullconn;
285 curproxy->conn_retries = defproxy.conn_retries;
286 curproxy->redispatch_after = defproxy.redispatch_after;
287 curproxy->max_ka_queue = defproxy.max_ka_queue;
288
Christopher Faulete5870d82020-04-15 11:32:03 +0200289 curproxy->tcpcheck_rules.flags = (defproxy.tcpcheck_rules.flags & ~TCPCHK_RULES_UNUSED_RS);
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200290 curproxy->tcpcheck_rules.list = defproxy.tcpcheck_rules.list;
Christopher Faulet7a1e2e12020-04-02 18:05:11 +0200291 if (!LIST_ISEMPTY(&defproxy.tcpcheck_rules.preset_vars)) {
292 if (!dup_tcpcheck_vars(&curproxy->tcpcheck_rules.preset_vars,
293 &defproxy.tcpcheck_rules.preset_vars)) {
294 ha_alert("parsing [%s:%d] : failed to duplicate tcpcheck preset-vars\n",
295 file, linenum);
296 err_code |= ERR_ALERT | ERR_FATAL;
297 goto out;
298 }
299 }
Gaetan Rivet04578db2020-02-07 15:37:17 +0100300
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100301 curproxy->ck_opts = defproxy.ck_opts;
302 if (defproxy.cookie_name)
303 curproxy->cookie_name = strdup(defproxy.cookie_name);
304 curproxy->cookie_len = defproxy.cookie_len;
305
306 if (defproxy.dyncookie_key)
307 curproxy->dyncookie_key = strdup(defproxy.dyncookie_key);
308 if (defproxy.cookie_domain)
309 curproxy->cookie_domain = strdup(defproxy.cookie_domain);
310
311 if (defproxy.cookie_maxidle)
312 curproxy->cookie_maxidle = defproxy.cookie_maxidle;
313
314 if (defproxy.cookie_maxlife)
315 curproxy->cookie_maxlife = defproxy.cookie_maxlife;
316
317 if (defproxy.rdp_cookie_name)
318 curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name);
319 curproxy->rdp_cookie_len = defproxy.rdp_cookie_len;
320
Christopher Faulet2f533902020-01-21 11:06:48 +0100321 if (defproxy.cookie_attrs)
322 curproxy->cookie_attrs = strdup(defproxy.cookie_attrs);
Willy Tarreau20e68372019-01-14 16:04:01 +0100323
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100324 if (defproxy.lbprm.arg_str)
325 curproxy->lbprm.arg_str = strdup(defproxy.lbprm.arg_str);
326 curproxy->lbprm.arg_len = defproxy.lbprm.arg_len;
Willy Tarreau20e68372019-01-14 16:04:01 +0100327 curproxy->lbprm.arg_opt1 = defproxy.lbprm.arg_opt1;
328 curproxy->lbprm.arg_opt2 = defproxy.lbprm.arg_opt2;
329 curproxy->lbprm.arg_opt3 = defproxy.lbprm.arg_opt3;
330
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100331 if (defproxy.conn_src.iface_name)
332 curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name);
333 curproxy->conn_src.iface_len = defproxy.conn_src.iface_len;
334 curproxy->conn_src.opts = defproxy.conn_src.opts;
335#if defined(CONFIG_HAP_TRANSPARENT)
336 curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr;
337#endif
338 curproxy->load_server_state_from_file = defproxy.load_server_state_from_file;
339 }
340
341 if (curproxy->cap & PR_CAP_FE) {
342 if (defproxy.capture_name)
343 curproxy->capture_name = strdup(defproxy.capture_name);
344 curproxy->capture_namelen = defproxy.capture_namelen;
345 curproxy->capture_len = defproxy.capture_len;
346 }
347
348 if (curproxy->cap & PR_CAP_FE) {
349 curproxy->timeout.client = defproxy.timeout.client;
350 curproxy->timeout.clientfin = defproxy.timeout.clientfin;
351 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
352 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
353 curproxy->timeout.httpka = defproxy.timeout.httpka;
354 curproxy->mon_net = defproxy.mon_net;
355 curproxy->mon_mask = defproxy.mon_mask;
356 if (defproxy.monitor_uri)
357 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
358 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
359 if (defproxy.defbe.name)
360 curproxy->defbe.name = strdup(defproxy.defbe.name);
361
362 /* get either a pointer to the logformat string or a copy of it */
363 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
364 if (curproxy->conf.logformat_string &&
365 curproxy->conf.logformat_string != default_http_log_format &&
366 curproxy->conf.logformat_string != default_tcp_log_format &&
367 curproxy->conf.logformat_string != clf_http_log_format)
368 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
369
370 if (defproxy.conf.lfs_file) {
371 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
372 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
373 }
374
375 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
376 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
377 if (curproxy->conf.logformat_sd_string &&
378 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
379 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
380
381 if (defproxy.conf.lfsd_file) {
382 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
383 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
384 }
385 }
386
387 if (curproxy->cap & PR_CAP_BE) {
388 curproxy->timeout.connect = defproxy.timeout.connect;
389 curproxy->timeout.server = defproxy.timeout.server;
390 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
391 curproxy->timeout.check = defproxy.timeout.check;
392 curproxy->timeout.queue = defproxy.timeout.queue;
393 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
394 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
395 curproxy->timeout.httpka = defproxy.timeout.httpka;
396 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
397 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
398 }
399
400 curproxy->mode = defproxy.mode;
401 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
402
403 /* copy default logsrvs to curproxy */
404 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
405 struct logsrv *node = malloc(sizeof(*node));
406 memcpy(node, tmplogsrv, sizeof(struct logsrv));
407 node->ref = tmplogsrv->ref;
408 LIST_INIT(&node->list);
409 LIST_ADDQ(&curproxy->logsrvs, &node->list);
410 }
411
412 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
413 if (curproxy->conf.uniqueid_format_string)
414 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
415
416 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
417
418 if (defproxy.conf.uif_file) {
419 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
420 curproxy->conf.uif_line = defproxy.conf.uif_line;
421 }
422
423 /* copy default header unique id */
Tim Duesterhus0643b0e2020-03-05 17:56:35 +0100424 if (isttest(defproxy.header_unique_id)) {
425 const struct ist copy = istdup(defproxy.header_unique_id);
426 if (!isttest(copy)) {
427 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
428 err_code |= ERR_ALERT | ERR_FATAL;
429 goto out;
430 }
431 curproxy->header_unique_id = copy;
432 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100433
434 /* default compression options */
435 if (defproxy.comp != NULL) {
436 curproxy->comp = calloc(1, sizeof(struct comp));
437 curproxy->comp->algos = defproxy.comp->algos;
438 curproxy->comp->types = defproxy.comp->types;
439 }
440
441 curproxy->grace = defproxy.grace;
442 curproxy->conf.used_listener_id = EB_ROOT;
443 curproxy->conf.used_server_id = EB_ROOT;
444
445 if (defproxy.check_path)
446 curproxy->check_path = strdup(defproxy.check_path);
447 if (defproxy.check_command)
448 curproxy->check_command = strdup(defproxy.check_command);
449
450 if (defproxy.email_alert.mailers.name)
451 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
452 if (defproxy.email_alert.from)
453 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
454 if (defproxy.email_alert.to)
455 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
456 if (defproxy.email_alert.myhostname)
457 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
458 curproxy->email_alert.level = defproxy.email_alert.level;
459 curproxy->email_alert.set = defproxy.email_alert.set;
460
461 goto out;
462 }
463 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
464 /* some variables may have already been initialized earlier */
465 /* FIXME-20070101: we should do this too at the end of the
466 * config parsing to free all default values.
467 */
468 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
469 err_code |= ERR_ABORT;
470 goto out;
471 }
472
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100473 free(defproxy.check_command);
474 free(defproxy.check_path);
475 free(defproxy.cookie_name);
476 free(defproxy.rdp_cookie_name);
477 free(defproxy.dyncookie_key);
478 free(defproxy.cookie_domain);
Christopher Faulet2f533902020-01-21 11:06:48 +0100479 free(defproxy.cookie_attrs);
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100480 free(defproxy.lbprm.arg_str);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100481 free(defproxy.capture_name);
482 free(defproxy.monitor_uri);
483 free(defproxy.defbe.name);
484 free(defproxy.conn_src.iface_name);
485 free(defproxy.fwdfor_hdr_name);
486 defproxy.fwdfor_hdr_len = 0;
487 free(defproxy.orgto_hdr_name);
488 defproxy.orgto_hdr_len = 0;
489 free(defproxy.server_id_hdr_name);
490 defproxy.server_id_hdr_len = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100491
492 if (defproxy.conf.logformat_string != default_http_log_format &&
493 defproxy.conf.logformat_string != default_tcp_log_format &&
494 defproxy.conf.logformat_string != clf_http_log_format)
495 free(defproxy.conf.logformat_string);
496
497 free(defproxy.conf.uniqueid_format_string);
498 free(defproxy.conf.lfs_file);
499 free(defproxy.conf.uif_file);
500 chunk_destroy(&defproxy.log_tag);
501 free_email_alert(&defproxy);
502
503 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
504 free(defproxy.conf.logformat_sd_string);
505 free(defproxy.conf.lfsd_file);
506
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100507 proxy_release_conf_errors(&defproxy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100508
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200509 deinit_proxy_tcpcheck(&defproxy);
510
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100511 /* we cannot free uri_auth because it might already be used */
512 init_default_instance();
513 curproxy = &defproxy;
514 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
515 curproxy->conf.args.line = curproxy->conf.line = linenum;
516 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
517 goto out;
518 }
519 else if (curproxy == NULL) {
520 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
521 err_code |= ERR_ALERT | ERR_FATAL;
522 goto out;
523 }
524
525 /* update the current file and line being parsed */
526 curproxy->conf.args.file = curproxy->conf.file;
527 curproxy->conf.args.line = linenum;
528
529 /* Now let's parse the proxy-specific keywords */
530 if (!strcmp(args[0], "server") ||
531 !strcmp(args[0], "default-server") ||
532 !strcmp(args[0], "server-template")) {
Frédéric Lécaille8ba10fe2020-04-03 09:43:47 +0200533 err_code |= parse_server(file, linenum, args, curproxy, &defproxy, 1, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100534 if (err_code & ERR_FATAL)
535 goto out;
536 }
537 else if (!strcmp(args[0], "bind")) { /* new listen addresses */
538 struct listener *l;
539 int cur_arg;
540
541 if (curproxy == &defproxy) {
542 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
543 err_code |= ERR_ALERT | ERR_FATAL;
544 goto out;
545 }
546 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
547 err_code |= ERR_WARN;
548
549 if (!*(args[1])) {
550 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
551 file, linenum, args[0]);
552 err_code |= ERR_ALERT | ERR_FATAL;
553 goto out;
554 }
555
556 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
557
558 /* use default settings for unix sockets */
559 bind_conf->ux.uid = global.unix_bind.ux.uid;
560 bind_conf->ux.gid = global.unix_bind.ux.gid;
561 bind_conf->ux.mode = global.unix_bind.ux.mode;
562
563 /* NOTE: the following line might create several listeners if there
564 * are comma-separated IPs or port ranges. So all further processing
565 * will have to be applied to all listeners created after last_listen.
566 */
567 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
568 if (errmsg && *errmsg) {
569 indent_msg(&errmsg, 2);
570 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
571 }
572 else
573 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
574 file, linenum, args[0], args[1]);
575 err_code |= ERR_ALERT | ERR_FATAL;
576 goto out;
577 }
578
579 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
580 /* Set default global rights and owner for unix bind */
581 global.maxsock++;
582 }
583
584 cur_arg = 2;
585 while (*(args[cur_arg])) {
586 static int bind_dumped;
587 struct bind_kw *kw;
588 char *err;
589
590 kw = bind_find_kw(args[cur_arg]);
591 if (kw) {
592 char *err = NULL;
593 int code;
594
595 if (!kw->parse) {
596 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
597 file, linenum, args[0], args[1], args[cur_arg]);
598 cur_arg += 1 + kw->skip ;
599 err_code |= ERR_ALERT | ERR_FATAL;
600 goto out;
601 }
602
603 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
604 err_code |= code;
605
606 if (code) {
607 if (err && *err) {
608 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200609 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
610 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
611 else
612 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100613 }
614 else
615 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
616 file, linenum, args[0], args[1], args[cur_arg]);
617 if (code & ERR_FATAL) {
618 free(err);
619 cur_arg += 1 + kw->skip;
620 goto out;
621 }
622 }
623 free(err);
624 cur_arg += 1 + kw->skip;
625 continue;
626 }
627
628 err = NULL;
629 if (!bind_dumped) {
630 bind_dump_kws(&err);
631 indent_msg(&err, 4);
632 bind_dumped = 1;
633 }
634
635 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
636 file, linenum, args[0], args[1], args[cur_arg],
637 err ? " Registered keywords :" : "", err ? err : "");
638 free(err);
639
640 err_code |= ERR_ALERT | ERR_FATAL;
641 goto out;
642 }
643 goto out;
644 }
645 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
646 if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) {
647 ha_alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
648 file, linenum, args[0]);
649 err_code |= ERR_ALERT | ERR_FATAL;
650 goto out;
651 }
652 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
653 err_code |= ERR_WARN;
654
655 /* flush useless bits */
656 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
657 goto out;
658 }
659 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
660 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
661 err_code |= ERR_WARN;
662
663 if (alertif_too_many_args(1, file, linenum, args, &err_code))
664 goto out;
665
666 if (!*args[1]) {
667 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
668 file, linenum, args[0]);
669 err_code |= ERR_ALERT | ERR_FATAL;
670 goto out;
671 }
672
673 free(curproxy->monitor_uri);
674 curproxy->monitor_uri_len = strlen(args[1]);
675 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
676 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
677 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
678
679 goto out;
680 }
681 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
682 if (alertif_too_many_args(1, file, linenum, args, &err_code))
683 goto out;
684
685 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
686 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
687 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
688 else {
689 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
690 err_code |= ERR_ALERT | ERR_FATAL;
691 goto out;
692 }
693 }
694 else if (!strcmp(args[0], "id")) {
695 struct eb32_node *node;
696
697 if (curproxy == &defproxy) {
698 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
699 file, linenum, args[0]);
700 err_code |= ERR_ALERT | ERR_FATAL;
701 goto out;
702 }
703
704 if (alertif_too_many_args(1, file, linenum, args, &err_code))
705 goto out;
706
707 if (!*args[1]) {
708 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
709 file, linenum, args[0]);
710 err_code |= ERR_ALERT | ERR_FATAL;
711 goto out;
712 }
713
714 curproxy->uuid = atol(args[1]);
715 curproxy->conf.id.key = curproxy->uuid;
716 curproxy->options |= PR_O_FORCED_ID;
717
718 if (curproxy->uuid <= 0) {
719 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
720 file, linenum);
721 err_code |= ERR_ALERT | ERR_FATAL;
722 goto out;
723 }
724
725 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
726 if (node) {
727 struct proxy *target = container_of(node, struct proxy, conf.id);
728 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
729 file, linenum, proxy_type_str(curproxy), curproxy->id,
730 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
731 err_code |= ERR_ALERT | ERR_FATAL;
732 goto out;
733 }
734 eb32_insert(&used_proxy_id, &curproxy->conf.id);
735 }
736 else if (!strcmp(args[0], "description")) {
737 int i, len=0;
738 char *d;
739
740 if (curproxy == &defproxy) {
741 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
742 file, linenum, args[0]);
743 err_code |= ERR_ALERT | ERR_FATAL;
744 goto out;
745 }
746
747 if (!*args[1]) {
748 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
749 file, linenum, args[0]);
750 return -1;
751 }
752
753 for (i = 1; *args[i]; i++)
754 len += strlen(args[i]) + 1;
755
756 d = calloc(1, len);
757 curproxy->desc = d;
758
759 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
760 for (i = 2; *args[i]; i++)
761 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
762
763 }
764 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
765 if (alertif_too_many_args(0, file, linenum, args, &err_code))
766 goto out;
767 curproxy->state = PR_STSTOPPED;
768 }
769 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
770 if (alertif_too_many_args(0, file, linenum, args, &err_code))
771 goto out;
772 curproxy->state = PR_STNEW;
773 }
774 else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */
775 int cur_arg = 1;
776 unsigned long set = 0;
777
778 while (*args[cur_arg]) {
779 if (strcmp(args[cur_arg], "all") == 0) {
780 set = 0;
781 break;
782 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100783 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100784 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
785 err_code |= ERR_ALERT | ERR_FATAL;
786 goto out;
787 }
788 cur_arg++;
789 }
790 curproxy->bind_proc = set;
791 }
792 else if (!strcmp(args[0], "acl")) { /* add an ACL */
793 if (curproxy == &defproxy) {
794 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
795 err_code |= ERR_ALERT | ERR_FATAL;
796 goto out;
797 }
798
799 err = invalid_char(args[1]);
800 if (err) {
801 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
802 file, linenum, *err, args[1]);
803 err_code |= ERR_ALERT | ERR_FATAL;
804 goto out;
805 }
806
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100807 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100808 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100809 "logical disjunction within a condition.\n",
810 file, linenum, args[1]);
811 err_code |= ERR_ALERT | ERR_FATAL;
812 goto out;
813 }
814
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100815 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
816 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
817 file, linenum, args[1], errmsg);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821 }
822 else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */
823
824 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
825 err_code |= ERR_WARN;
826
827 if (*(args[1]) == 0) {
828 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
829 file, linenum, args[0]);
830 err_code |= ERR_ALERT | ERR_FATAL;
831 goto out;
832 }
833 free(curproxy->dyncookie_key);
834 curproxy->dyncookie_key = strdup(args[1]);
835 }
836 else if (!strcmp(args[0], "cookie")) { /* cookie name */
837 int cur_arg;
838
839 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
840 err_code |= ERR_WARN;
841
842 if (*(args[1]) == 0) {
843 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
844 file, linenum, args[0]);
845 err_code |= ERR_ALERT | ERR_FATAL;
846 goto out;
847 }
848
849 curproxy->ck_opts = 0;
850 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
851 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
852 free(curproxy->cookie_name);
853 curproxy->cookie_name = strdup(args[1]);
854 curproxy->cookie_len = strlen(curproxy->cookie_name);
855
856 cur_arg = 2;
857 while (*(args[cur_arg])) {
858 if (!strcmp(args[cur_arg], "rewrite")) {
859 curproxy->ck_opts |= PR_CK_RW;
860 }
861 else if (!strcmp(args[cur_arg], "indirect")) {
862 curproxy->ck_opts |= PR_CK_IND;
863 }
864 else if (!strcmp(args[cur_arg], "insert")) {
865 curproxy->ck_opts |= PR_CK_INS;
866 }
867 else if (!strcmp(args[cur_arg], "nocache")) {
868 curproxy->ck_opts |= PR_CK_NOC;
869 }
870 else if (!strcmp(args[cur_arg], "postonly")) {
871 curproxy->ck_opts |= PR_CK_POST;
872 }
873 else if (!strcmp(args[cur_arg], "preserve")) {
874 curproxy->ck_opts |= PR_CK_PSV;
875 }
876 else if (!strcmp(args[cur_arg], "prefix")) {
877 curproxy->ck_opts |= PR_CK_PFX;
878 }
879 else if (!strcmp(args[cur_arg], "httponly")) {
880 curproxy->ck_opts |= PR_CK_HTTPONLY;
881 }
882 else if (!strcmp(args[cur_arg], "secure")) {
883 curproxy->ck_opts |= PR_CK_SECURE;
884 }
885 else if (!strcmp(args[cur_arg], "domain")) {
886 if (!*args[cur_arg + 1]) {
887 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
888 file, linenum, args[cur_arg]);
889 err_code |= ERR_ALERT | ERR_FATAL;
890 goto out;
891 }
892
Joao Moraise1583752019-10-30 21:04:00 -0300893 if (!strchr(args[cur_arg + 1], '.')) {
894 /* rfc6265, 5.2.3 The Domain Attribute */
895 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
896 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100897 file, linenum, args[cur_arg + 1]);
898 err_code |= ERR_WARN;
899 }
900
901 err = invalid_domainchar(args[cur_arg + 1]);
902 if (err) {
903 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
904 file, linenum, *err, args[cur_arg + 1]);
905 err_code |= ERR_ALERT | ERR_FATAL;
906 goto out;
907 }
908
909 if (!curproxy->cookie_domain) {
910 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
911 } else {
912 /* one domain was already specified, add another one by
913 * building the string which will be returned along with
914 * the cookie.
915 */
916 char *new_ptr;
917 int new_len = strlen(curproxy->cookie_domain) +
918 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
919 new_ptr = malloc(new_len);
920 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
921 free(curproxy->cookie_domain);
922 curproxy->cookie_domain = new_ptr;
923 }
924 cur_arg++;
925 }
926 else if (!strcmp(args[cur_arg], "maxidle")) {
927 unsigned int maxidle;
928 const char *res;
929
930 if (!*args[cur_arg + 1]) {
931 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
932 file, linenum, args[cur_arg]);
933 err_code |= ERR_ALERT | ERR_FATAL;
934 goto out;
935 }
936
937 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200938 if (res == PARSE_TIME_OVER) {
939 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
940 file, linenum, args[cur_arg+1], args[cur_arg]);
941 err_code |= ERR_ALERT | ERR_FATAL;
942 goto out;
943 }
944 else if (res == PARSE_TIME_UNDER) {
945 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
946 file, linenum, args[cur_arg+1], args[cur_arg]);
947 err_code |= ERR_ALERT | ERR_FATAL;
948 goto out;
949 }
950 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100951 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
952 file, linenum, *res, args[cur_arg]);
953 err_code |= ERR_ALERT | ERR_FATAL;
954 goto out;
955 }
956 curproxy->cookie_maxidle = maxidle;
957 cur_arg++;
958 }
959 else if (!strcmp(args[cur_arg], "maxlife")) {
960 unsigned int maxlife;
961 const char *res;
962
963 if (!*args[cur_arg + 1]) {
964 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
965 file, linenum, args[cur_arg]);
966 err_code |= ERR_ALERT | ERR_FATAL;
967 goto out;
968 }
969
Willy Tarreau9faebe32019-06-07 19:00:37 +0200970
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100971 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200972 if (res == PARSE_TIME_OVER) {
973 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
974 file, linenum, args[cur_arg+1], args[cur_arg]);
975 err_code |= ERR_ALERT | ERR_FATAL;
976 goto out;
977 }
978 else if (res == PARSE_TIME_UNDER) {
979 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
980 file, linenum, args[cur_arg+1], args[cur_arg]);
981 err_code |= ERR_ALERT | ERR_FATAL;
982 goto out;
983 }
984 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100985 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
986 file, linenum, *res, args[cur_arg]);
987 err_code |= ERR_ALERT | ERR_FATAL;
988 goto out;
989 }
990 curproxy->cookie_maxlife = maxlife;
991 cur_arg++;
992 }
993 else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */
994
995 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
996 err_code |= ERR_WARN;
997 curproxy->ck_opts |= PR_CK_DYNAMIC;
998 }
Christopher Faulet2f533902020-01-21 11:06:48 +0100999 else if (!strcmp(args[cur_arg], "attr")) {
1000 char *val;
1001 if (!*args[cur_arg + 1]) {
1002 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
1003 file, linenum, args[cur_arg]);
1004 err_code |= ERR_ALERT | ERR_FATAL;
1005 goto out;
1006 }
1007 val = args[cur_arg + 1];
1008 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +01001009 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +01001010 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
1011 file, linenum, *val);
1012 err_code |= ERR_ALERT | ERR_FATAL;
1013 goto out;
1014 }
1015 val++;
1016 }
1017 /* don't add ';' for the first attribute */
1018 if (!curproxy->cookie_attrs)
1019 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
1020 else
1021 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
1022 cur_arg++;
1023 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001024
1025 else {
Christopher Faulet2f533902020-01-21 11:06:48 +01001026 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 +01001027 file, linenum, args[0]);
1028 err_code |= ERR_ALERT | ERR_FATAL;
1029 goto out;
1030 }
1031 cur_arg++;
1032 }
1033 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
1034 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
1035 file, linenum);
1036 err_code |= ERR_ALERT | ERR_FATAL;
1037 }
1038
1039 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
1040 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
1041 file, linenum);
1042 err_code |= ERR_ALERT | ERR_FATAL;
1043 }
1044
1045 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
1046 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
1047 file, linenum);
1048 err_code |= ERR_ALERT | ERR_FATAL;
1049 }
1050 }/* end else if (!strcmp(args[0], "cookie")) */
1051 else if (!strcmp(args[0], "email-alert")) {
1052 if (*(args[1]) == 0) {
1053 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1054 file, linenum, args[0]);
1055 err_code |= ERR_ALERT | ERR_FATAL;
1056 goto out;
1057 }
1058
1059 if (!strcmp(args[1], "from")) {
1060 if (*(args[1]) == 0) {
1061 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1062 file, linenum, args[1]);
1063 err_code |= ERR_ALERT | ERR_FATAL;
1064 goto out;
1065 }
1066 free(curproxy->email_alert.from);
1067 curproxy->email_alert.from = strdup(args[2]);
1068 }
1069 else if (!strcmp(args[1], "mailers")) {
1070 if (*(args[1]) == 0) {
1071 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1072 file, linenum, args[1]);
1073 err_code |= ERR_ALERT | ERR_FATAL;
1074 goto out;
1075 }
1076 free(curproxy->email_alert.mailers.name);
1077 curproxy->email_alert.mailers.name = strdup(args[2]);
1078 }
1079 else if (!strcmp(args[1], "myhostname")) {
1080 if (*(args[1]) == 0) {
1081 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1082 file, linenum, args[1]);
1083 err_code |= ERR_ALERT | ERR_FATAL;
1084 goto out;
1085 }
1086 free(curproxy->email_alert.myhostname);
1087 curproxy->email_alert.myhostname = strdup(args[2]);
1088 }
1089 else if (!strcmp(args[1], "level")) {
1090 curproxy->email_alert.level = get_log_level(args[2]);
1091 if (curproxy->email_alert.level < 0) {
1092 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1093 file, linenum, args[1], args[2]);
1094 err_code |= ERR_ALERT | ERR_FATAL;
1095 goto out;
1096 }
1097 }
1098 else if (!strcmp(args[1], "to")) {
1099 if (*(args[1]) == 0) {
1100 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1101 file, linenum, args[1]);
1102 err_code |= ERR_ALERT | ERR_FATAL;
1103 goto out;
1104 }
1105 free(curproxy->email_alert.to);
1106 curproxy->email_alert.to = strdup(args[2]);
1107 }
1108 else {
1109 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1110 file, linenum, args[1]);
1111 err_code |= ERR_ALERT | ERR_FATAL;
1112 goto out;
1113 }
1114 /* Indicate that the email_alert is at least partially configured */
1115 curproxy->email_alert.set = 1;
1116 }/* end else if (!strcmp(args[0], "email-alert")) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001117 else if (!strcmp(args[0], "persist")) { /* persist */
1118 if (*(args[1]) == 0) {
1119 ha_alert("parsing [%s:%d] : missing persist method.\n",
1120 file, linenum);
1121 err_code |= ERR_ALERT | ERR_FATAL;
1122 goto out;
1123 }
1124
1125 if (!strncmp(args[1], "rdp-cookie", 10)) {
1126 curproxy->options2 |= PR_O2_RDPC_PRST;
1127
1128 if (*(args[1] + 10) == '(') { /* cookie name */
1129 const char *beg, *end;
1130
1131 beg = args[1] + 11;
1132 end = strchr(beg, ')');
1133
1134 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1135 goto out;
1136
1137 if (!end || end == beg) {
1138 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1139 file, linenum);
1140 err_code |= ERR_ALERT | ERR_FATAL;
1141 goto out;
1142 }
1143
1144 free(curproxy->rdp_cookie_name);
1145 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
1146 curproxy->rdp_cookie_len = end-beg;
1147 }
1148 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1149 free(curproxy->rdp_cookie_name);
1150 curproxy->rdp_cookie_name = strdup("msts");
1151 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1152 }
1153 else { /* syntax */
1154 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1155 file, linenum);
1156 err_code |= ERR_ALERT | ERR_FATAL;
1157 goto out;
1158 }
1159 }
1160 else {
1161 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1162 file, linenum);
1163 err_code |= ERR_ALERT | ERR_FATAL;
1164 goto out;
1165 }
1166 }
1167 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001168 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 +01001169 err_code |= ERR_ALERT | ERR_FATAL;
1170 goto out;
1171 }
1172 else if (!strcmp(args[0], "load-server-state-from-file")) {
1173 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1174 err_code |= ERR_WARN;
1175 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
1176 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1177 }
1178 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
1179 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1180 }
1181 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
1182 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1183 }
1184 else {
1185 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1186 file, linenum, args[0], args[1]);
1187 err_code |= ERR_ALERT | ERR_FATAL;
1188 goto out;
1189 }
1190 }
1191 else if (!strcmp(args[0], "server-state-file-name")) {
1192 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1193 err_code |= ERR_WARN;
1194 if (*(args[1]) == 0) {
1195 ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
1196 file, linenum, args[0]);
1197 err_code |= ERR_ALERT | ERR_FATAL;
1198 goto out;
1199 }
1200 else if (!strcmp(args[1], "use-backend-name"))
1201 curproxy->server_state_file_name = strdup(curproxy->id);
1202 else
1203 curproxy->server_state_file_name = strdup(args[1]);
1204 }
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001205 else if (!strcmp(args[0], "max-session-srv-conns")) {
1206 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1207 err_code |= ERR_WARN;
1208 if (*(args[1]) == 0) {
1209 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1210 file, linenum, args[0]);
1211 err_code |= ERR_ALERT | ERR_FATAL;
1212 goto out;
1213 }
1214 curproxy->max_out_conns = atoi(args[1]);
1215 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001216 else if (!strcmp(args[0], "capture")) {
1217 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1218 err_code |= ERR_WARN;
1219
1220 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
1221 if (curproxy == &defproxy) {
1222 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1223 err_code |= ERR_ALERT | ERR_FATAL;
1224 goto out;
1225 }
1226
1227 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1228 goto out;
1229
1230 if (*(args[4]) == 0) {
1231 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1232 file, linenum, args[0]);
1233 err_code |= ERR_ALERT | ERR_FATAL;
1234 goto out;
1235 }
1236 free(curproxy->capture_name);
1237 curproxy->capture_name = strdup(args[2]);
1238 curproxy->capture_namelen = strlen(curproxy->capture_name);
1239 curproxy->capture_len = atol(args[4]);
1240 curproxy->to_log |= LW_COOKIE;
1241 }
1242 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
1243 struct cap_hdr *hdr;
1244
1245 if (curproxy == &defproxy) {
1246 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1247 err_code |= ERR_ALERT | ERR_FATAL;
1248 goto out;
1249 }
1250
1251 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1252 goto out;
1253
1254 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1255 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1256 file, linenum, args[0], args[1]);
1257 err_code |= ERR_ALERT | ERR_FATAL;
1258 goto out;
1259 }
1260
1261 hdr = calloc(1, sizeof(*hdr));
1262 hdr->next = curproxy->req_cap;
1263 hdr->name = strdup(args[3]);
1264 hdr->namelen = strlen(args[3]);
1265 hdr->len = atol(args[5]);
1266 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1267 hdr->index = curproxy->nb_req_cap++;
1268 curproxy->req_cap = hdr;
1269 curproxy->to_log |= LW_REQHDR;
1270 }
1271 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
1272 struct cap_hdr *hdr;
1273
1274 if (curproxy == &defproxy) {
1275 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1276 err_code |= ERR_ALERT | ERR_FATAL;
1277 goto out;
1278 }
1279
1280 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1281 goto out;
1282
1283 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1284 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1285 file, linenum, args[0], args[1]);
1286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
1289 hdr = calloc(1, sizeof(*hdr));
1290 hdr->next = curproxy->rsp_cap;
1291 hdr->name = strdup(args[3]);
1292 hdr->namelen = strlen(args[3]);
1293 hdr->len = atol(args[5]);
1294 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1295 hdr->index = curproxy->nb_rsp_cap++;
1296 curproxy->rsp_cap = hdr;
1297 curproxy->to_log |= LW_RSPHDR;
1298 }
1299 else {
1300 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1301 file, linenum, args[0]);
1302 err_code |= ERR_ALERT | ERR_FATAL;
1303 goto out;
1304 }
1305 }
1306 else if (!strcmp(args[0], "retries")) { /* connection retries */
1307 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1308 err_code |= ERR_WARN;
1309
1310 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1311 goto out;
1312
1313 if (*(args[1]) == 0) {
1314 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1315 file, linenum, args[0]);
1316 err_code |= ERR_ALERT | ERR_FATAL;
1317 goto out;
1318 }
1319 curproxy->conn_retries = atol(args[1]);
1320 }
1321 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
1322 struct act_rule *rule;
1323
1324 if (curproxy == &defproxy) {
1325 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1326 err_code |= ERR_ALERT | ERR_FATAL;
1327 goto out;
1328 }
1329
1330 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1331 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001332 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001333 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1334 file, linenum, args[0]);
1335 err_code |= ERR_WARN;
1336 }
1337
1338 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1339
1340 if (!rule) {
1341 err_code |= ERR_ALERT | ERR_ABORT;
1342 goto out;
1343 }
1344
1345 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1346 err_code |= warnif_cond_conflicts(rule->cond,
1347 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1348 file, linenum);
1349
1350 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1351 }
1352 else if (!strcmp(args[0], "http-response")) { /* response access control */
1353 struct act_rule *rule;
1354
1355 if (curproxy == &defproxy) {
1356 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1357 err_code |= ERR_ALERT | ERR_FATAL;
1358 goto out;
1359 }
1360
1361 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1362 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001363 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001364 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1365 file, linenum, args[0]);
1366 err_code |= ERR_WARN;
1367 }
1368
1369 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1370
1371 if (!rule) {
1372 err_code |= ERR_ALERT | ERR_ABORT;
1373 goto out;
1374 }
1375
1376 err_code |= warnif_cond_conflicts(rule->cond,
1377 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1378 file, linenum);
1379
1380 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1381 }
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001382 else if (!strcmp(args[0], "http-after-response")) {
1383 struct act_rule *rule;
1384
1385 if (curproxy == &defproxy) {
1386 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1387 err_code |= ERR_ALERT | ERR_FATAL;
1388 goto out;
1389 }
1390
1391 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1392 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1393 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1394 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1395 file, linenum, args[0]);
1396 err_code |= ERR_WARN;
1397 }
1398
1399 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1400
1401 if (!rule) {
1402 err_code |= ERR_ALERT | ERR_ABORT;
1403 goto out;
1404 }
1405
1406 err_code |= warnif_cond_conflicts(rule->cond,
1407 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1408 file, linenum);
1409
1410 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1411 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001412 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
1413 /* set the header name and length into the proxy structure */
1414 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1415 err_code |= ERR_WARN;
1416
1417 if (!*args[1]) {
1418 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1419 file, linenum, args[0]);
1420 err_code |= ERR_ALERT | ERR_FATAL;
1421 goto out;
1422 }
1423
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001424 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001425 free(curproxy->server_id_hdr_name);
1426 curproxy->server_id_hdr_name = strdup(args[1]);
1427 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001428 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 +01001429 }
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001430 else if (!strcmp(args[0], "block")) {
1431 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 +01001432
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001433 err_code |= ERR_ALERT | ERR_FATAL;
1434 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001435 }
1436 else if (!strcmp(args[0], "redirect")) {
1437 struct redirect_rule *rule;
1438
1439 if (curproxy == &defproxy) {
1440 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1441 err_code |= ERR_ALERT | ERR_FATAL;
1442 goto out;
1443 }
1444
1445 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1446 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1447 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1448 err_code |= ERR_ALERT | ERR_FATAL;
1449 goto out;
1450 }
1451
1452 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1453 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1454 err_code |= warnif_cond_conflicts(rule->cond,
1455 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1456 file, linenum);
1457 }
1458 else if (!strcmp(args[0], "use_backend")) {
1459 struct switching_rule *rule;
1460
1461 if (curproxy == &defproxy) {
1462 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1463 err_code |= ERR_ALERT | ERR_FATAL;
1464 goto out;
1465 }
1466
1467 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1468 err_code |= ERR_WARN;
1469
1470 if (*(args[1]) == 0) {
1471 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1472 err_code |= ERR_ALERT | ERR_FATAL;
1473 goto out;
1474 }
1475
1476 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1477 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1478 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1479 file, linenum, errmsg);
1480 err_code |= ERR_ALERT | ERR_FATAL;
1481 goto out;
1482 }
1483
1484 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1485 }
1486 else if (*args[2]) {
1487 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1488 file, linenum, args[2]);
1489 err_code |= ERR_ALERT | ERR_FATAL;
1490 goto out;
1491 }
1492
1493 rule = calloc(1, sizeof(*rule));
1494 if (!rule) {
1495 ha_alert("Out of memory error.\n");
1496 goto out;
1497 }
1498 rule->cond = cond;
1499 rule->be.name = strdup(args[1]);
1500 rule->line = linenum;
1501 rule->file = strdup(file);
1502 if (!rule->file) {
1503 ha_alert("Out of memory error.\n");
1504 goto out;
1505 }
1506 LIST_INIT(&rule->list);
1507 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1508 }
1509 else if (strcmp(args[0], "use-server") == 0) {
1510 struct server_rule *rule;
1511
1512 if (curproxy == &defproxy) {
1513 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1514 err_code |= ERR_ALERT | ERR_FATAL;
1515 goto out;
1516 }
1517
1518 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1519 err_code |= ERR_WARN;
1520
1521 if (*(args[1]) == 0) {
1522 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1523 err_code |= ERR_ALERT | ERR_FATAL;
1524 goto out;
1525 }
1526
1527 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1528 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1529 file, linenum, args[0]);
1530 err_code |= ERR_ALERT | ERR_FATAL;
1531 goto out;
1532 }
1533
1534 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1535 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1536 file, linenum, errmsg);
1537 err_code |= ERR_ALERT | ERR_FATAL;
1538 goto out;
1539 }
1540
1541 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1542
1543 rule = calloc(1, sizeof(*rule));
1544 rule->cond = cond;
1545 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001546 rule->line = linenum;
1547 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001548 LIST_INIT(&rule->list);
1549 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1550 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1551 }
1552 else if ((!strcmp(args[0], "force-persist")) ||
1553 (!strcmp(args[0], "ignore-persist"))) {
1554 struct persist_rule *rule;
1555
1556 if (curproxy == &defproxy) {
1557 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1558 err_code |= ERR_ALERT | ERR_FATAL;
1559 goto out;
1560 }
1561
1562 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1563 err_code |= ERR_WARN;
1564
1565 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1566 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1567 file, linenum, args[0]);
1568 err_code |= ERR_ALERT | ERR_FATAL;
1569 goto out;
1570 }
1571
1572 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1573 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1574 file, linenum, args[0], errmsg);
1575 err_code |= ERR_ALERT | ERR_FATAL;
1576 goto out;
1577 }
1578
1579 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1580 * where force-persist is applied.
1581 */
1582 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1583
1584 rule = calloc(1, sizeof(*rule));
1585 rule->cond = cond;
1586 if (!strcmp(args[0], "force-persist")) {
1587 rule->type = PERSIST_TYPE_FORCE;
1588 } else {
1589 rule->type = PERSIST_TYPE_IGNORE;
1590 }
1591 LIST_INIT(&rule->list);
1592 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1593 }
1594 else if (!strcmp(args[0], "stick-table")) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001595 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001596
1597 if (curproxy == &defproxy) {
1598 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1599 file, linenum);
1600 err_code |= ERR_ALERT | ERR_FATAL;
1601 goto out;
1602 }
1603
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001604 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001605 if (other) {
1606 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 +01001607 file, linenum, curproxy->id,
1608 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1609 other->proxy ? other->id : other->peers.p->id,
1610 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001611 err_code |= ERR_ALERT | ERR_FATAL;
1612 goto out;
1613 }
1614
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001615 curproxy->table = calloc(1, sizeof *curproxy->table);
1616 if (!curproxy->table) {
1617 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1618 file, linenum, args[0], args[1]);
1619 err_code |= ERR_ALERT | ERR_FATAL;
1620 goto out;
1621 }
1622
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001623 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1624 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001625 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001626 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001627
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001628 /* Store the proxy in the stick-table. */
1629 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001630
1631 stktable_store_name(curproxy->table);
1632 curproxy->table->next = stktables_list;
1633 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001634
1635 /* Add this proxy to the list of proxies which refer to its stick-table. */
1636 if (curproxy->table->proxies_list != curproxy) {
1637 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1638 curproxy->table->proxies_list = curproxy;
1639 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001640 }
1641 else if (!strcmp(args[0], "stick")) {
1642 struct sticking_rule *rule;
1643 struct sample_expr *expr;
1644 int myidx = 0;
1645 const char *name = NULL;
1646 int flags;
1647
1648 if (curproxy == &defproxy) {
1649 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1650 err_code |= ERR_ALERT | ERR_FATAL;
1651 goto out;
1652 }
1653
1654 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1655 err_code |= ERR_WARN;
1656 goto out;
1657 }
1658
1659 myidx++;
1660 if ((strcmp(args[myidx], "store") == 0) ||
1661 (strcmp(args[myidx], "store-request") == 0)) {
1662 myidx++;
1663 flags = STK_IS_STORE;
1664 }
1665 else if (strcmp(args[myidx], "store-response") == 0) {
1666 myidx++;
1667 flags = STK_IS_STORE | STK_ON_RSP;
1668 }
1669 else if (strcmp(args[myidx], "match") == 0) {
1670 myidx++;
1671 flags = STK_IS_MATCH;
1672 }
1673 else if (strcmp(args[myidx], "on") == 0) {
1674 myidx++;
1675 flags = STK_IS_MATCH | STK_IS_STORE;
1676 }
1677 else {
1678 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1679 err_code |= ERR_ALERT | ERR_FATAL;
1680 goto out;
1681 }
1682
1683 if (*(args[myidx]) == 0) {
1684 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1685 err_code |= ERR_ALERT | ERR_FATAL;
1686 goto out;
1687 }
1688
1689 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001690 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001691 if (!expr) {
1692 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1693 err_code |= ERR_ALERT | ERR_FATAL;
1694 goto out;
1695 }
1696
1697 if (flags & STK_ON_RSP) {
1698 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1699 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1700 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1701 err_code |= ERR_ALERT | ERR_FATAL;
1702 free(expr);
1703 goto out;
1704 }
1705 } else {
1706 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1707 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1708 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1709 err_code |= ERR_ALERT | ERR_FATAL;
1710 free(expr);
1711 goto out;
1712 }
1713 }
1714
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001715 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001716 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1717
1718 if (strcmp(args[myidx], "table") == 0) {
1719 myidx++;
1720 name = args[myidx++];
1721 }
1722
1723 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1724 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1725 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1726 file, linenum, args[0], errmsg);
1727 err_code |= ERR_ALERT | ERR_FATAL;
1728 free(expr);
1729 goto out;
1730 }
1731 }
1732 else if (*(args[myidx])) {
1733 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1734 file, linenum, args[0], args[myidx]);
1735 err_code |= ERR_ALERT | ERR_FATAL;
1736 free(expr);
1737 goto out;
1738 }
1739 if (flags & STK_ON_RSP)
1740 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1741 else
1742 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1743
1744 rule = calloc(1, sizeof(*rule));
1745 rule->cond = cond;
1746 rule->expr = expr;
1747 rule->flags = flags;
1748 rule->table.name = name ? strdup(name) : NULL;
1749 LIST_INIT(&rule->list);
1750 if (flags & STK_ON_RSP)
1751 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1752 else
1753 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1754 }
1755 else if (!strcmp(args[0], "stats")) {
1756 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
1757 curproxy->uri_auth = NULL; /* we must detach from the default config */
1758
1759 if (!*args[1]) {
1760 goto stats_error_parsing;
1761 } else if (!strcmp(args[1], "admin")) {
1762 struct stats_admin_rule *rule;
1763
1764 if (curproxy == &defproxy) {
1765 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1766 err_code |= ERR_ALERT | ERR_FATAL;
1767 goto out;
1768 }
1769
1770 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1771 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1772 err_code |= ERR_ALERT | ERR_ABORT;
1773 goto out;
1774 }
1775
1776 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1777 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1778 file, linenum, args[0], args[1]);
1779 err_code |= ERR_ALERT | ERR_FATAL;
1780 goto out;
1781 }
1782 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1783 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1784 file, linenum, args[0], args[1], errmsg);
1785 err_code |= ERR_ALERT | ERR_FATAL;
1786 goto out;
1787 }
1788
1789 err_code |= warnif_cond_conflicts(cond,
1790 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1791 file, linenum);
1792
1793 rule = calloc(1, sizeof(*rule));
1794 rule->cond = cond;
1795 LIST_INIT(&rule->list);
1796 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
1797 } else if (!strcmp(args[1], "uri")) {
1798 if (*(args[2]) == 0) {
1799 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1800 err_code |= ERR_ALERT | ERR_FATAL;
1801 goto out;
1802 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1803 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1804 err_code |= ERR_ALERT | ERR_ABORT;
1805 goto out;
1806 }
1807 } else if (!strcmp(args[1], "realm")) {
1808 if (*(args[2]) == 0) {
1809 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1810 err_code |= ERR_ALERT | ERR_FATAL;
1811 goto out;
1812 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1813 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1814 err_code |= ERR_ALERT | ERR_ABORT;
1815 goto out;
1816 }
1817 } else if (!strcmp(args[1], "refresh")) {
1818 unsigned interval;
1819
1820 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001821 if (err == PARSE_TIME_OVER) {
1822 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1823 file, linenum, args[2]);
1824 err_code |= ERR_ALERT | ERR_FATAL;
1825 goto out;
1826 }
1827 else if (err == PARSE_TIME_UNDER) {
1828 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1829 file, linenum, args[2]);
1830 err_code |= ERR_ALERT | ERR_FATAL;
1831 goto out;
1832 }
1833 else if (err) {
1834 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001835 file, linenum, *err);
1836 err_code |= ERR_ALERT | ERR_FATAL;
1837 goto out;
1838 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1839 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1840 err_code |= ERR_ALERT | ERR_ABORT;
1841 goto out;
1842 }
1843 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
1844 struct act_rule *rule;
1845
1846 if (curproxy == &defproxy) {
1847 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1848 err_code |= ERR_ALERT | ERR_FATAL;
1849 goto out;
1850 }
1851
1852 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1853 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1854 err_code |= ERR_ALERT | ERR_ABORT;
1855 goto out;
1856 }
1857
1858 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1859 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1860 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1861 file, linenum, args[0]);
1862 err_code |= ERR_WARN;
1863 }
1864
1865 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1866
1867 if (!rule) {
1868 err_code |= ERR_ALERT | ERR_ABORT;
1869 goto out;
1870 }
1871
1872 err_code |= warnif_cond_conflicts(rule->cond,
1873 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1874 file, linenum);
1875 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1876
1877 } else if (!strcmp(args[1], "auth")) {
1878 if (*(args[2]) == 0) {
1879 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1880 err_code |= ERR_ALERT | ERR_FATAL;
1881 goto out;
1882 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1883 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1884 err_code |= ERR_ALERT | ERR_ABORT;
1885 goto out;
1886 }
1887 } else if (!strcmp(args[1], "scope")) {
1888 if (*(args[2]) == 0) {
1889 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1890 err_code |= ERR_ALERT | ERR_FATAL;
1891 goto out;
1892 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1893 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1894 err_code |= ERR_ALERT | ERR_ABORT;
1895 goto out;
1896 }
1897 } else if (!strcmp(args[1], "enable")) {
1898 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1899 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1900 err_code |= ERR_ALERT | ERR_ABORT;
1901 goto out;
1902 }
1903 } else if (!strcmp(args[1], "hide-version")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001904 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001905 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1906 err_code |= ERR_ALERT | ERR_ABORT;
1907 goto out;
1908 }
1909 } else if (!strcmp(args[1], "show-legends")) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001910 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001911 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1912 err_code |= ERR_ALERT | ERR_ABORT;
1913 goto out;
1914 }
1915 } else if (!strcmp(args[1], "show-node")) {
1916
1917 if (*args[2]) {
1918 int i;
1919 char c;
1920
1921 for (i=0; args[2][i]; i++) {
1922 c = args[2][i];
1923 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1924 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1925 break;
1926 }
1927
1928 if (!i || args[2][i]) {
1929 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1930 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1931 file, linenum, args[0], args[1]);
1932 err_code |= ERR_ALERT | ERR_FATAL;
1933 goto out;
1934 }
1935 }
1936
1937 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1938 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1939 err_code |= ERR_ALERT | ERR_ABORT;
1940 goto out;
1941 }
1942 } else if (!strcmp(args[1], "show-desc")) {
1943 char *desc = NULL;
1944
1945 if (*args[2]) {
1946 int i, len=0;
1947 char *d;
1948
1949 for (i = 2; *args[i]; i++)
1950 len += strlen(args[i]) + 1;
1951
1952 desc = d = calloc(1, len);
1953
1954 d += snprintf(d, desc + len - d, "%s", args[2]);
1955 for (i = 3; *args[i]; i++)
1956 d += snprintf(d, desc + len - d, " %s", args[i]);
1957 }
1958
1959 if (!*args[2] && !global.desc)
1960 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1961 file, linenum, args[1]);
1962 else {
1963 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1964 free(desc);
1965 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1966 err_code |= ERR_ALERT | ERR_ABORT;
1967 goto out;
1968 }
1969 free(desc);
1970 }
1971 } else {
1972stats_error_parsing:
1973 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1974 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1975 err_code |= ERR_ALERT | ERR_FATAL;
1976 goto out;
1977 }
1978 }
1979 else if (!strcmp(args[0], "option")) {
1980 int optnum;
1981
1982 if (*(args[1]) == '\0') {
1983 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1984 file, linenum, args[0]);
1985 err_code |= ERR_ALERT | ERR_FATAL;
1986 goto out;
1987 }
1988
1989 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
1990 if (!strcmp(args[1], cfg_opts[optnum].name)) {
1991 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1992 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1993 file, linenum, cfg_opts[optnum].name);
1994 err_code |= ERR_ALERT | ERR_FATAL;
1995 goto out;
1996 }
1997 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1998 goto out;
1999
2000 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
2001 err_code |= ERR_WARN;
2002 goto out;
2003 }
2004
2005 curproxy->no_options &= ~cfg_opts[optnum].val;
2006 curproxy->options &= ~cfg_opts[optnum].val;
2007
2008 switch (kwm) {
2009 case KWM_STD:
2010 curproxy->options |= cfg_opts[optnum].val;
2011 break;
2012 case KWM_NO:
2013 curproxy->no_options |= cfg_opts[optnum].val;
2014 break;
2015 case KWM_DEF: /* already cleared */
2016 break;
2017 }
2018
2019 goto out;
2020 }
2021 }
2022
2023 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
2024 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
2025 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2026 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2027 file, linenum, cfg_opts2[optnum].name);
2028 err_code |= ERR_ALERT | ERR_FATAL;
2029 goto out;
2030 }
2031 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2032 goto out;
2033 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2034 err_code |= ERR_WARN;
2035 goto out;
2036 }
2037
Christopher Faulet31930372019-07-15 10:16:58 +02002038 /* "[no] option http-use-htx" is deprecated */
2039 if (!strcmp(cfg_opts2[optnum].name, "http-use-htx")) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02002040 if (kwm ==KWM_NO) {
2041 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
2042 " The HTX mode is now the only supported mode.\n",
2043 file, linenum, cfg_opts2[optnum].name);
2044 err_code |= ERR_WARN;
2045 }
Christopher Faulet31930372019-07-15 10:16:58 +02002046 goto out;
2047 }
2048
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002049 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2050 curproxy->options2 &= ~cfg_opts2[optnum].val;
2051
2052 switch (kwm) {
2053 case KWM_STD:
2054 curproxy->options2 |= cfg_opts2[optnum].val;
2055 break;
2056 case KWM_NO:
2057 curproxy->no_options2 |= cfg_opts2[optnum].val;
2058 break;
2059 case KWM_DEF: /* already cleared */
2060 break;
2061 }
2062 goto out;
2063 }
2064 }
2065
2066 /* HTTP options override each other. They can be cancelled using
2067 * "no option xxx" which only switches to default mode if the mode
2068 * was this one (useful for cancelling options set in defaults
2069 * sections).
2070 */
2071 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02002072 if (strcmp(args[1], "forceclose") == 0) {
2073 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
2074 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
2075 file, linenum, args[1]);
2076 err_code |= ERR_WARN;
2077 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002078 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2079 goto out;
2080 if (kwm == KWM_STD) {
2081 curproxy->options &= ~PR_O_HTTP_MODE;
2082 curproxy->options |= PR_O_HTTP_CLO;
2083 goto out;
2084 }
2085 else if (kwm == KWM_NO) {
2086 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2087 curproxy->options &= ~PR_O_HTTP_MODE;
2088 goto out;
2089 }
2090 }
2091 else if (strcmp(args[1], "http-server-close") == 0) {
2092 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2093 goto out;
2094 if (kwm == KWM_STD) {
2095 curproxy->options &= ~PR_O_HTTP_MODE;
2096 curproxy->options |= PR_O_HTTP_SCL;
2097 goto out;
2098 }
2099 else if (kwm == KWM_NO) {
2100 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2101 curproxy->options &= ~PR_O_HTTP_MODE;
2102 goto out;
2103 }
2104 }
2105 else if (strcmp(args[1], "http-keep-alive") == 0) {
2106 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2107 goto out;
2108 if (kwm == KWM_STD) {
2109 curproxy->options &= ~PR_O_HTTP_MODE;
2110 curproxy->options |= PR_O_HTTP_KAL;
2111 goto out;
2112 }
2113 else if (kwm == KWM_NO) {
2114 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2115 curproxy->options &= ~PR_O_HTTP_MODE;
2116 goto out;
2117 }
2118 }
2119 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002120 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2121 file, linenum, args[1]);
2122 err_code |= ERR_WARN;
2123 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002124 }
2125
2126 /* Redispatch can take an integer argument that control when the
2127 * resispatch occurs. All values are relative to the retries option.
2128 * This can be cancelled using "no option xxx".
2129 */
2130 if (strcmp(args[1], "redispatch") == 0) {
2131 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2132 err_code |= ERR_WARN;
2133 goto out;
2134 }
2135
2136 curproxy->no_options &= ~PR_O_REDISP;
2137 curproxy->options &= ~PR_O_REDISP;
2138
2139 switch (kwm) {
2140 case KWM_STD:
2141 curproxy->options |= PR_O_REDISP;
2142 curproxy->redispatch_after = -1;
2143 if(*args[2]) {
2144 curproxy->redispatch_after = atol(args[2]);
2145 }
2146 break;
2147 case KWM_NO:
2148 curproxy->no_options |= PR_O_REDISP;
2149 curproxy->redispatch_after = 0;
2150 break;
2151 case KWM_DEF: /* already cleared */
2152 break;
2153 }
2154 goto out;
2155 }
2156
2157 if (kwm != KWM_STD) {
2158 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2159 file, linenum, args[1]);
2160 err_code |= ERR_ALERT | ERR_FATAL;
2161 goto out;
2162 }
2163
2164 if (!strcmp(args[1], "httplog")) {
2165 char *logformat;
2166 /* generate a complete HTTP log */
2167 logformat = default_http_log_format;
2168 if (*(args[2]) != '\0') {
2169 if (!strcmp(args[2], "clf")) {
2170 curproxy->options2 |= PR_O2_CLFLOG;
2171 logformat = clf_http_log_format;
2172 } else {
2173 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2174 err_code |= ERR_ALERT | ERR_FATAL;
2175 goto out;
2176 }
2177 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2178 goto out;
2179 }
2180 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2181 char *oldlogformat = "log-format";
2182 char *clflogformat = "";
2183
2184 if (curproxy->conf.logformat_string == default_http_log_format)
2185 oldlogformat = "option httplog";
2186 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2187 oldlogformat = "option tcplog";
2188 else if (curproxy->conf.logformat_string == clf_http_log_format)
2189 oldlogformat = "option httplog clf";
2190 if (logformat == clf_http_log_format)
2191 clflogformat = " clf";
2192 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2193 file, linenum, clflogformat, oldlogformat);
2194 }
2195 if (curproxy->conf.logformat_string != default_http_log_format &&
2196 curproxy->conf.logformat_string != default_tcp_log_format &&
2197 curproxy->conf.logformat_string != clf_http_log_format)
2198 free(curproxy->conf.logformat_string);
2199 curproxy->conf.logformat_string = logformat;
2200
2201 free(curproxy->conf.lfs_file);
2202 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2203 curproxy->conf.lfs_line = curproxy->conf.args.line;
2204
2205 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2206 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2207 file, linenum, curproxy->id);
2208 err_code |= ERR_WARN;
2209 }
2210 }
2211 else if (!strcmp(args[1], "tcplog")) {
2212 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2213 char *oldlogformat = "log-format";
2214
2215 if (curproxy->conf.logformat_string == default_http_log_format)
2216 oldlogformat = "option httplog";
2217 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2218 oldlogformat = "option tcplog";
2219 else if (curproxy->conf.logformat_string == clf_http_log_format)
2220 oldlogformat = "option httplog clf";
2221 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2222 file, linenum, oldlogformat);
2223 }
2224 /* generate a detailed TCP log */
2225 if (curproxy->conf.logformat_string != default_http_log_format &&
2226 curproxy->conf.logformat_string != default_tcp_log_format &&
2227 curproxy->conf.logformat_string != clf_http_log_format)
2228 free(curproxy->conf.logformat_string);
2229 curproxy->conf.logformat_string = default_tcp_log_format;
2230
2231 free(curproxy->conf.lfs_file);
2232 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2233 curproxy->conf.lfs_line = curproxy->conf.args.line;
2234
2235 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2236 goto out;
2237
2238 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2239 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2240 file, linenum, curproxy->id);
2241 err_code |= ERR_WARN;
2242 }
2243 }
2244 else if (!strcmp(args[1], "tcpka")) {
2245 /* enable TCP keep-alives on client and server streams */
2246 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2247 err_code |= ERR_WARN;
2248
2249 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2250 goto out;
2251
2252 if (curproxy->cap & PR_CAP_FE)
2253 curproxy->options |= PR_O_TCP_CLI_KA;
2254 if (curproxy->cap & PR_CAP_BE)
2255 curproxy->options |= PR_O_TCP_SRV_KA;
2256 }
2257 else if (!strcmp(args[1], "httpchk")) {
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002258 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2259 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002260 goto out;
2261 }
2262 else if (!strcmp(args[1], "ssl-hello-chk")) {
Christopher Faulet811f78c2020-04-01 11:10:27 +02002263 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum);
2264 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002265 goto out;
2266 }
2267 else if (!strcmp(args[1], "smtpchk")) {
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002268 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2269 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002270 goto out;
2271 }
2272 else if (!strcmp(args[1], "pgsql-check")) {
Christopher Fauletce355072020-04-02 11:44:39 +02002273 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2274 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002275 goto out;
2276 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002277 else if (!strcmp(args[1], "redis-check")) {
Christopher Faulet33f05df2020-04-01 11:08:50 +02002278 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2279 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002280 goto out;
2281 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002282 else if (!strcmp(args[1], "mysql-check")) {
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002283 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2284 if (err_code & ERR_FATAL)
2285 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002286 }
2287 else if (!strcmp(args[1], "ldap-check")) {
Christopher Faulet1997eca2020-04-03 23:13:50 +02002288 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2289 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002290 goto out;
2291 }
2292 else if (!strcmp(args[1], "spop-check")) {
Christopher Faulet267b01b2020-04-04 10:27:09 +02002293 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2294 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002295 goto out;
2296 }
2297 else if (!strcmp(args[1], "tcp-check")) {
Christopher Faulet430e4802020-04-09 15:28:16 +02002298 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2299 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002300 goto out;
2301 }
2302 else if (!strcmp(args[1], "external-check")) {
Christopher Faulet6f557912020-04-09 15:58:50 +02002303 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2304 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002305 goto out;
2306 }
2307 else if (!strcmp(args[1], "forwardfor")) {
2308 int cur_arg;
2309
2310 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002311 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002312 */
2313
2314 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2315
2316 free(curproxy->fwdfor_hdr_name);
2317 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2318 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2319
2320 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2321 cur_arg = 2;
2322 while (*(args[cur_arg])) {
2323 if (!strcmp(args[cur_arg], "except")) {
2324 /* suboption except - needs additional argument for it */
2325 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2326 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2327 file, linenum, args[0], args[1], args[cur_arg]);
2328 err_code |= ERR_ALERT | ERR_FATAL;
2329 goto out;
2330 }
2331 /* flush useless bits */
2332 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2333 cur_arg += 2;
2334 } else if (!strcmp(args[cur_arg], "header")) {
2335 /* suboption header - needs additional argument for it */
2336 if (*(args[cur_arg+1]) == 0) {
2337 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2338 file, linenum, args[0], args[1], args[cur_arg]);
2339 err_code |= ERR_ALERT | ERR_FATAL;
2340 goto out;
2341 }
2342 free(curproxy->fwdfor_hdr_name);
2343 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2344 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2345 cur_arg += 2;
2346 } else if (!strcmp(args[cur_arg], "if-none")) {
2347 curproxy->options &= ~PR_O_FF_ALWAYS;
2348 cur_arg += 1;
2349 } else {
2350 /* unknown suboption - catchall */
2351 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2352 file, linenum, args[0], args[1]);
2353 err_code |= ERR_ALERT | ERR_FATAL;
2354 goto out;
2355 }
2356 } /* end while loop */
2357 }
2358 else if (!strcmp(args[1], "originalto")) {
2359 int cur_arg;
2360
2361 /* insert x-original-to field, but not for the IP address listed as an except.
2362 * set default options (ie: bitfield, header name, etc)
2363 */
2364
2365 curproxy->options |= PR_O_ORGTO;
2366
2367 free(curproxy->orgto_hdr_name);
2368 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2369 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2370
2371 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2372 cur_arg = 2;
2373 while (*(args[cur_arg])) {
2374 if (!strcmp(args[cur_arg], "except")) {
2375 /* suboption except - needs additional argument for it */
2376 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2377 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2378 file, linenum, args[0], args[1], args[cur_arg]);
2379 err_code |= ERR_ALERT | ERR_FATAL;
2380 goto out;
2381 }
2382 /* flush useless bits */
2383 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2384 cur_arg += 2;
2385 } else if (!strcmp(args[cur_arg], "header")) {
2386 /* suboption header - needs additional argument for it */
2387 if (*(args[cur_arg+1]) == 0) {
2388 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2389 file, linenum, args[0], args[1], args[cur_arg]);
2390 err_code |= ERR_ALERT | ERR_FATAL;
2391 goto out;
2392 }
2393 free(curproxy->orgto_hdr_name);
2394 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2395 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2396 cur_arg += 2;
2397 } else {
2398 /* unknown suboption - catchall */
2399 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2400 file, linenum, args[0], args[1]);
2401 err_code |= ERR_ALERT | ERR_FATAL;
2402 goto out;
2403 }
2404 } /* end while loop */
2405 }
2406 else {
2407 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2408 err_code |= ERR_ALERT | ERR_FATAL;
2409 goto out;
2410 }
2411 goto out;
2412 }
2413 else if (!strcmp(args[0], "default_backend")) {
2414 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2415 err_code |= ERR_WARN;
2416
2417 if (*(args[1]) == 0) {
2418 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2419 err_code |= ERR_ALERT | ERR_FATAL;
2420 goto out;
2421 }
2422 free(curproxy->defbe.name);
2423 curproxy->defbe.name = strdup(args[1]);
2424
2425 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2426 goto out;
2427 }
2428 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002429 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 +01002430
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002431 err_code |= ERR_ALERT | ERR_FATAL;
2432 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002433 }
2434 else if (!strcmp(args[0], "http-reuse")) {
2435 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2436 err_code |= ERR_WARN;
2437
2438 if (strcmp(args[1], "never") == 0) {
2439 /* enable a graceful server shutdown on an HTTP 404 response */
2440 curproxy->options &= ~PR_O_REUSE_MASK;
2441 curproxy->options |= PR_O_REUSE_NEVR;
2442 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2443 goto out;
2444 }
2445 else if (strcmp(args[1], "safe") == 0) {
2446 /* enable a graceful server shutdown on an HTTP 404 response */
2447 curproxy->options &= ~PR_O_REUSE_MASK;
2448 curproxy->options |= PR_O_REUSE_SAFE;
2449 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2450 goto out;
2451 }
2452 else if (strcmp(args[1], "aggressive") == 0) {
2453 curproxy->options &= ~PR_O_REUSE_MASK;
2454 curproxy->options |= PR_O_REUSE_AGGR;
2455 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2456 goto out;
2457 }
2458 else if (strcmp(args[1], "always") == 0) {
2459 /* enable a graceful server shutdown on an HTTP 404 response */
2460 curproxy->options &= ~PR_O_REUSE_MASK;
2461 curproxy->options |= PR_O_REUSE_ALWS;
2462 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2463 goto out;
2464 }
2465 else {
2466 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2467 err_code |= ERR_ALERT | ERR_FATAL;
2468 goto out;
2469 }
2470 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002471 else if (!strcmp(args[0], "monitor")) {
2472 if (curproxy == &defproxy) {
2473 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2474 err_code |= ERR_ALERT | ERR_FATAL;
2475 goto out;
2476 }
2477
2478 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2479 err_code |= ERR_WARN;
2480
2481 if (strcmp(args[1], "fail") == 0) {
2482 /* add a condition to fail monitor requests */
2483 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2484 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2485 file, linenum, args[0], args[1]);
2486 err_code |= ERR_ALERT | ERR_FATAL;
2487 goto out;
2488 }
2489
2490 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2491 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2492 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2493 file, linenum, args[0], args[1], errmsg);
2494 err_code |= ERR_ALERT | ERR_FATAL;
2495 goto out;
2496 }
2497 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2498 }
2499 else {
2500 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2501 err_code |= ERR_ALERT | ERR_FATAL;
2502 goto out;
2503 }
2504 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002505#ifdef USE_TPROXY
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002506 else if (!strcmp(args[0], "transparent")) {
2507 /* enable transparent proxy connections */
2508 curproxy->options |= PR_O_TRANSP;
2509 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2510 goto out;
2511 }
2512#endif
2513 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
2514 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2515 err_code |= ERR_WARN;
2516
2517 if (*(args[1]) == 0) {
2518 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2519 err_code |= ERR_ALERT | ERR_FATAL;
2520 goto out;
2521 }
2522 curproxy->maxconn = atol(args[1]);
2523 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2524 goto out;
2525 }
2526 else if (!strcmp(args[0], "backlog")) { /* backlog */
2527 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2528 err_code |= ERR_WARN;
2529
2530 if (*(args[1]) == 0) {
2531 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2532 err_code |= ERR_ALERT | ERR_FATAL;
2533 goto out;
2534 }
2535 curproxy->backlog = atol(args[1]);
2536 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2537 goto out;
2538 }
2539 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
2540 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2541 err_code |= ERR_WARN;
2542
2543 if (*(args[1]) == 0) {
2544 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2545 err_code |= ERR_ALERT | ERR_FATAL;
2546 goto out;
2547 }
2548 curproxy->fullconn = atol(args[1]);
2549 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2550 goto out;
2551 }
2552 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
2553 if (*(args[1]) == 0) {
2554 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2555 err_code |= ERR_ALERT | ERR_FATAL;
2556 goto out;
2557 }
2558 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002559 if (err == PARSE_TIME_OVER) {
2560 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2561 file, linenum, args[1]);
2562 err_code |= ERR_ALERT | ERR_FATAL;
2563 goto out;
2564 }
2565 else if (err == PARSE_TIME_UNDER) {
2566 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2567 file, linenum, args[1]);
2568 err_code |= ERR_ALERT | ERR_FATAL;
2569 goto out;
2570 }
2571 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002572 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2573 file, linenum, *err);
2574 err_code |= ERR_ALERT | ERR_FATAL;
2575 goto out;
2576 }
2577 curproxy->grace = val;
2578 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2579 goto out;
2580 }
2581 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
2582 struct sockaddr_storage *sk;
2583 int port1, port2;
2584 struct protocol *proto;
2585
2586 if (curproxy == &defproxy) {
2587 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2588 err_code |= ERR_ALERT | ERR_FATAL;
2589 goto out;
2590 }
2591 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2592 err_code |= ERR_WARN;
2593
2594 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2595 if (!sk) {
2596 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2597 err_code |= ERR_ALERT | ERR_FATAL;
2598 goto out;
2599 }
2600
2601 proto = protocol_by_family(sk->ss_family);
2602 if (!proto || !proto->connect) {
2603 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2604 file, linenum, args[0], args[1]);
2605 err_code |= ERR_ALERT | ERR_FATAL;
2606 goto out;
2607 }
2608
2609 if (port1 != port2) {
2610 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
2611 file, linenum, args[0], args[1]);
2612 err_code |= ERR_ALERT | ERR_FATAL;
2613 goto out;
2614 }
2615
2616 if (!port1) {
2617 ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
2618 file, linenum, args[0], args[1]);
2619 err_code |= ERR_ALERT | ERR_FATAL;
2620 goto out;
2621 }
2622
2623 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2624 goto out;
2625
2626 curproxy->dispatch_addr = *sk;
2627 curproxy->options |= PR_O_DISPATCH;
2628 }
2629 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
2630 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2631 err_code |= ERR_WARN;
2632
2633 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2634 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2635 err_code |= ERR_ALERT | ERR_FATAL;
2636 goto out;
2637 }
2638 }
2639 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
2640 /**
2641 * The syntax for hash-type config element is
2642 * hash-type {map-based|consistent} [[<algo>] avalanche]
2643 *
2644 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2645 */
2646 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2647
2648 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2649 err_code |= ERR_WARN;
2650
2651 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2652 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2653 }
2654 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2655 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2656 }
2657 else if (strcmp(args[1], "avalanche") == 0) {
2658 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]);
2659 err_code |= ERR_ALERT | ERR_FATAL;
2660 goto out;
2661 }
2662 else {
2663 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2664 err_code |= ERR_ALERT | ERR_FATAL;
2665 goto out;
2666 }
2667
2668 /* set the hash function to use */
2669 if (!*args[2]) {
2670 /* the default algo is sdbm */
2671 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2672
2673 /* if consistent with no argument, then avalanche modifier is also applied */
2674 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2675 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2676 } else {
2677 /* set the hash function */
2678 if (!strcmp(args[2], "sdbm")) {
2679 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2680 }
2681 else if (!strcmp(args[2], "djb2")) {
2682 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2683 }
2684 else if (!strcmp(args[2], "wt6")) {
2685 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2686 }
2687 else if (!strcmp(args[2], "crc32")) {
2688 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2689 }
2690 else {
2691 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2692 err_code |= ERR_ALERT | ERR_FATAL;
2693 goto out;
2694 }
2695
2696 /* set the hash modifier */
2697 if (!strcmp(args[3], "avalanche")) {
2698 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2699 }
2700 else if (*args[3]) {
2701 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2702 err_code |= ERR_ALERT | ERR_FATAL;
2703 goto out;
2704 }
2705 }
2706 }
2707 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2708 if (*(args[1]) == 0) {
2709 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2710 err_code |= ERR_ALERT | ERR_FATAL;
2711 goto out;
2712 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002713 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2714 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002715 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2716 err_code |= ERR_ALERT | ERR_FATAL;
2717 goto out;
2718 }
2719 }
2720 else if (strcmp(args[0], "unique-id-format") == 0) {
2721 if (!*(args[1])) {
2722 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2723 err_code |= ERR_ALERT | ERR_FATAL;
2724 goto out;
2725 }
2726 if (*(args[2])) {
2727 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2728 err_code |= ERR_ALERT | ERR_FATAL;
2729 goto out;
2730 }
2731 free(curproxy->conf.uniqueid_format_string);
2732 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2733
2734 free(curproxy->conf.uif_file);
2735 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2736 curproxy->conf.uif_line = curproxy->conf.args.line;
2737 }
2738
2739 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002740 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002741 if (!*(args[1])) {
2742 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2743 err_code |= ERR_ALERT | ERR_FATAL;
2744 goto out;
2745 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002746 copy = strdup(args[1]);
2747 if (copy == NULL) {
2748 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2749 err_code |= ERR_ALERT | ERR_FATAL;
2750 goto out;
2751 }
2752
2753 istfree(&curproxy->header_unique_id);
2754 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002755 }
2756
2757 else if (strcmp(args[0], "log-format") == 0) {
2758 if (!*(args[1])) {
2759 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2760 err_code |= ERR_ALERT | ERR_FATAL;
2761 goto out;
2762 }
2763 if (*(args[2])) {
2764 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2765 err_code |= ERR_ALERT | ERR_FATAL;
2766 goto out;
2767 }
2768 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2769 char *oldlogformat = "log-format";
2770
2771 if (curproxy->conf.logformat_string == default_http_log_format)
2772 oldlogformat = "option httplog";
2773 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2774 oldlogformat = "option tcplog";
2775 else if (curproxy->conf.logformat_string == clf_http_log_format)
2776 oldlogformat = "option httplog clf";
2777 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2778 file, linenum, oldlogformat);
2779 }
2780 if (curproxy->conf.logformat_string != default_http_log_format &&
2781 curproxy->conf.logformat_string != default_tcp_log_format &&
2782 curproxy->conf.logformat_string != clf_http_log_format)
2783 free(curproxy->conf.logformat_string);
2784 curproxy->conf.logformat_string = strdup(args[1]);
2785
2786 free(curproxy->conf.lfs_file);
2787 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2788 curproxy->conf.lfs_line = curproxy->conf.args.line;
2789
2790 /* get a chance to improve log-format error reporting by
2791 * reporting the correct line-number when possible.
2792 */
2793 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2794 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2795 file, linenum, curproxy->id);
2796 err_code |= ERR_WARN;
2797 }
2798 }
2799 else if (!strcmp(args[0], "log-format-sd")) {
2800 if (!*(args[1])) {
2801 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2802 err_code |= ERR_ALERT | ERR_FATAL;
2803 goto out;
2804 }
2805 if (*(args[2])) {
2806 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2807 err_code |= ERR_ALERT | ERR_FATAL;
2808 goto out;
2809 }
2810
2811 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2812 free(curproxy->conf.logformat_sd_string);
2813 curproxy->conf.logformat_sd_string = strdup(args[1]);
2814
2815 free(curproxy->conf.lfsd_file);
2816 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2817 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2818
2819 /* get a chance to improve log-format-sd error reporting by
2820 * reporting the correct line-number when possible.
2821 */
2822 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2823 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2824 file, linenum, curproxy->id);
2825 err_code |= ERR_WARN;
2826 }
2827 }
2828 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
2829 if (*(args[1]) == 0) {
2830 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2831 err_code |= ERR_ALERT | ERR_FATAL;
2832 goto out;
2833 }
2834 chunk_destroy(&curproxy->log_tag);
2835 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
2836 }
2837 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
2838 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2839 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2840 err_code |= ERR_ALERT | ERR_FATAL;
2841 goto out;
2842 }
2843 }
2844 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
2845 int cur_arg;
2846 int port1, port2;
2847 struct sockaddr_storage *sk;
2848 struct protocol *proto;
2849
2850 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2851 err_code |= ERR_WARN;
2852
2853 if (!*args[1]) {
2854 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2855 file, linenum, "source", "usesrc", "interface");
2856 err_code |= ERR_ALERT | ERR_FATAL;
2857 goto out;
2858 }
2859
Christopher Faulet31930372019-07-15 10:16:58 +02002860 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002861 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2862 free(curproxy->conn_src.iface_name);
2863 curproxy->conn_src.iface_name = NULL;
2864 curproxy->conn_src.iface_len = 0;
2865
2866 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2867 if (!sk) {
2868 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2869 file, linenum, args[0], args[1], errmsg);
2870 err_code |= ERR_ALERT | ERR_FATAL;
2871 goto out;
2872 }
2873
2874 proto = protocol_by_family(sk->ss_family);
2875 if (!proto || !proto->connect) {
2876 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2877 file, linenum, args[0], args[1]);
2878 err_code |= ERR_ALERT | ERR_FATAL;
2879 goto out;
2880 }
2881
2882 if (port1 != port2) {
2883 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
2884 file, linenum, args[0], args[1]);
2885 err_code |= ERR_ALERT | ERR_FATAL;
2886 goto out;
2887 }
2888
2889 curproxy->conn_src.source_addr = *sk;
2890 curproxy->conn_src.opts |= CO_SRC_BIND;
2891
2892 cur_arg = 2;
2893 while (*(args[cur_arg])) {
2894 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
2895#if defined(CONFIG_HAP_TRANSPARENT)
2896 if (!*args[cur_arg + 1]) {
2897 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2898 file, linenum, "usesrc");
2899 err_code |= ERR_ALERT | ERR_FATAL;
2900 goto out;
2901 }
2902
2903 if (!strcmp(args[cur_arg + 1], "client")) {
2904 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2905 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
2906 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
2907 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2908 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2909 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2910 char *name, *end;
2911
2912 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002913 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002914 name++;
2915
2916 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002917 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002918 end++;
2919
2920 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2921 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
2922 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2923 curproxy->conn_src.bind_hdr_len = end - name;
2924 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2925 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2926 curproxy->conn_src.bind_hdr_occ = -1;
2927
2928 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002929 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002930 end++;
2931 if (*end == ',') {
2932 end++;
2933 name = end;
2934 if (*end == '-')
2935 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002936 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002937 end++;
2938 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2939 }
2940
2941 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2942 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2943 " occurrences values smaller than %d.\n",
2944 file, linenum, MAX_HDR_HISTORY);
2945 err_code |= ERR_ALERT | ERR_FATAL;
2946 goto out;
2947 }
2948 } else {
2949 struct sockaddr_storage *sk;
2950
2951 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
2952 if (!sk) {
2953 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2954 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2955 err_code |= ERR_ALERT | ERR_FATAL;
2956 goto out;
2957 }
2958
2959 proto = protocol_by_family(sk->ss_family);
2960 if (!proto || !proto->connect) {
2961 ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2962 file, linenum, args[cur_arg], args[cur_arg+1]);
2963 err_code |= ERR_ALERT | ERR_FATAL;
2964 goto out;
2965 }
2966
2967 if (port1 != port2) {
2968 ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
2969 file, linenum, args[cur_arg], args[cur_arg + 1]);
2970 err_code |= ERR_ALERT | ERR_FATAL;
2971 goto out;
2972 }
2973 curproxy->conn_src.tproxy_addr = *sk;
2974 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2975 }
2976 global.last_checks |= LSTCHK_NETADM;
2977#else /* no TPROXY support */
2978 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2979 file, linenum, "usesrc");
2980 err_code |= ERR_ALERT | ERR_FATAL;
2981 goto out;
2982#endif
2983 cur_arg += 2;
2984 continue;
2985 }
2986
2987 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
2988#ifdef SO_BINDTODEVICE
2989 if (!*args[cur_arg + 1]) {
2990 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2991 file, linenum, args[0]);
2992 err_code |= ERR_ALERT | ERR_FATAL;
2993 goto out;
2994 }
2995 free(curproxy->conn_src.iface_name);
2996 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2997 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2998 global.last_checks |= LSTCHK_NETADM;
2999#else
3000 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
3001 file, linenum, args[0], args[cur_arg]);
3002 err_code |= ERR_ALERT | ERR_FATAL;
3003 goto out;
3004#endif
3005 cur_arg += 2;
3006 continue;
3007 }
3008 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
3009 file, linenum, args[0], "interface", "usesrc");
3010 err_code |= ERR_ALERT | ERR_FATAL;
3011 goto out;
3012 }
3013 }
3014 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
3015 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3016 file, linenum, "usesrc", "source");
3017 err_code |= ERR_ALERT | ERR_FATAL;
3018 goto out;
3019 }
3020 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003021 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003022 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003023 file, linenum, args[0]);
3024 err_code |= ERR_ALERT | ERR_FATAL;
3025 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003026 }
3027 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003028 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3029 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3030 err_code |= ERR_ALERT | ERR_FATAL;
3031 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003032 }
3033 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003034 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3035 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3036 err_code |= ERR_ALERT | ERR_FATAL;
3037 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003038 }
3039 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003040 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3041 err_code |= ERR_ALERT | ERR_FATAL;
3042 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003043 }
3044 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003045 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3046 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3047 err_code |= ERR_ALERT | ERR_FATAL;
3048 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003049 }
3050 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003051 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3052 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3053 err_code |= ERR_ALERT | ERR_FATAL;
3054 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003055 }
3056 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003057 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3058 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3059 err_code |= ERR_ALERT | ERR_FATAL;
3060 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003061 }
3062 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003063 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3064 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3065 err_code |= ERR_ALERT | ERR_FATAL;
3066 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003067 }
3068 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003069 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3070 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3071 err_code |= ERR_ALERT | ERR_FATAL;
3072 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003073 }
3074 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003075 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3076 err_code |= ERR_ALERT | ERR_FATAL;
3077 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003078 }
3079 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003080 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3081 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3082 err_code |= ERR_ALERT | ERR_FATAL;
3083 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003084 }
3085 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003086 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3087 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3088 err_code |= ERR_ALERT | ERR_FATAL;
3089 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003090 }
3091 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003092 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3093 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3094 err_code |= ERR_ALERT | ERR_FATAL;
3095 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003096 }
3097 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003098 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3099 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3100 err_code |= ERR_ALERT | ERR_FATAL;
3101 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003102 }
3103 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003104 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3105 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3106 err_code |= ERR_ALERT | ERR_FATAL;
3107 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003108 }
3109 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003110 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3111 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3112 err_code |= ERR_ALERT | ERR_FATAL;
3113 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003114 }
3115 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303116 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003117 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3118 err_code |= ERR_ALERT | ERR_FATAL;
3119 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003120 }
3121 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003122 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3123 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3124 err_code |= ERR_ALERT | ERR_FATAL;
3125 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003126 }
3127 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003128 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3129 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3130 err_code |= ERR_ALERT | ERR_FATAL;
3131 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003132 }
3133 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003134 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3135 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3136 err_code |= ERR_ALERT | ERR_FATAL;
3137 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003138 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003139 else {
3140 struct cfg_kw_list *kwl;
3141 int index;
3142
3143 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3144 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3145 if (kwl->kw[index].section != CFG_LISTEN)
3146 continue;
3147 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3148 /* prepare error message just in case */
3149 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
3150 if (rc < 0) {
3151 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3152 err_code |= ERR_ALERT | ERR_FATAL;
3153 goto out;
3154 }
3155 else if (rc > 0) {
3156 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3157 err_code |= ERR_WARN;
3158 goto out;
3159 }
3160 goto out;
3161 }
3162 }
3163 }
3164
3165 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
3166 err_code |= ERR_ALERT | ERR_FATAL;
3167 goto out;
3168 }
3169 out:
3170 free(errmsg);
3171 return err_code;
3172}