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