blob: 689a28eb3d0a9f2ce58da958a5b0c569d8cfe3c8 [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
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100181 if (strcmp(args[0], "listen") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100182 rc = PR_CAP_LISTEN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100183 else if (strcmp(args[0], "frontend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100184 rc = PR_CAP_FE;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100185 else if (strcmp(args[0], "backend") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100186 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;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100372 if (defproxy.monitor_uri)
373 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
374 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
375 if (defproxy.defbe.name)
376 curproxy->defbe.name = strdup(defproxy.defbe.name);
377
378 /* get either a pointer to the logformat string or a copy of it */
379 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
380 if (curproxy->conf.logformat_string &&
381 curproxy->conf.logformat_string != default_http_log_format &&
382 curproxy->conf.logformat_string != default_tcp_log_format &&
383 curproxy->conf.logformat_string != clf_http_log_format)
384 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
385
386 if (defproxy.conf.lfs_file) {
387 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
388 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
389 }
390
391 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
392 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
393 if (curproxy->conf.logformat_sd_string &&
394 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
395 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
396
397 if (defproxy.conf.lfsd_file) {
398 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
399 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
400 }
401 }
402
403 if (curproxy->cap & PR_CAP_BE) {
404 curproxy->timeout.connect = defproxy.timeout.connect;
405 curproxy->timeout.server = defproxy.timeout.server;
406 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
407 curproxy->timeout.check = defproxy.timeout.check;
408 curproxy->timeout.queue = defproxy.timeout.queue;
409 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
410 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
411 curproxy->timeout.httpka = defproxy.timeout.httpka;
412 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
413 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
414 }
415
416 curproxy->mode = defproxy.mode;
417 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
418
419 /* copy default logsrvs to curproxy */
420 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
421 struct logsrv *node = malloc(sizeof(*node));
422 memcpy(node, tmplogsrv, sizeof(struct logsrv));
423 node->ref = tmplogsrv->ref;
424 LIST_INIT(&node->list);
425 LIST_ADDQ(&curproxy->logsrvs, &node->list);
426 }
427
428 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
429 if (curproxy->conf.uniqueid_format_string)
430 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
431
432 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
433
434 if (defproxy.conf.uif_file) {
435 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
436 curproxy->conf.uif_line = defproxy.conf.uif_line;
437 }
438
439 /* copy default header unique id */
Tim Duesterhus0643b0e2020-03-05 17:56:35 +0100440 if (isttest(defproxy.header_unique_id)) {
441 const struct ist copy = istdup(defproxy.header_unique_id);
442 if (!isttest(copy)) {
443 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
444 err_code |= ERR_ALERT | ERR_FATAL;
445 goto out;
446 }
447 curproxy->header_unique_id = copy;
448 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100449
450 /* default compression options */
451 if (defproxy.comp != NULL) {
Tim Duesterhuse52b6e52020-09-12 20:26:43 +0200452 curproxy->comp = calloc(1, sizeof(*curproxy->comp));
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100453 curproxy->comp->algos = defproxy.comp->algos;
454 curproxy->comp->types = defproxy.comp->types;
455 }
456
457 curproxy->grace = defproxy.grace;
458 curproxy->conf.used_listener_id = EB_ROOT;
459 curproxy->conf.used_server_id = EB_ROOT;
Thayne McCombs92149f92020-11-20 01:28:26 -0700460 curproxy->used_server_addr = EB_ROOT_UNIQUE;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100461
462 if (defproxy.check_path)
463 curproxy->check_path = strdup(defproxy.check_path);
464 if (defproxy.check_command)
465 curproxy->check_command = strdup(defproxy.check_command);
466
467 if (defproxy.email_alert.mailers.name)
468 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
469 if (defproxy.email_alert.from)
470 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
471 if (defproxy.email_alert.to)
472 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
473 if (defproxy.email_alert.myhostname)
474 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
475 curproxy->email_alert.level = defproxy.email_alert.level;
476 curproxy->email_alert.set = defproxy.email_alert.set;
477
478 goto out;
479 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100480 else if (strcmp(args[0], "defaults") == 0) { /* use this one to assign default values */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100481 /* some variables may have already been initialized earlier */
482 /* FIXME-20070101: we should do this too at the end of the
483 * config parsing to free all default values.
484 */
485 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
486 err_code |= ERR_ABORT;
487 goto out;
488 }
489
Amaury Denoyelle36b53662020-09-18 15:59:39 +0200490 free(defproxy.conf.file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100491 free(defproxy.check_command);
492 free(defproxy.check_path);
493 free(defproxy.cookie_name);
494 free(defproxy.rdp_cookie_name);
495 free(defproxy.dyncookie_key);
496 free(defproxy.cookie_domain);
Christopher Faulet2f533902020-01-21 11:06:48 +0100497 free(defproxy.cookie_attrs);
Willy Tarreau4c03d1c2019-01-14 15:23:54 +0100498 free(defproxy.lbprm.arg_str);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100499 free(defproxy.capture_name);
500 free(defproxy.monitor_uri);
501 free(defproxy.defbe.name);
502 free(defproxy.conn_src.iface_name);
503 free(defproxy.fwdfor_hdr_name);
504 defproxy.fwdfor_hdr_len = 0;
505 free(defproxy.orgto_hdr_name);
506 defproxy.orgto_hdr_len = 0;
507 free(defproxy.server_id_hdr_name);
508 defproxy.server_id_hdr_len = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100509
510 if (defproxy.conf.logformat_string != default_http_log_format &&
511 defproxy.conf.logformat_string != default_tcp_log_format &&
512 defproxy.conf.logformat_string != clf_http_log_format)
513 free(defproxy.conf.logformat_string);
514
515 free(defproxy.conf.uniqueid_format_string);
516 free(defproxy.conf.lfs_file);
517 free(defproxy.conf.uif_file);
518 chunk_destroy(&defproxy.log_tag);
519 free_email_alert(&defproxy);
520
521 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
522 free(defproxy.conf.logformat_sd_string);
523 free(defproxy.conf.lfsd_file);
524
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100525 proxy_release_conf_errors(&defproxy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100526
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200527 deinit_proxy_tcpcheck(&defproxy);
528
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100529 /* we cannot free uri_auth because it might already be used */
530 init_default_instance();
531 curproxy = &defproxy;
532 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
533 curproxy->conf.args.line = curproxy->conf.line = linenum;
534 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
535 goto out;
536 }
537 else if (curproxy == NULL) {
538 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
539 err_code |= ERR_ALERT | ERR_FATAL;
540 goto out;
541 }
542
543 /* update the current file and line being parsed */
544 curproxy->conf.args.file = curproxy->conf.file;
545 curproxy->conf.args.line = linenum;
546
547 /* Now let's parse the proxy-specific keywords */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100548 if (strcmp(args[0], "server") == 0 ||
549 strcmp(args[0], "default-server") == 0 ||
550 strcmp(args[0], "server-template") == 0) {
Emeric Brund3db3842020-07-21 16:54:36 +0200551 err_code |= parse_server(file, linenum, args, curproxy, &defproxy, 1, 0, 0);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100552 if (err_code & ERR_FATAL)
553 goto out;
554 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100555 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100556 struct listener *l;
557 int cur_arg;
558
559 if (curproxy == &defproxy) {
560 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
561 err_code |= ERR_ALERT | ERR_FATAL;
562 goto out;
563 }
564 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
565 err_code |= ERR_WARN;
566
567 if (!*(args[1])) {
568 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
569 file, linenum, args[0]);
570 err_code |= ERR_ALERT | ERR_FATAL;
571 goto out;
572 }
573
574 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
575
576 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200577 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
578 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
579 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100580
581 /* NOTE: the following line might create several listeners if there
582 * are comma-separated IPs or port ranges. So all further processing
583 * will have to be applied to all listeners created after last_listen.
584 */
585 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
586 if (errmsg && *errmsg) {
587 indent_msg(&errmsg, 2);
588 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
589 }
590 else
591 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
592 file, linenum, args[0], args[1]);
593 err_code |= ERR_ALERT | ERR_FATAL;
594 goto out;
595 }
596
597 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
598 /* Set default global rights and owner for unix bind */
599 global.maxsock++;
600 }
601
602 cur_arg = 2;
603 while (*(args[cur_arg])) {
604 static int bind_dumped;
605 struct bind_kw *kw;
606 char *err;
607
608 kw = bind_find_kw(args[cur_arg]);
609 if (kw) {
610 char *err = NULL;
611 int code;
612
613 if (!kw->parse) {
614 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
615 file, linenum, args[0], args[1], args[cur_arg]);
616 cur_arg += 1 + kw->skip ;
617 err_code |= ERR_ALERT | ERR_FATAL;
618 goto out;
619 }
620
621 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
622 err_code |= code;
623
624 if (code) {
625 if (err && *err) {
626 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200627 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
628 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
629 else
630 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100631 }
632 else
633 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
634 file, linenum, args[0], args[1], args[cur_arg]);
635 if (code & ERR_FATAL) {
636 free(err);
637 cur_arg += 1 + kw->skip;
638 goto out;
639 }
640 }
641 free(err);
642 cur_arg += 1 + kw->skip;
643 continue;
644 }
645
646 err = NULL;
647 if (!bind_dumped) {
648 bind_dump_kws(&err);
649 indent_msg(&err, 4);
650 bind_dumped = 1;
651 }
652
653 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
654 file, linenum, args[0], args[1], args[cur_arg],
655 err ? " Registered keywords :" : "", err ? err : "");
656 free(err);
657
658 err_code |= ERR_ALERT | ERR_FATAL;
659 goto out;
660 }
661 goto out;
662 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100663 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200664 ha_alert("parsing [%s:%d] : 'monitor-net' doesn't exist anymore. Please use 'http-request return status 200 if { src %s }' instead.\n", file, linenum, args[1]);
665 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100666 goto out;
667 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100668 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100669 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
670 err_code |= ERR_WARN;
671
672 if (alertif_too_many_args(1, file, linenum, args, &err_code))
673 goto out;
674
675 if (!*args[1]) {
676 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
677 file, linenum, args[0]);
678 err_code |= ERR_ALERT | ERR_FATAL;
679 goto out;
680 }
681
682 free(curproxy->monitor_uri);
683 curproxy->monitor_uri_len = strlen(args[1]);
684 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
685 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
686 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
687
688 goto out;
689 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100690 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100691 if (alertif_too_many_args(1, file, linenum, args, &err_code))
692 goto out;
693
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100694 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
695 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
696 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200697 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
698 err_code |= ERR_ALERT | ERR_FATAL;
699 goto out;
700 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100701 else {
702 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
703 err_code |= ERR_ALERT | ERR_FATAL;
704 goto out;
705 }
706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100708 struct eb32_node *node;
709
710 if (curproxy == &defproxy) {
711 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
712 file, linenum, args[0]);
713 err_code |= ERR_ALERT | ERR_FATAL;
714 goto out;
715 }
716
717 if (alertif_too_many_args(1, file, linenum, args, &err_code))
718 goto out;
719
720 if (!*args[1]) {
721 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
722 file, linenum, args[0]);
723 err_code |= ERR_ALERT | ERR_FATAL;
724 goto out;
725 }
726
727 curproxy->uuid = atol(args[1]);
728 curproxy->conf.id.key = curproxy->uuid;
729 curproxy->options |= PR_O_FORCED_ID;
730
731 if (curproxy->uuid <= 0) {
732 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
733 file, linenum);
734 err_code |= ERR_ALERT | ERR_FATAL;
735 goto out;
736 }
737
738 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
739 if (node) {
740 struct proxy *target = container_of(node, struct proxy, conf.id);
741 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
742 file, linenum, proxy_type_str(curproxy), curproxy->id,
743 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
744 err_code |= ERR_ALERT | ERR_FATAL;
745 goto out;
746 }
747 eb32_insert(&used_proxy_id, &curproxy->conf.id);
748 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100749 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100750 int i, len=0;
751 char *d;
752
753 if (curproxy == &defproxy) {
754 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
755 file, linenum, args[0]);
756 err_code |= ERR_ALERT | ERR_FATAL;
757 goto out;
758 }
759
760 if (!*args[1]) {
761 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
762 file, linenum, args[0]);
763 return -1;
764 }
765
766 for (i = 1; *args[i]; i++)
767 len += strlen(args[i]) + 1;
768
769 d = calloc(1, len);
770 curproxy->desc = d;
771
772 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
773 for (i = 2; *args[i]; i++)
774 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
775
776 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100777 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100778 if (alertif_too_many_args(0, file, linenum, args, &err_code))
779 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200780 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100781 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100782 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100783 if (alertif_too_many_args(0, file, linenum, args, &err_code))
784 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200785 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100788 int cur_arg = 1;
789 unsigned long set = 0;
790
791 while (*args[cur_arg]) {
792 if (strcmp(args[cur_arg], "all") == 0) {
793 set = 0;
794 break;
795 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100796 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100797 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
798 err_code |= ERR_ALERT | ERR_FATAL;
799 goto out;
800 }
801 cur_arg++;
802 }
803 curproxy->bind_proc = set;
804 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100805 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100806 if (curproxy == &defproxy) {
807 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
808 err_code |= ERR_ALERT | ERR_FATAL;
809 goto out;
810 }
811
812 err = invalid_char(args[1]);
813 if (err) {
814 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
815 file, linenum, *err, args[1]);
816 err_code |= ERR_ALERT | ERR_FATAL;
817 goto out;
818 }
819
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100820 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100821 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100822 "logical disjunction within a condition.\n",
823 file, linenum, args[1]);
824 err_code |= ERR_ALERT | ERR_FATAL;
825 goto out;
826 }
827
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100828 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
829 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
830 file, linenum, args[1], errmsg);
831 err_code |= ERR_ALERT | ERR_FATAL;
832 goto out;
833 }
834 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100835 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100836
837 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
838 err_code |= ERR_WARN;
839
840 if (*(args[1]) == 0) {
841 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
842 file, linenum, args[0]);
843 err_code |= ERR_ALERT | ERR_FATAL;
844 goto out;
845 }
846 free(curproxy->dyncookie_key);
847 curproxy->dyncookie_key = strdup(args[1]);
848 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100849 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100850 int cur_arg;
851
852 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
853 err_code |= ERR_WARN;
854
855 if (*(args[1]) == 0) {
856 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
857 file, linenum, args[0]);
858 err_code |= ERR_ALERT | ERR_FATAL;
859 goto out;
860 }
861
862 curproxy->ck_opts = 0;
863 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
864 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
865 free(curproxy->cookie_name);
866 curproxy->cookie_name = strdup(args[1]);
867 curproxy->cookie_len = strlen(curproxy->cookie_name);
868
869 cur_arg = 2;
870 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100871 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100872 curproxy->ck_opts |= PR_CK_RW;
873 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100874 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100875 curproxy->ck_opts |= PR_CK_IND;
876 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100877 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100878 curproxy->ck_opts |= PR_CK_INS;
879 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100880 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100881 curproxy->ck_opts |= PR_CK_NOC;
882 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100883 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100884 curproxy->ck_opts |= PR_CK_POST;
885 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100886 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100887 curproxy->ck_opts |= PR_CK_PSV;
888 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100889 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100890 curproxy->ck_opts |= PR_CK_PFX;
891 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100892 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100893 curproxy->ck_opts |= PR_CK_HTTPONLY;
894 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100895 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100896 curproxy->ck_opts |= PR_CK_SECURE;
897 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100898 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100899 if (!*args[cur_arg + 1]) {
900 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
901 file, linenum, args[cur_arg]);
902 err_code |= ERR_ALERT | ERR_FATAL;
903 goto out;
904 }
905
Joao Moraise1583752019-10-30 21:04:00 -0300906 if (!strchr(args[cur_arg + 1], '.')) {
907 /* rfc6265, 5.2.3 The Domain Attribute */
908 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
909 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100910 file, linenum, args[cur_arg + 1]);
911 err_code |= ERR_WARN;
912 }
913
914 err = invalid_domainchar(args[cur_arg + 1]);
915 if (err) {
916 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
917 file, linenum, *err, args[cur_arg + 1]);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921
922 if (!curproxy->cookie_domain) {
923 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
924 } else {
925 /* one domain was already specified, add another one by
926 * building the string which will be returned along with
927 * the cookie.
928 */
929 char *new_ptr;
930 int new_len = strlen(curproxy->cookie_domain) +
931 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
932 new_ptr = malloc(new_len);
933 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
934 free(curproxy->cookie_domain);
935 curproxy->cookie_domain = new_ptr;
936 }
937 cur_arg++;
938 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100939 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100940 unsigned int maxidle;
941 const char *res;
942
943 if (!*args[cur_arg + 1]) {
944 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
945 file, linenum, args[cur_arg]);
946 err_code |= ERR_ALERT | ERR_FATAL;
947 goto out;
948 }
949
950 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200951 if (res == PARSE_TIME_OVER) {
952 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
953 file, linenum, args[cur_arg+1], args[cur_arg]);
954 err_code |= ERR_ALERT | ERR_FATAL;
955 goto out;
956 }
957 else if (res == PARSE_TIME_UNDER) {
958 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
959 file, linenum, args[cur_arg+1], args[cur_arg]);
960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
962 }
963 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100964 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
965 file, linenum, *res, args[cur_arg]);
966 err_code |= ERR_ALERT | ERR_FATAL;
967 goto out;
968 }
969 curproxy->cookie_maxidle = maxidle;
970 cur_arg++;
971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100972 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100973 unsigned int maxlife;
974 const char *res;
975
976 if (!*args[cur_arg + 1]) {
977 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
978 file, linenum, args[cur_arg]);
979 err_code |= ERR_ALERT | ERR_FATAL;
980 goto out;
981 }
982
Willy Tarreau9faebe32019-06-07 19:00:37 +0200983
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100984 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200985 if (res == PARSE_TIME_OVER) {
986 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
987 file, linenum, args[cur_arg+1], args[cur_arg]);
988 err_code |= ERR_ALERT | ERR_FATAL;
989 goto out;
990 }
991 else if (res == PARSE_TIME_UNDER) {
992 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
993 file, linenum, args[cur_arg+1], args[cur_arg]);
994 err_code |= ERR_ALERT | ERR_FATAL;
995 goto out;
996 }
997 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100998 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
999 file, linenum, *res, args[cur_arg]);
1000 err_code |= ERR_ALERT | ERR_FATAL;
1001 goto out;
1002 }
1003 curproxy->cookie_maxlife = maxlife;
1004 cur_arg++;
1005 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001006 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001007
1008 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
1009 err_code |= ERR_WARN;
1010 curproxy->ck_opts |= PR_CK_DYNAMIC;
1011 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001012 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +01001013 char *val;
1014 if (!*args[cur_arg + 1]) {
1015 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
1016 file, linenum, args[cur_arg]);
1017 err_code |= ERR_ALERT | ERR_FATAL;
1018 goto out;
1019 }
1020 val = args[cur_arg + 1];
1021 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +01001022 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +01001023 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
1024 file, linenum, *val);
1025 err_code |= ERR_ALERT | ERR_FATAL;
1026 goto out;
1027 }
1028 val++;
1029 }
1030 /* don't add ';' for the first attribute */
1031 if (!curproxy->cookie_attrs)
1032 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
1033 else
1034 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
1035 cur_arg++;
1036 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001037
1038 else {
Christopher Faulet2f533902020-01-21 11:06:48 +01001039 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 +01001040 file, linenum, args[0]);
1041 err_code |= ERR_ALERT | ERR_FATAL;
1042 goto out;
1043 }
1044 cur_arg++;
1045 }
1046 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
1047 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
1048 file, linenum);
1049 err_code |= ERR_ALERT | ERR_FATAL;
1050 }
1051
1052 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
1053 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
1054 file, linenum);
1055 err_code |= ERR_ALERT | ERR_FATAL;
1056 }
1057
1058 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
1059 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
1060 file, linenum);
1061 err_code |= ERR_ALERT | ERR_FATAL;
1062 }
1063 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001064 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001065 if (*(args[1]) == 0) {
1066 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1067 file, linenum, args[0]);
1068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001072 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001073 if (*(args[1]) == 0) {
1074 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1075 file, linenum, args[1]);
1076 err_code |= ERR_ALERT | ERR_FATAL;
1077 goto out;
1078 }
1079 free(curproxy->email_alert.from);
1080 curproxy->email_alert.from = strdup(args[2]);
1081 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001082 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001083 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.mailers.name);
1090 curproxy->email_alert.mailers.name = strdup(args[2]);
1091 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001092 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001093 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.myhostname);
1100 curproxy->email_alert.myhostname = strdup(args[2]);
1101 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001102 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001103 curproxy->email_alert.level = get_log_level(args[2]);
1104 if (curproxy->email_alert.level < 0) {
1105 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
1106 file, linenum, args[1], args[2]);
1107 err_code |= ERR_ALERT | ERR_FATAL;
1108 goto out;
1109 }
1110 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001111 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001112 if (*(args[1]) == 0) {
1113 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
1114 file, linenum, args[1]);
1115 err_code |= ERR_ALERT | ERR_FATAL;
1116 goto out;
1117 }
1118 free(curproxy->email_alert.to);
1119 curproxy->email_alert.to = strdup(args[2]);
1120 }
1121 else {
1122 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
1123 file, linenum, args[1]);
1124 err_code |= ERR_ALERT | ERR_FATAL;
1125 goto out;
1126 }
1127 /* Indicate that the email_alert is at least partially configured */
1128 curproxy->email_alert.set = 1;
1129 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001130 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001131 if (*(args[1]) == 0) {
1132 ha_alert("parsing [%s:%d] : missing persist method.\n",
1133 file, linenum);
1134 err_code |= ERR_ALERT | ERR_FATAL;
1135 goto out;
1136 }
1137
1138 if (!strncmp(args[1], "rdp-cookie", 10)) {
1139 curproxy->options2 |= PR_O2_RDPC_PRST;
1140
1141 if (*(args[1] + 10) == '(') { /* cookie name */
1142 const char *beg, *end;
1143
1144 beg = args[1] + 11;
1145 end = strchr(beg, ')');
1146
1147 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1148 goto out;
1149
1150 if (!end || end == beg) {
1151 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1152 file, linenum);
1153 err_code |= ERR_ALERT | ERR_FATAL;
1154 goto out;
1155 }
1156
1157 free(curproxy->rdp_cookie_name);
1158 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
1159 curproxy->rdp_cookie_len = end-beg;
1160 }
1161 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
1162 free(curproxy->rdp_cookie_name);
1163 curproxy->rdp_cookie_name = strdup("msts");
1164 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
1165 }
1166 else { /* syntax */
1167 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1168 file, linenum);
1169 err_code |= ERR_ALERT | ERR_FATAL;
1170 goto out;
1171 }
1172 }
1173 else {
1174 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1175 file, linenum);
1176 err_code |= ERR_ALERT | ERR_FATAL;
1177 goto out;
1178 }
1179 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001180 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001181 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 +01001182 err_code |= ERR_ALERT | ERR_FATAL;
1183 goto out;
1184 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001185 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001186 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1187 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001188 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001189 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1190 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001191 else if (strcmp(args[1], "local") == 0) { /* use the server-state-file-name variable to locate the server-state file */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001192 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1193 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001194 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001195 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1196 }
1197 else {
1198 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1199 file, linenum, args[0], args[1]);
1200 err_code |= ERR_ALERT | ERR_FATAL;
1201 goto out;
1202 }
1203 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001204 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001205 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1206 err_code |= ERR_WARN;
1207 if (*(args[1]) == 0) {
1208 ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
1209 file, linenum, args[0]);
1210 err_code |= ERR_ALERT | ERR_FATAL;
1211 goto out;
1212 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001213 else if (strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001214 curproxy->server_state_file_name = strdup(curproxy->id);
1215 else
1216 curproxy->server_state_file_name = strdup(args[1]);
1217 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001218 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001219 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1220 err_code |= ERR_WARN;
1221 if (*(args[1]) == 0) {
1222 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1223 file, linenum, args[0]);
1224 err_code |= ERR_ALERT | ERR_FATAL;
1225 goto out;
1226 }
1227 curproxy->max_out_conns = atoi(args[1]);
1228 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001229 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001230 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1231 err_code |= ERR_WARN;
1232
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001233 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001234 if (curproxy == &defproxy) {
1235 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1236 err_code |= ERR_ALERT | ERR_FATAL;
1237 goto out;
1238 }
1239
1240 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1241 goto out;
1242
1243 if (*(args[4]) == 0) {
1244 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1245 file, linenum, args[0]);
1246 err_code |= ERR_ALERT | ERR_FATAL;
1247 goto out;
1248 }
1249 free(curproxy->capture_name);
1250 curproxy->capture_name = strdup(args[2]);
1251 curproxy->capture_namelen = strlen(curproxy->capture_name);
1252 curproxy->capture_len = atol(args[4]);
1253 curproxy->to_log |= LW_COOKIE;
1254 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001255 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001256 struct cap_hdr *hdr;
1257
1258 if (curproxy == &defproxy) {
1259 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1260 err_code |= ERR_ALERT | ERR_FATAL;
1261 goto out;
1262 }
1263
1264 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1265 goto out;
1266
1267 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1268 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1269 file, linenum, args[0], args[1]);
1270 err_code |= ERR_ALERT | ERR_FATAL;
1271 goto out;
1272 }
1273
1274 hdr = calloc(1, sizeof(*hdr));
1275 hdr->next = curproxy->req_cap;
1276 hdr->name = strdup(args[3]);
1277 hdr->namelen = strlen(args[3]);
1278 hdr->len = atol(args[5]);
1279 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1280 hdr->index = curproxy->nb_req_cap++;
1281 curproxy->req_cap = hdr;
1282 curproxy->to_log |= LW_REQHDR;
1283 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001284 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001285 struct cap_hdr *hdr;
1286
1287 if (curproxy == &defproxy) {
1288 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1289 err_code |= ERR_ALERT | ERR_FATAL;
1290 goto out;
1291 }
1292
1293 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1294 goto out;
1295
1296 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1297 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1298 file, linenum, args[0], args[1]);
1299 err_code |= ERR_ALERT | ERR_FATAL;
1300 goto out;
1301 }
1302 hdr = calloc(1, sizeof(*hdr));
1303 hdr->next = curproxy->rsp_cap;
1304 hdr->name = strdup(args[3]);
1305 hdr->namelen = strlen(args[3]);
1306 hdr->len = atol(args[5]);
1307 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
1308 hdr->index = curproxy->nb_rsp_cap++;
1309 curproxy->rsp_cap = hdr;
1310 curproxy->to_log |= LW_RSPHDR;
1311 }
1312 else {
1313 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1314 file, linenum, args[0]);
1315 err_code |= ERR_ALERT | ERR_FATAL;
1316 goto out;
1317 }
1318 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001319 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001320 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1321 err_code |= ERR_WARN;
1322
1323 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1324 goto out;
1325
1326 if (*(args[1]) == 0) {
1327 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1328 file, linenum, args[0]);
1329 err_code |= ERR_ALERT | ERR_FATAL;
1330 goto out;
1331 }
1332 curproxy->conn_retries = atol(args[1]);
1333 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001334 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001335 struct act_rule *rule;
1336
1337 if (curproxy == &defproxy) {
1338 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1339 err_code |= ERR_ALERT | ERR_FATAL;
1340 goto out;
1341 }
1342
1343 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1344 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001345 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001346 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1347 file, linenum, args[0]);
1348 err_code |= ERR_WARN;
1349 }
1350
1351 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1352
1353 if (!rule) {
1354 err_code |= ERR_ALERT | ERR_ABORT;
1355 goto out;
1356 }
1357
1358 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1359 err_code |= warnif_cond_conflicts(rule->cond,
1360 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1361 file, linenum);
1362
1363 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
1364 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001365 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001366 struct act_rule *rule;
1367
1368 if (curproxy == &defproxy) {
1369 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1370 err_code |= ERR_ALERT | ERR_FATAL;
1371 goto out;
1372 }
1373
1374 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1375 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001376 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001377 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1378 file, linenum, args[0]);
1379 err_code |= ERR_WARN;
1380 }
1381
1382 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1383
1384 if (!rule) {
1385 err_code |= ERR_ALERT | ERR_ABORT;
1386 goto out;
1387 }
1388
1389 err_code |= warnif_cond_conflicts(rule->cond,
1390 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1391 file, linenum);
1392
1393 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
1394 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001395 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001396 struct act_rule *rule;
1397
1398 if (curproxy == &defproxy) {
1399 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1400 err_code |= ERR_ALERT | ERR_FATAL;
1401 goto out;
1402 }
1403
1404 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1405 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1406 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1407 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1408 file, linenum, args[0]);
1409 err_code |= ERR_WARN;
1410 }
1411
1412 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1413
1414 if (!rule) {
1415 err_code |= ERR_ALERT | ERR_ABORT;
1416 goto out;
1417 }
1418
1419 err_code |= warnif_cond_conflicts(rule->cond,
1420 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1421 file, linenum);
1422
1423 LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list);
1424 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001425 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001426 /* set the header name and length into the proxy structure */
1427 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1428 err_code |= ERR_WARN;
1429
1430 if (!*args[1]) {
1431 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1432 file, linenum, args[0]);
1433 err_code |= ERR_ALERT | ERR_FATAL;
1434 goto out;
1435 }
1436
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001437 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001438 free(curproxy->server_id_hdr_name);
1439 curproxy->server_id_hdr_name = strdup(args[1]);
1440 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001441 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 +01001442 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001443 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001444 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 +01001445
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001446 err_code |= ERR_ALERT | ERR_FATAL;
1447 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001449 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001450 struct redirect_rule *rule;
1451
1452 if (curproxy == &defproxy) {
1453 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1454 err_code |= ERR_ALERT | ERR_FATAL;
1455 goto out;
1456 }
1457
1458 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1459 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1460 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1461 err_code |= ERR_ALERT | ERR_FATAL;
1462 goto out;
1463 }
1464
1465 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
1466 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1467 err_code |= warnif_cond_conflicts(rule->cond,
1468 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1469 file, linenum);
1470 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001471 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001472 struct switching_rule *rule;
1473
1474 if (curproxy == &defproxy) {
1475 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1476 err_code |= ERR_ALERT | ERR_FATAL;
1477 goto out;
1478 }
1479
1480 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1481 err_code |= ERR_WARN;
1482
1483 if (*(args[1]) == 0) {
1484 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1485 err_code |= ERR_ALERT | ERR_FATAL;
1486 goto out;
1487 }
1488
1489 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1490 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1491 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1492 file, linenum, errmsg);
1493 err_code |= ERR_ALERT | ERR_FATAL;
1494 goto out;
1495 }
1496
1497 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1498 }
1499 else if (*args[2]) {
1500 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1501 file, linenum, args[2]);
1502 err_code |= ERR_ALERT | ERR_FATAL;
1503 goto out;
1504 }
1505
1506 rule = calloc(1, sizeof(*rule));
1507 if (!rule) {
1508 ha_alert("Out of memory error.\n");
1509 goto out;
1510 }
1511 rule->cond = cond;
1512 rule->be.name = strdup(args[1]);
Tim Duesterhus5ce5a152021-01-03 22:54:43 +01001513 if (!rule->be.name) {
1514 ha_alert("Out of memory error.\n");
1515 goto out;
1516 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001517 rule->line = linenum;
1518 rule->file = strdup(file);
1519 if (!rule->file) {
1520 ha_alert("Out of memory error.\n");
1521 goto out;
1522 }
1523 LIST_INIT(&rule->list);
1524 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
1525 }
1526 else if (strcmp(args[0], "use-server") == 0) {
1527 struct server_rule *rule;
1528
1529 if (curproxy == &defproxy) {
1530 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1531 err_code |= ERR_ALERT | ERR_FATAL;
1532 goto out;
1533 }
1534
1535 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1536 err_code |= ERR_WARN;
1537
1538 if (*(args[1]) == 0) {
1539 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1540 err_code |= ERR_ALERT | ERR_FATAL;
1541 goto out;
1542 }
1543
1544 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1545 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1546 file, linenum, args[0]);
1547 err_code |= ERR_ALERT | ERR_FATAL;
1548 goto out;
1549 }
1550
1551 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1552 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1553 file, linenum, errmsg);
1554 err_code |= ERR_ALERT | ERR_FATAL;
1555 goto out;
1556 }
1557
1558 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1559
1560 rule = calloc(1, sizeof(*rule));
1561 rule->cond = cond;
1562 rule->srv.name = strdup(args[1]);
Jerome Magnin824186b2020-03-29 09:37:12 +02001563 rule->line = linenum;
1564 rule->file = strdup(file);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001565 LIST_INIT(&rule->list);
1566 LIST_ADDQ(&curproxy->server_rules, &rule->list);
1567 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1568 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001569 else if ((strcmp(args[0], "force-persist") == 0) ||
1570 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001571 struct persist_rule *rule;
1572
1573 if (curproxy == &defproxy) {
1574 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1575 err_code |= ERR_ALERT | ERR_FATAL;
1576 goto out;
1577 }
1578
1579 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1580 err_code |= ERR_WARN;
1581
1582 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1583 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1584 file, linenum, args[0]);
1585 err_code |= ERR_ALERT | ERR_FATAL;
1586 goto out;
1587 }
1588
1589 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1590 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1591 file, linenum, args[0], errmsg);
1592 err_code |= ERR_ALERT | ERR_FATAL;
1593 goto out;
1594 }
1595
1596 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1597 * where force-persist is applied.
1598 */
1599 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1600
1601 rule = calloc(1, sizeof(*rule));
1602 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001603 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001604 rule->type = PERSIST_TYPE_FORCE;
1605 } else {
1606 rule->type = PERSIST_TYPE_IGNORE;
1607 }
1608 LIST_INIT(&rule->list);
1609 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
1610 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001611 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001612 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001613
1614 if (curproxy == &defproxy) {
1615 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1616 file, linenum);
1617 err_code |= ERR_ALERT | ERR_FATAL;
1618 goto out;
1619 }
1620
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001621 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001622 if (other) {
1623 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 +01001624 file, linenum, curproxy->id,
1625 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1626 other->proxy ? other->id : other->peers.p->id,
1627 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001628 err_code |= ERR_ALERT | ERR_FATAL;
1629 goto out;
1630 }
1631
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001632 curproxy->table = calloc(1, sizeof *curproxy->table);
1633 if (!curproxy->table) {
1634 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1635 file, linenum, args[0], args[1]);
1636 err_code |= ERR_ALERT | ERR_FATAL;
1637 goto out;
1638 }
1639
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001640 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1641 curproxy->id, curproxy->id, NULL);
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001642 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001643 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001644
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001645 /* Store the proxy in the stick-table. */
1646 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001647
1648 stktable_store_name(curproxy->table);
1649 curproxy->table->next = stktables_list;
1650 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001651
1652 /* Add this proxy to the list of proxies which refer to its stick-table. */
1653 if (curproxy->table->proxies_list != curproxy) {
1654 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1655 curproxy->table->proxies_list = curproxy;
1656 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001657 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001658 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001659 struct sticking_rule *rule;
1660 struct sample_expr *expr;
1661 int myidx = 0;
1662 const char *name = NULL;
1663 int flags;
1664
1665 if (curproxy == &defproxy) {
1666 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1667 err_code |= ERR_ALERT | ERR_FATAL;
1668 goto out;
1669 }
1670
1671 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1672 err_code |= ERR_WARN;
1673 goto out;
1674 }
1675
1676 myidx++;
1677 if ((strcmp(args[myidx], "store") == 0) ||
1678 (strcmp(args[myidx], "store-request") == 0)) {
1679 myidx++;
1680 flags = STK_IS_STORE;
1681 }
1682 else if (strcmp(args[myidx], "store-response") == 0) {
1683 myidx++;
1684 flags = STK_IS_STORE | STK_ON_RSP;
1685 }
1686 else if (strcmp(args[myidx], "match") == 0) {
1687 myidx++;
1688 flags = STK_IS_MATCH;
1689 }
1690 else if (strcmp(args[myidx], "on") == 0) {
1691 myidx++;
1692 flags = STK_IS_MATCH | STK_IS_STORE;
1693 }
1694 else {
1695 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1696 err_code |= ERR_ALERT | ERR_FATAL;
1697 goto out;
1698 }
1699
1700 if (*(args[myidx]) == 0) {
1701 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1702 err_code |= ERR_ALERT | ERR_FATAL;
1703 goto out;
1704 }
1705
1706 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001707 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001708 if (!expr) {
1709 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1710 err_code |= ERR_ALERT | ERR_FATAL;
1711 goto out;
1712 }
1713
1714 if (flags & STK_ON_RSP) {
1715 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1716 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1717 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1718 err_code |= ERR_ALERT | ERR_FATAL;
1719 free(expr);
1720 goto out;
1721 }
1722 } else {
1723 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1724 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1725 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1726 err_code |= ERR_ALERT | ERR_FATAL;
1727 free(expr);
1728 goto out;
1729 }
1730 }
1731
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001732 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001733 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1734
1735 if (strcmp(args[myidx], "table") == 0) {
1736 myidx++;
1737 name = args[myidx++];
1738 }
1739
1740 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1741 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1742 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1743 file, linenum, args[0], errmsg);
1744 err_code |= ERR_ALERT | ERR_FATAL;
1745 free(expr);
1746 goto out;
1747 }
1748 }
1749 else if (*(args[myidx])) {
1750 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1751 file, linenum, args[0], args[myidx]);
1752 err_code |= ERR_ALERT | ERR_FATAL;
1753 free(expr);
1754 goto out;
1755 }
1756 if (flags & STK_ON_RSP)
1757 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1758 else
1759 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1760
1761 rule = calloc(1, sizeof(*rule));
1762 rule->cond = cond;
1763 rule->expr = expr;
1764 rule->flags = flags;
1765 rule->table.name = name ? strdup(name) : NULL;
1766 LIST_INIT(&rule->list);
1767 if (flags & STK_ON_RSP)
1768 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
1769 else
1770 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
1771 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001772 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001773 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
1774 curproxy->uri_auth = NULL; /* we must detach from the default config */
1775
1776 if (!*args[1]) {
1777 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001778 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001779 struct stats_admin_rule *rule;
1780
1781 if (curproxy == &defproxy) {
1782 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1783 err_code |= ERR_ALERT | ERR_FATAL;
1784 goto out;
1785 }
1786
1787 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1788 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1789 err_code |= ERR_ALERT | ERR_ABORT;
1790 goto out;
1791 }
1792
1793 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1794 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1795 file, linenum, args[0], args[1]);
1796 err_code |= ERR_ALERT | ERR_FATAL;
1797 goto out;
1798 }
1799 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1800 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1801 file, linenum, args[0], args[1], errmsg);
1802 err_code |= ERR_ALERT | ERR_FATAL;
1803 goto out;
1804 }
1805
1806 err_code |= warnif_cond_conflicts(cond,
1807 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1808 file, linenum);
1809
1810 rule = calloc(1, sizeof(*rule));
1811 rule->cond = cond;
1812 LIST_INIT(&rule->list);
1813 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001814 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001815 if (*(args[2]) == 0) {
1816 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1817 err_code |= ERR_ALERT | ERR_FATAL;
1818 goto out;
1819 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
1820 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1821 err_code |= ERR_ALERT | ERR_ABORT;
1822 goto out;
1823 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001824 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001825 if (*(args[2]) == 0) {
1826 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1827 err_code |= ERR_ALERT | ERR_FATAL;
1828 goto out;
1829 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
1830 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1831 err_code |= ERR_ALERT | ERR_ABORT;
1832 goto out;
1833 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001834 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001835 unsigned interval;
1836
1837 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001838 if (err == PARSE_TIME_OVER) {
1839 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1840 file, linenum, args[2]);
1841 err_code |= ERR_ALERT | ERR_FATAL;
1842 goto out;
1843 }
1844 else if (err == PARSE_TIME_UNDER) {
1845 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1846 file, linenum, args[2]);
1847 err_code |= ERR_ALERT | ERR_FATAL;
1848 goto out;
1849 }
1850 else if (err) {
1851 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001852 file, linenum, *err);
1853 err_code |= ERR_ALERT | ERR_FATAL;
1854 goto out;
1855 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
1856 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1857 err_code |= ERR_ALERT | ERR_ABORT;
1858 goto out;
1859 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001860 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001861 struct act_rule *rule;
1862
1863 if (curproxy == &defproxy) {
1864 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1865 err_code |= ERR_ALERT | ERR_FATAL;
1866 goto out;
1867 }
1868
1869 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1870 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1871 err_code |= ERR_ALERT | ERR_ABORT;
1872 goto out;
1873 }
1874
1875 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1876 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1877 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1878 file, linenum, args[0]);
1879 err_code |= ERR_WARN;
1880 }
1881
1882 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1883
1884 if (!rule) {
1885 err_code |= ERR_ALERT | ERR_ABORT;
1886 goto out;
1887 }
1888
1889 err_code |= warnif_cond_conflicts(rule->cond,
1890 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1891 file, linenum);
1892 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
1893
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001894 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001895 if (*(args[2]) == 0) {
1896 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1897 err_code |= ERR_ALERT | ERR_FATAL;
1898 goto out;
1899 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
1900 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1901 err_code |= ERR_ALERT | ERR_ABORT;
1902 goto out;
1903 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001904 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001905 if (*(args[2]) == 0) {
1906 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1907 err_code |= ERR_ALERT | ERR_FATAL;
1908 goto out;
1909 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
1910 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1911 err_code |= ERR_ALERT | ERR_ABORT;
1912 goto out;
1913 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001914 } else if (strcmp(args[1], "enable") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001915 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
1916 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1917 err_code |= ERR_ALERT | ERR_ABORT;
1918 goto out;
1919 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001920 } else if (strcmp(args[1], "hide-version") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001921 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001922 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1923 err_code |= ERR_ALERT | ERR_ABORT;
1924 goto out;
1925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001926 } else if (strcmp(args[1], "show-legends") == 0) {
Willy Tarreau708c4162019-10-09 10:19:16 +02001927 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
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 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001932 } else if (strcmp(args[1], "show-modules") == 0) {
Amaury Denoyelle0b70a8a2020-10-05 11:49:45 +02001933 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
1934 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1935 err_code |= ERR_ALERT | ERR_ABORT;
1936 goto out;
1937 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001938 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001939
1940 if (*args[2]) {
1941 int i;
1942 char c;
1943
1944 for (i=0; args[2][i]; i++) {
1945 c = args[2][i];
1946 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1947 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1948 break;
1949 }
1950
1951 if (!i || args[2][i]) {
1952 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1953 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1954 file, linenum, args[0], args[1]);
1955 err_code |= ERR_ALERT | ERR_FATAL;
1956 goto out;
1957 }
1958 }
1959
1960 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
1961 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1962 err_code |= ERR_ALERT | ERR_ABORT;
1963 goto out;
1964 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001965 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001966 char *desc = NULL;
1967
1968 if (*args[2]) {
1969 int i, len=0;
1970 char *d;
1971
1972 for (i = 2; *args[i]; i++)
1973 len += strlen(args[i]) + 1;
1974
1975 desc = d = calloc(1, len);
1976
1977 d += snprintf(d, desc + len - d, "%s", args[2]);
1978 for (i = 3; *args[i]; i++)
1979 d += snprintf(d, desc + len - d, " %s", args[i]);
1980 }
1981
1982 if (!*args[2] && !global.desc)
1983 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1984 file, linenum, args[1]);
1985 else {
1986 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1987 free(desc);
1988 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
1989 err_code |= ERR_ALERT | ERR_ABORT;
1990 goto out;
1991 }
1992 free(desc);
1993 }
1994 } else {
1995stats_error_parsing:
1996 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1997 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1998 err_code |= ERR_ALERT | ERR_FATAL;
1999 goto out;
2000 }
2001 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002002 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002003 int optnum;
2004
2005 if (*(args[1]) == '\0') {
2006 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
2007 file, linenum, args[0]);
2008 err_code |= ERR_ALERT | ERR_FATAL;
2009 goto out;
2010 }
2011
2012 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002013 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002014 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
2015 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2016 file, linenum, cfg_opts[optnum].name);
2017 err_code |= ERR_ALERT | ERR_FATAL;
2018 goto out;
2019 }
2020 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2021 goto out;
2022
2023 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
2024 err_code |= ERR_WARN;
2025 goto out;
2026 }
2027
2028 curproxy->no_options &= ~cfg_opts[optnum].val;
2029 curproxy->options &= ~cfg_opts[optnum].val;
2030
2031 switch (kwm) {
2032 case KWM_STD:
2033 curproxy->options |= cfg_opts[optnum].val;
2034 break;
2035 case KWM_NO:
2036 curproxy->no_options |= cfg_opts[optnum].val;
2037 break;
2038 case KWM_DEF: /* already cleared */
2039 break;
2040 }
2041
2042 goto out;
2043 }
2044 }
2045
2046 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002047 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002048 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
2049 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
2050 file, linenum, cfg_opts2[optnum].name);
2051 err_code |= ERR_ALERT | ERR_FATAL;
2052 goto out;
2053 }
2054 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2055 goto out;
2056 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
2057 err_code |= ERR_WARN;
2058 goto out;
2059 }
2060
Christopher Faulet31930372019-07-15 10:16:58 +02002061 /* "[no] option http-use-htx" is deprecated */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002062 if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) {
Christopher Fauletf89f0992019-07-19 11:17:38 +02002063 if (kwm ==KWM_NO) {
2064 ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored."
2065 " The HTX mode is now the only supported mode.\n",
2066 file, linenum, cfg_opts2[optnum].name);
2067 err_code |= ERR_WARN;
2068 }
Christopher Faulet31930372019-07-15 10:16:58 +02002069 goto out;
2070 }
2071
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002072 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
2073 curproxy->options2 &= ~cfg_opts2[optnum].val;
2074
2075 switch (kwm) {
2076 case KWM_STD:
2077 curproxy->options2 |= cfg_opts2[optnum].val;
2078 break;
2079 case KWM_NO:
2080 curproxy->no_options2 |= cfg_opts2[optnum].val;
2081 break;
2082 case KWM_DEF: /* already cleared */
2083 break;
2084 }
2085 goto out;
2086 }
2087 }
2088
2089 /* HTTP options override each other. They can be cancelled using
2090 * "no option xxx" which only switches to default mode if the mode
2091 * was this one (useful for cancelling options set in defaults
2092 * sections).
2093 */
2094 if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) {
Tim Duesterhus10c6c162019-05-14 20:58:00 +02002095 if (strcmp(args[1], "forceclose") == 0) {
2096 if (!already_warned(WARN_FORCECLOSE_DEPRECATED))
2097 ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n",
2098 file, linenum, args[1]);
2099 err_code |= ERR_WARN;
2100 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002101 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2102 goto out;
2103 if (kwm == KWM_STD) {
2104 curproxy->options &= ~PR_O_HTTP_MODE;
2105 curproxy->options |= PR_O_HTTP_CLO;
2106 goto out;
2107 }
2108 else if (kwm == KWM_NO) {
2109 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
2110 curproxy->options &= ~PR_O_HTTP_MODE;
2111 goto out;
2112 }
2113 }
2114 else if (strcmp(args[1], "http-server-close") == 0) {
2115 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2116 goto out;
2117 if (kwm == KWM_STD) {
2118 curproxy->options &= ~PR_O_HTTP_MODE;
2119 curproxy->options |= PR_O_HTTP_SCL;
2120 goto out;
2121 }
2122 else if (kwm == KWM_NO) {
2123 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
2124 curproxy->options &= ~PR_O_HTTP_MODE;
2125 goto out;
2126 }
2127 }
2128 else if (strcmp(args[1], "http-keep-alive") == 0) {
2129 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2130 goto out;
2131 if (kwm == KWM_STD) {
2132 curproxy->options &= ~PR_O_HTTP_MODE;
2133 curproxy->options |= PR_O_HTTP_KAL;
2134 goto out;
2135 }
2136 else if (kwm == KWM_NO) {
2137 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
2138 curproxy->options &= ~PR_O_HTTP_MODE;
2139 goto out;
2140 }
2141 }
2142 else if (strcmp(args[1], "http-tunnel") == 0) {
Christopher Faulet73e8ede2019-07-16 15:04:46 +02002143 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
2144 file, linenum, args[1]);
2145 err_code |= ERR_WARN;
2146 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002147 }
2148
2149 /* Redispatch can take an integer argument that control when the
2150 * resispatch occurs. All values are relative to the retries option.
2151 * This can be cancelled using "no option xxx".
2152 */
2153 if (strcmp(args[1], "redispatch") == 0) {
2154 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2155 err_code |= ERR_WARN;
2156 goto out;
2157 }
2158
2159 curproxy->no_options &= ~PR_O_REDISP;
2160 curproxy->options &= ~PR_O_REDISP;
2161
2162 switch (kwm) {
2163 case KWM_STD:
2164 curproxy->options |= PR_O_REDISP;
2165 curproxy->redispatch_after = -1;
2166 if(*args[2]) {
2167 curproxy->redispatch_after = atol(args[2]);
2168 }
2169 break;
2170 case KWM_NO:
2171 curproxy->no_options |= PR_O_REDISP;
2172 curproxy->redispatch_after = 0;
2173 break;
2174 case KWM_DEF: /* already cleared */
2175 break;
2176 }
2177 goto out;
2178 }
2179
2180 if (kwm != KWM_STD) {
2181 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2182 file, linenum, args[1]);
2183 err_code |= ERR_ALERT | ERR_FATAL;
2184 goto out;
2185 }
2186
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002187 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002188 char *logformat;
2189 /* generate a complete HTTP log */
2190 logformat = default_http_log_format;
2191 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002192 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002193 curproxy->options2 |= PR_O2_CLFLOG;
2194 logformat = clf_http_log_format;
2195 } else {
2196 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2197 err_code |= ERR_ALERT | ERR_FATAL;
2198 goto out;
2199 }
2200 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2201 goto out;
2202 }
2203 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2204 char *oldlogformat = "log-format";
2205 char *clflogformat = "";
2206
2207 if (curproxy->conf.logformat_string == default_http_log_format)
2208 oldlogformat = "option httplog";
2209 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2210 oldlogformat = "option tcplog";
2211 else if (curproxy->conf.logformat_string == clf_http_log_format)
2212 oldlogformat = "option httplog clf";
2213 if (logformat == clf_http_log_format)
2214 clflogformat = " clf";
2215 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2216 file, linenum, clflogformat, oldlogformat);
2217 }
2218 if (curproxy->conf.logformat_string != default_http_log_format &&
2219 curproxy->conf.logformat_string != default_tcp_log_format &&
2220 curproxy->conf.logformat_string != clf_http_log_format)
2221 free(curproxy->conf.logformat_string);
2222 curproxy->conf.logformat_string = logformat;
2223
2224 free(curproxy->conf.lfs_file);
2225 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2226 curproxy->conf.lfs_line = curproxy->conf.args.line;
2227
2228 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2229 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2230 file, linenum, curproxy->id);
2231 err_code |= ERR_WARN;
2232 }
2233 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002234 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002235 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2236 char *oldlogformat = "log-format";
2237
2238 if (curproxy->conf.logformat_string == default_http_log_format)
2239 oldlogformat = "option httplog";
2240 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2241 oldlogformat = "option tcplog";
2242 else if (curproxy->conf.logformat_string == clf_http_log_format)
2243 oldlogformat = "option httplog clf";
2244 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2245 file, linenum, oldlogformat);
2246 }
2247 /* generate a detailed TCP log */
2248 if (curproxy->conf.logformat_string != default_http_log_format &&
2249 curproxy->conf.logformat_string != default_tcp_log_format &&
2250 curproxy->conf.logformat_string != clf_http_log_format)
2251 free(curproxy->conf.logformat_string);
2252 curproxy->conf.logformat_string = default_tcp_log_format;
2253
2254 free(curproxy->conf.lfs_file);
2255 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2256 curproxy->conf.lfs_line = curproxy->conf.args.line;
2257
2258 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2259 goto out;
2260
2261 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2262 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2263 file, linenum, curproxy->id);
2264 err_code |= ERR_WARN;
2265 }
2266 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002267 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002268 /* enable TCP keep-alives on client and server streams */
2269 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2270 err_code |= ERR_WARN;
2271
2272 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2273 goto out;
2274
2275 if (curproxy->cap & PR_CAP_FE)
2276 curproxy->options |= PR_O_TCP_CLI_KA;
2277 if (curproxy->cap & PR_CAP_BE)
2278 curproxy->options |= PR_O_TCP_SRV_KA;
2279 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002280 else if (strcmp(args[1], "httpchk") == 0) {
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002281 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2282 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002283 goto out;
2284 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002285 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Christopher Faulet811f78c2020-04-01 11:10:27 +02002286 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum);
2287 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002288 goto out;
2289 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002290 else if (strcmp(args[1], "smtpchk") == 0) {
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002291 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, &defproxy, file, linenum);
2292 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002293 goto out;
2294 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002295 else if (strcmp(args[1], "pgsql-check") == 0) {
Christopher Fauletce355072020-04-02 11:44:39 +02002296 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2297 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002298 goto out;
2299 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002300 else if (strcmp(args[1], "redis-check") == 0) {
Christopher Faulet33f05df2020-04-01 11:08:50 +02002301 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2302 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002303 goto out;
2304 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002305 else if (strcmp(args[1], "mysql-check") == 0) {
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002306 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2307 if (err_code & ERR_FATAL)
2308 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002309 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002310 else if (strcmp(args[1], "ldap-check") == 0) {
Christopher Faulet1997eca2020-04-03 23:13:50 +02002311 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2312 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002313 goto out;
2314 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002315 else if (strcmp(args[1], "spop-check") == 0) {
Christopher Faulet267b01b2020-04-04 10:27:09 +02002316 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2317 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002318 goto out;
2319 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002320 else if (strcmp(args[1], "tcp-check") == 0) {
Christopher Faulet430e4802020-04-09 15:28:16 +02002321 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2322 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002323 goto out;
2324 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002325 else if (strcmp(args[1], "external-check") == 0) {
Christopher Faulet6f557912020-04-09 15:58:50 +02002326 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, &defproxy, file, linenum);
2327 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002328 goto out;
2329 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002330 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002331 int cur_arg;
2332
2333 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002334 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002335 */
2336
2337 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2338
2339 free(curproxy->fwdfor_hdr_name);
2340 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
2341 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
2342
2343 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2344 cur_arg = 2;
2345 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002346 if (strcmp(args[cur_arg], "except") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002347 /* suboption except - needs additional argument for it */
2348 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
2349 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2350 file, linenum, args[0], args[1], args[cur_arg]);
2351 err_code |= ERR_ALERT | ERR_FATAL;
2352 goto out;
2353 }
2354 /* flush useless bits */
2355 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
2356 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002357 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002358 /* suboption header - needs additional argument for it */
2359 if (*(args[cur_arg+1]) == 0) {
2360 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2361 file, linenum, args[0], args[1], args[cur_arg]);
2362 err_code |= ERR_ALERT | ERR_FATAL;
2363 goto out;
2364 }
2365 free(curproxy->fwdfor_hdr_name);
2366 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
2367 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2368 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002369 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002370 curproxy->options &= ~PR_O_FF_ALWAYS;
2371 cur_arg += 1;
2372 } else {
2373 /* unknown suboption - catchall */
2374 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2375 file, linenum, args[0], args[1]);
2376 err_code |= ERR_ALERT | ERR_FATAL;
2377 goto out;
2378 }
2379 } /* end while loop */
2380 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002381 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002382 int cur_arg;
2383
2384 /* insert x-original-to field, but not for the IP address listed as an except.
2385 * set default options (ie: bitfield, header name, etc)
2386 */
2387
2388 curproxy->options |= PR_O_ORGTO;
2389
2390 free(curproxy->orgto_hdr_name);
2391 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
2392 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
2393
2394 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2395 cur_arg = 2;
2396 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002397 if (strcmp(args[cur_arg], "except") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002398 /* suboption except - needs additional argument for it */
2399 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
2400 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2401 file, linenum, args[0], args[1], args[cur_arg]);
2402 err_code |= ERR_ALERT | ERR_FATAL;
2403 goto out;
2404 }
2405 /* flush useless bits */
2406 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
2407 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002408 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002409 /* suboption header - needs additional argument for it */
2410 if (*(args[cur_arg+1]) == 0) {
2411 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2412 file, linenum, args[0], args[1], args[cur_arg]);
2413 err_code |= ERR_ALERT | ERR_FATAL;
2414 goto out;
2415 }
2416 free(curproxy->orgto_hdr_name);
2417 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
2418 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2419 cur_arg += 2;
2420 } else {
2421 /* unknown suboption - catchall */
2422 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2423 file, linenum, args[0], args[1]);
2424 err_code |= ERR_ALERT | ERR_FATAL;
2425 goto out;
2426 }
2427 } /* end while loop */
2428 }
2429 else {
2430 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2431 err_code |= ERR_ALERT | ERR_FATAL;
2432 goto out;
2433 }
2434 goto out;
2435 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002436 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002437 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2438 err_code |= ERR_WARN;
2439
2440 if (*(args[1]) == 0) {
2441 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2442 err_code |= ERR_ALERT | ERR_FATAL;
2443 goto out;
2444 }
2445 free(curproxy->defbe.name);
2446 curproxy->defbe.name = strdup(args[1]);
2447
2448 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2449 goto out;
2450 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002451 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002452 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 +01002453
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002454 err_code |= ERR_ALERT | ERR_FATAL;
2455 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002456 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002457 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002458 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2459 err_code |= ERR_WARN;
2460
2461 if (strcmp(args[1], "never") == 0) {
2462 /* enable a graceful server shutdown on an HTTP 404 response */
2463 curproxy->options &= ~PR_O_REUSE_MASK;
2464 curproxy->options |= PR_O_REUSE_NEVR;
2465 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2466 goto out;
2467 }
2468 else if (strcmp(args[1], "safe") == 0) {
2469 /* enable a graceful server shutdown on an HTTP 404 response */
2470 curproxy->options &= ~PR_O_REUSE_MASK;
2471 curproxy->options |= PR_O_REUSE_SAFE;
2472 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2473 goto out;
2474 }
2475 else if (strcmp(args[1], "aggressive") == 0) {
2476 curproxy->options &= ~PR_O_REUSE_MASK;
2477 curproxy->options |= PR_O_REUSE_AGGR;
2478 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2479 goto out;
2480 }
2481 else if (strcmp(args[1], "always") == 0) {
2482 /* enable a graceful server shutdown on an HTTP 404 response */
2483 curproxy->options &= ~PR_O_REUSE_MASK;
2484 curproxy->options |= PR_O_REUSE_ALWS;
2485 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2486 goto out;
2487 }
2488 else {
2489 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2490 err_code |= ERR_ALERT | ERR_FATAL;
2491 goto out;
2492 }
2493 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002494 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002495 if (curproxy == &defproxy) {
2496 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2497 err_code |= ERR_ALERT | ERR_FATAL;
2498 goto out;
2499 }
2500
2501 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2502 err_code |= ERR_WARN;
2503
2504 if (strcmp(args[1], "fail") == 0) {
2505 /* add a condition to fail monitor requests */
2506 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2507 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2508 file, linenum, args[0], args[1]);
2509 err_code |= ERR_ALERT | ERR_FATAL;
2510 goto out;
2511 }
2512
2513 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2514 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2515 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2516 file, linenum, args[0], args[1], errmsg);
2517 err_code |= ERR_ALERT | ERR_FATAL;
2518 goto out;
2519 }
2520 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
2521 }
2522 else {
2523 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2524 err_code |= ERR_ALERT | ERR_FATAL;
2525 goto out;
2526 }
2527 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002528#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002529 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002530 /* enable transparent proxy connections */
2531 curproxy->options |= PR_O_TRANSP;
2532 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2533 goto out;
2534 }
2535#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002536 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002537 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2538 err_code |= ERR_WARN;
2539
2540 if (*(args[1]) == 0) {
2541 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2542 err_code |= ERR_ALERT | ERR_FATAL;
2543 goto out;
2544 }
2545 curproxy->maxconn = atol(args[1]);
2546 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2547 goto out;
2548 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002549 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002550 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2551 err_code |= ERR_WARN;
2552
2553 if (*(args[1]) == 0) {
2554 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2555 err_code |= ERR_ALERT | ERR_FATAL;
2556 goto out;
2557 }
2558 curproxy->backlog = atol(args[1]);
2559 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2560 goto out;
2561 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002562 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002563 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2564 err_code |= ERR_WARN;
2565
2566 if (*(args[1]) == 0) {
2567 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2568 err_code |= ERR_ALERT | ERR_FATAL;
2569 goto out;
2570 }
2571 curproxy->fullconn = atol(args[1]);
2572 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2573 goto out;
2574 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002575 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002576 if (*(args[1]) == 0) {
2577 ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
2578 err_code |= ERR_ALERT | ERR_FATAL;
2579 goto out;
2580 }
2581 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02002582 if (err == PARSE_TIME_OVER) {
2583 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n",
2584 file, linenum, args[1]);
2585 err_code |= ERR_ALERT | ERR_FATAL;
2586 goto out;
2587 }
2588 else if (err == PARSE_TIME_UNDER) {
2589 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n",
2590 file, linenum, args[1]);
2591 err_code |= ERR_ALERT | ERR_FATAL;
2592 goto out;
2593 }
2594 else if (err) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002595 ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
2596 file, linenum, *err);
2597 err_code |= ERR_ALERT | ERR_FATAL;
2598 goto out;
2599 }
2600 curproxy->grace = val;
2601 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2602 goto out;
Willy Tarreauab0a5192020-10-09 19:07:01 +02002603
2604 ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n",
2605 file, linenum, args[0]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002606 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002607 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002608 struct sockaddr_storage *sk;
2609 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002610
2611 if (curproxy == &defproxy) {
2612 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2613 err_code |= ERR_ALERT | ERR_FATAL;
2614 goto out;
2615 }
2616 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2617 err_code |= ERR_WARN;
2618
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002619 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2620 &errmsg, NULL, NULL,
2621 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 +01002622 if (!sk) {
2623 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2624 err_code |= ERR_ALERT | ERR_FATAL;
2625 goto out;
2626 }
2627
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002628 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2629 goto out;
2630
2631 curproxy->dispatch_addr = *sk;
2632 curproxy->options |= PR_O_DISPATCH;
2633 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002634 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002635 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2636 err_code |= ERR_WARN;
2637
2638 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2639 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2640 err_code |= ERR_ALERT | ERR_FATAL;
2641 goto out;
2642 }
2643 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002644 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002645 /**
2646 * The syntax for hash-type config element is
2647 * hash-type {map-based|consistent} [[<algo>] avalanche]
2648 *
2649 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2650 */
2651 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2652
2653 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2654 err_code |= ERR_WARN;
2655
2656 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2657 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2658 }
2659 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2660 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2661 }
2662 else if (strcmp(args[1], "avalanche") == 0) {
2663 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]);
2664 err_code |= ERR_ALERT | ERR_FATAL;
2665 goto out;
2666 }
2667 else {
2668 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2669 err_code |= ERR_ALERT | ERR_FATAL;
2670 goto out;
2671 }
2672
2673 /* set the hash function to use */
2674 if (!*args[2]) {
2675 /* the default algo is sdbm */
2676 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2677
2678 /* if consistent with no argument, then avalanche modifier is also applied */
2679 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2680 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2681 } else {
2682 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002683 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002684 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2685 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002686 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002687 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2688 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002689 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002690 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2691 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002692 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002693 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2694 }
2695 else {
2696 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2697 err_code |= ERR_ALERT | ERR_FATAL;
2698 goto out;
2699 }
2700
2701 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002702 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002703 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2704 }
2705 else if (*args[3]) {
2706 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2707 err_code |= ERR_ALERT | ERR_FATAL;
2708 goto out;
2709 }
2710 }
2711 }
2712 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2713 if (*(args[1]) == 0) {
2714 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2715 err_code |= ERR_ALERT | ERR_FATAL;
2716 goto out;
2717 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002718 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2719 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002720 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2721 err_code |= ERR_ALERT | ERR_FATAL;
2722 goto out;
2723 }
2724 }
2725 else if (strcmp(args[0], "unique-id-format") == 0) {
2726 if (!*(args[1])) {
2727 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2728 err_code |= ERR_ALERT | ERR_FATAL;
2729 goto out;
2730 }
2731 if (*(args[2])) {
2732 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2733 err_code |= ERR_ALERT | ERR_FATAL;
2734 goto out;
2735 }
2736 free(curproxy->conf.uniqueid_format_string);
2737 curproxy->conf.uniqueid_format_string = strdup(args[1]);
2738
2739 free(curproxy->conf.uif_file);
2740 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2741 curproxy->conf.uif_line = curproxy->conf.args.line;
2742 }
2743
2744 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002745 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002746 if (!*(args[1])) {
2747 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2748 err_code |= ERR_ALERT | ERR_FATAL;
2749 goto out;
2750 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002751 copy = strdup(args[1]);
2752 if (copy == NULL) {
2753 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2754 err_code |= ERR_ALERT | ERR_FATAL;
2755 goto out;
2756 }
2757
2758 istfree(&curproxy->header_unique_id);
2759 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002760 }
2761
2762 else if (strcmp(args[0], "log-format") == 0) {
2763 if (!*(args[1])) {
2764 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2765 err_code |= ERR_ALERT | ERR_FATAL;
2766 goto out;
2767 }
2768 if (*(args[2])) {
2769 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2770 err_code |= ERR_ALERT | ERR_FATAL;
2771 goto out;
2772 }
2773 if (curproxy->conf.logformat_string && curproxy == &defproxy) {
2774 char *oldlogformat = "log-format";
2775
2776 if (curproxy->conf.logformat_string == default_http_log_format)
2777 oldlogformat = "option httplog";
2778 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2779 oldlogformat = "option tcplog";
2780 else if (curproxy->conf.logformat_string == clf_http_log_format)
2781 oldlogformat = "option httplog clf";
2782 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2783 file, linenum, oldlogformat);
2784 }
2785 if (curproxy->conf.logformat_string != default_http_log_format &&
2786 curproxy->conf.logformat_string != default_tcp_log_format &&
2787 curproxy->conf.logformat_string != clf_http_log_format)
2788 free(curproxy->conf.logformat_string);
2789 curproxy->conf.logformat_string = strdup(args[1]);
2790
2791 free(curproxy->conf.lfs_file);
2792 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2793 curproxy->conf.lfs_line = curproxy->conf.args.line;
2794
2795 /* get a chance to improve log-format error reporting by
2796 * reporting the correct line-number when possible.
2797 */
2798 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2799 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2800 file, linenum, curproxy->id);
2801 err_code |= ERR_WARN;
2802 }
2803 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002804 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002805 if (!*(args[1])) {
2806 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2807 err_code |= ERR_ALERT | ERR_FATAL;
2808 goto out;
2809 }
2810 if (*(args[2])) {
2811 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2812 err_code |= ERR_ALERT | ERR_FATAL;
2813 goto out;
2814 }
2815
2816 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2817 free(curproxy->conf.logformat_sd_string);
2818 curproxy->conf.logformat_sd_string = strdup(args[1]);
2819
2820 free(curproxy->conf.lfsd_file);
2821 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2822 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2823
2824 /* get a chance to improve log-format-sd error reporting by
2825 * reporting the correct line-number when possible.
2826 */
2827 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
2828 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2829 file, linenum, curproxy->id);
2830 err_code |= ERR_WARN;
2831 }
2832 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002833 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002834 if (*(args[1]) == 0) {
2835 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2836 err_code |= ERR_ALERT | ERR_FATAL;
2837 goto out;
2838 }
2839 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002840 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2841 if (b_orig(&curproxy->log_tag) == NULL) {
2842 chunk_destroy(&curproxy->log_tag);
2843 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2844 err_code |= ERR_ALERT | ERR_FATAL;
2845 goto out;
2846 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002847 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002848 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002849 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
2850 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2851 err_code |= ERR_ALERT | ERR_FATAL;
2852 goto out;
2853 }
2854 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002855 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002856 int cur_arg;
2857 int port1, port2;
2858 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002859
2860 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2861 err_code |= ERR_WARN;
2862
2863 if (!*args[1]) {
2864 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2865 file, linenum, "source", "usesrc", "interface");
2866 err_code |= ERR_ALERT | ERR_FATAL;
2867 goto out;
2868 }
2869
Christopher Faulet31930372019-07-15 10:16:58 +02002870 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002871 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2872 free(curproxy->conn_src.iface_name);
2873 curproxy->conn_src.iface_name = NULL;
2874 curproxy->conn_src.iface_len = 0;
2875
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002876 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2877 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002878 if (!sk) {
2879 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2880 file, linenum, args[0], args[1], errmsg);
2881 err_code |= ERR_ALERT | ERR_FATAL;
2882 goto out;
2883 }
2884
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002885 curproxy->conn_src.source_addr = *sk;
2886 curproxy->conn_src.opts |= CO_SRC_BIND;
2887
2888 cur_arg = 2;
2889 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002890 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002891#if defined(CONFIG_HAP_TRANSPARENT)
2892 if (!*args[cur_arg + 1]) {
2893 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2894 file, linenum, "usesrc");
2895 err_code |= ERR_ALERT | ERR_FATAL;
2896 goto out;
2897 }
2898
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002899 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002900 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2901 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002902 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002903 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2904 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2905 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2906 char *name, *end;
2907
2908 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002909 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002910 name++;
2911
2912 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002913 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002914 end++;
2915
2916 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2917 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002918 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002919 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
2920 curproxy->conn_src.bind_hdr_len = end - name;
2921 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2922 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2923 curproxy->conn_src.bind_hdr_occ = -1;
2924
2925 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002926 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002927 end++;
2928 if (*end == ',') {
2929 end++;
2930 name = end;
2931 if (*end == '-')
2932 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002933 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002934 end++;
2935 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2936 }
2937
2938 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2939 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2940 " occurrences values smaller than %d.\n",
2941 file, linenum, MAX_HDR_HISTORY);
2942 err_code |= ERR_ALERT | ERR_FATAL;
2943 goto out;
2944 }
2945 } else {
2946 struct sockaddr_storage *sk;
2947
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002948 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2949 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002950 if (!sk) {
2951 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2952 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2953 err_code |= ERR_ALERT | ERR_FATAL;
2954 goto out;
2955 }
2956
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002957 curproxy->conn_src.tproxy_addr = *sk;
2958 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2959 }
2960 global.last_checks |= LSTCHK_NETADM;
2961#else /* no TPROXY support */
2962 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2963 file, linenum, "usesrc");
2964 err_code |= ERR_ALERT | ERR_FATAL;
2965 goto out;
2966#endif
2967 cur_arg += 2;
2968 continue;
2969 }
2970
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002971 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002972#ifdef SO_BINDTODEVICE
2973 if (!*args[cur_arg + 1]) {
2974 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2975 file, linenum, args[0]);
2976 err_code |= ERR_ALERT | ERR_FATAL;
2977 goto out;
2978 }
2979 free(curproxy->conn_src.iface_name);
2980 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
2981 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2982 global.last_checks |= LSTCHK_NETADM;
2983#else
2984 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2985 file, linenum, args[0], args[cur_arg]);
2986 err_code |= ERR_ALERT | ERR_FATAL;
2987 goto out;
2988#endif
2989 cur_arg += 2;
2990 continue;
2991 }
2992 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2993 file, linenum, args[0], "interface", "usesrc");
2994 err_code |= ERR_ALERT | ERR_FATAL;
2995 goto out;
2996 }
2997 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002998 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002999 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
3000 file, linenum, "usesrc", "source");
3001 err_code |= ERR_ALERT | ERR_FATAL;
3002 goto out;
3003 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003004 else if (strcmp(args[0], "cliexp") == 0 || strcmp(args[0], "reqrep") == 0) { /* replace request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003005 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01003006 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003007 file, linenum, args[0]);
3008 err_code |= ERR_ALERT | ERR_FATAL;
3009 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003010 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003011 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003012 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3013 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3014 err_code |= ERR_ALERT | ERR_FATAL;
3015 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003016 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003017 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003018 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
3019 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3020 err_code |= ERR_ALERT | ERR_FATAL;
3021 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003022 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003023 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003024 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3025 err_code |= ERR_ALERT | ERR_FATAL;
3026 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003027 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003028 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003029 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3030 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3031 err_code |= ERR_ALERT | ERR_FATAL;
3032 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003033 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003034 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003035 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3036 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3037 err_code |= ERR_ALERT | ERR_FATAL;
3038 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003039 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003040 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003041 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3042 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
3043 err_code |= ERR_ALERT | ERR_FATAL;
3044 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003045 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003046 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003047 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3048 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
3049 err_code |= ERR_ALERT | ERR_FATAL;
3050 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003051 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003052 else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003053 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3054 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
3055 err_code |= ERR_ALERT | ERR_FATAL;
3056 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003057 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003058 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003059 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
3060 err_code |= ERR_ALERT | ERR_FATAL;
3061 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003062 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003063 else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003064 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3065 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
3066 err_code |= ERR_ALERT | ERR_FATAL;
3067 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003068 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003069 else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003070 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3071 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
3072 err_code |= ERR_ALERT | ERR_FATAL;
3073 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003074 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003075 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003076 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3077 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3078 err_code |= ERR_ALERT | ERR_FATAL;
3079 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003080 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003081 else if (strcmp(args[0], "srvexp") == 0 || strcmp(args[0], "rsprep") == 0) { /* replace response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003082 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3083 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3084 err_code |= ERR_ALERT | ERR_FATAL;
3085 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003086 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003087 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003088 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3089 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3090 err_code |= ERR_ALERT | ERR_FATAL;
3091 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003092 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003093 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003094 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3095 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3096 err_code |= ERR_ALERT | ERR_FATAL;
3097 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003098 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003099 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303100 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003101 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3102 err_code |= ERR_ALERT | ERR_FATAL;
3103 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003104 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003105 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003106 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3107 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3108 err_code |= ERR_ALERT | ERR_FATAL;
3109 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003110 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003111 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003112 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3113 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3114 err_code |= ERR_ALERT | ERR_FATAL;
3115 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003116 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003117 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003118 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3119 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3120 err_code |= ERR_ALERT | ERR_FATAL;
3121 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003122 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003123 else {
3124 struct cfg_kw_list *kwl;
3125 int index;
3126
3127 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3128 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3129 if (kwl->kw[index].section != CFG_LISTEN)
3130 continue;
3131 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
3132 /* prepare error message just in case */
3133 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
3134 if (rc < 0) {
3135 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3136 err_code |= ERR_ALERT | ERR_FATAL;
3137 goto out;
3138 }
3139 else if (rc > 0) {
3140 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3141 err_code |= ERR_WARN;
3142 goto out;
3143 }
3144 goto out;
3145 }
3146 }
3147 }
3148
3149 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
3150 err_code |= ERR_ALERT | ERR_FATAL;
3151 goto out;
3152 }
3153 out:
3154 free(errmsg);
3155 return err_code;
3156}