blob: 790566a62d2202f7c94a727a983608871f0d3685 [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;
William Lallemand8e765b82021-08-03 11:58:03 +0200596 curproxy->disabled = PR_DISABLED;
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
Willy Tarreau25241232021-07-18 19:18:56 +02002027 if (strcmp(args[1], "http_proxy") == 0) {
2028 ha_alert("parsing [%s:%d]: option '%s' is not supported any more since HAProxy 2.5. This option stopped working in HAProxy 1.9 and usually had nasty side effects. It can be more reliably implemented with combinations of 'http-request set-dst' and 'http-request set-uri', and even 'http-request do-resolve' if DNS resolution is desired.\n",
2029 file, linenum, args[1]);
2030 err_code |= ERR_ALERT | ERR_FATAL;
2031 goto out;
2032 }
2033
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002034 if (kwm != KWM_STD) {
2035 ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
2036 file, linenum, args[1]);
2037 err_code |= ERR_ALERT | ERR_FATAL;
2038 goto out;
2039 }
2040
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002041 if (strcmp(args[1], "httplog") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002042 char *logformat;
2043 /* generate a complete HTTP log */
2044 logformat = default_http_log_format;
2045 if (*(args[2]) != '\0') {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002046 if (strcmp(args[2], "clf") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002047 curproxy->options2 |= PR_O2_CLFLOG;
2048 logformat = clf_http_log_format;
2049 } else {
2050 ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
2051 err_code |= ERR_ALERT | ERR_FATAL;
2052 goto out;
2053 }
2054 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
2055 goto out;
2056 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002057 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002058 char *oldlogformat = "log-format";
2059 char *clflogformat = "";
2060
2061 if (curproxy->conf.logformat_string == default_http_log_format)
2062 oldlogformat = "option httplog";
2063 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2064 oldlogformat = "option tcplog";
2065 else if (curproxy->conf.logformat_string == clf_http_log_format)
2066 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002067 else if (curproxy->conf.logformat_string == default_https_log_format)
2068 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002069 if (logformat == clf_http_log_format)
2070 clflogformat = " clf";
2071 ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n",
2072 file, linenum, clflogformat, oldlogformat);
2073 }
2074 if (curproxy->conf.logformat_string != default_http_log_format &&
2075 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002076 curproxy->conf.logformat_string != clf_http_log_format &&
2077 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002078 free(curproxy->conf.logformat_string);
2079 curproxy->conf.logformat_string = logformat;
2080
2081 free(curproxy->conf.lfs_file);
2082 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2083 curproxy->conf.lfs_line = curproxy->conf.args.line;
2084
Willy Tarreau5d095c22021-02-12 10:15:59 +01002085 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002086 ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n",
2087 file, linenum, curproxy->id);
2088 err_code |= ERR_WARN;
2089 }
2090 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002091 else if (strcmp(args[1], "tcplog") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002092 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002093 char *oldlogformat = "log-format";
2094
2095 if (curproxy->conf.logformat_string == default_http_log_format)
2096 oldlogformat = "option httplog";
2097 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2098 oldlogformat = "option tcplog";
2099 else if (curproxy->conf.logformat_string == clf_http_log_format)
2100 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002101 else if (curproxy->conf.logformat_string == default_https_log_format)
2102 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002103 ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n",
2104 file, linenum, oldlogformat);
2105 }
2106 /* generate a detailed TCP log */
2107 if (curproxy->conf.logformat_string != default_http_log_format &&
2108 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002109 curproxy->conf.logformat_string != clf_http_log_format &&
2110 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002111 free(curproxy->conf.logformat_string);
2112 curproxy->conf.logformat_string = default_tcp_log_format;
2113
2114 free(curproxy->conf.lfs_file);
2115 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2116 curproxy->conf.lfs_line = curproxy->conf.args.line;
2117
2118 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2119 goto out;
2120
Willy Tarreau5d095c22021-02-12 10:15:59 +01002121 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002122 ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n",
2123 file, linenum, curproxy->id);
2124 err_code |= ERR_WARN;
2125 }
2126 }
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002127 else if (strcmp(args[1], "httpslog") == 0) {
2128 char *logformat;
2129 /* generate a complete HTTP log */
2130 logformat = default_https_log_format;
2131 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
2132 char *oldlogformat = "log-format";
2133
2134 if (curproxy->conf.logformat_string == default_http_log_format)
2135 oldlogformat = "option httplog";
2136 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2137 oldlogformat = "option tcplog";
2138 else if (curproxy->conf.logformat_string == clf_http_log_format)
2139 oldlogformat = "option httplog clf";
2140 else if (curproxy->conf.logformat_string == default_https_log_format)
2141 oldlogformat = "option httpslog";
2142 ha_warning("parsing [%s:%d]: 'option httplog' overrides previous '%s' in 'defaults' section.\n",
2143 file, linenum, oldlogformat);
2144 }
2145 if (curproxy->conf.logformat_string != default_http_log_format &&
2146 curproxy->conf.logformat_string != default_tcp_log_format &&
2147 curproxy->conf.logformat_string != clf_http_log_format &&
2148 curproxy->conf.logformat_string != default_https_log_format)
2149 free(curproxy->conf.logformat_string);
2150 curproxy->conf.logformat_string = logformat;
2151
2152 free(curproxy->conf.lfs_file);
2153 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2154 curproxy->conf.lfs_line = curproxy->conf.args.line;
2155
2156 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
2157 ha_warning("parsing [%s:%d] : backend '%s' : 'option httpslog' directive is ignored in backends.\n",
2158 file, linenum, curproxy->id);
2159 err_code |= ERR_WARN;
2160 }
2161 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002162 else if (strcmp(args[1], "tcpka") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002163 /* enable TCP keep-alives on client and server streams */
2164 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
2165 err_code |= ERR_WARN;
2166
2167 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2168 goto out;
2169
2170 if (curproxy->cap & PR_CAP_FE)
2171 curproxy->options |= PR_O_TCP_CLI_KA;
2172 if (curproxy->cap & PR_CAP_BE)
2173 curproxy->options |= PR_O_TCP_SRV_KA;
2174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002175 else if (strcmp(args[1], "httpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002176 err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6c2a7432020-04-09 14:48:48 +02002177 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002178 goto out;
2179 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002180 else if (strcmp(args[1], "ssl-hello-chk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002181 err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet811f78c2020-04-01 11:10:27 +02002182 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002183 goto out;
2184 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002185 else if (strcmp(args[1], "smtpchk") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002186 err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletfbcc77c2020-04-01 20:54:05 +02002187 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002188 goto out;
2189 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002190 else if (strcmp(args[1], "pgsql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002191 err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletce355072020-04-02 11:44:39 +02002192 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002193 goto out;
2194 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002195 else if (strcmp(args[1], "redis-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002196 err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet33f05df2020-04-01 11:08:50 +02002197 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002198 goto out;
2199 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002200 else if (strcmp(args[1], "mysql-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002201 err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Fauletf2b3be52020-04-02 18:07:37 +02002202 if (err_code & ERR_FATAL)
2203 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002204 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002205 else if (strcmp(args[1], "ldap-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002206 err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet1997eca2020-04-03 23:13:50 +02002207 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002208 goto out;
2209 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002210 else if (strcmp(args[1], "spop-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002211 err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet267b01b2020-04-04 10:27:09 +02002212 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002213 goto out;
2214 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002215 else if (strcmp(args[1], "tcp-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002216 err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet430e4802020-04-09 15:28:16 +02002217 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002218 goto out;
2219 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002220 else if (strcmp(args[1], "external-check") == 0) {
Willy Tarreauab3410c2021-02-12 12:17:30 +01002221 err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum);
Christopher Faulet6f557912020-04-09 15:58:50 +02002222 if (err_code & ERR_FATAL)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002223 goto out;
2224 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002225 else if (strcmp(args[1], "forwardfor") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002226 int cur_arg;
2227
2228 /* insert x-forwarded-for field, but not for the IP address listed as an except.
Christopher Faulet31930372019-07-15 10:16:58 +02002229 * set default options (ie: bitfield, header name, etc)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002230 */
2231
2232 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
2233
2234 free(curproxy->fwdfor_hdr_name);
2235 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002236 if (!curproxy->fwdfor_hdr_name)
2237 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002238 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002239 curproxy->except_xff_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002240
2241 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
2242 cur_arg = 2;
2243 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002244 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002245 unsigned char mask;
2246 int i;
2247
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002248 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002249 if (*(args[cur_arg+1]) &&
2250 str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) {
2251 curproxy->except_xff_net.family = AF_INET;
2252 curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr;
2253 }
2254 else if (*(args[cur_arg+1]) &&
2255 str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) {
2256 curproxy->except_xff_net.family = AF_INET6;
2257 len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask);
2258 for (i = 0; i < 16; i++)
2259 curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i];
2260 }
2261 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002262 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2263 file, linenum, args[0], args[1], args[cur_arg]);
2264 err_code |= ERR_ALERT | ERR_FATAL;
2265 goto out;
2266 }
2267 /* flush useless bits */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002268 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002269 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002270 /* suboption header - needs additional argument for it */
2271 if (*(args[cur_arg+1]) == 0) {
2272 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2273 file, linenum, args[0], args[1], args[cur_arg]);
2274 err_code |= ERR_ALERT | ERR_FATAL;
2275 goto out;
2276 }
2277 free(curproxy->fwdfor_hdr_name);
2278 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002279 if (!curproxy->fwdfor_hdr_name)
2280 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002281 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
2282 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002283 } else if (strcmp(args[cur_arg], "if-none") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002284 curproxy->options &= ~PR_O_FF_ALWAYS;
2285 cur_arg += 1;
2286 } else {
2287 /* unknown suboption - catchall */
2288 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
2289 file, linenum, args[0], args[1]);
2290 err_code |= ERR_ALERT | ERR_FATAL;
2291 goto out;
2292 }
2293 } /* end while loop */
2294 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002295 else if (strcmp(args[1], "originalto") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002296 int cur_arg;
2297
2298 /* insert x-original-to field, but not for the IP address listed as an except.
2299 * set default options (ie: bitfield, header name, etc)
2300 */
2301
2302 curproxy->options |= PR_O_ORGTO;
2303
2304 free(curproxy->orgto_hdr_name);
2305 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002306 if (!curproxy->orgto_hdr_name)
2307 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002308 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
Christopher Faulet5d1def62021-02-26 09:19:15 +01002309 curproxy->except_xot_net.family = AF_UNSPEC;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002310
2311 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
2312 cur_arg = 2;
2313 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002314 if (strcmp(args[cur_arg], "except") == 0) {
Christopher Faulet5d1def62021-02-26 09:19:15 +01002315 unsigned char mask;
2316 int i;
2317
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002318 /* suboption except - needs additional argument for it */
Christopher Faulet5d1def62021-02-26 09:19:15 +01002319 if (*(args[cur_arg+1]) &&
2320 str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) {
2321 curproxy->except_xot_net.family = AF_INET;
2322 curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr;
2323 }
2324 else if (*(args[cur_arg+1]) &&
2325 str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) {
2326 curproxy->except_xot_net.family = AF_INET6;
2327 len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask);
2328 for (i = 0; i < 16; i++)
2329 curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i];
2330 }
2331 else {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002332 ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
2333 file, linenum, args[0], args[1], args[cur_arg]);
2334 err_code |= ERR_ALERT | ERR_FATAL;
2335 goto out;
2336 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002337 cur_arg += 2;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002338 } else if (strcmp(args[cur_arg], "header") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002339 /* suboption header - needs additional argument for it */
2340 if (*(args[cur_arg+1]) == 0) {
2341 ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
2342 file, linenum, args[0], args[1], args[cur_arg]);
2343 err_code |= ERR_ALERT | ERR_FATAL;
2344 goto out;
2345 }
2346 free(curproxy->orgto_hdr_name);
2347 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002348 if (!curproxy->orgto_hdr_name)
2349 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002350 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
2351 cur_arg += 2;
2352 } else {
2353 /* unknown suboption - catchall */
2354 ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
2355 file, linenum, args[0], args[1]);
2356 err_code |= ERR_ALERT | ERR_FATAL;
2357 goto out;
2358 }
2359 } /* end while loop */
2360 }
2361 else {
Willy Tarreau31a3cea2021-03-15 11:11:55 +01002362 const char *best = proxy_find_best_option(args[1], common_options);
2363
2364 if (best)
2365 ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best);
2366 else
2367 ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
2368
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002369 err_code |= ERR_ALERT | ERR_FATAL;
2370 goto out;
2371 }
2372 goto out;
2373 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002374 else if (strcmp(args[0], "default_backend") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002375 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2376 err_code |= ERR_WARN;
2377
2378 if (*(args[1]) == 0) {
2379 ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
2380 err_code |= ERR_ALERT | ERR_FATAL;
2381 goto out;
2382 }
2383 free(curproxy->defbe.name);
2384 curproxy->defbe.name = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002385 if (!curproxy->defbe.name)
2386 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002387
2388 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
2389 goto out;
2390 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002391 else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) {
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002392 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 +01002393
Tim Duesterhusdac168b2019-05-14 20:57:58 +02002394 err_code |= ERR_ALERT | ERR_FATAL;
2395 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002396 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002397 else if (strcmp(args[0], "http-reuse") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002398 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2399 err_code |= ERR_WARN;
2400
2401 if (strcmp(args[1], "never") == 0) {
2402 /* enable a graceful server shutdown on an HTTP 404 response */
2403 curproxy->options &= ~PR_O_REUSE_MASK;
2404 curproxy->options |= PR_O_REUSE_NEVR;
2405 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2406 goto out;
2407 }
2408 else if (strcmp(args[1], "safe") == 0) {
2409 /* enable a graceful server shutdown on an HTTP 404 response */
2410 curproxy->options &= ~PR_O_REUSE_MASK;
2411 curproxy->options |= PR_O_REUSE_SAFE;
2412 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2413 goto out;
2414 }
2415 else if (strcmp(args[1], "aggressive") == 0) {
2416 curproxy->options &= ~PR_O_REUSE_MASK;
2417 curproxy->options |= PR_O_REUSE_AGGR;
2418 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2419 goto out;
2420 }
2421 else if (strcmp(args[1], "always") == 0) {
2422 /* enable a graceful server shutdown on an HTTP 404 response */
2423 curproxy->options &= ~PR_O_REUSE_MASK;
2424 curproxy->options |= PR_O_REUSE_ALWS;
2425 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
2426 goto out;
2427 }
2428 else {
2429 ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
2430 err_code |= ERR_ALERT | ERR_FATAL;
2431 goto out;
2432 }
2433 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002434 else if (strcmp(args[0], "monitor") == 0) {
Willy Tarreau5d095c22021-02-12 10:15:59 +01002435 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002436 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2437 err_code |= ERR_ALERT | ERR_FATAL;
2438 goto out;
2439 }
2440
2441 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2442 err_code |= ERR_WARN;
2443
2444 if (strcmp(args[1], "fail") == 0) {
2445 /* add a condition to fail monitor requests */
2446 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
2447 ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
2448 file, linenum, args[0], args[1]);
2449 err_code |= ERR_ALERT | ERR_FATAL;
2450 goto out;
2451 }
2452
2453 err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail");
2454 if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
2455 ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
2456 file, linenum, args[0], args[1], errmsg);
2457 err_code |= ERR_ALERT | ERR_FATAL;
2458 goto out;
2459 }
Willy Tarreau2b718102021-04-21 07:32:39 +02002460 LIST_APPEND(&curproxy->mon_fail_cond, &cond->list);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002461 }
2462 else {
2463 ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
2464 err_code |= ERR_ALERT | ERR_FATAL;
2465 goto out;
2466 }
2467 }
Willy Tarreaue5733232019-05-22 19:24:06 +02002468#ifdef USE_TPROXY
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002469 else if (strcmp(args[0], "transparent") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002470 /* enable transparent proxy connections */
2471 curproxy->options |= PR_O_TRANSP;
2472 if (alertif_too_many_args(0, file, linenum, args, &err_code))
2473 goto out;
2474 }
2475#endif
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002476 else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002477 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
2478 err_code |= ERR_WARN;
2479
2480 if (*(args[1]) == 0) {
2481 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2482 err_code |= ERR_ALERT | ERR_FATAL;
2483 goto out;
2484 }
2485 curproxy->maxconn = atol(args[1]);
2486 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2487 goto out;
2488 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002489 else if (strcmp(args[0], "backlog") == 0) { /* backlog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002490 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
2491 err_code |= ERR_WARN;
2492
2493 if (*(args[1]) == 0) {
2494 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2495 err_code |= ERR_ALERT | ERR_FATAL;
2496 goto out;
2497 }
2498 curproxy->backlog = atol(args[1]);
2499 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2500 goto out;
2501 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002502 else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002503 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
2504 err_code |= ERR_WARN;
2505
2506 if (*(args[1]) == 0) {
2507 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2508 err_code |= ERR_ALERT | ERR_FATAL;
2509 goto out;
2510 }
2511 curproxy->fullconn = atol(args[1]);
2512 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2513 goto out;
2514 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002515 else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */
Willy Tarreaueb778242021-06-11 16:27:10 +02002516 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 +02002517 file, linenum, args[0]);
Willy Tarreaueb778242021-06-11 16:27:10 +02002518 err_code |= ERR_ALERT | ERR_FATAL;
2519 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002520 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002521 else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002522 struct sockaddr_storage *sk;
2523 int port1, port2;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002524
Willy Tarreau5d095c22021-02-12 10:15:59 +01002525 if (curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002526 ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
2527 err_code |= ERR_ALERT | ERR_FATAL;
2528 goto out;
2529 }
2530 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2531 err_code |= ERR_WARN;
2532
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002533 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2534 &errmsg, NULL, NULL,
2535 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 +01002536 if (!sk) {
2537 ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
2538 err_code |= ERR_ALERT | ERR_FATAL;
2539 goto out;
2540 }
2541
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002542 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2543 goto out;
2544
2545 curproxy->dispatch_addr = *sk;
2546 curproxy->options |= PR_O_DISPATCH;
2547 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002548 else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002549 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2550 err_code |= ERR_WARN;
2551
2552 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
2553 ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
2554 err_code |= ERR_ALERT | ERR_FATAL;
2555 goto out;
2556 }
2557 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002558 else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002559 /**
2560 * The syntax for hash-type config element is
2561 * hash-type {map-based|consistent} [[<algo>] avalanche]
2562 *
2563 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
2564 */
2565 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
2566
2567 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2568 err_code |= ERR_WARN;
2569
2570 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
2571 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
2572 }
2573 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
2574 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
2575 }
2576 else if (strcmp(args[1], "avalanche") == 0) {
2577 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]);
2578 err_code |= ERR_ALERT | ERR_FATAL;
2579 goto out;
2580 }
2581 else {
2582 ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
2583 err_code |= ERR_ALERT | ERR_FATAL;
2584 goto out;
2585 }
2586
2587 /* set the hash function to use */
2588 if (!*args[2]) {
2589 /* the default algo is sdbm */
2590 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2591
2592 /* if consistent with no argument, then avalanche modifier is also applied */
2593 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
2594 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2595 } else {
2596 /* set the hash function */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002597 if (strcmp(args[2], "sdbm") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002598 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
2599 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002600 else if (strcmp(args[2], "djb2") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002601 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
2602 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002603 else if (strcmp(args[2], "wt6") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002604 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
2605 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002606 else if (strcmp(args[2], "crc32") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002607 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
2608 }
2609 else {
2610 ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
2611 err_code |= ERR_ALERT | ERR_FATAL;
2612 goto out;
2613 }
2614
2615 /* set the hash modifier */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002616 if (strcmp(args[3], "avalanche") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002617 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
2618 }
2619 else if (*args[3]) {
2620 ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
2621 err_code |= ERR_ALERT | ERR_FATAL;
2622 goto out;
2623 }
2624 }
2625 }
2626 else if (strcmp(args[0], "hash-balance-factor") == 0) {
2627 if (*(args[1]) == 0) {
2628 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
2629 err_code |= ERR_ALERT | ERR_FATAL;
2630 goto out;
2631 }
Willy Tarreau76e84f52019-01-14 16:50:58 +01002632 curproxy->lbprm.hash_balance_factor = atol(args[1]);
2633 if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002634 ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
2635 err_code |= ERR_ALERT | ERR_FATAL;
2636 goto out;
2637 }
2638 }
2639 else if (strcmp(args[0], "unique-id-format") == 0) {
2640 if (!*(args[1])) {
2641 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2642 err_code |= ERR_ALERT | ERR_FATAL;
2643 goto out;
2644 }
2645 if (*(args[2])) {
2646 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2647 err_code |= ERR_ALERT | ERR_FATAL;
2648 goto out;
2649 }
2650 free(curproxy->conf.uniqueid_format_string);
2651 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002652 if (!curproxy->conf.uniqueid_format_string)
2653 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002654
2655 free(curproxy->conf.uif_file);
2656 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
2657 curproxy->conf.uif_line = curproxy->conf.args.line;
2658 }
2659
2660 else if (strcmp(args[0], "unique-id-header") == 0) {
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002661 char *copy;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002662 if (!*(args[1])) {
2663 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2664 err_code |= ERR_ALERT | ERR_FATAL;
2665 goto out;
2666 }
Tim Duesterhus0643b0e2020-03-05 17:56:35 +01002667 copy = strdup(args[1]);
2668 if (copy == NULL) {
2669 ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
2670 err_code |= ERR_ALERT | ERR_FATAL;
2671 goto out;
2672 }
2673
2674 istfree(&curproxy->header_unique_id);
2675 curproxy->header_unique_id = ist(copy);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002676 }
2677
2678 else if (strcmp(args[0], "log-format") == 0) {
2679 if (!*(args[1])) {
2680 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2681 err_code |= ERR_ALERT | ERR_FATAL;
2682 goto out;
2683 }
2684 if (*(args[2])) {
2685 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2686 err_code |= ERR_ALERT | ERR_FATAL;
2687 goto out;
2688 }
Willy Tarreau5d095c22021-02-12 10:15:59 +01002689 if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002690 char *oldlogformat = "log-format";
2691
2692 if (curproxy->conf.logformat_string == default_http_log_format)
2693 oldlogformat = "option httplog";
2694 else if (curproxy->conf.logformat_string == default_tcp_log_format)
2695 oldlogformat = "option tcplog";
2696 else if (curproxy->conf.logformat_string == clf_http_log_format)
2697 oldlogformat = "option httplog clf";
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002698 else if (curproxy->conf.logformat_string == default_https_log_format)
2699 oldlogformat = "option httpslog";
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002700 ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n",
2701 file, linenum, oldlogformat);
2702 }
2703 if (curproxy->conf.logformat_string != default_http_log_format &&
2704 curproxy->conf.logformat_string != default_tcp_log_format &&
Remi Tricot-Le Breton98b930d2021-07-29 09:45:52 +02002705 curproxy->conf.logformat_string != clf_http_log_format &&
2706 curproxy->conf.logformat_string != default_https_log_format)
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002707 free(curproxy->conf.logformat_string);
2708 curproxy->conf.logformat_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002709 if (!curproxy->conf.logformat_string)
2710 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002711
2712 free(curproxy->conf.lfs_file);
2713 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
2714 curproxy->conf.lfs_line = curproxy->conf.args.line;
2715
2716 /* get a chance to improve log-format error reporting by
2717 * reporting the correct line-number when possible.
2718 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002719 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002720 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
2721 file, linenum, curproxy->id);
2722 err_code |= ERR_WARN;
2723 }
2724 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002725 else if (strcmp(args[0], "log-format-sd") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002726 if (!*(args[1])) {
2727 ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
2728 err_code |= ERR_ALERT | ERR_FATAL;
2729 goto out;
2730 }
2731 if (*(args[2])) {
2732 ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
2733 err_code |= ERR_ALERT | ERR_FATAL;
2734 goto out;
2735 }
2736
2737 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2738 free(curproxy->conf.logformat_sd_string);
2739 curproxy->conf.logformat_sd_string = strdup(args[1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002740 if (!curproxy->conf.logformat_sd_string)
2741 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002742
2743 free(curproxy->conf.lfsd_file);
2744 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
2745 curproxy->conf.lfsd_line = curproxy->conf.args.line;
2746
2747 /* get a chance to improve log-format-sd error reporting by
2748 * reporting the correct line-number when possible.
2749 */
Willy Tarreau5d095c22021-02-12 10:15:59 +01002750 if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002751 ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
2752 file, linenum, curproxy->id);
2753 err_code |= ERR_WARN;
2754 }
2755 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002756 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002757 if (*(args[1]) == 0) {
2758 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
2759 err_code |= ERR_ALERT | ERR_FATAL;
2760 goto out;
2761 }
2762 chunk_destroy(&curproxy->log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +02002763 chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
2764 if (b_orig(&curproxy->log_tag) == NULL) {
2765 chunk_destroy(&curproxy->log_tag);
2766 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
2767 err_code |= ERR_ALERT | ERR_FATAL;
2768 goto out;
2769 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002770 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002771 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +02002772 if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002773 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
2774 err_code |= ERR_ALERT | ERR_FATAL;
2775 goto out;
2776 }
2777 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002778 else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002779 int cur_arg;
2780 int port1, port2;
2781 struct sockaddr_storage *sk;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002782
2783 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
2784 err_code |= ERR_WARN;
2785
2786 if (!*args[1]) {
2787 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
2788 file, linenum, "source", "usesrc", "interface");
2789 err_code |= ERR_ALERT | ERR_FATAL;
2790 goto out;
2791 }
2792
Christopher Faulet31930372019-07-15 10:16:58 +02002793 /* we must first clear any optional default setting */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002794 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
Willy Tarreau61cfdf42021-02-20 10:46:51 +01002795 ha_free(&curproxy->conn_src.iface_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002796 curproxy->conn_src.iface_len = 0;
2797
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002798 sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
2799 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002800 if (!sk) {
2801 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2802 file, linenum, args[0], args[1], errmsg);
2803 err_code |= ERR_ALERT | ERR_FATAL;
2804 goto out;
2805 }
2806
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002807 curproxy->conn_src.source_addr = *sk;
2808 curproxy->conn_src.opts |= CO_SRC_BIND;
2809
2810 cur_arg = 2;
2811 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002812 if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002813#if defined(CONFIG_HAP_TRANSPARENT)
2814 if (!*args[cur_arg + 1]) {
2815 ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
2816 file, linenum, "usesrc");
2817 err_code |= ERR_ALERT | ERR_FATAL;
2818 goto out;
2819 }
2820
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002821 if (strcmp(args[cur_arg + 1], "client") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002822 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2823 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002824 } else if (strcmp(args[cur_arg + 1], "clientip") == 0) {
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002825 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2826 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
2827 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
2828 char *name, *end;
2829
2830 name = args[cur_arg+1] + 7;
Willy Tarreau90807112020-02-25 08:16:33 +01002831 while (isspace((unsigned char)*name))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002832 name++;
2833
2834 end = name;
Willy Tarreau90807112020-02-25 08:16:33 +01002835 while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')')
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002836 end++;
2837
2838 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
2839 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
Amaury Denoyelle69c5c3a2021-01-26 14:35:22 +01002840 free(curproxy->conn_src.bind_hdr_name);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002841 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002842 if (!curproxy->conn_src.bind_hdr_name)
2843 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002844 curproxy->conn_src.bind_hdr_len = end - name;
2845 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
2846 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
2847 curproxy->conn_src.bind_hdr_occ = -1;
2848
2849 /* now look for an occurrence number */
Willy Tarreau90807112020-02-25 08:16:33 +01002850 while (isspace((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002851 end++;
2852 if (*end == ',') {
2853 end++;
2854 name = end;
2855 if (*end == '-')
2856 end++;
Willy Tarreau90807112020-02-25 08:16:33 +01002857 while (isdigit((unsigned char)*end))
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002858 end++;
2859 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
2860 }
2861
2862 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
2863 ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
2864 " occurrences values smaller than %d.\n",
2865 file, linenum, MAX_HDR_HISTORY);
2866 err_code |= ERR_ALERT | ERR_FATAL;
2867 goto out;
2868 }
2869 } else {
2870 struct sockaddr_storage *sk;
2871
Willy Tarreau65ec4e32020-09-16 19:17:08 +02002872 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
2873 &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002874 if (!sk) {
2875 ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
2876 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
2877 err_code |= ERR_ALERT | ERR_FATAL;
2878 goto out;
2879 }
2880
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002881 curproxy->conn_src.tproxy_addr = *sk;
2882 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
2883 }
2884 global.last_checks |= LSTCHK_NETADM;
2885#else /* no TPROXY support */
2886 ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
2887 file, linenum, "usesrc");
2888 err_code |= ERR_ALERT | ERR_FATAL;
2889 goto out;
2890#endif
2891 cur_arg += 2;
2892 continue;
2893 }
2894
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002895 if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002896#ifdef SO_BINDTODEVICE
2897 if (!*args[cur_arg + 1]) {
2898 ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n",
2899 file, linenum, args[0]);
2900 err_code |= ERR_ALERT | ERR_FATAL;
2901 goto out;
2902 }
2903 free(curproxy->conn_src.iface_name);
2904 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
Christopher Fauletb15625a2021-04-12 21:31:45 +02002905 if (!curproxy->conn_src.iface_name)
2906 goto alloc_error;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002907 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
2908 global.last_checks |= LSTCHK_NETADM;
2909#else
2910 ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
2911 file, linenum, args[0], args[cur_arg]);
2912 err_code |= ERR_ALERT | ERR_FATAL;
2913 goto out;
2914#endif
2915 cur_arg += 2;
2916 continue;
2917 }
2918 ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
2919 file, linenum, args[0], "interface", "usesrc");
2920 err_code |= ERR_ALERT | ERR_FATAL;
2921 goto out;
2922 }
2923 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002924 else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002925 ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
2926 file, linenum, "usesrc", "source");
2927 err_code |= ERR_ALERT | ERR_FATAL;
2928 goto out;
2929 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002930 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 +02002931 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Willy Tarreau262c3f12019-12-17 06:52:51 +01002932 "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n",
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002933 file, linenum, args[0]);
2934 err_code |= ERR_ALERT | ERR_FATAL;
2935 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002936 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002937 else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002938 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2939 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2940 err_code |= ERR_ALERT | ERR_FATAL;
2941 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002942 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002943 else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002944 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. "
2945 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2946 err_code |= ERR_ALERT | ERR_FATAL;
2947 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002948 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002949 else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002950 ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2951 err_code |= ERR_ALERT | ERR_FATAL;
2952 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002953 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002954 else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002955 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2956 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2957 err_code |= ERR_ALERT | ERR_FATAL;
2958 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002959 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002960 else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002961 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2962 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2963 err_code |= ERR_ALERT | ERR_FATAL;
2964 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002965 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002966 else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002967 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2968 "Use 'http-request replace-header' instead.\n", file, linenum, args[0]);
2969 err_code |= ERR_ALERT | ERR_FATAL;
2970 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002971 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002972 else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002973 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2974 "Use 'http-request del-header' instead.\n", file, linenum, args[0]);
2975 err_code |= ERR_ALERT | ERR_FATAL;
2976 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002977 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002978 else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002979 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2980 "Use 'http-request deny' instead.\n", file, linenum, args[0]);
2981 err_code |= ERR_ALERT | ERR_FATAL;
2982 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002983 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002984 else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02002985 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]);
2986 err_code |= ERR_ALERT | ERR_FATAL;
2987 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002988 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002989 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 +02002990 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2991 "Use 'http-request allow' instead.\n", file, linenum, args[0]);
2992 err_code |= ERR_ALERT | ERR_FATAL;
2993 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01002994 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01002995 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 +02002996 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
2997 "Use 'http-request tarpit' instead.\n", file, linenum, args[0]);
2998 err_code |= ERR_ALERT | ERR_FATAL;
2999 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003000 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003001 else if (strcmp(args[0], "reqadd") == 0) { /* add request header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003002 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3003 "Use 'http-request add-header' instead.\n", file, linenum, args[0]);
3004 err_code |= ERR_ALERT | ERR_FATAL;
3005 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003006 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003007 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 +02003008 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3009 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3010 err_code |= ERR_ALERT | ERR_FATAL;
3011 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003012 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003013 else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003014 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3015 "Use 'http-response del-header' .\n", file, linenum, args[0]);
3016 err_code |= ERR_ALERT | ERR_FATAL;
3017 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003018 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003019 else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003020 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3021 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3022 err_code |= ERR_ALERT | ERR_FATAL;
3023 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003024 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003025 else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */
Balvinder Singh Rawatdef595e2020-03-14 12:11:50 +05303026 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003027 "Use 'http-response replace-header' instead.\n", file, linenum, args[0]);
3028 err_code |= ERR_ALERT | ERR_FATAL;
3029 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003030 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003031 else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003032 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3033 "Use 'http-response del-header' instead.\n", file, linenum, args[0]);
3034 err_code |= ERR_ALERT | ERR_FATAL;
3035 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003036 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003037 else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003038 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3039 "Use 'http-response deny' instead.\n", file, linenum, args[0]);
3040 err_code |= ERR_ALERT | ERR_FATAL;
3041 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003042 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01003043 else if (strcmp(args[0], "rspadd") == 0) { /* add response header */
Christopher Fauleta6a56e62019-07-17 15:13:28 +02003044 ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. "
3045 "Use 'http-response add-header' instead.\n", file, linenum, args[0]);
3046 err_code |= ERR_ALERT | ERR_FATAL;
3047 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003048 }
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003049 else {
3050 struct cfg_kw_list *kwl;
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003051 const char *best;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003052 int index;
3053
3054 list_for_each_entry(kwl, &cfg_keywords.list, list) {
3055 for (index = 0; kwl->kw[index].kw != NULL; index++) {
3056 if (kwl->kw[index].section != CFG_LISTEN)
3057 continue;
3058 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003059 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02003060 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02003061 err_code |= ERR_ALERT | ERR_FATAL;
3062 goto out;
3063 }
3064
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003065 /* prepare error message just in case */
Willy Tarreauab3410c2021-02-12 12:17:30 +01003066 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003067 if (rc < 0) {
3068 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3069 err_code |= ERR_ALERT | ERR_FATAL;
3070 goto out;
3071 }
3072 else if (rc > 0) {
3073 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
3074 err_code |= ERR_WARN;
3075 goto out;
3076 }
3077 goto out;
3078 }
3079 }
3080 }
3081
Willy Tarreauc0ff6792021-03-12 09:14:19 +01003082 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list);
3083 if (best)
3084 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
3085 else
3086 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003087 err_code |= ERR_ALERT | ERR_FATAL;
3088 goto out;
3089 }
3090 out:
3091 free(errmsg);
3092 return err_code;
Christopher Fauletb15625a2021-04-12 21:31:45 +02003093
3094 alloc_error:
3095 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
3096 err_code |= ERR_ALERT | ERR_ABORT;
3097 goto out;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +01003098}