blob: 0929ba4d8ab6ad2b7c6aeca27ac1651517d32ad3 [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 Tarreau72faef32021-06-15 08:36:30 +0200612 if (parse_process_number(args[cur_arg], &set, 1, 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 }
Willy Tarreaub54ca702021-06-15 11:37:35 +0200619 ha_warning("parsing [%s:%d]: '%s' has no effect, is deprecated, and will be removed in version 2.7.\n",
620 file, linenum, args[0]);
621 err_code |= ERR_WARN;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100622 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100623 else if (strcmp(args[0], "acl") == 0) { /* add an ACL */
Willy Tarreau5d095c22021-02-12 10:15:59 +0100624 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100625 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
626 err_code |= ERR_ALERT | ERR_FATAL;
627 goto out;
628 }
629
630 err = invalid_char(args[1]);
631 if (err) {
632 ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
633 file, linenum, *err, args[1]);
634 err_code |= ERR_ALERT | ERR_FATAL;
635 goto out;
636 }
637
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100638 if (strcasecmp(args[1], "or") == 0) {
Tim Duesterhusf1bc24c2020-02-06 22:04:03 +0100639 ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a "
Tim Duesterhus0cf811a2020-02-05 21:00:50 +0100640 "logical disjunction within a condition.\n",
641 file, linenum, args[1]);
642 err_code |= ERR_ALERT | ERR_FATAL;
643 goto out;
644 }
645
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100646 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
647 ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
648 file, linenum, args[1], errmsg);
649 err_code |= ERR_ALERT | ERR_FATAL;
650 goto out;
651 }
652 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100653 else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100654
655 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
656 err_code |= ERR_WARN;
657
658 if (*(args[1]) == 0) {
659 ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
660 file, linenum, args[0]);
661 err_code |= ERR_ALERT | ERR_FATAL;
662 goto out;
663 }
664 free(curproxy->dyncookie_key);
665 curproxy->dyncookie_key = strdup(args[1]);
666 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100667 else if (strcmp(args[0], "cookie") == 0) { /* cookie name */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100668 int cur_arg;
669
670 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
671 err_code |= ERR_WARN;
672
673 if (*(args[1]) == 0) {
674 ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
675 file, linenum, args[0]);
676 err_code |= ERR_ALERT | ERR_FATAL;
677 goto out;
678 }
679
680 curproxy->ck_opts = 0;
681 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau61cfdf42021-02-20 10:46:51 +0100682 ha_free(&curproxy->cookie_domain);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100683 free(curproxy->cookie_name);
684 curproxy->cookie_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200685 if (!curproxy->cookie_name)
686 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100687 curproxy->cookie_len = strlen(curproxy->cookie_name);
688
689 cur_arg = 2;
690 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100691 if (strcmp(args[cur_arg], "rewrite") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100692 curproxy->ck_opts |= PR_CK_RW;
693 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100694 else if (strcmp(args[cur_arg], "indirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100695 curproxy->ck_opts |= PR_CK_IND;
696 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100697 else if (strcmp(args[cur_arg], "insert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100698 curproxy->ck_opts |= PR_CK_INS;
699 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100700 else if (strcmp(args[cur_arg], "nocache") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100701 curproxy->ck_opts |= PR_CK_NOC;
702 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100703 else if (strcmp(args[cur_arg], "postonly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100704 curproxy->ck_opts |= PR_CK_POST;
705 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100706 else if (strcmp(args[cur_arg], "preserve") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100707 curproxy->ck_opts |= PR_CK_PSV;
708 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100709 else if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100710 curproxy->ck_opts |= PR_CK_PFX;
711 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100712 else if (strcmp(args[cur_arg], "httponly") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100713 curproxy->ck_opts |= PR_CK_HTTPONLY;
714 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100715 else if (strcmp(args[cur_arg], "secure") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100716 curproxy->ck_opts |= PR_CK_SECURE;
717 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100718 else if (strcmp(args[cur_arg], "domain") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100719 if (!*args[cur_arg + 1]) {
720 ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
721 file, linenum, args[cur_arg]);
722 err_code |= ERR_ALERT | ERR_FATAL;
723 goto out;
724 }
725
Joao Moraise1583752019-10-30 21:04:00 -0300726 if (!strchr(args[cur_arg + 1], '.')) {
727 /* rfc6265, 5.2.3 The Domain Attribute */
728 ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot,"
729 " this configuration may not work properly (see RFC6265#5.2.3).\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100730 file, linenum, args[cur_arg + 1]);
731 err_code |= ERR_WARN;
732 }
733
734 err = invalid_domainchar(args[cur_arg + 1]);
735 if (err) {
736 ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
737 file, linenum, *err, args[cur_arg + 1]);
738 err_code |= ERR_ALERT | ERR_FATAL;
739 goto out;
740 }
741
742 if (!curproxy->cookie_domain) {
743 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
744 } else {
745 /* one domain was already specified, add another one by
746 * building the string which will be returned along with
747 * the cookie.
748 */
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200749 memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
750 }
751
Christopher Fauletb15625a2021-04-12 21:31:45 +0200752 if (!curproxy->cookie_domain)
753 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100754 cur_arg++;
755 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100756 else if (strcmp(args[cur_arg], "maxidle") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100757 unsigned int maxidle;
758 const char *res;
759
760 if (!*args[cur_arg + 1]) {
761 ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
762 file, linenum, args[cur_arg]);
763 err_code |= ERR_ALERT | ERR_FATAL;
764 goto out;
765 }
766
767 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200768 if (res == PARSE_TIME_OVER) {
769 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
770 file, linenum, args[cur_arg+1], args[cur_arg]);
771 err_code |= ERR_ALERT | ERR_FATAL;
772 goto out;
773 }
774 else if (res == PARSE_TIME_UNDER) {
775 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
776 file, linenum, args[cur_arg+1], args[cur_arg]);
777 err_code |= ERR_ALERT | ERR_FATAL;
778 goto out;
779 }
780 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100781 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
782 file, linenum, *res, args[cur_arg]);
783 err_code |= ERR_ALERT | ERR_FATAL;
784 goto out;
785 }
786 curproxy->cookie_maxidle = maxidle;
787 cur_arg++;
788 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100789 else if (strcmp(args[cur_arg], "maxlife") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100790 unsigned int maxlife;
791 const char *res;
792
793 if (!*args[cur_arg + 1]) {
794 ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
795 file, linenum, args[cur_arg]);
796 err_code |= ERR_ALERT | ERR_FATAL;
797 goto out;
798 }
799
Willy Tarreau9faebe32019-06-07 19:00:37 +0200800
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100801 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200802 if (res == PARSE_TIME_OVER) {
803 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n",
804 file, linenum, args[cur_arg+1], args[cur_arg]);
805 err_code |= ERR_ALERT | ERR_FATAL;
806 goto out;
807 }
808 else if (res == PARSE_TIME_UNDER) {
809 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n",
810 file, linenum, args[cur_arg+1], args[cur_arg]);
811 err_code |= ERR_ALERT | ERR_FATAL;
812 goto out;
813 }
814 else if (res) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100815 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
816 file, linenum, *res, args[cur_arg]);
817 err_code |= ERR_ALERT | ERR_FATAL;
818 goto out;
819 }
820 curproxy->cookie_maxlife = maxlife;
821 cur_arg++;
822 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100823 else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100824
825 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
826 err_code |= ERR_WARN;
827 curproxy->ck_opts |= PR_CK_DYNAMIC;
828 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100829 else if (strcmp(args[cur_arg], "attr") == 0) {
Christopher Faulet2f533902020-01-21 11:06:48 +0100830 char *val;
831 if (!*args[cur_arg + 1]) {
832 ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n",
833 file, linenum, args[cur_arg]);
834 err_code |= ERR_ALERT | ERR_FATAL;
835 goto out;
836 }
837 val = args[cur_arg + 1];
838 while (*val) {
Willy Tarreau90807112020-02-25 08:16:33 +0100839 if (iscntrl((unsigned char)*val) || *val == ';') {
Christopher Faulet2f533902020-01-21 11:06:48 +0100840 ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n",
841 file, linenum, *val);
842 err_code |= ERR_ALERT | ERR_FATAL;
843 goto out;
844 }
845 val++;
846 }
847 /* don't add ';' for the first attribute */
848 if (!curproxy->cookie_attrs)
849 curproxy->cookie_attrs = strdup(args[cur_arg + 1]);
850 else
851 memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +0200852
Christopher Fauletb15625a2021-04-12 21:31:45 +0200853 if (!curproxy->cookie_attrs)
854 goto alloc_error;
Christopher Faulet2f533902020-01-21 11:06:48 +0100855 cur_arg++;
856 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100857
858 else {
Christopher Faulet2f533902020-01-21 11:06:48 +0100859 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 +0100860 file, linenum, args[0]);
861 err_code |= ERR_ALERT | ERR_FATAL;
862 goto out;
863 }
864 cur_arg++;
865 }
866 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
867 ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
868 file, linenum);
869 err_code |= ERR_ALERT | ERR_FATAL;
870 }
871
872 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
873 ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
874 file, linenum);
875 err_code |= ERR_ALERT | ERR_FATAL;
876 }
877
878 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
879 ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
880 file, linenum);
881 err_code |= ERR_ALERT | ERR_FATAL;
882 }
883 }/* end else if (!strcmp(args[0], "cookie")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100884 else if (strcmp(args[0], "email-alert") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100885 if (*(args[1]) == 0) {
886 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
887 file, linenum, args[0]);
888 err_code |= ERR_ALERT | ERR_FATAL;
889 goto out;
890 }
891
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100892 if (strcmp(args[1], "from") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100893 if (*(args[1]) == 0) {
894 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
895 file, linenum, args[1]);
896 err_code |= ERR_ALERT | ERR_FATAL;
897 goto out;
898 }
899 free(curproxy->email_alert.from);
900 curproxy->email_alert.from = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200901 if (!curproxy->email_alert.from)
902 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100903 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100904 else if (strcmp(args[1], "mailers") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100905 if (*(args[1]) == 0) {
906 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
907 file, linenum, args[1]);
908 err_code |= ERR_ALERT | ERR_FATAL;
909 goto out;
910 }
911 free(curproxy->email_alert.mailers.name);
912 curproxy->email_alert.mailers.name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200913 if (!curproxy->email_alert.mailers.name)
914 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100915 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100916 else if (strcmp(args[1], "myhostname") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100917 if (*(args[1]) == 0) {
918 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
919 file, linenum, args[1]);
920 err_code |= ERR_ALERT | ERR_FATAL;
921 goto out;
922 }
923 free(curproxy->email_alert.myhostname);
924 curproxy->email_alert.myhostname = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200925 if (!curproxy->email_alert.myhostname)
926 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100927 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100928 else if (strcmp(args[1], "level") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100929 curproxy->email_alert.level = get_log_level(args[2]);
930 if (curproxy->email_alert.level < 0) {
931 ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
932 file, linenum, args[1], args[2]);
933 err_code |= ERR_ALERT | ERR_FATAL;
934 goto out;
935 }
936 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100937 else if (strcmp(args[1], "to") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100938 if (*(args[1]) == 0) {
939 ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
940 file, linenum, args[1]);
941 err_code |= ERR_ALERT | ERR_FATAL;
942 goto out;
943 }
944 free(curproxy->email_alert.to);
945 curproxy->email_alert.to = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200946 if (!curproxy->email_alert.to)
947 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100948 }
949 else {
950 ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
951 file, linenum, args[1]);
952 err_code |= ERR_ALERT | ERR_FATAL;
953 goto out;
954 }
955 /* Indicate that the email_alert is at least partially configured */
956 curproxy->email_alert.set = 1;
957 }/* end else if (!strcmp(args[0], "email-alert")) */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100958 else if (strcmp(args[0], "persist") == 0) { /* persist */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100959 if (*(args[1]) == 0) {
960 ha_alert("parsing [%s:%d] : missing persist method.\n",
961 file, linenum);
962 err_code |= ERR_ALERT | ERR_FATAL;
963 goto out;
964 }
965
966 if (!strncmp(args[1], "rdp-cookie", 10)) {
967 curproxy->options2 |= PR_O2_RDPC_PRST;
968
969 if (*(args[1] + 10) == '(') { /* cookie name */
970 const char *beg, *end;
971
972 beg = args[1] + 11;
973 end = strchr(beg, ')');
974
975 if (alertif_too_many_args(1, file, linenum, args, &err_code))
976 goto out;
977
978 if (!end || end == beg) {
979 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
980 file, linenum);
981 err_code |= ERR_ALERT | ERR_FATAL;
982 goto out;
983 }
984
985 free(curproxy->rdp_cookie_name);
986 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
Christopher Fauletb15625a2021-04-12 21:31:45 +0200987 if (!curproxy->rdp_cookie_name)
988 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100989 curproxy->rdp_cookie_len = end-beg;
990 }
991 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
992 free(curproxy->rdp_cookie_name);
993 curproxy->rdp_cookie_name = strdup("msts");
Christopher Fauletb15625a2021-04-12 21:31:45 +0200994 if (!curproxy->rdp_cookie_name)
995 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100996 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
997 }
998 else { /* syntax */
999 ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
1000 file, linenum);
1001 err_code |= ERR_ALERT | ERR_FATAL;
1002 goto out;
1003 }
1004 }
1005 else {
1006 ha_alert("parsing [%s:%d] : unknown persist method.\n",
1007 file, linenum);
1008 err_code |= ERR_ALERT | ERR_FATAL;
1009 goto out;
1010 }
1011 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001012 else if (strcmp(args[0], "appsession") == 0) { /* cookie name */
Tim Duesterhus473c2832019-05-06 01:19:52 +02001013 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 +01001014 err_code |= ERR_ALERT | ERR_FATAL;
1015 goto out;
1016 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001017 else if (strcmp(args[0], "load-server-state-from-file") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001018 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1019 err_code |= ERR_WARN;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001020 if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001021 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
1022 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001023 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 +01001024 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
1025 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001026 else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001027 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
1028 }
1029 else {
1030 ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
1031 file, linenum, args[0], args[1]);
1032 err_code |= ERR_ALERT | ERR_FATAL;
1033 goto out;
1034 }
1035 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001036 else if (strcmp(args[0], "server-state-file-name") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001037 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1038 err_code |= ERR_WARN;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001039 if (alertif_too_many_args(1, file, linenum, args, &err_code))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001040 goto out;
Christopher Faulet583b6de2021-02-12 09:27:10 +01001041
Willy Tarreau61cfdf42021-02-20 10:46:51 +01001042 ha_free(&curproxy->server_state_file_name);
Christopher Faulet583b6de2021-02-12 09:27:10 +01001043
1044 if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001045 curproxy->server_state_file_name = strdup(curproxy->id);
1046 else
1047 curproxy->server_state_file_name = strdup(args[1]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001048
Christopher Fauletb15625a2021-04-12 21:31:45 +02001049 if (!curproxy->server_state_file_name)
1050 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001051 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001052 else if (strcmp(args[0], "max-session-srv-conns") == 0) {
Olivier Houcharda4d4fdf2018-12-14 19:27:06 +01001053 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1054 err_code |= ERR_WARN;
1055 if (*(args[1]) == 0) {
1056 ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n",
1057 file, linenum, args[0]);
1058 err_code |= ERR_ALERT | ERR_FATAL;
1059 goto out;
1060 }
1061 curproxy->max_out_conns = atoi(args[1]);
1062 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001063 else if (strcmp(args[0], "capture") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001064 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1065 err_code |= ERR_WARN;
1066
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001067 if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */
Willy Tarreau5d095c22021-02-12 10:15:59 +01001068 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001069 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1070 err_code |= ERR_ALERT | ERR_FATAL;
1071 goto out;
1072 }
1073
1074 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1075 goto out;
1076
1077 if (*(args[4]) == 0) {
1078 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
1079 file, linenum, args[0]);
1080 err_code |= ERR_ALERT | ERR_FATAL;
1081 goto out;
1082 }
1083 free(curproxy->capture_name);
1084 curproxy->capture_name = strdup(args[2]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001085 if (!curproxy->capture_name)
1086 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001087 curproxy->capture_namelen = strlen(curproxy->capture_name);
1088 curproxy->capture_len = atol(args[4]);
1089 curproxy->to_log |= LW_COOKIE;
1090 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001091 else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001092 struct cap_hdr *hdr;
1093
Willy Tarreau5d095c22021-02-12 10:15:59 +01001094 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001095 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1096 err_code |= ERR_ALERT | ERR_FATAL;
1097 goto out;
1098 }
1099
1100 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1101 goto out;
1102
1103 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1104 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1105 file, linenum, args[0], args[1]);
1106 err_code |= ERR_ALERT | ERR_FATAL;
1107 goto out;
1108 }
1109
1110 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001111 if (!hdr)
1112 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001113 hdr->next = curproxy->req_cap;
1114 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001115 if (!hdr->name)
1116 goto req_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001117 hdr->namelen = strlen(args[3]);
1118 hdr->len = atol(args[5]);
1119 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001120 if (!hdr->pool) {
1121 req_caphdr_alloc_error:
1122 if (hdr)
1123 ha_free(&hdr->name);
1124 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001125 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001126 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001127 hdr->index = curproxy->nb_req_cap++;
1128 curproxy->req_cap = hdr;
1129 curproxy->to_log |= LW_REQHDR;
1130 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001131 else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001132 struct cap_hdr *hdr;
1133
Willy Tarreau5d095c22021-02-12 10:15:59 +01001134 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001135 ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1136 err_code |= ERR_ALERT | ERR_FATAL;
1137 goto out;
1138 }
1139
1140 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
1141 goto out;
1142
1143 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
1144 ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
1145 file, linenum, args[0], args[1]);
1146 err_code |= ERR_ALERT | ERR_FATAL;
1147 goto out;
1148 }
1149 hdr = calloc(1, sizeof(*hdr));
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001150 if (!hdr)
1151 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001152 hdr->next = curproxy->rsp_cap;
1153 hdr->name = strdup(args[3]);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001154 if (!hdr->name)
1155 goto res_caphdr_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001156 hdr->namelen = strlen(args[3]);
1157 hdr->len = atol(args[5]);
1158 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001159 if (!hdr->pool) {
1160 res_caphdr_alloc_error:
1161 if (hdr)
1162 ha_free(&hdr->name);
1163 ha_free(&hdr);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001164 goto alloc_error;
Christopher Fauletb45a7d42021-04-12 18:46:52 +02001165 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001166 hdr->index = curproxy->nb_rsp_cap++;
1167 curproxy->rsp_cap = hdr;
1168 curproxy->to_log |= LW_RSPHDR;
1169 }
1170 else {
1171 ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
1172 file, linenum, args[0]);
1173 err_code |= ERR_ALERT | ERR_FATAL;
1174 goto out;
1175 }
1176 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001177 else if (strcmp(args[0], "retries") == 0) { /* connection retries */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001178 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1179 err_code |= ERR_WARN;
1180
1181 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1182 goto out;
1183
1184 if (*(args[1]) == 0) {
1185 ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
1186 file, linenum, args[0]);
1187 err_code |= ERR_ALERT | ERR_FATAL;
1188 goto out;
1189 }
1190 curproxy->conn_retries = atol(args[1]);
1191 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001192 else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001193 struct act_rule *rule;
1194
Willy Tarreau5d095c22021-02-12 10:15:59 +01001195 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001196 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1197 err_code |= ERR_ALERT | ERR_FATAL;
1198 goto out;
1199 }
1200
1201 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
1202 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001203 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001204 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1205 file, linenum, args[0]);
1206 err_code |= ERR_WARN;
1207 }
1208
1209 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
1210
1211 if (!rule) {
1212 err_code |= ERR_ALERT | ERR_ABORT;
1213 goto out;
1214 }
1215
1216 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
1217 err_code |= warnif_cond_conflicts(rule->cond,
1218 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1219 file, linenum);
1220
Willy Tarreau2b718102021-04-21 07:32:39 +02001221 LIST_APPEND(&curproxy->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001222 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001223 else if (strcmp(args[0], "http-response") == 0) { /* response access control */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001224 struct act_rule *rule;
1225
Willy Tarreau5d095c22021-02-12 10:15:59 +01001226 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001227 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1228 err_code |= ERR_ALERT | ERR_FATAL;
1229 goto out;
1230 }
1231
1232 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
1233 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Christopher Faulet245cf792019-12-18 14:58:12 +01001234 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001235 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1236 file, linenum, args[0]);
1237 err_code |= ERR_WARN;
1238 }
1239
1240 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
1241
1242 if (!rule) {
1243 err_code |= ERR_ALERT | ERR_ABORT;
1244 goto out;
1245 }
1246
1247 err_code |= warnif_cond_conflicts(rule->cond,
1248 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1249 file, linenum);
1250
Willy Tarreau2b718102021-04-21 07:32:39 +02001251 LIST_APPEND(&curproxy->http_res_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001252 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001253 else if (strcmp(args[0], "http-after-response") == 0) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001254 struct act_rule *rule;
1255
Willy Tarreau5d095c22021-02-12 10:15:59 +01001256 if (curproxy->cap & PR_CAP_DEF) {
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001257 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1258 err_code |= ERR_ALERT | ERR_FATAL;
1259 goto out;
1260 }
1261
1262 if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) &&
1263 !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond &&
1264 (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) {
1265 ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
1266 file, linenum, args[0]);
1267 err_code |= ERR_WARN;
1268 }
1269
1270 rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy);
1271
1272 if (!rule) {
1273 err_code |= ERR_ALERT | ERR_ABORT;
1274 goto out;
1275 }
1276
1277 err_code |= warnif_cond_conflicts(rule->cond,
1278 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
1279 file, linenum);
1280
Willy Tarreau2b718102021-04-21 07:32:39 +02001281 LIST_APPEND(&curproxy->http_after_res_rules, &rule->list);
Christopher Faulet6d0c3df2020-01-22 09:26:35 +01001282 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001283 else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001284 /* set the header name and length into the proxy structure */
1285 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1286 err_code |= ERR_WARN;
1287
1288 if (!*args[1]) {
1289 ha_alert("parsing [%s:%d] : '%s' requires a header string.\n",
1290 file, linenum, args[0]);
1291 err_code |= ERR_ALERT | ERR_FATAL;
1292 goto out;
1293 }
1294
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001295 /* set the desired header name, in lower case */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001296 free(curproxy->server_id_hdr_name);
1297 curproxy->server_id_hdr_name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001298 if (!curproxy->server_id_hdr_name)
1299 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001300 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
Christopher Fauletdabcc8e2019-10-02 10:45:55 +02001301 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 +01001302 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001303 else if (strcmp(args[0], "block") == 0) {
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001304 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 +01001305
Tim Duesterhus7b7c47f2019-05-14 20:57:57 +02001306 err_code |= ERR_ALERT | ERR_FATAL;
1307 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001308 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001309 else if (strcmp(args[0], "redirect") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001310 struct redirect_rule *rule;
1311
Willy Tarreau5d095c22021-02-12 10:15:59 +01001312 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001313 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1314 err_code |= ERR_ALERT | ERR_FATAL;
1315 goto out;
1316 }
1317
1318 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
1319 ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
1320 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
1321 err_code |= ERR_ALERT | ERR_FATAL;
1322 goto out;
1323 }
1324
Willy Tarreau2b718102021-04-21 07:32:39 +02001325 LIST_APPEND(&curproxy->redirect_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001326 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
1327 err_code |= warnif_cond_conflicts(rule->cond,
1328 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1329 file, linenum);
1330 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001331 else if (strcmp(args[0], "use_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001332 struct switching_rule *rule;
1333
Willy Tarreau5d095c22021-02-12 10:15:59 +01001334 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001335 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1336 err_code |= ERR_ALERT | ERR_FATAL;
1337 goto out;
1338 }
1339
1340 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1341 err_code |= ERR_WARN;
1342
1343 if (*(args[1]) == 0) {
1344 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1345 err_code |= ERR_ALERT | ERR_FATAL;
1346 goto out;
1347 }
1348
1349 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
1350 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1351 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1352 file, linenum, errmsg);
1353 err_code |= ERR_ALERT | ERR_FATAL;
1354 goto out;
1355 }
1356
1357 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
1358 }
1359 else if (*args[2]) {
1360 ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
1361 file, linenum, args[2]);
1362 err_code |= ERR_ALERT | ERR_FATAL;
1363 goto out;
1364 }
1365
1366 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001367 if (!rule)
1368 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001369 rule->cond = cond;
1370 rule->be.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001371 if (!rule->be.name)
1372 goto use_backend_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001373 rule->line = linenum;
1374 rule->file = strdup(file);
1375 if (!rule->file) {
Christopher Faulet2e848a92021-04-12 16:28:30 +02001376 use_backend_alloc_error:
1377 if (cond)
1378 prune_acl_cond(cond);
1379 ha_free(&cond);
1380 if (rule)
1381 ha_free(&(rule->be.name));
1382 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001383 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001384 }
1385 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001386 LIST_APPEND(&curproxy->switching_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001387 }
1388 else if (strcmp(args[0], "use-server") == 0) {
1389 struct server_rule *rule;
1390
Willy Tarreau5d095c22021-02-12 10:15:59 +01001391 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001392 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1393 err_code |= ERR_ALERT | ERR_FATAL;
1394 goto out;
1395 }
1396
1397 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1398 err_code |= ERR_WARN;
1399
1400 if (*(args[1]) == 0) {
1401 ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
1402 err_code |= ERR_ALERT | ERR_FATAL;
1403 goto out;
1404 }
1405
1406 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1407 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1408 file, linenum, args[0]);
1409 err_code |= ERR_ALERT | ERR_FATAL;
1410 goto out;
1411 }
1412
1413 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1414 ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
1415 file, linenum, errmsg);
1416 err_code |= ERR_ALERT | ERR_FATAL;
1417 goto out;
1418 }
1419
1420 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1421
1422 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001423 if (!rule)
1424 goto use_server_alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001425 rule->cond = cond;
1426 rule->srv.name = strdup(args[1]);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001427 if (!rule->srv.name)
1428 goto use_server_alloc_error;
Jerome Magnin824186b2020-03-29 09:37:12 +02001429 rule->line = linenum;
1430 rule->file = strdup(file);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001431 if (!rule->file) {
1432 use_server_alloc_error:
1433 if (cond)
1434 prune_acl_cond(cond);
1435 ha_free(&cond);
1436 if (rule)
1437 ha_free(&(rule->srv.name));
1438 ha_free(&rule);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001439 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001440 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001441 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001442 LIST_APPEND(&curproxy->server_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001443 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
1444 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001445 else if ((strcmp(args[0], "force-persist") == 0) ||
1446 (strcmp(args[0], "ignore-persist") == 0)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001447 struct persist_rule *rule;
1448
Willy Tarreau5d095c22021-02-12 10:15:59 +01001449 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001450 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1451 err_code |= ERR_ALERT | ERR_FATAL;
1452 goto out;
1453 }
1454
1455 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1456 err_code |= ERR_WARN;
1457
1458 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
1459 ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
1460 file, linenum, args[0]);
1461 err_code |= ERR_ALERT | ERR_FATAL;
1462 goto out;
1463 }
1464
1465 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
1466 ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
1467 file, linenum, args[0], errmsg);
1468 err_code |= ERR_ALERT | ERR_FATAL;
1469 goto out;
1470 }
1471
1472 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
1473 * where force-persist is applied.
1474 */
1475 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
1476
1477 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001478 if (!rule) {
1479 if (cond)
1480 prune_acl_cond(cond);
1481 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001482 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001483 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001484 rule->cond = cond;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001485 if (strcmp(args[0], "force-persist") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001486 rule->type = PERSIST_TYPE_FORCE;
1487 } else {
1488 rule->type = PERSIST_TYPE_IGNORE;
1489 }
1490 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001491 LIST_APPEND(&curproxy->persist_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001492 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001493 else if (strcmp(args[0], "stick-table") == 0) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001494 struct stktable *other;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001495
Willy Tarreau5d095c22021-02-12 10:15:59 +01001496 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001497 ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n",
1498 file, linenum);
1499 err_code |= ERR_ALERT | ERR_FATAL;
1500 goto out;
1501 }
1502
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001503 other = stktable_find_by_name(curproxy->id);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001504 if (other) {
1505 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 +01001506 file, linenum, curproxy->id,
1507 other->proxy ? proxy_cap_str(other->proxy->cap) : "peers",
1508 other->proxy ? other->id : other->peers.p->id,
1509 other->conf.file, other->conf.line);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001510 err_code |= ERR_ALERT | ERR_FATAL;
1511 goto out;
1512 }
1513
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001514 curproxy->table = calloc(1, sizeof *curproxy->table);
1515 if (!curproxy->table) {
1516 ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
1517 file, linenum, args[0], args[1]);
1518 err_code |= ERR_ALERT | ERR_FATAL;
1519 goto out;
1520 }
1521
Frédéric Lécaillec02766a2019-03-20 15:06:55 +01001522 err_code |= parse_stick_table(file, linenum, args, curproxy->table,
1523 curproxy->id, curproxy->id, NULL);
Christopher Faulet2e848a92021-04-12 16:28:30 +02001524 if (err_code & ERR_FATAL) {
1525 ha_free(&curproxy->table);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001526 goto out;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001527 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001528
Frédéric Lécailled456aa42019-03-08 14:47:00 +01001529 /* Store the proxy in the stick-table. */
1530 curproxy->table->proxy = curproxy;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001531
1532 stktable_store_name(curproxy->table);
1533 curproxy->table->next = stktables_list;
1534 stktables_list = curproxy->table;
Frédéric Lécaille015e4d72019-03-19 14:55:01 +01001535
1536 /* Add this proxy to the list of proxies which refer to its stick-table. */
1537 if (curproxy->table->proxies_list != curproxy) {
1538 curproxy->next_stkt_ref = curproxy->table->proxies_list;
1539 curproxy->table->proxies_list = curproxy;
1540 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001541 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001542 else if (strcmp(args[0], "stick") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001543 struct sticking_rule *rule;
1544 struct sample_expr *expr;
1545 int myidx = 0;
1546 const char *name = NULL;
1547 int flags;
1548
Willy Tarreau5d095c22021-02-12 10:15:59 +01001549 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001550 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1551 err_code |= ERR_ALERT | ERR_FATAL;
1552 goto out;
1553 }
1554
1555 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
1556 err_code |= ERR_WARN;
1557 goto out;
1558 }
1559
1560 myidx++;
1561 if ((strcmp(args[myidx], "store") == 0) ||
1562 (strcmp(args[myidx], "store-request") == 0)) {
1563 myidx++;
1564 flags = STK_IS_STORE;
1565 }
1566 else if (strcmp(args[myidx], "store-response") == 0) {
1567 myidx++;
1568 flags = STK_IS_STORE | STK_ON_RSP;
1569 }
1570 else if (strcmp(args[myidx], "match") == 0) {
1571 myidx++;
1572 flags = STK_IS_MATCH;
1573 }
1574 else if (strcmp(args[myidx], "on") == 0) {
1575 myidx++;
1576 flags = STK_IS_MATCH | STK_IS_STORE;
1577 }
1578 else {
1579 ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
1580 err_code |= ERR_ALERT | ERR_FATAL;
1581 goto out;
1582 }
1583
1584 if (*(args[myidx]) == 0) {
1585 ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
1586 err_code |= ERR_ALERT | ERR_FATAL;
1587 goto out;
1588 }
1589
1590 curproxy->conf.args.ctx = ARGC_STK;
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01001591 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001592 if (!expr) {
1593 ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
1594 err_code |= ERR_ALERT | ERR_FATAL;
1595 goto out;
1596 }
1597
1598 if (flags & STK_ON_RSP) {
1599 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
1600 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
1601 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1602 err_code |= ERR_ALERT | ERR_FATAL;
1603 free(expr);
1604 goto out;
1605 }
1606 } else {
1607 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
1608 ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
1609 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
1610 err_code |= ERR_ALERT | ERR_FATAL;
1611 free(expr);
1612 goto out;
1613 }
1614 }
1615
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001616 /* check if we need to allocate an http_txn struct for HTTP parsing */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001617 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
1618
1619 if (strcmp(args[myidx], "table") == 0) {
1620 myidx++;
1621 name = args[myidx++];
1622 }
1623
1624 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
1625 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
1626 ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
1627 file, linenum, args[0], errmsg);
1628 err_code |= ERR_ALERT | ERR_FATAL;
1629 free(expr);
1630 goto out;
1631 }
1632 }
1633 else if (*(args[myidx])) {
1634 ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
1635 file, linenum, args[0], args[myidx]);
1636 err_code |= ERR_ALERT | ERR_FATAL;
1637 free(expr);
1638 goto out;
1639 }
1640 if (flags & STK_ON_RSP)
1641 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
1642 else
1643 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
1644
1645 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001646 if (!rule) {
1647 if (cond)
1648 prune_acl_cond(cond);
1649 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001650 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001651 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001652 rule->cond = cond;
1653 rule->expr = expr;
1654 rule->flags = flags;
1655 rule->table.name = name ? strdup(name) : NULL;
1656 LIST_INIT(&rule->list);
1657 if (flags & STK_ON_RSP)
Willy Tarreau2b718102021-04-21 07:32:39 +02001658 LIST_APPEND(&curproxy->storersp_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001659 else
Willy Tarreau2b718102021-04-21 07:32:39 +02001660 LIST_APPEND(&curproxy->sticking_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001661 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001662 else if (strcmp(args[0], "stats") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01001663 if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001664 curproxy->uri_auth = NULL; /* we must detach from the default config */
1665
1666 if (!*args[1]) {
1667 goto stats_error_parsing;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001668 } else if (strcmp(args[1], "admin") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001669 struct stats_admin_rule *rule;
1670
Willy Tarreau5d095c22021-02-12 10:15:59 +01001671 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001672 ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
1673 err_code |= ERR_ALERT | ERR_FATAL;
1674 goto out;
1675 }
1676
Christopher Fauletb15625a2021-04-12 21:31:45 +02001677 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1678 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001679
1680 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
1681 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
1682 file, linenum, args[0], args[1]);
1683 err_code |= ERR_ALERT | ERR_FATAL;
1684 goto out;
1685 }
1686 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
1687 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
1688 file, linenum, args[0], args[1], errmsg);
1689 err_code |= ERR_ALERT | ERR_FATAL;
1690 goto out;
1691 }
1692
1693 err_code |= warnif_cond_conflicts(cond,
1694 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1695 file, linenum);
1696
1697 rule = calloc(1, sizeof(*rule));
Christopher Faulet2e848a92021-04-12 16:28:30 +02001698 if (!rule) {
1699 if (cond)
1700 prune_acl_cond(cond);
1701 ha_free(&cond);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001702 goto alloc_error;
Christopher Faulet2e848a92021-04-12 16:28:30 +02001703 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001704 rule->cond = cond;
1705 LIST_INIT(&rule->list);
Willy Tarreau2b718102021-04-21 07:32:39 +02001706 LIST_APPEND(&curproxy->uri_auth->admin_rules, &rule->list);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001707 } else if (strcmp(args[1], "uri") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001708 if (*(args[2]) == 0) {
1709 ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
1710 err_code |= ERR_ALERT | ERR_FATAL;
1711 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001712 } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
1713 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001714 } else if (strcmp(args[1], "realm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001715 if (*(args[2]) == 0) {
1716 ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
1717 err_code |= ERR_ALERT | ERR_FATAL;
1718 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001719 } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
1720 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001721 } else if (strcmp(args[1], "refresh") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001722 unsigned interval;
1723
1724 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001725 if (err == PARSE_TIME_OVER) {
1726 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n",
1727 file, linenum, args[2]);
1728 err_code |= ERR_ALERT | ERR_FATAL;
1729 goto out;
1730 }
1731 else if (err == PARSE_TIME_UNDER) {
1732 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n",
1733 file, linenum, args[2]);
1734 err_code |= ERR_ALERT | ERR_FATAL;
1735 goto out;
1736 }
1737 else if (err) {
1738 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n",
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001739 file, linenum, *err);
1740 err_code |= ERR_ALERT | ERR_FATAL;
1741 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001742 } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
1743 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001744 } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001745 struct act_rule *rule;
1746
Willy Tarreau5d095c22021-02-12 10:15:59 +01001747 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001748 ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1749 err_code |= ERR_ALERT | ERR_FATAL;
1750 goto out;
1751 }
1752
Christopher Fauletb15625a2021-04-12 21:31:45 +02001753 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1754 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001755
1756 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
1757 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
1758 ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
1759 file, linenum, args[0]);
1760 err_code |= ERR_WARN;
1761 }
1762
1763 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
1764
1765 if (!rule) {
1766 err_code |= ERR_ALERT | ERR_ABORT;
1767 goto out;
1768 }
1769
1770 err_code |= warnif_cond_conflicts(rule->cond,
1771 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
1772 file, linenum);
Willy Tarreau2b718102021-04-21 07:32:39 +02001773 LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001774
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001775 } else if (strcmp(args[1], "auth") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001776 if (*(args[2]) == 0) {
1777 ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
1778 err_code |= ERR_ALERT | ERR_FATAL;
1779 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001780 } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
1781 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001782 } else if (strcmp(args[1], "scope") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001783 if (*(args[2]) == 0) {
1784 ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
1785 err_code |= ERR_ALERT | ERR_FATAL;
1786 goto out;
Christopher Fauletb15625a2021-04-12 21:31:45 +02001787 } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
1788 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001789 } else if (strcmp(args[1], "enable") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001790 if (!stats_check_init_uri_auth(&curproxy->uri_auth))
1791 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001792 } else if (strcmp(args[1], "hide-version") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001793 if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
1794 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001795 } else if (strcmp(args[1], "show-legends") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001796 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
1797 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001798 } else if (strcmp(args[1], "show-modules") == 0) {
Christopher Fauletb15625a2021-04-12 21:31:45 +02001799 if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
1800 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001801 } else if (strcmp(args[1], "show-node") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001802
1803 if (*args[2]) {
1804 int i;
1805 char c;
1806
1807 for (i=0; args[2][i]; i++) {
1808 c = args[2][i];
1809 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1810 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
1811 break;
1812 }
1813
1814 if (!i || args[2][i]) {
1815 ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
1816 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
1817 file, linenum, args[0], args[1]);
1818 err_code |= ERR_ALERT | ERR_FATAL;
1819 goto out;
1820 }
1821 }
1822
Christopher Fauletb15625a2021-04-12 21:31:45 +02001823 if (!stats_set_node(&curproxy->uri_auth, args[2]))
1824 goto alloc_error;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001825 } else if (strcmp(args[1], "show-desc") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001826 char *desc = NULL;
1827
1828 if (*args[2]) {
1829 int i, len=0;
1830 char *d;
1831
1832 for (i = 2; *args[i]; i++)
1833 len += strlen(args[i]) + 1;
1834
1835 desc = d = calloc(1, len);
1836
1837 d += snprintf(d, desc + len - d, "%s", args[2]);
1838 for (i = 3; *args[i]; i++)
1839 d += snprintf(d, desc + len - d, " %s", args[i]);
1840 }
1841
1842 if (!*args[2] && !global.desc)
1843 ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
1844 file, linenum, args[1]);
1845 else {
1846 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
1847 free(desc);
Christopher Fauletb15625a2021-04-12 21:31:45 +02001848 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001849 }
1850 free(desc);
1851 }
1852 } else {
1853stats_error_parsing:
1854 ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
1855 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
1856 err_code |= ERR_ALERT | ERR_FATAL;
1857 goto out;
1858 }
1859 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001860 else if (strcmp(args[0], "option") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001861 int optnum;
1862
1863 if (*(args[1]) == '\0') {
1864 ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
1865 file, linenum, args[0]);
1866 err_code |= ERR_ALERT | ERR_FATAL;
1867 goto out;
1868 }
1869
1870 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001871 if (strcmp(args[1], cfg_opts[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001872 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
1873 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1874 file, linenum, cfg_opts[optnum].name);
1875 err_code |= ERR_ALERT | ERR_FATAL;
1876 goto out;
1877 }
1878 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1879 goto out;
1880
1881 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
1882 err_code |= ERR_WARN;
1883 goto out;
1884 }
1885
1886 curproxy->no_options &= ~cfg_opts[optnum].val;
1887 curproxy->options &= ~cfg_opts[optnum].val;
1888
1889 switch (kwm) {
1890 case KWM_STD:
1891 curproxy->options |= cfg_opts[optnum].val;
1892 break;
1893 case KWM_NO:
1894 curproxy->no_options |= cfg_opts[optnum].val;
1895 break;
1896 case KWM_DEF: /* already cleared */
1897 break;
1898 }
1899
1900 goto out;
1901 }
1902 }
1903
1904 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001905 if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001906 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
1907 ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
1908 file, linenum, cfg_opts2[optnum].name);
1909 err_code |= ERR_ALERT | ERR_FATAL;
1910 goto out;
1911 }
1912 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1913 goto out;
1914 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
1915 err_code |= ERR_WARN;
1916 goto out;
1917 }
1918
1919 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
1920 curproxy->options2 &= ~cfg_opts2[optnum].val;
1921
1922 switch (kwm) {
1923 case KWM_STD:
1924 curproxy->options2 |= cfg_opts2[optnum].val;
1925 break;
1926 case KWM_NO:
1927 curproxy->no_options2 |= cfg_opts2[optnum].val;
1928 break;
1929 case KWM_DEF: /* already cleared */
1930 break;
1931 }
1932 goto out;
1933 }
1934 }
1935
1936 /* HTTP options override each other. They can be cancelled using
1937 * "no option xxx" which only switches to default mode if the mode
1938 * was this one (useful for cancelling options set in defaults
1939 * sections).
1940 */
Willy Tarreau6ba69842021-06-11 16:01:50 +02001941 if (strcmp(args[1], "forceclose") == 0) {
1942 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",
1943 file, linenum, args[1]);
1944 err_code |= ERR_ALERT | ERR_FATAL;
1945 goto out;
1946 }
1947 else if (strcmp(args[1], "httpclose") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001948 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1949 goto out;
1950 if (kwm == KWM_STD) {
1951 curproxy->options &= ~PR_O_HTTP_MODE;
1952 curproxy->options |= PR_O_HTTP_CLO;
1953 goto out;
1954 }
1955 else if (kwm == KWM_NO) {
1956 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
1957 curproxy->options &= ~PR_O_HTTP_MODE;
1958 goto out;
1959 }
1960 }
1961 else if (strcmp(args[1], "http-server-close") == 0) {
1962 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1963 goto out;
1964 if (kwm == KWM_STD) {
1965 curproxy->options &= ~PR_O_HTTP_MODE;
1966 curproxy->options |= PR_O_HTTP_SCL;
1967 goto out;
1968 }
1969 else if (kwm == KWM_NO) {
1970 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
1971 curproxy->options &= ~PR_O_HTTP_MODE;
1972 goto out;
1973 }
1974 }
1975 else if (strcmp(args[1], "http-keep-alive") == 0) {
1976 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
1977 goto out;
1978 if (kwm == KWM_STD) {
1979 curproxy->options &= ~PR_O_HTTP_MODE;
1980 curproxy->options |= PR_O_HTTP_KAL;
1981 goto out;
1982 }
1983 else if (kwm == KWM_NO) {
1984 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
1985 curproxy->options &= ~PR_O_HTTP_MODE;
1986 goto out;
1987 }
1988 }
1989 else if (strcmp(args[1], "http-tunnel") == 0) {
Willy Tarreaud2f25372021-06-11 16:06:29 +02001990 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 +02001991 file, linenum, args[1]);
Willy Tarreaud2f25372021-06-11 16:06:29 +02001992 err_code |= ERR_ALERT | ERR_FATAL;
Christopher Faulet73e8ede2019-07-16 15:04:46 +02001993 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01001994 }
1995
1996 /* Redispatch can take an integer argument that control when the
1997 * resispatch occurs. All values are relative to the retries option.
1998 * This can be cancelled using "no option xxx".
1999 */
2000 if (strcmp(args[1], "redispatch") == 0) {
2001 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
2002 err_code |= ERR_WARN;
2003 goto out;
2004 }
2005
2006 curproxy->no_options &= ~PR_O_REDISP;
2007 curproxy->options &= ~PR_O_REDISP;
2008
2009 switch (kwm) {
2010 case KWM_STD:
2011 curproxy->options |= PR_O_REDISP;
2012 curproxy->redispatch_after = -1;
2013 if(*args[2]) {
2014 curproxy->redispatch_after = atol(args[2]);
2015 }
2016 break;
2017 case KWM_NO:
2018 curproxy->no_options |= PR_O_REDISP;
2019 curproxy->redispatch_after = 0;
2020 break;
2021 case KWM_DEF: /* already cleared */
2022 break;
2023 }
2024 goto out;
2025 }
2026
2027 if (kwm != KWM_STD) {
2028 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2029 file, linenum, args[1]);
2030 err_code |= ERR_ALERT | ERR_FATAL;
2031 goto out;
2032 }
2033
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002034 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002035 char *logformat;
2036 /* generate a complete HTTP log */
2037 logformat = default_http_log_format;
2038 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002039 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002040 curproxy->options2 |= PR_O2_CLFLOG;
2041 logformat = clf_http_log_format;
2042 } else {
2043 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2044 err_code |= ERR_ALERT | ERR_FATAL;
2045 goto out;
2046 }
2047 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2048 goto out;
2049 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002050 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002051 char *oldlogformat = "log-format";
2052 char *clflogformat = "";
2053
2054 if (curproxy->conf.logformat_string == default_http_log_format)
2055 oldlogformat = "option httplog";
2056 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2057 oldlogformat = "option tcplog";
2058 else if (curproxy->conf.logformat_string == clf_http_log_format)
2059 oldlogformat = "option httplog clf";
2060 if (logformat == clf_http_log_format)
2061 clflogformat = " clf";
2062 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2063 file, linenum, clflogformat, oldlogformat);
2064 }
2065 if (curproxy->conf.logformat_string != default_http_log_format &&
2066 curproxy->conf.logformat_string != default_tcp_log_format &&
2067 curproxy->conf.logformat_string != clf_http_log_format)
2068 free(curproxy->conf.logformat_string);
2069 curproxy->conf.logformat_string = logformat;
2070
2071 free(curproxy->conf.lfs_file);
2072 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2073 curproxy->conf.lfs_line = curproxy->conf.args.line;
2074
Willy Tarreau5d095c22021-02-12 10:15:59 +01002075 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002076 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2077 file, linenum, curproxy->id);
2078 err_code |= ERR_WARN;
2079 }
2080 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002081 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002082 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002083 char *oldlogformat = "log-format";
2084
2085 if (curproxy->conf.logformat_string == default_http_log_format)
2086 oldlogformat = "option httplog";
2087 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2088 oldlogformat = "option tcplog";
2089 else if (curproxy->conf.logformat_string == clf_http_log_format)
2090 oldlogformat = "option httplog clf";
2091 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2092 file, linenum, oldlogformat);
2093 }
2094 /* generate a detailed TCP log */
2095 if (curproxy->conf.logformat_string != default_http_log_format &&
2096 curproxy->conf.logformat_string != default_tcp_log_format &&
2097 curproxy->conf.logformat_string != clf_http_log_format)
2098 free(curproxy->conf.logformat_string);
2099 curproxy->conf.logformat_string = default_tcp_log_format;
2100
2101 free(curproxy->conf.lfs_file);
2102 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2103 curproxy->conf.lfs_line = curproxy->conf.args.line;
2104
2105 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2106 goto out;
2107
Willy Tarreau5d095c22021-02-12 10:15:59 +01002108 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002109 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2110 file, linenum, curproxy->id);
2111 err_code |= ERR_WARN;
2112 }
2113 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002114 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002115 /* enable TCP keep-alives on client and server streams */
2116 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2117 err_code |= ERR_WARN;
2118
2119 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2120 goto out;
2121
2122 if (curproxy->cap & PR_CAP_FE)
2123 curproxy->options |= PR_O_TCP_CLI_KA;
2124 if (curproxy->cap & PR_CAP_BE)
2125 curproxy->options |= PR_O_TCP_SRV_KA;
2126 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002127 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002128 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002129 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002130 goto out;
2131 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002132 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002133 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002134 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002135 goto out;
2136 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002137 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002138 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002139 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002140 goto out;
2141 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002142 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002143 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002144 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002145 goto out;
2146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002147 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002148 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002149 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002150 goto out;
2151 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002152 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002153 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002154 if (err_code & ERR_FATAL)
2155 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002156 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002157 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002158 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002159 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002160 goto out;
2161 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002162 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002163 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002164 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002165 goto out;
2166 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002167 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002168 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002169 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002170 goto out;
2171 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002172 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002173 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002174 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002175 goto out;
2176 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002177 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002178 int cur_arg;
2179
2180 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002181 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002182 */
2183
2184 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2185
2186 free(curproxy->fwdfor_hdr_name);
2187 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002188 if (!curproxy->fwdfor_hdr_name)
2189 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002190 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002191 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002192
2193 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2194 cur_arg = 2;
2195 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002196 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002197 unsigned char mask;
2198 int i;
2199
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002200 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002201 if (*(args[cur_arg+1]) &&
2202 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2203 curproxy->except_xff_net.family = AF_INET;
2204 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2205 }
2206 else if (*(args[cur_arg+1]) &&
2207 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2208 curproxy->except_xff_net.family = AF_INET6;
2209 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2210 for (i = 0; i < 16; i++)
2211 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2212 }
2213 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002214 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2215 file, linenum, args[0], args[1], args[cur_arg]);
2216 err_code |= ERR_ALERT | ERR_FATAL;
2217 goto out;
2218 }
2219 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002220 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002221 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002222 /* suboption header - needs additional argument for it */
2223 if (*(args[cur_arg+1]) == 0) {
2224 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2225 file, linenum, args[0], args[1], args[cur_arg]);
2226 err_code |= ERR_ALERT | ERR_FATAL;
2227 goto out;
2228 }
2229 free(curproxy->fwdfor_hdr_name);
2230 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002231 if (!curproxy->fwdfor_hdr_name)
2232 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002233 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2234 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002235 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002236 curproxy->options &= ~PR_O_FF_ALWAYS;
2237 cur_arg += 1;
2238 } else {
2239 /* unknown suboption - catchall */
2240 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2241 file, linenum, args[0], args[1]);
2242 err_code |= ERR_ALERT | ERR_FATAL;
2243 goto out;
2244 }
2245 } /* end while loop */
2246 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002247 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002248 int cur_arg;
2249
2250 /* insert x-original-to field, but not for the IP address listed as an except.
2251 * set default options (ie: bitfield, header name, etc)
2252 */
2253
2254 curproxy->options |= PR_O_ORGTO;
2255
2256 free(curproxy->orgto_hdr_name);
2257 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002258 if (!curproxy->orgto_hdr_name)
2259 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002260 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002261 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002262
2263 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2264 cur_arg = 2;
2265 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002266 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002267 unsigned char mask;
2268 int i;
2269
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002270 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002271 if (*(args[cur_arg+1]) &&
2272 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2273 curproxy->except_xot_net.family = AF_INET;
2274 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2275 }
2276 else if (*(args[cur_arg+1]) &&
2277 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2278 curproxy->except_xot_net.family = AF_INET6;
2279 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2280 for (i = 0; i < 16; i++)
2281 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2282 }
2283 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002284 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2285 file, linenum, args[0], args[1], args[cur_arg]);
2286 err_code |= ERR_ALERT | ERR_FATAL;
2287 goto out;
2288 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002289 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002290 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002291 /* suboption header - needs additional argument for it */
2292 if (*(args[cur_arg+1]) == 0) {
2293 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2294 file, linenum, args[0], args[1], args[cur_arg]);
2295 err_code |= ERR_ALERT | ERR_FATAL;
2296 goto out;
2297 }
2298 free(curproxy->orgto_hdr_name);
2299 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002300 if (!curproxy->orgto_hdr_name)
2301 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002302 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2303 cur_arg += 2;
2304 } else {
2305 /* unknown suboption - catchall */
2306 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2307 file, linenum, args[0], args[1]);
2308 err_code |= ERR_ALERT | ERR_FATAL;
2309 goto out;
2310 }
2311 } /* end while loop */
2312 }
2313 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002314 const char *best = proxy_find_best_option(args[1], common_options);
2315
2316 if (best)
2317 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2318 else
2319 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2320
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002321 err_code |= ERR_ALERT | ERR_FATAL;
2322 goto out;
2323 }
2324 goto out;
2325 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002326 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002327 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2328 err_code |= ERR_WARN;
2329
2330 if (*(args[1]) == 0) {
2331 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2332 err_code |= ERR_ALERT | ERR_FATAL;
2333 goto out;
2334 }
2335 free(curproxy->defbe.name);
2336 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002337 if (!curproxy->defbe.name)
2338 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002339
2340 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2341 goto out;
2342 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002343 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002344 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 +01002345
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002346 err_code |= ERR_ALERT | ERR_FATAL;
2347 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002348 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002349 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002350 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2351 err_code |= ERR_WARN;
2352
2353 if (strcmp(args[1], "never") == 0) {
2354 /* enable a graceful server shutdown on an HTTP 404 response */
2355 curproxy->options &= ~PR_O_REUSE_MASK;
2356 curproxy->options |= PR_O_REUSE_NEVR;
2357 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2358 goto out;
2359 }
2360 else if (strcmp(args[1], "safe") == 0) {
2361 /* enable a graceful server shutdown on an HTTP 404 response */
2362 curproxy->options &= ~PR_O_REUSE_MASK;
2363 curproxy->options |= PR_O_REUSE_SAFE;
2364 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2365 goto out;
2366 }
2367 else if (strcmp(args[1], "aggressive") == 0) {
2368 curproxy->options &= ~PR_O_REUSE_MASK;
2369 curproxy->options |= PR_O_REUSE_AGGR;
2370 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2371 goto out;
2372 }
2373 else if (strcmp(args[1], "always") == 0) {
2374 /* enable a graceful server shutdown on an HTTP 404 response */
2375 curproxy->options &= ~PR_O_REUSE_MASK;
2376 curproxy->options |= PR_O_REUSE_ALWS;
2377 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2378 goto out;
2379 }
2380 else {
2381 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2382 err_code |= ERR_ALERT | ERR_FATAL;
2383 goto out;
2384 }
2385 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002386 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002387 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002388 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2389 err_code |= ERR_ALERT | ERR_FATAL;
2390 goto out;
2391 }
2392
2393 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2394 err_code |= ERR_WARN;
2395
2396 if (strcmp(args[1], "fail") == 0) {
2397 /* add a condition to fail monitor requests */
2398 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2399 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2400 file, linenum, args[0], args[1]);
2401 err_code |= ERR_ALERT | ERR_FATAL;
2402 goto out;
2403 }
2404
2405 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2406 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2407 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2408 file, linenum, args[0], args[1], errmsg);
2409 err_code |= ERR_ALERT | ERR_FATAL;
2410 goto out;
2411 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002412 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002413 }
2414 else {
2415 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2416 err_code |= ERR_ALERT | ERR_FATAL;
2417 goto out;
2418 }
2419 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002420#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002421 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002422 /* enable transparent proxy connections */
2423 curproxy->options |= PR_O_TRANSP;
2424 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2425 goto out;
2426 }
2427#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002428 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002429 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2430 err_code |= ERR_WARN;
2431
2432 if (*(args[1]) == 0) {
2433 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2434 err_code |= ERR_ALERT | ERR_FATAL;
2435 goto out;
2436 }
2437 curproxy->maxconn = atol(args[1]);
2438 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2439 goto out;
2440 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002441 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002442 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2443 err_code |= ERR_WARN;
2444
2445 if (*(args[1]) == 0) {
2446 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2447 err_code |= ERR_ALERT | ERR_FATAL;
2448 goto out;
2449 }
2450 curproxy->backlog = atol(args[1]);
2451 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2452 goto out;
2453 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002454 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002455 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2456 err_code |= ERR_WARN;
2457
2458 if (*(args[1]) == 0) {
2459 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2460 err_code |= ERR_ALERT | ERR_FATAL;
2461 goto out;
2462 }
2463 curproxy->fullconn = atol(args[1]);
2464 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2465 goto out;
2466 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002467 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002468 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 +02002469 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002470 err_code |= ERR_ALERT | ERR_FATAL;
2471 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002472 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002473 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002474 struct sockaddr_storage *sk;
2475 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002476
Willy Tarreau5d095c22021-02-12 10:15:59 +01002477 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002478 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2479 err_code |= ERR_ALERT | ERR_FATAL;
2480 goto out;
2481 }
2482 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2483 err_code |= ERR_WARN;
2484
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002485 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2486 &errmsg, NULL, NULL,
2487 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 +01002488 if (!sk) {
2489 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2490 err_code |= ERR_ALERT | ERR_FATAL;
2491 goto out;
2492 }
2493
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002494 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2495 goto out;
2496
2497 curproxy->dispatch_addr = *sk;
2498 curproxy->options |= PR_O_DISPATCH;
2499 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002500 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002501 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2502 err_code |= ERR_WARN;
2503
2504 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2505 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2506 err_code |= ERR_ALERT | ERR_FATAL;
2507 goto out;
2508 }
2509 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002510 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002511 /**
2512 * The syntax for hash-type config element is
2513 * hash-type {map-based|consistent} [[<algo>] avalanche]
2514 *
2515 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2516 */
2517 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2518
2519 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2520 err_code |= ERR_WARN;
2521
2522 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2523 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2524 }
2525 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2526 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2527 }
2528 else if (strcmp(args[1], "avalanche") == 0) {
2529 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]);
2530 err_code |= ERR_ALERT | ERR_FATAL;
2531 goto out;
2532 }
2533 else {
2534 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2535 err_code |= ERR_ALERT | ERR_FATAL;
2536 goto out;
2537 }
2538
2539 /* set the hash function to use */
2540 if (!*args[2]) {
2541 /* the default algo is sdbm */
2542 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2543
2544 /* if consistent with no argument, then avalanche modifier is also applied */
2545 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2546 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2547 } else {
2548 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002549 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002550 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2551 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002552 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002553 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2554 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002555 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002556 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2557 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002558 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002559 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2560 }
2561 else {
2562 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2563 err_code |= ERR_ALERT | ERR_FATAL;
2564 goto out;
2565 }
2566
2567 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002568 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002569 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2570 }
2571 else if (*args[3]) {
2572 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2573 err_code |= ERR_ALERT | ERR_FATAL;
2574 goto out;
2575 }
2576 }
2577 }
2578 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2579 if (*(args[1]) == 0) {
2580 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2581 err_code |= ERR_ALERT | ERR_FATAL;
2582 goto out;
2583 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002584 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2585 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002586 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2587 err_code |= ERR_ALERT | ERR_FATAL;
2588 goto out;
2589 }
2590 }
2591 else if (strcmp(args[0], "unique-id-format") == 0) {
2592 if (!*(args[1])) {
2593 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2594 err_code |= ERR_ALERT | ERR_FATAL;
2595 goto out;
2596 }
2597 if (*(args[2])) {
2598 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2599 err_code |= ERR_ALERT | ERR_FATAL;
2600 goto out;
2601 }
2602 free(curproxy->conf.uniqueid_format_string);
2603 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002604 if (!curproxy->conf.uniqueid_format_string)
2605 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002606
2607 free(curproxy->conf.uif_file);
2608 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2609 curproxy->conf.uif_line = curproxy->conf.args.line;
2610 }
2611
2612 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002613 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002614 if (!*(args[1])) {
2615 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2616 err_code |= ERR_ALERT | ERR_FATAL;
2617 goto out;
2618 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002619 copy = strdup(args[1]);
2620 if (copy == NULL) {
2621 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2622 err_code |= ERR_ALERT | ERR_FATAL;
2623 goto out;
2624 }
2625
2626 istfree(&curproxy->header_unique_id);
2627 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002628 }
2629
2630 else if (strcmp(args[0], "log-format") == 0) {
2631 if (!*(args[1])) {
2632 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2633 err_code |= ERR_ALERT | ERR_FATAL;
2634 goto out;
2635 }
2636 if (*(args[2])) {
2637 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2638 err_code |= ERR_ALERT | ERR_FATAL;
2639 goto out;
2640 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002641 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002642 char *oldlogformat = "log-format";
2643
2644 if (curproxy->conf.logformat_string == default_http_log_format)
2645 oldlogformat = "option httplog";
2646 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2647 oldlogformat = "option tcplog";
2648 else if (curproxy->conf.logformat_string == clf_http_log_format)
2649 oldlogformat = "option httplog clf";
2650 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2651 file, linenum, oldlogformat);
2652 }
2653 if (curproxy->conf.logformat_string != default_http_log_format &&
2654 curproxy->conf.logformat_string != default_tcp_log_format &&
2655 curproxy->conf.logformat_string != clf_http_log_format)
2656 free(curproxy->conf.logformat_string);
2657 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002658 if (!curproxy->conf.logformat_string)
2659 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002660
2661 free(curproxy->conf.lfs_file);
2662 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2663 curproxy->conf.lfs_line = curproxy->conf.args.line;
2664
2665 /* get a chance to improve log-format error reporting by
2666 * reporting the correct line-number when possible.
2667 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002668 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002669 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2670 file, linenum, curproxy->id);
2671 err_code |= ERR_WARN;
2672 }
2673 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002674 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002675 if (!*(args[1])) {
2676 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2677 err_code |= ERR_ALERT | ERR_FATAL;
2678 goto out;
2679 }
2680 if (*(args[2])) {
2681 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2682 err_code |= ERR_ALERT | ERR_FATAL;
2683 goto out;
2684 }
2685
2686 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2687 free(curproxy->conf.logformat_sd_string);
2688 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002689 if (!curproxy->conf.logformat_sd_string)
2690 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002691
2692 free(curproxy->conf.lfsd_file);
2693 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2694 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2695
2696 /* get a chance to improve log-format-sd error reporting by
2697 * reporting the correct line-number when possible.
2698 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002699 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002700 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2701 file, linenum, curproxy->id);
2702 err_code |= ERR_WARN;
2703 }
2704 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002705 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002706 if (*(args[1]) == 0) {
2707 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2708 err_code |= ERR_ALERT | ERR_FATAL;
2709 goto out;
2710 }
2711 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002712 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2713 if (b_orig(&curproxy->log_tag) == NULL) {
2714 chunk_destroy(&curproxy->log_tag);
2715 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2716 err_code |= ERR_ALERT | ERR_FATAL;
2717 goto out;
2718 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002719 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002720 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002721 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002722 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2723 err_code |= ERR_ALERT | ERR_FATAL;
2724 goto out;
2725 }
2726 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002727 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002728 int cur_arg;
2729 int port1, port2;
2730 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002731
2732 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2733 err_code |= ERR_WARN;
2734
2735 if (!*args[1]) {
2736 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2737 file, linenum, "source", "usesrc", "interface");
2738 err_code |= ERR_ALERT | ERR_FATAL;
2739 goto out;
2740 }
2741
Christopher Faulet31930372019-07-15 10:16:58 +02002742 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002743 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002744 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002745 curproxy->conn_src.iface_len = 0;
2746
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002747 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2748 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002749 if (!sk) {
2750 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2751 file, linenum, args[0], args[1], errmsg);
2752 err_code |= ERR_ALERT | ERR_FATAL;
2753 goto out;
2754 }
2755
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002756 curproxy->conn_src.source_addr = *sk;
2757 curproxy->conn_src.opts |= CO_SRC_BIND;
2758
2759 cur_arg = 2;
2760 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002761 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002762#if defined(CONFIG_HAP_TRANSPARENT)
2763 if (!*args[cur_arg + 1]) {
2764 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2765 file, linenum, "usesrc");
2766 err_code |= ERR_ALERT | ERR_FATAL;
2767 goto out;
2768 }
2769
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002770 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002771 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2772 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002773 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002774 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2775 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2776 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2777 char *name, *end;
2778
2779 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002780 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002781 name++;
2782
2783 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002784 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002785 end++;
2786
2787 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2788 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002789 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002790 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002791 if (!curproxy->conn_src.bind_hdr_name)
2792 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002793 curproxy->conn_src.bind_hdr_len = end - name;
2794 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2795 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2796 curproxy->conn_src.bind_hdr_occ = -1;
2797
2798 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002799 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002800 end++;
2801 if (*end == ',') {
2802 end++;
2803 name = end;
2804 if (*end == '-')
2805 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002806 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002807 end++;
2808 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2809 }
2810
2811 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2812 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2813 " occurrences values smaller than %d.\n",
2814 file, linenum, MAX_HDR_HISTORY);
2815 err_code |= ERR_ALERT | ERR_FATAL;
2816 goto out;
2817 }
2818 } else {
2819 struct sockaddr_storage *sk;
2820
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002821 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2822 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002823 if (!sk) {
2824 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2825 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2826 err_code |= ERR_ALERT | ERR_FATAL;
2827 goto out;
2828 }
2829
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002830 curproxy->conn_src.tproxy_addr = *sk;
2831 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2832 }
2833 global.last_checks |= LSTCHK_NETADM;
2834#else /* no TPROXY support */
2835 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2836 file, linenum, "usesrc");
2837 err_code |= ERR_ALERT | ERR_FATAL;
2838 goto out;
2839#endif
2840 cur_arg += 2;
2841 continue;
2842 }
2843
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002844 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002845#ifdef SO_BINDTODEVICE
2846 if (!*args[cur_arg + 1]) {
2847 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2848 file, linenum, args[0]);
2849 err_code |= ERR_ALERT | ERR_FATAL;
2850 goto out;
2851 }
2852 free(curproxy->conn_src.iface_name);
2853 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002854 if (!curproxy->conn_src.iface_name)
2855 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002856 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2857 global.last_checks |= LSTCHK_NETADM;
2858#else
2859 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2860 file, linenum, args[0], args[cur_arg]);
2861 err_code |= ERR_ALERT | ERR_FATAL;
2862 goto out;
2863#endif
2864 cur_arg += 2;
2865 continue;
2866 }
2867 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2868 file, linenum, args[0], "interface", "usesrc");
2869 err_code |= ERR_ALERT | ERR_FATAL;
2870 goto out;
2871 }
2872 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002873 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002874 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2875 file, linenum, "usesrc", "source");
2876 err_code |= ERR_ALERT | ERR_FATAL;
2877 goto out;
2878 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002879 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 +02002880 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002881 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002882 file, linenum, args[0]);
2883 err_code |= ERR_ALERT | ERR_FATAL;
2884 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002885 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002886 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002887 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2888 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2889 err_code |= ERR_ALERT | ERR_FATAL;
2890 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002891 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002892 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002893 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2894 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2895 err_code |= ERR_ALERT | ERR_FATAL;
2896 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002897 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002898 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002899 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2900 err_code |= ERR_ALERT | ERR_FATAL;
2901 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002902 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002903 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002904 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2905 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2906 err_code |= ERR_ALERT | ERR_FATAL;
2907 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002908 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002909 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002910 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2911 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2912 err_code |= ERR_ALERT | ERR_FATAL;
2913 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002914 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002915 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002916 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2917 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2918 err_code |= ERR_ALERT | ERR_FATAL;
2919 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002920 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002921 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002922 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2923 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2924 err_code |= ERR_ALERT | ERR_FATAL;
2925 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002926 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002927 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 +02002928 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2929 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2930 err_code |= ERR_ALERT | ERR_FATAL;
2931 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002932 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002933 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002934 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2935 err_code |= ERR_ALERT | ERR_FATAL;
2936 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002937 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002938 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 +02002939 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2940 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2941 err_code |= ERR_ALERT | ERR_FATAL;
2942 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002943 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002944 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 +02002945 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2946 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2947 err_code |= ERR_ALERT | ERR_FATAL;
2948 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002949 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002950 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002951 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2952 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
2953 err_code |= ERR_ALERT | ERR_FATAL;
2954 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002955 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002956 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 +02002957 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2958 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2959 err_code |= ERR_ALERT | ERR_FATAL;
2960 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002961 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002962 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002963 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2964 "Use 'http-response del-header' .\n", file, linenum, args[0]);
2965 err_code |= ERR_ALERT | ERR_FATAL;
2966 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002967 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002968 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002969 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2970 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2971 err_code |= ERR_ALERT | ERR_FATAL;
2972 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002973 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002974 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05302975 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002976 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
2977 err_code |= ERR_ALERT | ERR_FATAL;
2978 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002979 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002980 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002981 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2982 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
2983 err_code |= ERR_ALERT | ERR_FATAL;
2984 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002985 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002986 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002987 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2988 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
2989 err_code |= ERR_ALERT | ERR_FATAL;
2990 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002991 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002992 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002993 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2994 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
2995 err_code |= ERR_ALERT | ERR_FATAL;
2996 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002997 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002998 else {
2999 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003000 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003001 int index;
3002
3003 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3004 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3005 if (kwl->kw[index].section != CFG_LISTEN)
3006 continue;
3007 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003008 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003009 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003010 err_code |= ERR_ALERT | ERR_FATAL;
3011 goto out;
3012 }
3013
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003014 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003015 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003016 if (rc < 0) {
3017 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3018 err_code |= ERR_ALERT | ERR_FATAL;
3019 goto out;
3020 }
3021 else if (rc > 0) {
3022 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3023 err_code |= ERR_WARN;
3024 goto out;
3025 }
3026 goto out;
3027 }
3028 }
3029 }
3030
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003031 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3032 if (best)
3033 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3034 else
3035 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003036 err_code |= ERR_ALERT | ERR_FATAL;
3037 goto out;
3038 }
3039 out:
3040 free(errmsg);
3041 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003042
3043 alloc_error:
3044 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3045 err_code |= ERR_ALERT | ERR_ABORT;
3046 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003047}