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