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