blob: ea9dae6641b5b5abb59d3171128d70ecb1da048c [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>
Willy Tarreaue9dcb3c2021-05-08 13:00:23 +020034#include <haproxy/tools.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020035#include <haproxy/uri_auth.h>
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010036
Willy Tarreauc0ff6792021-03-12 09:14:19 +010037/* some keywords that are still being parsed using strcmp() and are not
38 * registered anywhere. They are used as suggestions for mistyped words.
39 */
40static const char *common_kw_list[] = {
41 "listen", "frontend", "backend", "defaults", "server",
42 "default-server", "server-template", "bind", "monitor-net",
43 "monitor-uri", "mode", "id", "description", "disabled", "enabled",
44 "bind-process", "acl", "dynamic-cookie-key", "cookie", "email-alert",
45 "persist", "appsession", "load-server-state-from-file",
46 "server-state-file-name", "max-session-srv-conns", "capture",
47 "retries", "http-request", "http-response", "http-after-response",
48 "http-send-name-header", "block", "redirect", "use_backend",
49 "use-server", "force-persist", "ignore-persist", "force-persist",
50 "stick-table", "stick", "stats", "option", "default_backend",
51 "http-reuse", "monitor", "transparent", "maxconn", "backlog",
Willy Tarreaueb778242021-06-11 16:27:10 +020052 "fullconn", "dispatch", "balance", "hash-type",
Willy Tarreauc0ff6792021-03-12 09:14:19 +010053 "hash-balance-factor", "unique-id-format", "unique-id-header",
54 "log-format", "log-format-sd", "log-tag", "log", "source", "usesrc",
55 NULL /* must be last */
56};
Willy Tarreau7d0c1432021-02-12 12:29:28 +010057
Willy Tarreau31a3cea2021-03-15 11:11:55 +010058static const char *common_options[] = {
Willy Tarreau6ba69842021-06-11 16:01:50 +020059 "httpclose", "http-server-close", "http-keep-alive",
Willy Tarreaud2f25372021-06-11 16:06:29 +020060 "redispatch", "httplog", "tcplog", "tcpka", "httpchk",
Willy Tarreau31a3cea2021-03-15 11:11:55 +010061 "ssl-hello-chk", "smtpchk", "pgsql-check", "redis-check",
62 "mysql-check", "ldap-check", "spop-check", "tcp-check",
63 "external-check", "forwardfor", "original-to",
64 NULL /* must be last */
65};
66
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010067/* Report a warning if a rule is placed after a 'tcp-request session' rule.
68 * Return 1 if the warning has been emitted, otherwise 0.
69 */
70int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
71{
72 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
73 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
74 file, line, arg);
75 return 1;
76 }
77 return 0;
78}
79
80/* Report a warning if a rule is placed after a 'tcp-request content' rule.
81 * Return 1 if the warning has been emitted, otherwise 0.
82 */
83int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
84{
85 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
86 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
87 file, line, arg);
88 return 1;
89 }
90 return 0;
91}
92
93/* Report a warning if a rule is placed after a 'monitor fail' rule.
94 * Return 1 if the warning has been emitted, otherwise 0.
95 */
96int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
97{
98 if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) {
99 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n",
100 file, line, arg);
101 return 1;
102 }
103 return 0;
104}
105
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100106/* Report a warning if a rule is placed after an 'http_request' rule.
107 * Return 1 if the warning has been emitted, otherwise 0.
108 */
109int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
110{
111 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
112 ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
113 file, line, arg);
114 return 1;
115 }
116 return 0;
117}
118
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100119/* Report a warning if a rule is placed after a redirect rule.
120 * Return 1 if the warning has been emitted, otherwise 0.
121 */
122int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
123{
124 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
125 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
126 file, line, arg);
127 return 1;
128 }
129 return 0;
130}
131
132/* Report a warning if a rule is placed after a 'use_backend' rule.
133 * Return 1 if the warning has been emitted, otherwise 0.
134 */
135int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
136{
137 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
138 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
139 file, line, arg);
140 return 1;
141 }
142 return 0;
143}
144
145/* Report a warning if a rule is placed after a 'use-server' rule.
146 * Return 1 if the warning has been emitted, otherwise 0.
147 */
148int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
149{
150 if (!LIST_ISEMPTY(&proxy->server_rules)) {
151 ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
152 file, line, arg);
153 return 1;
154 }
155 return 0;
156}
157
158/* report a warning if a redirect rule is dangerously placed */
159int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
160{
161 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
162 warnif_rule_after_use_server(proxy, file, line, arg);
163}
164
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100165/* report a warning if an http-request rule is dangerously placed */
166int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
167{
Christopher Faulet1b6adb42019-07-17 15:33:14 +0200168 return warnif_rule_after_redirect(proxy, file, line, arg) ||
169 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100170}
171
172/* report a warning if a block rule is dangerously placed */
Christopher Faulet8c3b63a2019-07-17 15:19:51 +0200173int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100174{
175 return warnif_rule_after_http_req(proxy, file, line, arg) ||
176 warnif_misplaced_http_req(proxy, file, line, arg);
177}
178
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100179/* report a warning if a "tcp request content" rule is dangerously placed */
180int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
181{
182 return warnif_rule_after_monitor(proxy, file, line, arg) ||
183 warnif_misplaced_monitor(proxy, file, line, arg);
184}
185
186/* report a warning if a "tcp request session" rule is dangerously placed */
187int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
188{
189 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
190 warnif_misplaced_tcp_cont(proxy, file, line, arg);
191}
192
193/* report a warning if a "tcp request connection" rule is dangerously placed */
194int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
195{
196 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
197 warnif_misplaced_tcp_sess(proxy, file, line, arg);
198}
199
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100200int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
201{
202 static struct proxy *curproxy = NULL;
Willy Tarreauab3410c2021-02-12 12:17:30 +0100203 static struct proxy *curr_defproxy = NULL;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100204 static struct proxy *last_defproxy = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100205 const char *err;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100206 int rc;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100207 int err_code = 0;
208 struct acl_cond *cond = NULL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100209 char *errmsg = NULL;
210 struct bind_conf *bind_conf;
211
Willy Tarreaue90904d2021-02-12 14:08:31 +0100212 if (!last_defproxy) {
213 /* we need a default proxy and none was created yet */
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100214 last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg);
215 proxy_preset_defaults(last_defproxy);
216
Willy Tarreaue90904d2021-02-12 14:08:31 +0100217 curr_defproxy = last_defproxy;
218 if (!last_defproxy) {
219 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
220 err_code |= ERR_ALERT | ERR_ABORT;
221 goto out;
222 }
Willy Tarreau7d0c1432021-02-12 12:29:28 +0100223 }
224
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100225 if (strcmp(args[0], "listen") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200226 rc = PR_CAP_LISTEN | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100227 else if (strcmp(args[0], "frontend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200228 rc = PR_CAP_FE | PR_CAP_LB;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100229 else if (strcmp(args[0], "backend") == 0)
Amaury Denoyelleb979f592021-05-07 15:12:20 +0200230 rc = PR_CAP_BE | PR_CAP_LB;
Willy Tarreaue90904d2021-02-12 14:08:31 +0100231 else if (strcmp(args[0], "defaults") == 0) {
232 /* "defaults" must first delete the last no-name defaults if any */
233 proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0));
234 curr_defproxy = NULL;
235 rc = PR_CAP_DEF | PR_CAP_LISTEN;
236 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100237 else
238 rc = PR_CAP_NONE;
239
Willy Tarreaue90904d2021-02-12 14:08:31 +0100240 if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100241 if (!*args[1]) {
Willy Tarreaub2ec9942021-02-12 13:28:22 +0100242 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100243 file, linenum, args[0]);
244 err_code |= ERR_ALERT | ERR_ABORT;
245 goto out;
246 }
247
248 err = invalid_char(args[1]);
249 if (err) {
250 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
251 file, linenum, *err, args[0], args[1]);
252 err_code |= ERR_ALERT | ERR_FATAL;
253 }
254
255 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
256 if (curproxy) {
257 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
258 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
259 curproxy->id, curproxy->conf.file, curproxy->conf.line);
260 err_code |= ERR_ALERT | ERR_FATAL;
261 }
262
Emeric Brunb0c331f2020-10-07 17:05:59 +0200263 curproxy = log_forward_by_name(args[1]);
264 if (curproxy) {
265 ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
266 file, linenum, proxy_cap_str(rc), args[1],
267 curproxy->id, curproxy->conf.file, curproxy->conf.line);
268 err_code |= ERR_ALERT | ERR_FATAL;
269 }
270
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100271 if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
272 alertif_too_many_args(3, file, linenum, args, &err_code)) {
Willy Tarreau76838932021-02-12 08:49:47 +0100273 if (rc & PR_CAP_FE)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100274 ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
275 goto out;
276 }
Willy Tarreaue90904d2021-02-12 14:08:31 +0100277 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100278
Willy Tarreaue90904d2021-02-12 14:08:31 +0100279 if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */
Willy Tarreau7c0b4d82021-02-12 14:58:08 +0100280 const char *name = args[1];
281 int arg = 2;
282
283 if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) {
284 // also support "defaults from blah" (no name then)
285 arg = 1;
286 name = "";
287 }
288
289 /* only regular proxies inherit from the previous defaults section */
290 if (!(rc & PR_CAP_DEF))
291 curr_defproxy = last_defproxy;
292
293 if (strcmp(args[arg], "from") == 0) {
294 curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
295
296 if (!curr_defproxy) {
297 ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name);
298 err_code |= ERR_ALERT | ERR_ABORT;
299 goto out;
300 }
301
302 if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
303 struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
304
305 ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
306 file, linenum, args[arg+1], proxy_cap_str(rc), name,
307 curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line);
308 err_code |= ERR_ALERT | ERR_FATAL;
309 }
310
311 err = invalid_char(args[arg+1]);
312 if (err) {
313 ha_alert("parsing [%s:%d] : character '%c' is not permitted in defaults section name '%s' when designated by its name (section found at %s:%d).\n",
314 file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
315 err_code |= ERR_ALERT | ERR_FATAL;
316 }
317 }
318
Amaury Denoyelle476b9ad2021-03-23 17:27:05 +0100319 curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);
Willy Tarreau76838932021-02-12 08:49:47 +0100320 if (!curproxy) {
Willy Tarreau76838932021-02-12 08:49:47 +0100321 err_code |= ERR_ALERT | ERR_ABORT;
Christopher Faulet76edc0f2020-01-13 15:52:01 +0100322 goto out;
323 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100324
Willy Tarreaue90904d2021-02-12 14:08:31 +0100325 if (rc & PR_CAP_DEF) {
326 /* last and current proxies must be updated to this one */
327 curr_defproxy = last_defproxy = curproxy;
328 } else {
329 /* regular proxies are in a list */
330 curproxy->next = proxies_list;
331 proxies_list = curproxy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100332 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100333 goto out;
334 }
335 else if (curproxy == NULL) {
336 ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
337 err_code |= ERR_ALERT | ERR_FATAL;
338 goto out;
339 }
340
341 /* update the current file and line being parsed */
342 curproxy->conf.args.file = curproxy->conf.file;
343 curproxy->conf.args.line = linenum;
344
345 /* Now let's parse the proxy-specific keywords */
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100346 if ((strcmp(args[0], "server") == 0)) {
347 err_code |= parse_server(file, linenum, args,
348 curproxy, curr_defproxy,
349 SRV_PARSE_PARSE_ADDR);
350
351 if (err_code & ERR_FATAL)
352 goto out;
353 }
354 else if (strcmp(args[0], "default-server") == 0) {
355 err_code |= parse_server(file, linenum, args,
356 curproxy, curr_defproxy,
357 SRV_PARSE_DEFAULT_SERVER);
358
359 if (err_code & ERR_FATAL)
360 goto out;
361 }
362 else if (strcmp(args[0], "server-template") == 0) {
363 err_code |= parse_server(file, linenum, args,
364 curproxy, curr_defproxy,
365 SRV_PARSE_TEMPLATE|SRV_PARSE_PARSE_ADDR);
366
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100367 if (err_code & ERR_FATAL)
368 goto out;
369 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100370 else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100371 struct listener *l;
372 int cur_arg;
373
Willy Tarreau5d095c22021-02-12 10:15:59 +0100374 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100375 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
376 err_code |= ERR_ALERT | ERR_FATAL;
377 goto out;
378 }
379 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
380 err_code |= ERR_WARN;
381
382 if (!*(args[1])) {
383 ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
384 file, linenum, args[0]);
385 err_code |= ERR_ALERT | ERR_FATAL;
386 goto out;
387 }
388
389 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Christopher Fauletb15625a2021-04-12 21:31:45 +0200390 if (!bind_conf)
391 goto alloc_error;
392
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100393 /* use default settings for unix sockets */
Willy Tarreau6e459d72020-09-03 07:09:09 +0200394 bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
395 bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
396 bind_conf->settings.ux.mode = global.unix_bind.ux.mode;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100397
398 /* NOTE: the following line might create several listeners if there
399 * are comma-separated IPs or port ranges. So all further processing
400 * will have to be applied to all listeners created after last_listen.
401 */
402 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
403 if (errmsg && *errmsg) {
404 indent_msg(&errmsg, 2);
405 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
406 }
407 else
408 ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
409 file, linenum, args[0], args[1]);
410 err_code |= ERR_ALERT | ERR_FATAL;
411 goto out;
412 }
413
414 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
415 /* Set default global rights and owner for unix bind */
416 global.maxsock++;
417 }
418
419 cur_arg = 2;
420 while (*(args[cur_arg])) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100421 struct bind_kw *kw;
Willy Tarreau433b05f2021-03-12 10:14:07 +0100422 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100423
424 kw = bind_find_kw(args[cur_arg]);
425 if (kw) {
426 char *err = NULL;
427 int code;
428
429 if (!kw->parse) {
430 ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
431 file, linenum, args[0], args[1], args[cur_arg]);
432 cur_arg += 1 + kw->skip ;
433 err_code |= ERR_ALERT | ERR_FATAL;
434 goto out;
435 }
436
437 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
438 err_code |= code;
439
440 if (code) {
441 if (err && *err) {
442 indent_msg(&err, 2);
Emeric Brun0655c9b2019-10-17 16:45:56 +0200443 if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
444 ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
445 else
446 ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100447 }
448 else
449 ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
450 file, linenum, args[0], args[1], args[cur_arg]);
451 if (code & ERR_FATAL) {
452 free(err);
453 cur_arg += 1 + kw->skip;
454 goto out;
455 }
456 }
457 free(err);
458 cur_arg += 1 + kw->skip;
459 continue;
460 }
461
Willy Tarreau433b05f2021-03-12 10:14:07 +0100462 best = bind_find_best_kw(args[cur_arg]);
463 if (best)
464 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
465 file, linenum, args[0], args[1], args[cur_arg], best);
466 else
467 ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
468 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100469
470 err_code |= ERR_ALERT | ERR_FATAL;
471 goto out;
472 }
473 goto out;
474 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100475 else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */
Willy Tarreau9e9919d2020-10-14 15:55:23 +0200476 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]);
477 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100478 goto out;
479 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100480 else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100481 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
482 err_code |= ERR_WARN;
483
484 if (alertif_too_many_args(1, file, linenum, args, &err_code))
485 goto out;
486
487 if (!*args[1]) {
488 ha_alert("parsing [%s:%d] : '%s' expects an URI.\n",
489 file, linenum, args[0]);
490 err_code |= ERR_ALERT | ERR_FATAL;
491 goto out;
492 }
493
494 free(curproxy->monitor_uri);
495 curproxy->monitor_uri_len = strlen(args[1]);
496 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200497 if (!curproxy->monitor_uri)
498 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100499 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
500 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
501
502 goto out;
503 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100504 else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100505 if (alertif_too_many_args(1, file, linenum, args, &err_code))
506 goto out;
507
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100508 if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP;
509 else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP;
510 else if (strcmp(args[1], "health") == 0) {
Willy Tarreau77e0dae2020-10-14 15:44:27 +0200511 ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum);
512 err_code |= ERR_ALERT | ERR_FATAL;
513 goto out;
514 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100515 else {
516 ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
517 err_code |= ERR_ALERT | ERR_FATAL;
518 goto out;
519 }
520 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100521 else if (strcmp(args[0], "id") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100522 struct eb32_node *node;
523
Willy Tarreau5d095c22021-02-12 10:15:59 +0100524 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100525 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
526 file, linenum, args[0]);
527 err_code |= ERR_ALERT | ERR_FATAL;
528 goto out;
529 }
530
531 if (alertif_too_many_args(1, file, linenum, args, &err_code))
532 goto out;
533
534 if (!*args[1]) {
535 ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
536 file, linenum, args[0]);
537 err_code |= ERR_ALERT | ERR_FATAL;
538 goto out;
539 }
540
541 curproxy->uuid = atol(args[1]);
542 curproxy->conf.id.key = curproxy->uuid;
543 curproxy->options |= PR_O_FORCED_ID;
544
545 if (curproxy->uuid <= 0) {
546 ha_alert("parsing [%s:%d]: custom id has to be > 0.\n",
547 file, linenum);
548 err_code |= ERR_ALERT | ERR_FATAL;
549 goto out;
550 }
551
552 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
553 if (node) {
554 struct proxy *target = container_of(node, struct proxy, conf.id);
555 ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
556 file, linenum, proxy_type_str(curproxy), curproxy->id,
557 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
558 err_code |= ERR_ALERT | ERR_FATAL;
559 goto out;
560 }
561 eb32_insert(&used_proxy_id, &curproxy->conf.id);
562 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100563 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100564 int i, len=0;
565 char *d;
566
Willy Tarreau5d095c22021-02-12 10:15:59 +0100567 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100568 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
569 file, linenum, args[0]);
570 err_code |= ERR_ALERT | ERR_FATAL;
571 goto out;
572 }
573
574 if (!*args[1]) {
575 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
576 file, linenum, args[0]);
577 return -1;
578 }
579
580 for (i = 1; *args[i]; i++)
581 len += strlen(args[i]) + 1;
582
583 d = calloc(1, len);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200584 if (!d)
585 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100586 curproxy->desc = d;
587
588 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
589 for (i = 2; *args[i]; i++)
590 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
591
592 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100593 else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100594 if (alertif_too_many_args(0, file, linenum, args, &err_code))
595 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200596 curproxy->disabled = 1;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100597 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100598 else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100599 if (alertif_too_many_args(0, file, linenum, args, &err_code))
600 goto out;
Willy Tarreauc3914d42020-09-24 08:39:22 +0200601 curproxy->disabled = 0;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100602 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100603 else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100604 int cur_arg = 1;
605 unsigned long set = 0;
606
607 while (*args[cur_arg]) {
608 if (strcmp(args[cur_arg], "all") == 0) {
609 set = 0;
610 break;
611 }
Willy Tarreauff9c9142019-02-07 10:39:36 +0100612 if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100613 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
614 err_code |= ERR_ALERT | ERR_FATAL;
615 goto out;
616 }
617 cur_arg++;
618 }
619 curproxy->bind_proc = set;
620 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100621 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100622 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100623 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
624 err_code |= ERR_ALERT | ERR_FATAL;
625 goto out;
626 }
627
628 err = invalid_char(args[1]);
629 if (err) {
630 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
631 file, linenum, *err, args[1]);
632 err_code |= ERR_ALERT | ERR_FATAL;
633 goto out;
634 }
635
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100636 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100637 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100638 "logical disjunction within a condition.\n",
639 file, linenum, args[1]);
640 err_code |= ERR_ALERT | ERR_FATAL;
641 goto out;
642 }
643
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100644 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
645 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
646 file, linenum, args[1], errmsg);
647 err_code |= ERR_ALERT | ERR_FATAL;
648 goto out;
649 }
650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100651 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100652
653 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
654 err_code |= ERR_WARN;
655
656 if (*(args[1]) == 0) {
657 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
658 file, linenum, args[0]);
659 err_code |= ERR_ALERT | ERR_FATAL;
660 goto out;
661 }
662 free(curproxy->dyncookie_key);
663 curproxy->dyncookie_key = strdup(args[1]);
664 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100665 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100666 int cur_arg;
667
668 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
669 err_code |= ERR_WARN;
670
671 if (*(args[1]) == 0) {
672 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
673 file, linenum, args[0]);
674 err_code |= ERR_ALERT | ERR_FATAL;
675 goto out;
676 }
677
678 curproxy->ck_opts = 0;
679 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100680 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100681 free(curproxy->cookie_name);
682 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200683 if (!curproxy->cookie_name)
684 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100685 curproxy->cookie_len = strlen(curproxy->cookie_name);
686
687 cur_arg = 2;
688 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100689 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100690 curproxy->ck_opts |= PR_CK_RW;
691 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100692 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100693 curproxy->ck_opts |= PR_CK_IND;
694 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100695 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100696 curproxy->ck_opts |= PR_CK_INS;
697 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100698 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100699 curproxy->ck_opts |= PR_CK_NOC;
700 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100701 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100702 curproxy->ck_opts |= PR_CK_POST;
703 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100704 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100705 curproxy->ck_opts |= PR_CK_PSV;
706 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100707 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100708 curproxy->ck_opts |= PR_CK_PFX;
709 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100710 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100711 curproxy->ck_opts |= PR_CK_HTTPONLY;
712 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100713 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100714 curproxy->ck_opts |= PR_CK_SECURE;
715 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100716 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100717 if (!*args[cur_arg + 1]) {
718 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
719 file, linenum, args[cur_arg]);
720 err_code |= ERR_ALERT | ERR_FATAL;
721 goto out;
722 }
723
Joao Moraise1583752019-10-30 21:04:00 -0300724 if (!strchr(args[cur_arg + 1], '.')) {
725 /* rfc6265, 5.2.3 The Domain Attribute */
726 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
727 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100728 file, linenum, args[cur_arg + 1]);
729 err_code |= ERR_WARN;
730 }
731
732 err = invalid_domainchar(args[cur_arg + 1]);
733 if (err) {
734 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
735 file, linenum, *err, args[cur_arg + 1]);
736 err_code |= ERR_ALERT | ERR_FATAL;
737 goto out;
738 }
739
740 if (!curproxy->cookie_domain) {
741 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
742 } else {
743 /* one domain was already specified, add another one by
744 * building the string which will be returned along with
745 * the cookie.
746 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200747 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
748 }
749
Christopher Fauletb15625a2021-04-12 21:31:45 +0200750 if (!curproxy->cookie_domain)
751 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100752 cur_arg++;
753 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100754 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100755 unsigned int maxidle;
756 const char *res;
757
758 if (!*args[cur_arg + 1]) {
759 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
760 file, linenum, args[cur_arg]);
761 err_code |= ERR_ALERT | ERR_FATAL;
762 goto out;
763 }
764
765 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200766 if (res == PARSE_TIME_OVER) {
767 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
768 file, linenum, args[cur_arg+1], args[cur_arg]);
769 err_code |= ERR_ALERT | ERR_FATAL;
770 goto out;
771 }
772 else if (res == PARSE_TIME_UNDER) {
773 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
774 file, linenum, args[cur_arg+1], args[cur_arg]);
775 err_code |= ERR_ALERT | ERR_FATAL;
776 goto out;
777 }
778 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100779 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
780 file, linenum, *res, args[cur_arg]);
781 err_code |= ERR_ALERT | ERR_FATAL;
782 goto out;
783 }
784 curproxy->cookie_maxidle = maxidle;
785 cur_arg++;
786 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100787 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100788 unsigned int maxlife;
789 const char *res;
790
791 if (!*args[cur_arg + 1]) {
792 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
793 file, linenum, args[cur_arg]);
794 err_code |= ERR_ALERT | ERR_FATAL;
795 goto out;
796 }
797
Willy Tarreau9faebe32019-06-07 19:00:37 +0200798
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100799 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200800 if (res == PARSE_TIME_OVER) {
801 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
802 file, linenum, args[cur_arg+1], args[cur_arg]);
803 err_code |= ERR_ALERT | ERR_FATAL;
804 goto out;
805 }
806 else if (res == PARSE_TIME_UNDER) {
807 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
808 file, linenum, args[cur_arg+1], args[cur_arg]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100813 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
814 file, linenum, *res, args[cur_arg]);
815 err_code |= ERR_ALERT | ERR_FATAL;
816 goto out;
817 }
818 curproxy->cookie_maxlife = maxlife;
819 cur_arg++;
820 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100821 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100822
823 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
824 err_code |= ERR_WARN;
825 curproxy->ck_opts |= PR_CK_DYNAMIC;
826 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100827 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100828 char *val;
829 if (!*args[cur_arg + 1]) {
830 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
831 file, linenum, args[cur_arg]);
832 err_code |= ERR_ALERT | ERR_FATAL;
833 goto out;
834 }
835 val = args[cur_arg + 1];
836 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100837 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100838 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
839 file, linenum, *val);
840 err_code |= ERR_ALERT | ERR_FATAL;
841 goto out;
842 }
843 val++;
844 }
845 /* don't add ';' for the first attribute */
846 if (!curproxy->cookie_attrs)
847 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
848 else
849 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200850
Christopher Fauletb15625a2021-04-12 21:31:45 +0200851 if (!curproxy->cookie_attrs)
852 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100853 cur_arg++;
854 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100855
856 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100857 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 +0100858 file, linenum, args[0]);
859 err_code |= ERR_ALERT | ERR_FATAL;
860 goto out;
861 }
862 cur_arg++;
863 }
864 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
865 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
866 file, linenum);
867 err_code |= ERR_ALERT | ERR_FATAL;
868 }
869
870 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
871 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
872 file, linenum);
873 err_code |= ERR_ALERT | ERR_FATAL;
874 }
875
876 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
877 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
878 file, linenum);
879 err_code |= ERR_ALERT | ERR_FATAL;
880 }
881 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100882 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100883 if (*(args[1]) == 0) {
884 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
885 file, linenum, args[0]);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto out;
888 }
889
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100890 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100891 if (*(args[1]) == 0) {
892 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
893 file, linenum, args[1]);
894 err_code |= ERR_ALERT | ERR_FATAL;
895 goto out;
896 }
897 free(curproxy->email_alert.from);
898 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200899 if (!curproxy->email_alert.from)
900 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100901 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100902 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100903 if (*(args[1]) == 0) {
904 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
905 file, linenum, args[1]);
906 err_code |= ERR_ALERT | ERR_FATAL;
907 goto out;
908 }
909 free(curproxy->email_alert.mailers.name);
910 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200911 if (!curproxy->email_alert.mailers.name)
912 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100913 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100914 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100915 if (*(args[1]) == 0) {
916 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
917 file, linenum, args[1]);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921 free(curproxy->email_alert.myhostname);
922 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200923 if (!curproxy->email_alert.myhostname)
924 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100925 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100926 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100927 curproxy->email_alert.level = get_log_level(args[2]);
928 if (curproxy->email_alert.level < 0) {
929 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
930 file, linenum, args[1], args[2]);
931 err_code |= ERR_ALERT | ERR_FATAL;
932 goto out;
933 }
934 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100935 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100936 if (*(args[1]) == 0) {
937 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
938 file, linenum, args[1]);
939 err_code |= ERR_ALERT | ERR_FATAL;
940 goto out;
941 }
942 free(curproxy->email_alert.to);
943 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200944 if (!curproxy->email_alert.to)
945 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100946 }
947 else {
948 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
949 file, linenum, args[1]);
950 err_code |= ERR_ALERT | ERR_FATAL;
951 goto out;
952 }
953 /* Indicate that the email_alert is at least partially configured */
954 curproxy->email_alert.set = 1;
955 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100956 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100957 if (*(args[1]) == 0) {
958 ha_alert("parsing [%s:%d] : missing persist method.\n",
959 file, linenum);
960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
962 }
963
964 if (!strncmp(args[1], "rdp-cookie", 10)) {
965 curproxy->options2 |= PR_O2_RDPC_PRST;
966
967 if (*(args[1] + 10) == '(') { /* cookie name */
968 const char *beg, *end;
969
970 beg = args[1] + 11;
971 end = strchr(beg, ')');
972
973 if (alertif_too_many_args(1, file, linenum, args, &err_code))
974 goto out;
975
976 if (!end || end == beg) {
977 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
978 file, linenum);
979 err_code |= ERR_ALERT | ERR_FATAL;
980 goto out;
981 }
982
983 free(curproxy->rdp_cookie_name);
984 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200985 if (!curproxy->rdp_cookie_name)
986 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100987 curproxy->rdp_cookie_len = end-beg;
988 }
989 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
990 free(curproxy->rdp_cookie_name);
991 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +0200992 if (!curproxy->rdp_cookie_name)
993 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100994 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
995 }
996 else { /* syntax */
997 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
998 file, linenum);
999 err_code |= ERR_ALERT | ERR_FATAL;
1000 goto out;
1001 }
1002 }
1003 else {
1004 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1005 file, linenum);
1006 err_code |= ERR_ALERT | ERR_FATAL;
1007 goto out;
1008 }
1009 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001010 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001011 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 +01001012 err_code |= ERR_ALERT | ERR_FATAL;
1013 goto out;
1014 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001015 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001016 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1017 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001018 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001019 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1020 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001021 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 +01001022 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1023 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001024 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001025 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1026 }
1027 else {
1028 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1029 file, linenum, args[0], args[1]);
1030 err_code |= ERR_ALERT | ERR_FATAL;
1031 goto out;
1032 }
1033 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001034 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001035 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1036 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001037 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001038 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001039
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001040 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001041
1042 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001043 curproxy->server_state_file_name = strdup(curproxy->id);
1044 else
1045 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001046
Christopher Fauletb15625a2021-04-12 21:31:45 +02001047 if (!curproxy->server_state_file_name)
1048 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001049 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001050 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001051 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1052 err_code |= ERR_WARN;
1053 if (*(args[1]) == 0) {
1054 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1055 file, linenum, args[0]);
1056 err_code |= ERR_ALERT | ERR_FATAL;
1057 goto out;
1058 }
1059 curproxy->max_out_conns = atoi(args[1]);
1060 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001061 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001062 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1063 err_code |= ERR_WARN;
1064
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001065 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001066 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001067 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071
1072 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1073 goto out;
1074
1075 if (*(args[4]) == 0) {
1076 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1077 file, linenum, args[0]);
1078 err_code |= ERR_ALERT | ERR_FATAL;
1079 goto out;
1080 }
1081 free(curproxy->capture_name);
1082 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001083 if (!curproxy->capture_name)
1084 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001085 curproxy->capture_namelen = strlen(curproxy->capture_name);
1086 curproxy->capture_len = atol(args[4]);
1087 curproxy->to_log |= LW_COOKIE;
1088 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001089 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001090 struct cap_hdr *hdr;
1091
Willy Tarreau5d095c22021-02-12 10:15:59 +01001092 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001093 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1094 err_code |= ERR_ALERT | ERR_FATAL;
1095 goto out;
1096 }
1097
1098 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1099 goto out;
1100
1101 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1102 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1103 file, linenum, args[0], args[1]);
1104 err_code |= ERR_ALERT | ERR_FATAL;
1105 goto out;
1106 }
1107
1108 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001109 if (!hdr)
1110 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001111 hdr->next = curproxy->req_cap;
1112 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001113 if (!hdr->name)
1114 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001115 hdr->namelen = strlen(args[3]);
1116 hdr->len = atol(args[5]);
1117 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001118 if (!hdr->pool) {
1119 req_caphdr_alloc_error:
1120 if (hdr)
1121 ha_free(&hdr->name);
1122 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001123 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001124 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001125 hdr->index = curproxy->nb_req_cap++;
1126 curproxy->req_cap = hdr;
1127 curproxy->to_log |= LW_REQHDR;
1128 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001129 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001130 struct cap_hdr *hdr;
1131
Willy Tarreau5d095c22021-02-12 10:15:59 +01001132 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001133 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1134 err_code |= ERR_ALERT | ERR_FATAL;
1135 goto out;
1136 }
1137
1138 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1139 goto out;
1140
1141 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1142 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1143 file, linenum, args[0], args[1]);
1144 err_code |= ERR_ALERT | ERR_FATAL;
1145 goto out;
1146 }
1147 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001148 if (!hdr)
1149 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001150 hdr->next = curproxy->rsp_cap;
1151 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001152 if (!hdr->name)
1153 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001154 hdr->namelen = strlen(args[3]);
1155 hdr->len = atol(args[5]);
1156 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001157 if (!hdr->pool) {
1158 res_caphdr_alloc_error:
1159 if (hdr)
1160 ha_free(&hdr->name);
1161 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001162 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001163 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001164 hdr->index = curproxy->nb_rsp_cap++;
1165 curproxy->rsp_cap = hdr;
1166 curproxy->to_log |= LW_RSPHDR;
1167 }
1168 else {
1169 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1170 file, linenum, args[0]);
1171 err_code |= ERR_ALERT | ERR_FATAL;
1172 goto out;
1173 }
1174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001175 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001176 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1177 err_code |= ERR_WARN;
1178
1179 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1180 goto out;
1181
1182 if (*(args[1]) == 0) {
1183 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1184 file, linenum, args[0]);
1185 err_code |= ERR_ALERT | ERR_FATAL;
1186 goto out;
1187 }
1188 curproxy->conn_retries = atol(args[1]);
1189 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001190 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001191 struct act_rule *rule;
1192
Willy Tarreau5d095c22021-02-12 10:15:59 +01001193 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001194 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1195 err_code |= ERR_ALERT | ERR_FATAL;
1196 goto out;
1197 }
1198
1199 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1200 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001201 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001202 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1203 file, linenum, args[0]);
1204 err_code |= ERR_WARN;
1205 }
1206
1207 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1208
1209 if (!rule) {
1210 err_code |= ERR_ALERT | ERR_ABORT;
1211 goto out;
1212 }
1213
1214 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1215 err_code |= warnif_cond_conflicts(rule->cond,
1216 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1217 file, linenum);
1218
Willy Tarreau2b718102021-04-21 07:32:39 +02001219 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001220 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001221 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001222 struct act_rule *rule;
1223
Willy Tarreau5d095c22021-02-12 10:15:59 +01001224 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001225 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1226 err_code |= ERR_ALERT | ERR_FATAL;
1227 goto out;
1228 }
1229
1230 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1231 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001232 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001233 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1234 file, linenum, args[0]);
1235 err_code |= ERR_WARN;
1236 }
1237
1238 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1239
1240 if (!rule) {
1241 err_code |= ERR_ALERT | ERR_ABORT;
1242 goto out;
1243 }
1244
1245 err_code |= warnif_cond_conflicts(rule->cond,
1246 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1247 file, linenum);
1248
Willy Tarreau2b718102021-04-21 07:32:39 +02001249 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001250 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001251 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001252 struct act_rule *rule;
1253
Willy Tarreau5d095c22021-02-12 10:15:59 +01001254 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001255 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1256 err_code |= ERR_ALERT | ERR_FATAL;
1257 goto out;
1258 }
1259
1260 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1261 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1262 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1263 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1264 file, linenum, args[0]);
1265 err_code |= ERR_WARN;
1266 }
1267
1268 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1269
1270 if (!rule) {
1271 err_code |= ERR_ALERT | ERR_ABORT;
1272 goto out;
1273 }
1274
1275 err_code |= warnif_cond_conflicts(rule->cond,
1276 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1277 file, linenum);
1278
Willy Tarreau2b718102021-04-21 07:32:39 +02001279 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001280 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001281 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001282 /* set the header name and length into the proxy structure */
1283 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1284 err_code |= ERR_WARN;
1285
1286 if (!*args[1]) {
1287 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1288 file, linenum, args[0]);
1289 err_code |= ERR_ALERT | ERR_FATAL;
1290 goto out;
1291 }
1292
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001293 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001294 free(curproxy->server_id_hdr_name);
1295 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001296 if (!curproxy->server_id_hdr_name)
1297 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001298 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001299 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 +01001300 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001301 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001302 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 +01001303
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001304 err_code |= ERR_ALERT | ERR_FATAL;
1305 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001306 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001307 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001308 struct redirect_rule *rule;
1309
Willy Tarreau5d095c22021-02-12 10:15:59 +01001310 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001311 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1312 err_code |= ERR_ALERT | ERR_FATAL;
1313 goto out;
1314 }
1315
1316 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1317 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1318 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1319 err_code |= ERR_ALERT | ERR_FATAL;
1320 goto out;
1321 }
1322
Willy Tarreau2b718102021-04-21 07:32:39 +02001323 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001324 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1325 err_code |= warnif_cond_conflicts(rule->cond,
1326 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1327 file, linenum);
1328 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001329 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001330 struct switching_rule *rule;
1331
Willy Tarreau5d095c22021-02-12 10:15:59 +01001332 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001333 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1334 err_code |= ERR_ALERT | ERR_FATAL;
1335 goto out;
1336 }
1337
1338 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1339 err_code |= ERR_WARN;
1340
1341 if (*(args[1]) == 0) {
1342 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1343 err_code |= ERR_ALERT | ERR_FATAL;
1344 goto out;
1345 }
1346
1347 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1348 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1349 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1350 file, linenum, errmsg);
1351 err_code |= ERR_ALERT | ERR_FATAL;
1352 goto out;
1353 }
1354
1355 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1356 }
1357 else if (*args[2]) {
1358 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1359 file, linenum, args[2]);
1360 err_code |= ERR_ALERT | ERR_FATAL;
1361 goto out;
1362 }
1363
1364 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001365 if (!rule)
1366 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001367 rule->cond = cond;
1368 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001369 if (!rule->be.name)
1370 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001371 rule->line = linenum;
1372 rule->file = strdup(file);
1373 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001374 use_backend_alloc_error:
1375 if (cond)
1376 prune_acl_cond(cond);
1377 ha_free(&cond);
1378 if (rule)
1379 ha_free(&(rule->be.name));
1380 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001381 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001382 }
1383 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001384 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001385 }
1386 else if (strcmp(args[0], "use-server") == 0) {
1387 struct server_rule *rule;
1388
Willy Tarreau5d095c22021-02-12 10:15:59 +01001389 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001390 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1391 err_code |= ERR_ALERT | ERR_FATAL;
1392 goto out;
1393 }
1394
1395 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1396 err_code |= ERR_WARN;
1397
1398 if (*(args[1]) == 0) {
1399 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1400 err_code |= ERR_ALERT | ERR_FATAL;
1401 goto out;
1402 }
1403
1404 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1405 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1406 file, linenum, args[0]);
1407 err_code |= ERR_ALERT | ERR_FATAL;
1408 goto out;
1409 }
1410
1411 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1412 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1413 file, linenum, errmsg);
1414 err_code |= ERR_ALERT | ERR_FATAL;
1415 goto out;
1416 }
1417
1418 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1419
1420 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001421 if (!rule)
1422 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001423 rule->cond = cond;
1424 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001425 if (!rule->srv.name)
1426 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001427 rule->line = linenum;
1428 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001429 if (!rule->file) {
1430 use_server_alloc_error:
1431 if (cond)
1432 prune_acl_cond(cond);
1433 ha_free(&cond);
1434 if (rule)
1435 ha_free(&(rule->srv.name));
1436 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001437 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001438 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001439 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001440 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001441 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1442 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001443 else if ((strcmp(args[0], "force-persist") == 0) ||
1444 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001445 struct persist_rule *rule;
1446
Willy Tarreau5d095c22021-02-12 10:15:59 +01001447 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001448 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1449 err_code |= ERR_ALERT | ERR_FATAL;
1450 goto out;
1451 }
1452
1453 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1454 err_code |= ERR_WARN;
1455
1456 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1457 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1458 file, linenum, args[0]);
1459 err_code |= ERR_ALERT | ERR_FATAL;
1460 goto out;
1461 }
1462
1463 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1464 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1465 file, linenum, args[0], errmsg);
1466 err_code |= ERR_ALERT | ERR_FATAL;
1467 goto out;
1468 }
1469
1470 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1471 * where force-persist is applied.
1472 */
1473 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1474
1475 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001476 if (!rule) {
1477 if (cond)
1478 prune_acl_cond(cond);
1479 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001480 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001481 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001482 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001483 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001484 rule->type = PERSIST_TYPE_FORCE;
1485 } else {
1486 rule->type = PERSIST_TYPE_IGNORE;
1487 }
1488 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001489 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001490 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001491 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001492 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001493
Willy Tarreau5d095c22021-02-12 10:15:59 +01001494 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001495 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1496 file, linenum);
1497 err_code |= ERR_ALERT | ERR_FATAL;
1498 goto out;
1499 }
1500
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001501 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001502 if (other) {
1503 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 +01001504 file, linenum, curproxy->id,
1505 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1506 other->proxy ? other->id : other->peers.p->id,
1507 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001508 err_code |= ERR_ALERT | ERR_FATAL;
1509 goto out;
1510 }
1511
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001512 curproxy->table = calloc(1, sizeof *curproxy->table);
1513 if (!curproxy->table) {
1514 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1515 file, linenum, args[0], args[1]);
1516 err_code |= ERR_ALERT | ERR_FATAL;
1517 goto out;
1518 }
1519
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001520 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1521 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001522 if (err_code & ERR_FATAL) {
1523 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001524 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001525 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001526
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001527 /* Store the proxy in the stick-table. */
1528 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001529
1530 stktable_store_name(curproxy->table);
1531 curproxy->table->next = stktables_list;
1532 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001533
1534 /* Add this proxy to the list of proxies which refer to its stick-table. */
1535 if (curproxy->table->proxies_list != curproxy) {
1536 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1537 curproxy->table->proxies_list = curproxy;
1538 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001539 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001540 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001541 struct sticking_rule *rule;
1542 struct sample_expr *expr;
1543 int myidx = 0;
1544 const char *name = NULL;
1545 int flags;
1546
Willy Tarreau5d095c22021-02-12 10:15:59 +01001547 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001548 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1549 err_code |= ERR_ALERT | ERR_FATAL;
1550 goto out;
1551 }
1552
1553 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1554 err_code |= ERR_WARN;
1555 goto out;
1556 }
1557
1558 myidx++;
1559 if ((strcmp(args[myidx], "store") == 0) ||
1560 (strcmp(args[myidx], "store-request") == 0)) {
1561 myidx++;
1562 flags = STK_IS_STORE;
1563 }
1564 else if (strcmp(args[myidx], "store-response") == 0) {
1565 myidx++;
1566 flags = STK_IS_STORE | STK_ON_RSP;
1567 }
1568 else if (strcmp(args[myidx], "match") == 0) {
1569 myidx++;
1570 flags = STK_IS_MATCH;
1571 }
1572 else if (strcmp(args[myidx], "on") == 0) {
1573 myidx++;
1574 flags = STK_IS_MATCH | STK_IS_STORE;
1575 }
1576 else {
1577 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1578 err_code |= ERR_ALERT | ERR_FATAL;
1579 goto out;
1580 }
1581
1582 if (*(args[myidx]) == 0) {
1583 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1584 err_code |= ERR_ALERT | ERR_FATAL;
1585 goto out;
1586 }
1587
1588 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001589 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001590 if (!expr) {
1591 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1592 err_code |= ERR_ALERT | ERR_FATAL;
1593 goto out;
1594 }
1595
1596 if (flags & STK_ON_RSP) {
1597 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1598 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1599 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1600 err_code |= ERR_ALERT | ERR_FATAL;
1601 free(expr);
1602 goto out;
1603 }
1604 } else {
1605 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1606 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1607 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1608 err_code |= ERR_ALERT | ERR_FATAL;
1609 free(expr);
1610 goto out;
1611 }
1612 }
1613
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001614 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001615 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1616
1617 if (strcmp(args[myidx], "table") == 0) {
1618 myidx++;
1619 name = args[myidx++];
1620 }
1621
1622 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1623 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1624 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1625 file, linenum, args[0], errmsg);
1626 err_code |= ERR_ALERT | ERR_FATAL;
1627 free(expr);
1628 goto out;
1629 }
1630 }
1631 else if (*(args[myidx])) {
1632 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1633 file, linenum, args[0], args[myidx]);
1634 err_code |= ERR_ALERT | ERR_FATAL;
1635 free(expr);
1636 goto out;
1637 }
1638 if (flags & STK_ON_RSP)
1639 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1640 else
1641 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1642
1643 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001644 if (!rule) {
1645 if (cond)
1646 prune_acl_cond(cond);
1647 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001648 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001649 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001650 rule->cond = cond;
1651 rule->expr = expr;
1652 rule->flags = flags;
1653 rule->table.name = name ? strdup(name) : NULL;
1654 LIST_INIT(&rule->list);
1655 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001656 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001657 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001658 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001659 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001660 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001661 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001662 curproxy->uri_auth = NULL; /* we must detach from the default config */
1663
1664 if (!*args[1]) {
1665 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001666 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001667 struct stats_admin_rule *rule;
1668
Willy Tarreau5d095c22021-02-12 10:15:59 +01001669 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001670 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1671 err_code |= ERR_ALERT | ERR_FATAL;
1672 goto out;
1673 }
1674
Christopher Fauletb15625a2021-04-12 21:31:45 +02001675 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1676 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001677
1678 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1679 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1680 file, linenum, args[0], args[1]);
1681 err_code |= ERR_ALERT | ERR_FATAL;
1682 goto out;
1683 }
1684 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1685 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1686 file, linenum, args[0], args[1], errmsg);
1687 err_code |= ERR_ALERT | ERR_FATAL;
1688 goto out;
1689 }
1690
1691 err_code |= warnif_cond_conflicts(cond,
1692 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1693 file, linenum);
1694
1695 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001696 if (!rule) {
1697 if (cond)
1698 prune_acl_cond(cond);
1699 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001700 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001701 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001702 rule->cond = cond;
1703 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001704 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001705 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001706 if (*(args[2]) == 0) {
1707 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1708 err_code |= ERR_ALERT | ERR_FATAL;
1709 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001710 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1711 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001712 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001713 if (*(args[2]) == 0) {
1714 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1715 err_code |= ERR_ALERT | ERR_FATAL;
1716 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001717 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1718 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001719 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001720 unsigned interval;
1721
1722 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001723 if (err == PARSE_TIME_OVER) {
1724 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1725 file, linenum, args[2]);
1726 err_code |= ERR_ALERT | ERR_FATAL;
1727 goto out;
1728 }
1729 else if (err == PARSE_TIME_UNDER) {
1730 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1731 file, linenum, args[2]);
1732 err_code |= ERR_ALERT | ERR_FATAL;
1733 goto out;
1734 }
1735 else if (err) {
1736 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001737 file, linenum, *err);
1738 err_code |= ERR_ALERT | ERR_FATAL;
1739 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001740 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1741 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001742 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001743 struct act_rule *rule;
1744
Willy Tarreau5d095c22021-02-12 10:15:59 +01001745 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001746 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1747 err_code |= ERR_ALERT | ERR_FATAL;
1748 goto out;
1749 }
1750
Christopher Fauletb15625a2021-04-12 21:31:45 +02001751 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1752 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001753
1754 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1755 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1756 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1757 file, linenum, args[0]);
1758 err_code |= ERR_WARN;
1759 }
1760
1761 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1762
1763 if (!rule) {
1764 err_code |= ERR_ALERT | ERR_ABORT;
1765 goto out;
1766 }
1767
1768 err_code |= warnif_cond_conflicts(rule->cond,
1769 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1770 file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001771 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001772
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001773 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001774 if (*(args[2]) == 0) {
1775 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1776 err_code |= ERR_ALERT | ERR_FATAL;
1777 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001778 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1779 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001780 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001781 if (*(args[2]) == 0) {
1782 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1783 err_code |= ERR_ALERT | ERR_FATAL;
1784 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001785 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1786 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001787 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001788 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1789 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001790 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001791 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1792 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001793 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001794 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1795 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001796 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001797 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1798 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001799 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001800
1801 if (*args[2]) {
1802 int i;
1803 char c;
1804
1805 for (i=0; args[2][i]; i++) {
1806 c = args[2][i];
1807 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1808 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1809 break;
1810 }
1811
1812 if (!i || args[2][i]) {
1813 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1814 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1815 file, linenum, args[0], args[1]);
1816 err_code |= ERR_ALERT | ERR_FATAL;
1817 goto out;
1818 }
1819 }
1820
Christopher Fauletb15625a2021-04-12 21:31:45 +02001821 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1822 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001823 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001824 char *desc = NULL;
1825
1826 if (*args[2]) {
1827 int i, len=0;
1828 char *d;
1829
1830 for (i = 2; *args[i]; i++)
1831 len += strlen(args[i]) + 1;
1832
1833 desc = d = calloc(1, len);
1834
1835 d += snprintf(d, desc + len - d, "%s", args[2]);
1836 for (i = 3; *args[i]; i++)
1837 d += snprintf(d, desc + len - d, " %s", args[i]);
1838 }
1839
1840 if (!*args[2] && !global.desc)
1841 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1842 file, linenum, args[1]);
1843 else {
1844 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1845 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001846 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001847 }
1848 free(desc);
1849 }
1850 } else {
1851stats_error_parsing:
1852 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1853 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1854 err_code |= ERR_ALERT | ERR_FATAL;
1855 goto out;
1856 }
1857 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001858 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001859 int optnum;
1860
1861 if (*(args[1]) == '\0') {
1862 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1863 file, linenum, args[0]);
1864 err_code |= ERR_ALERT | ERR_FATAL;
1865 goto out;
1866 }
1867
1868 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001869 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001870 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1871 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1872 file, linenum, cfg_opts[optnum].name);
1873 err_code |= ERR_ALERT | ERR_FATAL;
1874 goto out;
1875 }
1876 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1877 goto out;
1878
1879 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1880 err_code |= ERR_WARN;
1881 goto out;
1882 }
1883
1884 curproxy->no_options &= ~cfg_opts[optnum].val;
1885 curproxy->options &= ~cfg_opts[optnum].val;
1886
1887 switch (kwm) {
1888 case KWM_STD:
1889 curproxy->options |= cfg_opts[optnum].val;
1890 break;
1891 case KWM_NO:
1892 curproxy->no_options |= cfg_opts[optnum].val;
1893 break;
1894 case KWM_DEF: /* already cleared */
1895 break;
1896 }
1897
1898 goto out;
1899 }
1900 }
1901
1902 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001903 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001904 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1905 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1906 file, linenum, cfg_opts2[optnum].name);
1907 err_code |= ERR_ALERT | ERR_FATAL;
1908 goto out;
1909 }
1910 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1911 goto out;
1912 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1913 err_code |= ERR_WARN;
1914 goto out;
1915 }
1916
1917 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1918 curproxy->options2 &= ~cfg_opts2[optnum].val;
1919
1920 switch (kwm) {
1921 case KWM_STD:
1922 curproxy->options2 |= cfg_opts2[optnum].val;
1923 break;
1924 case KWM_NO:
1925 curproxy->no_options2 |= cfg_opts2[optnum].val;
1926 break;
1927 case KWM_DEF: /* already cleared */
1928 break;
1929 }
1930 goto out;
1931 }
1932 }
1933
1934 /* HTTP options override each other. They can be cancelled using
1935 * "no option xxx" which only switches to default mode if the mode
1936 * was this one (useful for cancelling options set in defaults
1937 * sections).
1938 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001939 if (strcmp(args[1], "forceclose") == 0) {
1940 ha_alert("parsing [%s:%d]: option '%s' is not supported any more since HAProxy 2.0, please just remove it, or use 'option httpclose' if absolutely needed.\n",
1941 file, linenum, args[1]);
1942 err_code |= ERR_ALERT | ERR_FATAL;
1943 goto out;
1944 }
1945 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001946 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1947 goto out;
1948 if (kwm == KWM_STD) {
1949 curproxy->options &= ~PR_O_HTTP_MODE;
1950 curproxy->options |= PR_O_HTTP_CLO;
1951 goto out;
1952 }
1953 else if (kwm == KWM_NO) {
1954 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1955 curproxy->options &= ~PR_O_HTTP_MODE;
1956 goto out;
1957 }
1958 }
1959 else if (strcmp(args[1], "http-server-close") == 0) {
1960 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1961 goto out;
1962 if (kwm == KWM_STD) {
1963 curproxy->options &= ~PR_O_HTTP_MODE;
1964 curproxy->options |= PR_O_HTTP_SCL;
1965 goto out;
1966 }
1967 else if (kwm == KWM_NO) {
1968 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1969 curproxy->options &= ~PR_O_HTTP_MODE;
1970 goto out;
1971 }
1972 }
1973 else if (strcmp(args[1], "http-keep-alive") == 0) {
1974 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1975 goto out;
1976 if (kwm == KWM_STD) {
1977 curproxy->options &= ~PR_O_HTTP_MODE;
1978 curproxy->options |= PR_O_HTTP_KAL;
1979 goto out;
1980 }
1981 else if (kwm == KWM_NO) {
1982 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1983 curproxy->options &= ~PR_O_HTTP_MODE;
1984 goto out;
1985 }
1986 }
1987 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02001988 ha_alert("parsing [%s:%d]: option '%s' is not supported any more since HAProxy 2.1, please just remove it, it shouldn't be needed.\n",
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001989 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02001990 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001991 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001992 }
1993
1994 /* Redispatch can take an integer argument that control when the
1995 * resispatch occurs. All values are relative to the retries option.
1996 * This can be cancelled using "no option xxx".
1997 */
1998 if (strcmp(args[1], "redispatch") == 0) {
1999 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2000 err_code |= ERR_WARN;
2001 goto out;
2002 }
2003
2004 curproxy->no_options &= ~PR_O_REDISP;
2005 curproxy->options &= ~PR_O_REDISP;
2006
2007 switch (kwm) {
2008 case KWM_STD:
2009 curproxy->options |= PR_O_REDISP;
2010 curproxy->redispatch_after = -1;
2011 if(*args[2]) {
2012 curproxy->redispatch_after = atol(args[2]);
2013 }
2014 break;
2015 case KWM_NO:
2016 curproxy->no_options |= PR_O_REDISP;
2017 curproxy->redispatch_after = 0;
2018 break;
2019 case KWM_DEF: /* already cleared */
2020 break;
2021 }
2022 goto out;
2023 }
2024
2025 if (kwm != KWM_STD) {
2026 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2027 file, linenum, args[1]);
2028 err_code |= ERR_ALERT | ERR_FATAL;
2029 goto out;
2030 }
2031
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002032 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002033 char *logformat;
2034 /* generate a complete HTTP log */
2035 logformat = default_http_log_format;
2036 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002037 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002038 curproxy->options2 |= PR_O2_CLFLOG;
2039 logformat = clf_http_log_format;
2040 } else {
2041 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2042 err_code |= ERR_ALERT | ERR_FATAL;
2043 goto out;
2044 }
2045 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2046 goto out;
2047 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002048 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002049 char *oldlogformat = "log-format";
2050 char *clflogformat = "";
2051
2052 if (curproxy->conf.logformat_string == default_http_log_format)
2053 oldlogformat = "option httplog";
2054 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2055 oldlogformat = "option tcplog";
2056 else if (curproxy->conf.logformat_string == clf_http_log_format)
2057 oldlogformat = "option httplog clf";
2058 if (logformat == clf_http_log_format)
2059 clflogformat = " clf";
2060 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2061 file, linenum, clflogformat, oldlogformat);
2062 }
2063 if (curproxy->conf.logformat_string != default_http_log_format &&
2064 curproxy->conf.logformat_string != default_tcp_log_format &&
2065 curproxy->conf.logformat_string != clf_http_log_format)
2066 free(curproxy->conf.logformat_string);
2067 curproxy->conf.logformat_string = logformat;
2068
2069 free(curproxy->conf.lfs_file);
2070 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2071 curproxy->conf.lfs_line = curproxy->conf.args.line;
2072
Willy Tarreau5d095c22021-02-12 10:15:59 +01002073 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002074 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2075 file, linenum, curproxy->id);
2076 err_code |= ERR_WARN;
2077 }
2078 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002079 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002080 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002081 char *oldlogformat = "log-format";
2082
2083 if (curproxy->conf.logformat_string == default_http_log_format)
2084 oldlogformat = "option httplog";
2085 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2086 oldlogformat = "option tcplog";
2087 else if (curproxy->conf.logformat_string == clf_http_log_format)
2088 oldlogformat = "option httplog clf";
2089 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2090 file, linenum, oldlogformat);
2091 }
2092 /* generate a detailed TCP log */
2093 if (curproxy->conf.logformat_string != default_http_log_format &&
2094 curproxy->conf.logformat_string != default_tcp_log_format &&
2095 curproxy->conf.logformat_string != clf_http_log_format)
2096 free(curproxy->conf.logformat_string);
2097 curproxy->conf.logformat_string = default_tcp_log_format;
2098
2099 free(curproxy->conf.lfs_file);
2100 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2101 curproxy->conf.lfs_line = curproxy->conf.args.line;
2102
2103 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2104 goto out;
2105
Willy Tarreau5d095c22021-02-12 10:15:59 +01002106 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002107 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2108 file, linenum, curproxy->id);
2109 err_code |= ERR_WARN;
2110 }
2111 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002112 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002113 /* enable TCP keep-alives on client and server streams */
2114 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2115 err_code |= ERR_WARN;
2116
2117 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2118 goto out;
2119
2120 if (curproxy->cap & PR_CAP_FE)
2121 curproxy->options |= PR_O_TCP_CLI_KA;
2122 if (curproxy->cap & PR_CAP_BE)
2123 curproxy->options |= PR_O_TCP_SRV_KA;
2124 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002125 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002126 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002127 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002128 goto out;
2129 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002130 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002131 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002132 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002133 goto out;
2134 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002135 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002136 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002137 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002138 goto out;
2139 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002140 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002141 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002142 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002143 goto out;
2144 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002145 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002146 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002147 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002148 goto out;
2149 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002150 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002151 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002152 if (err_code & ERR_FATAL)
2153 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002154 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002155 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002156 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002157 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002158 goto out;
2159 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002160 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002161 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002162 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002163 goto out;
2164 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002165 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002166 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002167 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002168 goto out;
2169 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002170 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002171 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002172 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002173 goto out;
2174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002175 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002176 int cur_arg;
2177
2178 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002179 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002180 */
2181
2182 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2183
2184 free(curproxy->fwdfor_hdr_name);
2185 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002186 if (!curproxy->fwdfor_hdr_name)
2187 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002188 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002189 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002190
2191 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2192 cur_arg = 2;
2193 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002194 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002195 unsigned char mask;
2196 int i;
2197
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002198 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002199 if (*(args[cur_arg+1]) &&
2200 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2201 curproxy->except_xff_net.family = AF_INET;
2202 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2203 }
2204 else if (*(args[cur_arg+1]) &&
2205 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2206 curproxy->except_xff_net.family = AF_INET6;
2207 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2208 for (i = 0; i < 16; i++)
2209 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2210 }
2211 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002212 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2213 file, linenum, args[0], args[1], args[cur_arg]);
2214 err_code |= ERR_ALERT | ERR_FATAL;
2215 goto out;
2216 }
2217 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002218 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002219 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002220 /* suboption header - needs additional argument for it */
2221 if (*(args[cur_arg+1]) == 0) {
2222 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2223 file, linenum, args[0], args[1], args[cur_arg]);
2224 err_code |= ERR_ALERT | ERR_FATAL;
2225 goto out;
2226 }
2227 free(curproxy->fwdfor_hdr_name);
2228 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002229 if (!curproxy->fwdfor_hdr_name)
2230 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002231 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2232 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002233 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002234 curproxy->options &= ~PR_O_FF_ALWAYS;
2235 cur_arg += 1;
2236 } else {
2237 /* unknown suboption - catchall */
2238 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2239 file, linenum, args[0], args[1]);
2240 err_code |= ERR_ALERT | ERR_FATAL;
2241 goto out;
2242 }
2243 } /* end while loop */
2244 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002245 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002246 int cur_arg;
2247
2248 /* insert x-original-to field, but not for the IP address listed as an except.
2249 * set default options (ie: bitfield, header name, etc)
2250 */
2251
2252 curproxy->options |= PR_O_ORGTO;
2253
2254 free(curproxy->orgto_hdr_name);
2255 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002256 if (!curproxy->orgto_hdr_name)
2257 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002258 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002259 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002260
2261 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2262 cur_arg = 2;
2263 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002264 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002265 unsigned char mask;
2266 int i;
2267
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002268 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002269 if (*(args[cur_arg+1]) &&
2270 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2271 curproxy->except_xot_net.family = AF_INET;
2272 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2273 }
2274 else if (*(args[cur_arg+1]) &&
2275 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2276 curproxy->except_xot_net.family = AF_INET6;
2277 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2278 for (i = 0; i < 16; i++)
2279 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2280 }
2281 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002282 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2283 file, linenum, args[0], args[1], args[cur_arg]);
2284 err_code |= ERR_ALERT | ERR_FATAL;
2285 goto out;
2286 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002287 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002288 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002289 /* suboption header - needs additional argument for it */
2290 if (*(args[cur_arg+1]) == 0) {
2291 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2292 file, linenum, args[0], args[1], args[cur_arg]);
2293 err_code |= ERR_ALERT | ERR_FATAL;
2294 goto out;
2295 }
2296 free(curproxy->orgto_hdr_name);
2297 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002298 if (!curproxy->orgto_hdr_name)
2299 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002300 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2301 cur_arg += 2;
2302 } else {
2303 /* unknown suboption - catchall */
2304 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2305 file, linenum, args[0], args[1]);
2306 err_code |= ERR_ALERT | ERR_FATAL;
2307 goto out;
2308 }
2309 } /* end while loop */
2310 }
2311 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002312 const char *best = proxy_find_best_option(args[1], common_options);
2313
2314 if (best)
2315 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2316 else
2317 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2318
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002319 err_code |= ERR_ALERT | ERR_FATAL;
2320 goto out;
2321 }
2322 goto out;
2323 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002324 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002325 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2326 err_code |= ERR_WARN;
2327
2328 if (*(args[1]) == 0) {
2329 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2330 err_code |= ERR_ALERT | ERR_FATAL;
2331 goto out;
2332 }
2333 free(curproxy->defbe.name);
2334 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002335 if (!curproxy->defbe.name)
2336 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002337
2338 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2339 goto out;
2340 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002341 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002342 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 +01002343
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002344 err_code |= ERR_ALERT | ERR_FATAL;
2345 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002346 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002347 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002348 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2349 err_code |= ERR_WARN;
2350
2351 if (strcmp(args[1], "never") == 0) {
2352 /* enable a graceful server shutdown on an HTTP 404 response */
2353 curproxy->options &= ~PR_O_REUSE_MASK;
2354 curproxy->options |= PR_O_REUSE_NEVR;
2355 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2356 goto out;
2357 }
2358 else if (strcmp(args[1], "safe") == 0) {
2359 /* enable a graceful server shutdown on an HTTP 404 response */
2360 curproxy->options &= ~PR_O_REUSE_MASK;
2361 curproxy->options |= PR_O_REUSE_SAFE;
2362 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2363 goto out;
2364 }
2365 else if (strcmp(args[1], "aggressive") == 0) {
2366 curproxy->options &= ~PR_O_REUSE_MASK;
2367 curproxy->options |= PR_O_REUSE_AGGR;
2368 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2369 goto out;
2370 }
2371 else if (strcmp(args[1], "always") == 0) {
2372 /* enable a graceful server shutdown on an HTTP 404 response */
2373 curproxy->options &= ~PR_O_REUSE_MASK;
2374 curproxy->options |= PR_O_REUSE_ALWS;
2375 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2376 goto out;
2377 }
2378 else {
2379 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2380 err_code |= ERR_ALERT | ERR_FATAL;
2381 goto out;
2382 }
2383 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002384 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002385 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002386 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2387 err_code |= ERR_ALERT | ERR_FATAL;
2388 goto out;
2389 }
2390
2391 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2392 err_code |= ERR_WARN;
2393
2394 if (strcmp(args[1], "fail") == 0) {
2395 /* add a condition to fail monitor requests */
2396 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2397 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2398 file, linenum, args[0], args[1]);
2399 err_code |= ERR_ALERT | ERR_FATAL;
2400 goto out;
2401 }
2402
2403 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2404 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2405 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2406 file, linenum, args[0], args[1], errmsg);
2407 err_code |= ERR_ALERT | ERR_FATAL;
2408 goto out;
2409 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002410 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002411 }
2412 else {
2413 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2414 err_code |= ERR_ALERT | ERR_FATAL;
2415 goto out;
2416 }
2417 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002418#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002419 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002420 /* enable transparent proxy connections */
2421 curproxy->options |= PR_O_TRANSP;
2422 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2423 goto out;
2424 }
2425#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002426 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002427 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2428 err_code |= ERR_WARN;
2429
2430 if (*(args[1]) == 0) {
2431 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2432 err_code |= ERR_ALERT | ERR_FATAL;
2433 goto out;
2434 }
2435 curproxy->maxconn = atol(args[1]);
2436 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2437 goto out;
2438 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002439 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002440 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2441 err_code |= ERR_WARN;
2442
2443 if (*(args[1]) == 0) {
2444 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2445 err_code |= ERR_ALERT | ERR_FATAL;
2446 goto out;
2447 }
2448 curproxy->backlog = atol(args[1]);
2449 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2450 goto out;
2451 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002452 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002453 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2454 err_code |= ERR_WARN;
2455
2456 if (*(args[1]) == 0) {
2457 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2458 err_code |= ERR_ALERT | ERR_FATAL;
2459 goto out;
2460 }
2461 curproxy->fullconn = atol(args[1]);
2462 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2463 goto out;
2464 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002465 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002466 ha_alert("parsing [%s:%d]: the '%s' keyword is not supported any more since HAProxy version 2.5.\n",
Willy Tarreauab0a5192020-10-09 19:07:01 +02002467 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002468 err_code |= ERR_ALERT | ERR_FATAL;
2469 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002470 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002471 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002472 struct sockaddr_storage *sk;
2473 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002474
Willy Tarreau5d095c22021-02-12 10:15:59 +01002475 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002476 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2477 err_code |= ERR_ALERT | ERR_FATAL;
2478 goto out;
2479 }
2480 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2481 err_code |= ERR_WARN;
2482
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002483 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2484 &errmsg, NULL, NULL,
2485 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 +01002486 if (!sk) {
2487 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2488 err_code |= ERR_ALERT | ERR_FATAL;
2489 goto out;
2490 }
2491
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002492 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2493 goto out;
2494
2495 curproxy->dispatch_addr = *sk;
2496 curproxy->options |= PR_O_DISPATCH;
2497 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002498 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002499 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2500 err_code |= ERR_WARN;
2501
2502 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2503 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2504 err_code |= ERR_ALERT | ERR_FATAL;
2505 goto out;
2506 }
2507 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002508 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002509 /**
2510 * The syntax for hash-type config element is
2511 * hash-type {map-based|consistent} [[<algo>] avalanche]
2512 *
2513 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2514 */
2515 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2516
2517 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2518 err_code |= ERR_WARN;
2519
2520 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2521 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2522 }
2523 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2524 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2525 }
2526 else if (strcmp(args[1], "avalanche") == 0) {
2527 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]);
2528 err_code |= ERR_ALERT | ERR_FATAL;
2529 goto out;
2530 }
2531 else {
2532 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2533 err_code |= ERR_ALERT | ERR_FATAL;
2534 goto out;
2535 }
2536
2537 /* set the hash function to use */
2538 if (!*args[2]) {
2539 /* the default algo is sdbm */
2540 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2541
2542 /* if consistent with no argument, then avalanche modifier is also applied */
2543 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2544 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2545 } else {
2546 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002547 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002548 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2549 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002550 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002551 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2552 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002553 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002554 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2555 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002556 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002557 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2558 }
2559 else {
2560 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2561 err_code |= ERR_ALERT | ERR_FATAL;
2562 goto out;
2563 }
2564
2565 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002566 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002567 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2568 }
2569 else if (*args[3]) {
2570 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2571 err_code |= ERR_ALERT | ERR_FATAL;
2572 goto out;
2573 }
2574 }
2575 }
2576 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2577 if (*(args[1]) == 0) {
2578 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2579 err_code |= ERR_ALERT | ERR_FATAL;
2580 goto out;
2581 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002582 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2583 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002584 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2585 err_code |= ERR_ALERT | ERR_FATAL;
2586 goto out;
2587 }
2588 }
2589 else if (strcmp(args[0], "unique-id-format") == 0) {
2590 if (!*(args[1])) {
2591 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2592 err_code |= ERR_ALERT | ERR_FATAL;
2593 goto out;
2594 }
2595 if (*(args[2])) {
2596 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2597 err_code |= ERR_ALERT | ERR_FATAL;
2598 goto out;
2599 }
2600 free(curproxy->conf.uniqueid_format_string);
2601 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002602 if (!curproxy->conf.uniqueid_format_string)
2603 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604
2605 free(curproxy->conf.uif_file);
2606 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2607 curproxy->conf.uif_line = curproxy->conf.args.line;
2608 }
2609
2610 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002611 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002612 if (!*(args[1])) {
2613 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2614 err_code |= ERR_ALERT | ERR_FATAL;
2615 goto out;
2616 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002617 copy = strdup(args[1]);
2618 if (copy == NULL) {
2619 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2620 err_code |= ERR_ALERT | ERR_FATAL;
2621 goto out;
2622 }
2623
2624 istfree(&curproxy->header_unique_id);
2625 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002626 }
2627
2628 else if (strcmp(args[0], "log-format") == 0) {
2629 if (!*(args[1])) {
2630 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2631 err_code |= ERR_ALERT | ERR_FATAL;
2632 goto out;
2633 }
2634 if (*(args[2])) {
2635 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2636 err_code |= ERR_ALERT | ERR_FATAL;
2637 goto out;
2638 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002639 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002640 char *oldlogformat = "log-format";
2641
2642 if (curproxy->conf.logformat_string == default_http_log_format)
2643 oldlogformat = "option httplog";
2644 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2645 oldlogformat = "option tcplog";
2646 else if (curproxy->conf.logformat_string == clf_http_log_format)
2647 oldlogformat = "option httplog clf";
2648 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2649 file, linenum, oldlogformat);
2650 }
2651 if (curproxy->conf.logformat_string != default_http_log_format &&
2652 curproxy->conf.logformat_string != default_tcp_log_format &&
2653 curproxy->conf.logformat_string != clf_http_log_format)
2654 free(curproxy->conf.logformat_string);
2655 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002656 if (!curproxy->conf.logformat_string)
2657 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002658
2659 free(curproxy->conf.lfs_file);
2660 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2661 curproxy->conf.lfs_line = curproxy->conf.args.line;
2662
2663 /* get a chance to improve log-format error reporting by
2664 * reporting the correct line-number when possible.
2665 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002666 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002667 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2668 file, linenum, curproxy->id);
2669 err_code |= ERR_WARN;
2670 }
2671 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002672 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002673 if (!*(args[1])) {
2674 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2675 err_code |= ERR_ALERT | ERR_FATAL;
2676 goto out;
2677 }
2678 if (*(args[2])) {
2679 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2680 err_code |= ERR_ALERT | ERR_FATAL;
2681 goto out;
2682 }
2683
2684 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2685 free(curproxy->conf.logformat_sd_string);
2686 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002687 if (!curproxy->conf.logformat_sd_string)
2688 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002689
2690 free(curproxy->conf.lfsd_file);
2691 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2692 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2693
2694 /* get a chance to improve log-format-sd error reporting by
2695 * reporting the correct line-number when possible.
2696 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002697 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002698 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2699 file, linenum, curproxy->id);
2700 err_code |= ERR_WARN;
2701 }
2702 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002703 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002704 if (*(args[1]) == 0) {
2705 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2706 err_code |= ERR_ALERT | ERR_FATAL;
2707 goto out;
2708 }
2709 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002710 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2711 if (b_orig(&curproxy->log_tag) == NULL) {
2712 chunk_destroy(&curproxy->log_tag);
2713 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2714 err_code |= ERR_ALERT | ERR_FATAL;
2715 goto out;
2716 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002717 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002718 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002719 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002720 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2721 err_code |= ERR_ALERT | ERR_FATAL;
2722 goto out;
2723 }
2724 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002725 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002726 int cur_arg;
2727 int port1, port2;
2728 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002729
2730 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2731 err_code |= ERR_WARN;
2732
2733 if (!*args[1]) {
2734 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2735 file, linenum, "source", "usesrc", "interface");
2736 err_code |= ERR_ALERT | ERR_FATAL;
2737 goto out;
2738 }
2739
Christopher Faulet31930372019-07-15 10:16:58 +02002740 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002741 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002742 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002743 curproxy->conn_src.iface_len = 0;
2744
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002745 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2746 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002747 if (!sk) {
2748 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2749 file, linenum, args[0], args[1], errmsg);
2750 err_code |= ERR_ALERT | ERR_FATAL;
2751 goto out;
2752 }
2753
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002754 curproxy->conn_src.source_addr = *sk;
2755 curproxy->conn_src.opts |= CO_SRC_BIND;
2756
2757 cur_arg = 2;
2758 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002759 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002760#if defined(CONFIG_HAP_TRANSPARENT)
2761 if (!*args[cur_arg + 1]) {
2762 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2763 file, linenum, "usesrc");
2764 err_code |= ERR_ALERT | ERR_FATAL;
2765 goto out;
2766 }
2767
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002768 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002769 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2770 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002771 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002772 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2773 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2774 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2775 char *name, *end;
2776
2777 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002778 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002779 name++;
2780
2781 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002782 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002783 end++;
2784
2785 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2786 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002787 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002788 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002789 if (!curproxy->conn_src.bind_hdr_name)
2790 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002791 curproxy->conn_src.bind_hdr_len = end - name;
2792 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2793 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2794 curproxy->conn_src.bind_hdr_occ = -1;
2795
2796 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002797 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002798 end++;
2799 if (*end == ',') {
2800 end++;
2801 name = end;
2802 if (*end == '-')
2803 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002804 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002805 end++;
2806 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2807 }
2808
2809 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2810 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2811 " occurrences values smaller than %d.\n",
2812 file, linenum, MAX_HDR_HISTORY);
2813 err_code |= ERR_ALERT | ERR_FATAL;
2814 goto out;
2815 }
2816 } else {
2817 struct sockaddr_storage *sk;
2818
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002819 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2820 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002821 if (!sk) {
2822 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2823 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2824 err_code |= ERR_ALERT | ERR_FATAL;
2825 goto out;
2826 }
2827
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002828 curproxy->conn_src.tproxy_addr = *sk;
2829 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2830 }
2831 global.last_checks |= LSTCHK_NETADM;
2832#else /* no TPROXY support */
2833 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2834 file, linenum, "usesrc");
2835 err_code |= ERR_ALERT | ERR_FATAL;
2836 goto out;
2837#endif
2838 cur_arg += 2;
2839 continue;
2840 }
2841
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002842 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002843#ifdef SO_BINDTODEVICE
2844 if (!*args[cur_arg + 1]) {
2845 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2846 file, linenum, args[0]);
2847 err_code |= ERR_ALERT | ERR_FATAL;
2848 goto out;
2849 }
2850 free(curproxy->conn_src.iface_name);
2851 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002852 if (!curproxy->conn_src.iface_name)
2853 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002854 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2855 global.last_checks |= LSTCHK_NETADM;
2856#else
2857 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2858 file, linenum, args[0], args[cur_arg]);
2859 err_code |= ERR_ALERT | ERR_FATAL;
2860 goto out;
2861#endif
2862 cur_arg += 2;
2863 continue;
2864 }
2865 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2866 file, linenum, args[0], "interface", "usesrc");
2867 err_code |= ERR_ALERT | ERR_FATAL;
2868 goto out;
2869 }
2870 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002871 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002872 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2873 file, linenum, "usesrc", "source");
2874 err_code |= ERR_ALERT | ERR_FATAL;
2875 goto out;
2876 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002877 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 +02002878 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002879 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002880 file, linenum, args[0]);
2881 err_code |= ERR_ALERT | ERR_FATAL;
2882 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002883 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002884 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002885 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2886 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2887 err_code |= ERR_ALERT | ERR_FATAL;
2888 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002889 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002890 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002891 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2892 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2893 err_code |= ERR_ALERT | ERR_FATAL;
2894 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002895 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002896 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002897 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2898 err_code |= ERR_ALERT | ERR_FATAL;
2899 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002900 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002901 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002902 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2903 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2904 err_code |= ERR_ALERT | ERR_FATAL;
2905 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002906 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002907 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002908 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2909 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2910 err_code |= ERR_ALERT | ERR_FATAL;
2911 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002912 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002913 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002914 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2915 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2916 err_code |= ERR_ALERT | ERR_FATAL;
2917 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002918 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002919 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002920 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2921 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2922 err_code |= ERR_ALERT | ERR_FATAL;
2923 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002924 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002925 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 +02002926 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2927 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2928 err_code |= ERR_ALERT | ERR_FATAL;
2929 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002930 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002931 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002932 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2933 err_code |= ERR_ALERT | ERR_FATAL;
2934 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002935 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002936 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 +02002937 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2938 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2939 err_code |= ERR_ALERT | ERR_FATAL;
2940 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002941 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002942 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 +02002943 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2944 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2945 err_code |= ERR_ALERT | ERR_FATAL;
2946 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002947 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002948 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002949 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2950 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2951 err_code |= ERR_ALERT | ERR_FATAL;
2952 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002953 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002954 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 +02002955 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2956 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2957 err_code |= ERR_ALERT | ERR_FATAL;
2958 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002959 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002960 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002961 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2962 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2963 err_code |= ERR_ALERT | ERR_FATAL;
2964 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002965 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002966 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002967 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2968 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2969 err_code |= ERR_ALERT | ERR_FATAL;
2970 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002972 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302973 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002974 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2975 err_code |= ERR_ALERT | ERR_FATAL;
2976 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002977 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002978 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002979 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2980 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2981 err_code |= ERR_ALERT | ERR_FATAL;
2982 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002983 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002984 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002985 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2986 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2987 err_code |= ERR_ALERT | ERR_FATAL;
2988 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002989 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002990 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002991 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2992 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2993 err_code |= ERR_ALERT | ERR_FATAL;
2994 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002995 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002996 else {
2997 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01002998 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002999 int index;
3000
3001 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3002 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3003 if (kwl->kw[index].section != CFG_LISTEN)
3004 continue;
3005 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003006 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003007 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003008 err_code |= ERR_ALERT | ERR_FATAL;
3009 goto out;
3010 }
3011
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003012 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003013 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003014 if (rc < 0) {
3015 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3016 err_code |= ERR_ALERT | ERR_FATAL;
3017 goto out;
3018 }
3019 else if (rc > 0) {
3020 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3021 err_code |= ERR_WARN;
3022 goto out;
3023 }
3024 goto out;
3025 }
3026 }
3027 }
3028
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003029 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3030 if (best)
3031 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3032 else
3033 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003034 err_code |= ERR_ALERT | ERR_FATAL;
3035 goto out;
3036 }
3037 out:
3038 free(errmsg);
3039 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003040
3041 alloc_error:
3042 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3043 err_code |= ERR_ALERT | ERR_ABORT;
3044 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003045}