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